From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265769905170.68504747472025; Fri, 1 Sep 2017 04:36:09 -0700 (PDT) Received: from localhost ([::1]:36396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkF6-0004Yu-RF for importer@patchew.org; Fri, 01 Sep 2017 07:36:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkAc-0000wI-4J for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkAX-0006fW-HE for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkAX-0006fN-Ap for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E8088B125; Fri, 1 Sep 2017 11:31:24 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E6DE7EBF0; Fri, 1 Sep 2017 11:31:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4E8088B125 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:17 +0200 Message-Id: <20170901112829.2571-2-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 01 Sep 2017 11:31:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 01/13] qemu.py: fix is_running() return before first launch() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" is_running() returns None when called before the first time we call launch(): >>> import qemu >>> vm =3D qemu.QEMUMachine('qemu-system-x86_64') >>> vm.is_running() >>> It should return False instead. This patch fixes that. For consistence, this patch removes the parenthesis from the second clause as it's not really needed. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 880e3e8219..0ae5d39414 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -86,7 +86,7 @@ class QEMUMachine(object): raise =20 def is_running(self): - return self._popen and (self._popen.returncode is None) + return self._popen is not None and self._popen.returncode is None =20 def exitcode(self): if self._popen is None: --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265605153830.6409531400016; Fri, 1 Sep 2017 04:33:25 -0700 (PDT) Received: from localhost ([::1]:36372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkCR-00024O-MH for importer@patchew.org; Fri, 01 Sep 2017 07:33:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkAb-0000wG-TY for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkAa-0006ib-S7 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkAa-0006hj-J1 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9EE9581E05; Fri, 1 Sep 2017 11:31:27 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8E2F77DC1; Fri, 1 Sep 2017 11:31:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9EE9581E05 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:18 +0200 Message-Id: <20170901112829.2571-3-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Sep 2017 11:31:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 02/13] qemu.py: avoid writing to stdout/stderr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This module should not write directly to stdout/stderr. Instead, it should either raise exceptions or just log the messages and let the callers handle them and decide what to do. For example, scripts could choose to send the log messages stderr or/and write them to a file if verbose or debugging mode is enabled. This patch replaces the writes to stderr by an exception in the send_fd_scm() when _socket_scm_helper is not set or not present. In the same method, the subprocess Popen will now redirect the stdout/stderr to logging.debug instead of writing to system stderr. As consequence, since the Popen.communicate() is now used (in order to get the stdout), the further call to wait() became redundant and was replaced by Popen.returncode. The shutdown() message on negative exit code will now be logged to logging.warn instead of written to system stderr. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 0ae5d39414..aca6fa4d82 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -13,6 +13,7 @@ # =20 import errno +import logging import string import os import sys @@ -20,6 +21,15 @@ import subprocess import qmp.qmp =20 =20 +LOG =3D logging.getLogger(__name__) + + +class QEMUMachineError(Exception): + """ + Exception called when an error in QEMUMachine happens. + """ + + class QEMUMachine(object): '''A QEMU VM''' =20 @@ -62,18 +72,21 @@ class QEMUMachine(object): # In iotest.py, the qmp should always use unix socket. assert self._qmp.is_scm_available() if self._socket_scm_helper is None: - print >>sys.stderr, "No path to socket_scm_helper set" - return -1 + raise QEMUMachineError("No path to socket_scm_helper set") if os.path.exists(self._socket_scm_helper) =3D=3D False: - print >>sys.stderr, "%s does not exist" % self._socket_scm_hel= per - return -1 + raise QEMUMachineError("%s does not exist" % + self._socket_scm_helper) fd_param =3D ["%s" % self._socket_scm_helper, "%d" % self._qmp.get_sock_fd(), "%s" % fd_file_path] devnull =3D open('/dev/null', 'rb') - p =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsys.std= out, - stderr=3Dsys.stderr) - return p.wait() + p =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsubproc= ess.PIPE, + stderr=3Dsubprocess.STDOUT) + output =3D p.communicate()[0] + if output: + LOG.debug(output) + + return p.returncode =20 @staticmethod def _remove_if_exists(path): @@ -154,7 +167,8 @@ class QEMUMachine(object): =20 exitcode =3D self._popen.wait() if exitcode < 0: - sys.stderr.write('qemu received signal %i: %s\n' % (-exitc= ode, ' '.join(self._args))) + LOG.warn('qemu received signal %i: %s', -exitcode, + ' '.join(self._args)) self._load_io_log() self._post_shutdown() =20 --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265612643625.427558357282; Fri, 1 Sep 2017 04:33:32 -0700 (PDT) Received: from localhost ([::1]:36373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkCZ-0002BH-A7 for importer@patchew.org; Fri, 01 Sep 2017 07:33:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkAh-0000zI-AY for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkAe-0006mb-62 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkAd-0006mM-W7 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13D42267F5; Fri, 1 Sep 2017 11:31:31 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 119AA7F5F5; Fri, 1 Sep 2017 11:31:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13D42267F5 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:19 +0200 Message-Id: <20170901112829.2571-4-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 01 Sep 2017 11:31:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 03/13] qemu.py: use os.path.null instead of /dev/null X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For increased portability, let's use os.path.devnull. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qemu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index aca6fa4d82..a6e06291ea 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -79,7 +79,7 @@ class QEMUMachine(object): fd_param =3D ["%s" % self._socket_scm_helper, "%d" % self._qmp.get_sock_fd(), "%s" % fd_file_path] - devnull =3D open('/dev/null', 'rb') + devnull =3D open(os.path.devnull, 'rb') p =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsubproc= ess.PIPE, stderr=3Dsubprocess.STDOUT) output =3D p.communicate()[0] @@ -140,7 +140,7 @@ class QEMUMachine(object): =20 def launch(self): '''Launch the VM and establish a QMP connection''' - devnull =3D open('/dev/null', 'rb') + devnull =3D open(os.path.devnull, 'rb') qemulog =3D open(self._qemu_log_path, 'wb') try: self._pre_launch() --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265932234197.67164822699488; Fri, 1 Sep 2017 04:38:52 -0700 (PDT) Received: from localhost ([::1]:36411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkHj-00079I-00 for importer@patchew.org; Fri, 01 Sep 2017 07:38:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkAm-00013s-FP for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkAh-0006qq-GC for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51786) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkAh-0006oy-74 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4243D8B135; Fri, 1 Sep 2017 11:31:34 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DA8A77DC1; Fri, 1 Sep 2017 11:31:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4243D8B135 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:20 +0200 Message-Id: <20170901112829.2571-5-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 01 Sep 2017 11:31:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 04/13] qemu.py: improve message on negative exit code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The current message shows 'self._args', which contains only part of the options used in the Qemu command line. This patch makes the qemu full args list an instance variable and then uses it in the negative exit code message. Message was moved outside the 'if is_running' block to make sure it will be logged if the VM finishes before the call to shutdown(). Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index a6e06291ea..670c048569 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -49,6 +49,7 @@ class QEMUMachine(object): self._iolog =3D None self._socket_scm_helper =3D socket_scm_helper self._debug =3D debug + self._qemu_full_args =3D None =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -140,13 +141,18 @@ class QEMUMachine(object): =20 def launch(self): '''Launch the VM and establish a QMP connection''' + self._qemu_full_args =3D None devnull =3D open(os.path.devnull, 'rb') qemulog =3D open(self._qemu_log_path, 'wb') try: self._pre_launch() - args =3D self._wrapper + [self._binary] + self._base_args() + = self._args - self._popen =3D subprocess.Popen(args, stdin=3Ddevnull, stdout= =3Dqemulog, - stderr=3Dsubprocess.STDOUT, she= ll=3DFalse) + self._qemu_full_args =3D (self._wrapper + [self._binary] + + self._base_args() + self._args) + self._popen =3D subprocess.Popen(self._qemu_full_args, + stdin=3Ddevnull, + stdout=3Dqemulog, + stderr=3Dsubprocess.STDOUT, + shell=3DFalse) self._post_launch() except: if self.is_running(): @@ -164,14 +170,20 @@ class QEMUMachine(object): self._qmp.close() except: self._popen.kill() + self._popen.wait() =20 - exitcode =3D self._popen.wait() - if exitcode < 0: - LOG.warn('qemu received signal %i: %s', -exitcode, - ' '.join(self._args)) self._load_io_log() self._post_shutdown() =20 + exitcode =3D self.exitcode() + if exitcode is not None and exitcode < 0: + msg =3D 'qemu received signal %i: %s' + if self._qemu_full_args: + command =3D ' '.join(self._qemu_full_args) + else: + command =3D '' + LOG.warn(msg, exitcode, command) + underscore_to_dash =3D string.maketrans('_', '-') def qmp(self, cmd, conv_keys=3DTrue, **args): '''Invoke a QMP command and return the result dict''' --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265840149750.5289558217161; Fri, 1 Sep 2017 04:37:20 -0700 (PDT) Received: from localhost ([::1]:36398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkGF-0005pw-7h for importer@patchew.org; Fri, 01 Sep 2017 07:37:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkAt-0001BH-EI for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkAq-0006tS-8y for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkAq-0006tK-2X for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25CD768CE; Fri, 1 Sep 2017 11:31:43 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D9FA77DC1; Fri, 1 Sep 2017 11:31:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 25CD768CE Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:21 +0200 Message-Id: <20170901112829.2571-6-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 01 Sep 2017 11:31:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 05/13] qemu.py: include debug information on launch error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When launching a VM, if an exception happens and the VM is not initiated, it might be useful to see the qemu command line and the qemu command output. This patch creates that message. Notice that self._iolog needs to be cleaned up in the beginning of the launch() to make sure we will not expose the qemu log from a previous launch if the current one fails. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qemu.py b/scripts/qemu.py index 670c048569..3ebe5ee0a4 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -141,6 +141,7 @@ class QEMUMachine(object): =20 def launch(self): '''Launch the VM and establish a QMP connection''' + self._iolog =3D None self._qemu_full_args =3D None devnull =3D open(os.path.devnull, 'rb') qemulog =3D open(self._qemu_log_path, 'wb') @@ -160,6 +161,12 @@ class QEMUMachine(object): self._popen.wait() self._load_io_log() self._post_shutdown() + + LOG.debug('Error launching VM') + if self._qemu_full_args: + LOG.debug('Command: %r', ' '.join(self._qemu_full_args)) + if self._iolog: + LOG.debug('Output: %r', self._iolog) raise =20 def shutdown(self): --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265632820510.93229576955287; Fri, 1 Sep 2017 04:33:52 -0700 (PDT) Received: from localhost ([::1]:36374 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkCt-0002Q4-Mc for importer@patchew.org; Fri, 01 Sep 2017 07:33:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkAu-0001CA-HD for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkAt-0006vq-D7 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkAt-0006uA-4v for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D18C552D1; Fri, 1 Sep 2017 11:31:46 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 820297EBF0; Fri, 1 Sep 2017 11:31:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3D18C552D1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:22 +0200 Message-Id: <20170901112829.2571-7-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 01 Sep 2017 11:31:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 06/13] qemu.py: make sure we only remove files we create X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To launch a VM, we need to create basically two files: the monitor socket (if it's a UNIX socket) and the qemu log file. For the qemu log file, we currently just open the path, which will create the file if it does not exist or overwrite the file if it does exist. For the monitor socket, if it already exists, we are currently removing it, even if it's not created by us. This patch moves to pre_launch() the responsibility to make sure we only create files that are not pre-existent and to populate a list of controlled files. This list will then be used as the reference of files to remove during the cleanup (post_shutdown()). Signed-off-by: Amador Pahim --- scripts/qemu.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 3ebe5ee0a4..c26e1412f9 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -41,6 +41,7 @@ class QEMUMachine(object): monitor_address =3D os.path.join(test_dir, name + "-monitor.so= ck") self._monitor_address =3D monitor_address self._qemu_log_path =3D os.path.join(test_dir, name + ".log") + self._qemu_log_fd =3D None self._popen =3D None self._binary =3D binary self._args =3D list(args) # Force copy args in case we modify them @@ -50,6 +51,7 @@ class QEMUMachine(object): self._socket_scm_helper =3D socket_scm_helper self._debug =3D debug self._qemu_full_args =3D None + self._created_files =3D [] =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -128,30 +130,44 @@ class QEMUMachine(object): '-display', 'none', '-vga', 'none'] =20 def _pre_launch(self): - self._qmp =3D qmp.qmp.QEMUMonitorProtocol(self._monitor_address, s= erver=3DTrue, - debug=3Dself._debug) + try: + self._qmp =3D qmp.qmp.QEMUMonitorProtocol(self._monitor_addres= s, + server=3DTrue, + debug=3Dself._debug) + except: + raise + else: + if not isinstance(self._monitor_address, tuple): + self._created_files.append(self._monitor_address) + + try: + flags =3D os.O_CREAT | os.O_EXCL | os.O_WRONLY + os.open(self._qemu_log_path, flags) + except: + raise + else: + self._created_files.append(self._qemu_log_path) + self._qemu_log_fd =3D open(self._qemu_log_path, 'wb') =20 def _post_launch(self): self._qmp.accept() =20 def _post_shutdown(self): - if not isinstance(self._monitor_address, tuple): - self._remove_if_exists(self._monitor_address) - self._remove_if_exists(self._qemu_log_path) + while self._created_files: + self._remove_if_exists(self._created_files.pop()) =20 def launch(self): '''Launch the VM and establish a QMP connection''' self._iolog =3D None self._qemu_full_args =3D None devnull =3D open(os.path.devnull, 'rb') - qemulog =3D open(self._qemu_log_path, 'wb') try: self._pre_launch() self._qemu_full_args =3D (self._wrapper + [self._binary] + self._base_args() + self._args) self._popen =3D subprocess.Popen(self._qemu_full_args, stdin=3Ddevnull, - stdout=3Dqemulog, + stdout=3Dself._qemu_log_fd, stderr=3Dsubprocess.STDOUT, shell=3DFalse) self._post_launch() --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15042657950481019.3954475227519; Fri, 1 Sep 2017 04:36:35 -0700 (PDT) Received: from localhost ([::1]:36397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkFV-0004xZ-Uk for importer@patchew.org; Fri, 01 Sep 2017 07:36:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkB5-0001K2-Q5 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkAw-0006wd-BL for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57884) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkAw-0006wQ-51 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:50 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F1415BECB; Fri, 1 Sep 2017 11:31:49 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 939187F5F5; Fri, 1 Sep 2017 11:31:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3F1415BECB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:23 +0200 Message-Id: <20170901112829.2571-8-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 01 Sep 2017 11:31:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 07/13] qemu.py: close _qemu_log_path on cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are opening the _qemu_log_path during the launch() but we are forgetting to close it. This patch makes sure we will close the self._qemu_log_path during the cleanup (post_shutdown()). Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/qemu.py b/scripts/qemu.py index c26e1412f9..1b77fec48b 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -153,6 +153,9 @@ class QEMUMachine(object): self._qmp.accept() =20 def _post_shutdown(self): + if self._qemu_log_fd is not None: + self._qemu_log_fd.close() + while self._created_files: self._remove_if_exists(self._created_files.pop()) =20 --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265928844108.63488768676109; Fri, 1 Sep 2017 04:38:48 -0700 (PDT) Received: from localhost ([::1]:36410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkHe-000755-O2 for importer@patchew.org; Fri, 01 Sep 2017 07:38:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkB3-0001Ik-Hx for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkB0-0006xZ-Cp for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkB0-0006xG-75 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 475157EA9B; Fri, 1 Sep 2017 11:31:53 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52787E8F8; Fri, 1 Sep 2017 11:31:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 475157EA9B Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:24 +0200 Message-Id: <20170901112829.2571-9-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 01 Sep 2017 11:31:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 08/13] qemu.py: refactor launch() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is just an refactor to separate the exception handler from the actual launch procedure, improving the readability and making future maintenances in this piece of code easier. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 1b77fec48b..06f07bfaa2 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -160,20 +160,14 @@ class QEMUMachine(object): self._remove_if_exists(self._created_files.pop()) =20 def launch(self): - '''Launch the VM and establish a QMP connection''' + ''' + Try to launch the VM and make sure we cleanup and expose the + command line/output in case of exception. + ''' self._iolog =3D None self._qemu_full_args =3D None - devnull =3D open(os.path.devnull, 'rb') try: - self._pre_launch() - self._qemu_full_args =3D (self._wrapper + [self._binary] + - self._base_args() + self._args) - self._popen =3D subprocess.Popen(self._qemu_full_args, - stdin=3Ddevnull, - stdout=3Dself._qemu_log_fd, - stderr=3Dsubprocess.STDOUT, - shell=3DFalse) - self._post_launch() + self._launch() except: if self.is_running(): self._popen.kill() @@ -188,6 +182,19 @@ class QEMUMachine(object): LOG.debug('Output: %r', self._iolog) raise =20 + def _launch(self): + '''Launch the VM and establish a QMP connection''' + devnull =3D open(os.path.devnull, 'rb') + self._pre_launch() + self._qemu_full_args =3D (self._wrapper + [self._binary] + + self._base_args() + self._args) + self._popen =3D subprocess.Popen(self._qemu_full_args, + stdin=3Ddevnull, + stdout=3Dself._qemu_log_fd, + stderr=3Dsubprocess.STDOUT, + shell=3DFalse) + self._post_launch() + def shutdown(self): '''Terminate the VM and clean up''' if self.is_running(): --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265953312444.56713189799825; Fri, 1 Sep 2017 04:39:13 -0700 (PDT) Received: from localhost ([::1]:36412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkI3-0007Rs-U9 for importer@patchew.org; Fri, 01 Sep 2017 07:39:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkB6-0001KN-6T for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkB5-0006zA-Da for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51012) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkB5-0006yv-8A for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:31:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58164C047B74; Fri, 1 Sep 2017 11:31:58 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3A8877DC1; Fri, 1 Sep 2017 11:31:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 58164C047B74 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:25 +0200 Message-Id: <20170901112829.2571-10-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 01 Sep 2017 11:31:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 09/13] qemu.py: always cleanup on shutdown() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently we only cleanup on shutdown() if the VM is running. To make sure we will always cleanup, this patch makes the cleanup to always happen in shutdown, regardless the VM running state. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 06f07bfaa2..ede734328b 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -205,8 +205,8 @@ class QEMUMachine(object): self._popen.kill() self._popen.wait() =20 - self._load_io_log() - self._post_shutdown() + self._load_io_log() + self._post_shutdown() =20 exitcode =3D self.exitcode() if exitcode is not None and exitcode < 0: --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504266090828419.9244483056377; Fri, 1 Sep 2017 04:41:30 -0700 (PDT) Received: from localhost ([::1]:36472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkKH-0001OF-Qt for importer@patchew.org; Fri, 01 Sep 2017 07:41:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkBF-0001Sh-6g for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkBA-00070s-Kx for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkBA-00070c-FE for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A26881E19; Fri, 1 Sep 2017 11:32:03 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7FC381881; Fri, 1 Sep 2017 11:31:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8A26881E19 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:26 +0200 Message-Id: <20170901112829.2571-11-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Sep 2017 11:32:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 10/13] qemu.py: use poll() instead of 'returncode' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The 'returncode' Popen attribute is not guaranteed to be updated. It actually depends on a call to either poll(), wait() or communicate(). On the other hand, poll() will: "Check if child process has terminated. Set and return returncode attribute." Let's use the poll() to check whether the process is running and to get the updated process exit code, when the process is finished. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index ede734328b..87a2212b77 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -102,12 +102,12 @@ class QEMUMachine(object): raise =20 def is_running(self): - return self._popen is not None and self._popen.returncode is None + return self._popen is not None and self._popen.poll() is None =20 def exitcode(self): if self._popen is None: return None - return self._popen.returncode + return self._popen.poll() =20 def get_pid(self): if not self.is_running(): --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504265996465385.8173016572813; Fri, 1 Sep 2017 04:39:56 -0700 (PDT) Received: from localhost ([::1]:36413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkIl-00084l-Cr for importer@patchew.org; Fri, 01 Sep 2017 07:39:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkBG-0001U4-Lo for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkBF-00072k-J8 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkBF-00072M-E9 for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87D0761481; Fri, 1 Sep 2017 11:32:08 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id E85D17F5F5; Fri, 1 Sep 2017 11:32:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 87D0761481 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:27 +0200 Message-Id: <20170901112829.2571-12-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 01 Sep 2017 11:32:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 11/13] qemu.py: cleanup redundant calls in launch() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now that shutdown() is guaranteed to always execute self._load_io_log() and self._post_shutdown(), their calls in 'except' became redundant and we can safely replace it by a call to shutdown(). Due to this change, shutdown() can be now called even before the creation of the _qemu_log_path. So, to avoid errors with _load_io_log(), this patch makes sure we will only read the _qemu_log_path if it was previously created by us. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 87a2212b77..03e4cc34b7 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -115,8 +115,9 @@ class QEMUMachine(object): return self._popen.pid =20 def _load_io_log(self): - with open(self._qemu_log_path, "r") as fh: - self._iolog =3D fh.read() + if self._qemu_log_path in self._created_files: + with open(self._qemu_log_path, "r") as fh: + self._iolog =3D fh.read() =20 def _base_args(self): if isinstance(self._monitor_address, tuple): @@ -169,11 +170,7 @@ class QEMUMachine(object): try: self._launch() except: - if self.is_running(): - self._popen.kill() - self._popen.wait() - self._load_io_log() - self._post_shutdown() + self.shutdown() =20 LOG.debug('Error launching VM') if self._qemu_full_args: --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504266113332315.1231382131723; Fri, 1 Sep 2017 04:41:53 -0700 (PDT) Received: from localhost ([::1]:36473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkKe-0001iI-8E for importer@patchew.org; Fri, 01 Sep 2017 07:41:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkBO-0001aX-2V for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkBJ-00073p-HK for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52892) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkBJ-00073d-BH for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:13 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5DFD4821C3; Fri, 1 Sep 2017 11:32:12 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id E395877DC1; Fri, 1 Sep 2017 11:32:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5DFD4821C3 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:28 +0200 Message-Id: <20170901112829.2571-13-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 01 Sep 2017 11:32:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 12/13] qemu.py: launch vm only if it's not running X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A new call to launch() with a running VM will fall in exception and consequently call shutdown(). This patch makes launch() to raise an exception when it's called with VM already running. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/qemu.py b/scripts/qemu.py index 03e4cc34b7..363f649a7e 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -165,6 +165,9 @@ class QEMUMachine(object): Try to launch the VM and make sure we cleanup and expose the command line/output in case of exception. ''' + if self.is_running(): + raise QEMUMachineError('VM already running') + self._iolog =3D None self._qemu_full_args =3D None try: --=20 2.13.5 From nobody Tue Nov 4 08:27:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504266250812370.0247035970152; Fri, 1 Sep 2017 04:44:10 -0700 (PDT) Received: from localhost ([::1]:36542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkMr-0003ud-HC for importer@patchew.org; Fri, 01 Sep 2017 07:44:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnkBQ-0001ca-8n for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnkBP-00075l-Au for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37148) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnkBP-00075W-4T for qemu-devel@nongnu.org; Fri, 01 Sep 2017 07:32:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37272356CE; Fri, 1 Sep 2017 11:32:18 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-134.brq.redhat.com [10.40.204.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF66C77DC1; Fri, 1 Sep 2017 11:32:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 37272356CE Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:28:29 +0200 Message-Id: <20170901112829.2571-14-apahim@redhat.com> In-Reply-To: <20170901112829.2571-1-apahim@redhat.com> References: <20170901112829.2571-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 01 Sep 2017 11:32:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 13/13] qemu.py: don't launch again before shutdown() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If a VM is launched, files are created and a cleanup is required before a new launch. This cleanup is executed by shutdown(), so shutdown() must be called even if the VM is manually terminated (i.e. using kill). This patch creates a control to make sure launch() will not be executed again if shutdown() is not called after the previous launch(). Signed-off-by: Amador Pahim --- scripts/qemu.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qemu.py b/scripts/qemu.py index 363f649a7e..05fca4d268 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -52,6 +52,7 @@ class QEMUMachine(object): self._debug =3D debug self._qemu_full_args =3D None self._created_files =3D [] + self._pending_shutdown =3D False =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -168,10 +169,14 @@ class QEMUMachine(object): if self.is_running(): raise QEMUMachineError('VM already running') =20 + if self._pending_shutdown: + raise QEMUMachineError('Shutdown pending after previous launch= ') + self._iolog =3D None self._qemu_full_args =3D None try: self._launch() + self._pending_shutdown =3D True except: self.shutdown() =20 @@ -217,6 +222,8 @@ class QEMUMachine(object): command =3D '' LOG.warn(msg, exitcode, command) =20 + self._pending_shutdown =3D False + underscore_to_dash =3D string.maketrans('_', '-') def qmp(self, cmd, conv_keys=3DTrue, **args): '''Invoke a QMP command and return the result dict''' --=20 2.13.5