From patchwork Mon Aug 26 03:13:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 269803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B44DA2C0085 for ; Mon, 26 Aug 2013 13:17:03 +1000 (EST) Received: from localhost ([::1]:48496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDnIb-00073X-Iw for incoming@patchwork.ozlabs.org; Sun, 25 Aug 2013 23:17:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDnHt-0006UL-Dw for qemu-devel@nongnu.org; Sun, 25 Aug 2013 23:16:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDnHl-0006MD-HI for qemu-devel@nongnu.org; Sun, 25 Aug 2013 23:16:17 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:53460) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDnHk-0006KY-Sh for qemu-devel@nongnu.org; Sun, 25 Aug 2013 23:16:09 -0400 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Aug 2013 08:37:59 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 26 Aug 2013 08:37:58 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 5DB121258043 for ; Mon, 26 Aug 2013 08:45:54 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r7Q3He3o35717342 for ; Mon, 26 Aug 2013 08:47:40 +0530 Received: from d28av05.in.ibm.com (localhost [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r7Q3G4UO026445 for ; Mon, 26 Aug 2013 08:46:04 +0530 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.153]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r7Q3DrmT021933; Mon, 26 Aug 2013 08:46:02 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 26 Aug 2013 11:13:47 +0800 Message-Id: <1377486828-10788-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1377486828-10788-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1377486828-10788-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13082603-5564-0000-0000-0000096BA11D X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.4 Cc: pbonzini@redhat.com, Wenchao Xia , armbru@redhat.com, anthony@codemonkey.ws, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 2/3] qemu-iotests: add infrastructure of fd passing via SCM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch make use of the compiled scm helper program to transfer fd via unix socket at runtime. Signed-off-by: Wenchao Xia --- QMP/qmp.py | 6 ++++++ tests/qemu-iotests/check | 1 + tests/qemu-iotests/iotests.py | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 0 deletions(-) diff --git a/QMP/qmp.py b/QMP/qmp.py index c551df1..074f09a 100644 --- a/QMP/qmp.py +++ b/QMP/qmp.py @@ -188,3 +188,9 @@ class QEMUMonitorProtocol: 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 diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check index 74628ae..2f7f78e 100755 --- a/tests/qemu-iotests/check +++ b/tests/qemu-iotests/check @@ -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 diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 33ad0ec..d40b2de 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -38,6 +38,8 @@ imgfmt = os.environ.get('IMGFMT', 'raw') 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+') @@ -80,6 +82,12 @@ class VM(object): '-display', 'none', '-vga', 'none'] self._num_drives = 0 + #This can be used to add unused monitor + 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', @@ -112,6 +120,24 @@ class VM(object): self._args.append(','.join(options)) return self + #Sendmsg must carry out some data to get qemu's notice, so send a blank + #by default. + def send_fd_scm(self, fd, msg=' '): + #In iotest.py, the qmp should always use unix socket. + assert self._qmp.is_scm_available() + fd_bin = socket_scm_helper + if os.path.exists(fd_bin) == False: + print "Scm help program does not present, path %s." % fd_bin + return -1 + fd_param = ["%s" % fd_bin, + "%d" % self._qmp.get_sock_fd(), + "%d" % fd, + "%s" % msg] + 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')