Skip to content

Commit

Permalink
qemu-iotests: add infrastructure of fd passing via SCM
Browse files Browse the repository at this point in the history
This patch make use of the compiled scm helper program to transfer
fd via unix socket at runtime.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Wenchao Xia authored and kevmw committed Sep 12, 2013
1 parent f93296e commit 30b005d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions QMP/qmp.py
Expand Up @@ -188,3 +188,9 @@ def close(self):

def settimeout(self, timeout):
self.__sock.settimeout(timeout)

def get_sock_fd(self):
return self.__sock.fileno()

def is_scm_available(self):
return self.__sock.family == socket.AF_UNIX
1 change: 1 addition & 0 deletions tests/qemu-iotests/check
Expand Up @@ -164,6 +164,7 @@ QEMU_IO -- $QEMU_IO
IMGFMT -- $FULL_IMGFMT_DETAILS
IMGPROTO -- $FULL_IMGPROTO_DETAILS
PLATFORM -- $FULL_HOST_DETAILS
SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
EOF
#MKFS_OPTIONS -- $FULL_MKFS_OPTIONS
Expand Down
23 changes: 23 additions & 0 deletions tests/qemu-iotests/iotests.py
Expand Up @@ -38,6 +38,8 @@
imgproto = os.environ.get('IMGPROTO', 'file')
test_dir = os.environ.get('TEST_DIR', '/var/tmp')

socket_scm_helper = os.environ.get('SOCKET_SCM_HELPER', 'socket_scm_helper')

def qemu_img(*args):
'''Run qemu-img and return the exit code'''
devnull = open('/dev/null', 'r+')
Expand Down Expand Up @@ -80,6 +82,12 @@ def __init__(self):
'-display', 'none', '-vga', 'none']
self._num_drives = 0

# This can be used to add an unused monitor instance.
def add_monitor_telnet(self, ip, port):
args = 'tcp:%s:%d,server,nowait,telnet' % (ip, port)
self._args.append('-monitor')
self._args.append(args)

def add_drive(self, path, opts=''):
'''Add a virtio-blk drive to the VM'''
options = ['if=virtio',
Expand Down Expand Up @@ -112,6 +120,21 @@ def add_fd(self, fd, fdset, opaque, opts=''):
self._args.append(','.join(options))
return self

def send_fd_scm(self, fd_file_path):
# In iotest.py, the qmp should always use unix socket.
assert self._qmp.is_scm_available()
bin = socket_scm_helper
if os.path.exists(bin) == False:
print "Scm help program does not present, path '%s'." % bin
return -1
fd_param = ["%s" % bin,
"%d" % self._qmp.get_sock_fd(),
"%s" % fd_file_path]
devnull = open('/dev/null', 'rb')
p = subprocess.Popen(fd_param, stdin=devnull, stdout=sys.stdout,
stderr=sys.stderr)
return p.wait()

def launch(self):
'''Launch the VM and establish a QMP connection'''
devnull = open('/dev/null', 'rb')
Expand Down

0 comments on commit 30b005d

Please sign in to comment.