From nobody Sat May 18 18:58:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637268555149688.9328580043746; Thu, 18 Nov 2021 12:49:15 -0800 (PST) Received: from localhost ([::1]:49404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnoLJ-00065x-3j for importer@patchew.org; Thu, 18 Nov 2021 15:49:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIg-0001nh-1U for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41285) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIc-0000La-Os for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:29 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244-yMf4MsvrPS--8u9IK4ys4Q-1; Thu, 18 Nov 2021 15:46:23 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16A191023F53 for ; Thu, 18 Nov 2021 20:46:23 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6298F67843; Thu, 18 Nov 2021 20:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637268385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z9SJ6jSzDcs9tlf6yXTJM4PepioMSeOnMyYx/zHEHUs=; b=YLxAx7Z8fpPgODSZuU3zCLZDbFhApEENpPBkFS6xSQEOef5L1JY4td3iLNJFuYCXAFHSEB oCKbjtcQD14Nsy51oCJrLMp46GXvi4N+9AtDwK06cPzEXKyjijG2Z4+O1GVIoQV1XIqKt7 CLiwpcvAbEqlRvhaTGiGjid9EWXjlBo= X-MC-Unique: yMf4MsvrPS--8u9IK4ys4Q-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 1/7] python/machine: add @sock_dir property Date: Thu, 18 Nov 2021 15:46:14 -0500 Message-Id: <20211118204620.1897674-2-jsnow@redhat.com> In-Reply-To: <20211118204620.1897674-1-jsnow@redhat.com> References: <20211118204620.1897674-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637268555465100001 Content-Type: text/plain; charset="utf-8" Analogous to temp_dir and log_dir, add a sock_dir property that defaults to @temp_dir -- instead of base_temp_dir -- when the user hasn't overridden the sock dir value in the initializer. This gives us a much more unique directory to put sockfiles in by default. Signed-off-by: John Snow Reviewed-by: Willian Rampazzo --- python/qemu/machine/machine.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index a487c39745..b1dd77b538 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -134,8 +134,9 @@ def __init__(self, self._qmp_timer =3D qmp_timer =20 self._name =3D name or "qemu-%d" % os.getpid() + self._temp_dir: Optional[str] =3D None self._base_temp_dir =3D base_temp_dir - self._sock_dir =3D sock_dir or self._base_temp_dir + self._sock_dir =3D sock_dir self._log_dir =3D log_dir =20 if monitor_address is not None: @@ -143,7 +144,7 @@ def __init__(self, self._remove_monitor_sockfile =3D False else: self._monitor_address =3D os.path.join( - self._sock_dir, f"{self._name}-monitor.sock" + self.sock_dir, f"{self._name}-monitor.sock" ) self._remove_monitor_sockfile =3D True =20 @@ -163,14 +164,13 @@ def __init__(self, self._qmp_set =3D True # Enable QMP monitor by default. self._qmp_connection: Optional[QEMUMonitorProtocol] =3D None self._qemu_full_args: Tuple[str, ...] =3D () - self._temp_dir: Optional[str] =3D None self._launched =3D False self._machine: Optional[str] =3D None self._console_index =3D 0 self._console_set =3D False self._console_device_type: Optional[str] =3D None self._console_address =3D os.path.join( - self._sock_dir, f"{self._name}-console.sock" + self.sock_dir, f"{self._name}-console.sock" ) self._console_socket: Optional[socket.socket] =3D None self._remove_files: List[str] =3D [] @@ -816,6 +816,15 @@ def temp_dir(self) -> str: dir=3Dself._base_temp_dir) return self._temp_dir =20 + @property + def sock_dir(self) -> str: + """ + Returns the directory used for sockfiles by this machine. + """ + if self._sock_dir: + return self._sock_dir + return self.temp_dir + @property def log_dir(self) -> str: """ --=20 2.31.1 From nobody Sat May 18 18:58:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637268532325152.86076529276158; Thu, 18 Nov 2021 12:48:52 -0800 (PST) Received: from localhost ([::1]:47390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnoKx-0004i5-BZ for importer@patchew.org; Thu, 18 Nov 2021 15:48:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIh-0001oH-F0 for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIc-0000Lj-Rq for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:31 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-B3XbFxYTNI-2-vEKVJbl7w-1; Thu, 18 Nov 2021 15:46:24 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC94D15720 for ; Thu, 18 Nov 2021 20:46:23 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4262867842; Thu, 18 Nov 2021 20:46:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637268385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bdUu5CfzqntHpvXBavXpjt94i2KgQd7VPm1c0E1JaMU=; b=diWnL2biaqu1SaJfkItdCTf/GsYz+HPX/XKU5eLRv1s89A5fwJd0Q3caNxbWuGVzRJH3N0 Wnc0FLIAEzju64AuDgrmDKUg++KZDzqEu81IyuvUSTelT8OZka10Fi77rF/0TBIg2w2VFO pH1geuqBTVt9vjYA94sR3UFVC2i7jPc= X-MC-Unique: B3XbFxYTNI-2-vEKVJbl7w-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 2/7] python/machine: remove _remove_monitor_sockfile property Date: Thu, 18 Nov 2021 15:46:15 -0500 Message-Id: <20211118204620.1897674-3-jsnow@redhat.com> In-Reply-To: <20211118204620.1897674-1-jsnow@redhat.com> References: <20211118204620.1897674-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637268532695100003 Content-Type: text/plain; charset="utf-8" It doesn't matter if it was the user or the class itself that specified where the sockfile should be created; the fact is that if we are using a sockfile here, we created it and we can clean it up. Signed-off-by: John Snow Reviewed-by: Willian Rampazzo --- python/qemu/machine/machine.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index b1dd77b538..ea9e07805d 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -141,12 +141,10 @@ def __init__(self, =20 if monitor_address is not None: self._monitor_address =3D monitor_address - self._remove_monitor_sockfile =3D False else: self._monitor_address =3D os.path.join( self.sock_dir, f"{self._name}-monitor.sock" ) - self._remove_monitor_sockfile =3D True =20 self._console_log_path =3D console_log if self._console_log_path: @@ -315,8 +313,7 @@ def _pre_launch(self) -> None: self._remove_files.append(self._console_address) =20 if self._qmp_set: - if self._remove_monitor_sockfile: - assert isinstance(self._monitor_address, str) + if isinstance(self._monitor_address, str): self._remove_files.append(self._monitor_address) self._qmp_connection =3D QEMUMonitorProtocol( self._monitor_address, --=20 2.31.1 From nobody Sat May 18 18:58:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637268529871412.5769697270307; Thu, 18 Nov 2021 12:48:49 -0800 (PST) Received: from localhost ([::1]:47094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnoKq-0004Wq-JJ for importer@patchew.org; Thu, 18 Nov 2021 15:48:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIh-0001ni-0f for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39649) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIe-0000Ln-43 for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:30 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-545-pJAC2Q10M166kQO7DFup1g-1; Thu, 18 Nov 2021 15:46:25 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE2BA804141 for ; Thu, 18 Nov 2021 20:46:24 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22284604CC; Thu, 18 Nov 2021 20:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637268387; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jTQfIyuS37HzgltknYvlF9196x/vDU6R5jL5EMLI21s=; b=FTTNyjgwrZtqvv5F4UmAyLDKUnvRqQ6VOvWRuMZ+36jfPzu8kVGJl89Nhz9nYNKkEuJbjE UnMpOnIHTEUhTdKbc43KZxMJAoXNd9otmvvT64mFpRQKrG9Ty/SOeDyQjOUq0ohWgtM+cN L4uypb+N+U8V6DQaRp2tIsNLqoVQfig= X-MC-Unique: pJAC2Q10M166kQO7DFup1g-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 3/7] python/machine: add instance disambiguator to default nickname Date: Thu, 18 Nov 2021 15:46:16 -0500 Message-Id: <20211118204620.1897674-4-jsnow@redhat.com> In-Reply-To: <20211118204620.1897674-1-jsnow@redhat.com> References: <20211118204620.1897674-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637268530631100001 Content-Type: text/plain; charset="utf-8" If you create two instances of QEMUMachine(), they'll both create the same nickname by default -- which is not that helpful. Luckily, they'll both create unique temporary directories ... but due to user configuration, they may share logging and sockfile directories, meaning two instances can collide. The Python logging will also be quite confusing, with no differentiation between the two instances. Add an instance disambiguator (The memory address of the instance) to the default nickname to foolproof this in all cases. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Willian Rampazzo --- python/qemu/machine/machine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index ea9e07805d..ad529fd92a 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -133,7 +133,7 @@ def __init__(self, self._wrapper =3D wrapper self._qmp_timer =3D qmp_timer =20 - self._name =3D name or "qemu-%d" % os.getpid() + self._name =3D name or f"qemu-{os.getpid()}-{id(self):02x}" self._temp_dir: Optional[str] =3D None self._base_temp_dir =3D base_temp_dir self._sock_dir =3D sock_dir --=20 2.31.1 From nobody Sat May 18 18:58:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637268653090670.6164162182283; Thu, 18 Nov 2021 12:50:53 -0800 (PST) Received: from localhost ([::1]:55022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnoMu-0001Tq-0u for importer@patchew.org; Thu, 18 Nov 2021 15:50:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIi-0001qH-Ig for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIh-0000OR-6a for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:32 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-152-xPfTBnTSOOGsZ9B6_THCUA-1; Thu, 18 Nov 2021 15:46:26 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B04E41927802 for ; Thu, 18 Nov 2021 20:46:25 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07D5667842; Thu, 18 Nov 2021 20:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637268390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uK6BvNr0nSFx88TjfyzcxERx7R9UJc4NK57PTYpit4A=; b=B6FGiUJ35upbWIdJbSRsPatjhgItDEf2vWJtWu+WQujnQ2Ynztt+M8MT7N81vFuDqkXjGu xun+zM5EZc3IkZ/Q6xlny8yXWn7bS8rHZysGAsY4VUhTnTGEfWhuwwbdZcFFELpUgRy7F6 AFR7bwCOAydhlBcopXwzq0emKDrEKsM= X-MC-Unique: xPfTBnTSOOGsZ9B6_THCUA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 4/7] python/machine: move more variable initializations to _pre_launch Date: Thu, 18 Nov 2021 15:46:17 -0500 Message-Id: <20211118204620.1897674-5-jsnow@redhat.com> In-Reply-To: <20211118204620.1897674-1-jsnow@redhat.com> References: <20211118204620.1897674-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637268654443100001 Content-Type: text/plain; charset="utf-8" No need to clear them only to set them later. Signed-off-by: John Snow Reviewed-by: Willian Rampazzo --- python/qemu/machine/machine.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index ad529fd92a..f92e73de40 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -327,6 +327,14 @@ def _pre_launch(self) -> None: self._qemu_log_path =3D os.path.join(self.log_dir, self._name + ".= log") self._qemu_log_file =3D open(self._qemu_log_path, 'wb') =20 + self._iolog =3D None + self._qemu_full_args =3D tuple(chain( + self._wrapper, + [self._binary], + self._base_args, + self._args + )) + def _post_launch(self) -> None: if self._qmp_connection: self._qmp.accept(self._qmp_timer) @@ -390,8 +398,6 @@ def launch(self) -> None: if self._launched: raise QEMUMachineError('VM already launched') =20 - self._iolog =3D None - self._qemu_full_args =3D () try: self._launch() self._launched =3D True @@ -410,12 +416,6 @@ def _launch(self) -> None: Launch the VM and establish a QMP connection """ self._pre_launch() - self._qemu_full_args =3D tuple( - chain(self._wrapper, - [self._binary], - self._base_args, - self._args) - ) LOG.debug('VM launch command: %r', ' '.join(self._qemu_full_args)) =20 # Cleaning up of this subprocess is guaranteed by _do_shutdown. --=20 2.31.1 From nobody Sat May 18 18:58:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637268525699754.0825592073932; Thu, 18 Nov 2021 12:48:45 -0800 (PST) Received: from localhost ([::1]:47114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnoKq-0004XT-5F for importer@patchew.org; Thu, 18 Nov 2021 15:48:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIh-0001ov-SD for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIg-0000O7-BW for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:31 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-KResAx11OPyKgQvLRwgmig-1; Thu, 18 Nov 2021 15:46:28 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FA2987D541 for ; Thu, 18 Nov 2021 20:46:26 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBAA867842; Thu, 18 Nov 2021 20:46:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637268389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f3j2XgNV29TROon2KsCm5KyGGCp4QNigpFpnQvIxyw0=; b=bqYRdsKC9a9m2O/6Gh4zLw5Z3TQckYDEkai0Cr65svZjqoXFULkzfW8joAQ+jnEz+xfyCb 47ELUWkL+JGMqhMe60Ni6TJizgC8u3yHd55SSes3FeLks2eGWp/4AXoljz613/ETZ48ueq vLl6W8yxu0C8JFq129WB+lwKWiGTp6s= X-MC-Unique: KResAx11OPyKgQvLRwgmig-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 5/7] python/machine: handle "fast" QEMU terminations Date: Thu, 18 Nov 2021 15:46:18 -0500 Message-Id: <20211118204620.1897674-6-jsnow@redhat.com> In-Reply-To: <20211118204620.1897674-1-jsnow@redhat.com> References: <20211118204620.1897674-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637268527978100001 Content-Type: text/plain; charset="utf-8" In the case that the QEMU process actually launches -- but then dies so quickly that we can't establish a QMP connection to it -- QEMUMachine currently calls _post_shutdown() assuming that it never launched the VM process. This isn't true, though: it "merely" may have failed to establish a QMP connection and the process is in the middle of its own exit path. If we don't wait for the subprocess, the caller may get a bogus `None` return for .exitcode(). This behavior was observed from device-crash-test; after the switch to Async QMP, the timings were changed such that it was now seemingly possible to witness the failure of "vm.launch()" *prior* to the exitcode becoming available. The semantic of the `_launched` property is changed in this patch. Instead of representing the condition "launch() executed successfully", it will now represent "has forked a child process successfully". This way, wait() when called in the exit path won't become a no-op. Signed-off-by: John Snow Signed-off-by: John Snow Reviewed-by: Willian Rampazzo --- python/qemu/machine/machine.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index f92e73de40..67ab06ca2b 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -349,9 +349,6 @@ def _post_shutdown(self) -> None: Called to cleanup the VM instance after the process has exited. May also be called after a failed launch. """ - # Comprehensive reset for the failed launch case: - self._early_cleanup() - try: self._close_qmp_connection() except Exception as err: # pylint: disable=3Dbroad-except @@ -400,9 +397,16 @@ def launch(self) -> None: =20 try: self._launch() - self._launched =3D True except: - self._post_shutdown() + # We may have launched the process but it may + # have exited before we could connect via QMP. + # Assume the VM didn't launch or is exiting. + # If we don't wait for the process, exitcode() may still be + # 'None' by the time control is ceded back to the caller. + if self._launched: + self.wait() + else: + self._post_shutdown() =20 LOG.debug('Error launching VM') if self._qemu_full_args: @@ -426,6 +430,7 @@ def _launch(self) -> None: stderr=3Dsubprocess.STDOUT, shell=3DFalse, close_fds=3DFalse) + self._launched =3D True self._post_launch() =20 def _close_qmp_connection(self) -> None: @@ -457,8 +462,8 @@ def _early_cleanup(self) -> None: """ Perform any cleanup that needs to happen before the VM exits. =20 - May be invoked by both soft and hard shutdown in failover scenario= s. - Called additionally by _post_shutdown for comprehensive cleanup. + This method may be called twice upon shutdown, once each by soft + and hard shutdown in failover scenarios. """ # If we keep the console socket open, we may deadlock waiting # for QEMU to exit, while QEMU is waiting for the socket to --=20 2.31.1 From nobody Sat May 18 18:58:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637268650384786.8127434144609; Thu, 18 Nov 2021 12:50:50 -0800 (PST) Received: from localhost ([::1]:54998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnoMr-0001Ss-Cw for importer@patchew.org; Thu, 18 Nov 2021 15:50:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIj-0001rW-BQ for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIh-0000Og-FD for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:33 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-a_njv5GlNEuCWnGqB_GLEQ-1; Thu, 18 Nov 2021 15:46:28 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 705B815721 for ; Thu, 18 Nov 2021 20:46:27 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB49767842; Thu, 18 Nov 2021 20:46:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637268390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pw8ppGcFOwuUUQDWoc2/GNdlfv73Uuqd1UuHVrAbZdg=; b=bGHXImH/nxTdzSZjV7Al25Gn5MOYhOYVsbl3F472U/AtqHcV2IJJA7Aw4hqza0lBXAzE4a s8NVb76mcyjLqg8uR929eW5RoOZSqAolgKlyoaBoVXDO0Q6Ph6YmroYKe3RVurzas8APjN gmbO9zJD+Id6Fa5djDUx9MCHI6qDqaQ= X-MC-Unique: a_njv5GlNEuCWnGqB_GLEQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 6/7] scripts/device-crash-test: Use a QMP timeout Date: Thu, 18 Nov 2021 15:46:19 -0500 Message-Id: <20211118204620.1897674-7-jsnow@redhat.com> In-Reply-To: <20211118204620.1897674-1-jsnow@redhat.com> References: <20211118204620.1897674-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637268652374100001 Content-Type: text/plain; charset="utf-8" Despite all the previous fixes, it's still possible for device-crash-test to wedge itself in the case that QEMU terminates *so quickly* that it doesn't even begin a connection attempt to our QMP client. Python will just joyfully wait ad infinitum for a connection that will now never arrive. The real fix is to use asyncio to simultaneously poll both the health of the launched process AND the connection attempt. That's quite a bit more invasive than just setting a connection timeout, though. Do the very simplest thing for now. Signed-off-by: John Snow --- scripts/device-crash-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/device-crash-test b/scripts/device-crash-test index 1c73dac93e..7fbd99158b 100755 --- a/scripts/device-crash-test +++ b/scripts/device-crash-test @@ -353,7 +353,7 @@ def checkOneCase(args, testcase): '-device', qemuOptsEscape(device)] cmdline =3D ' '.join([binary] + args) dbg("will launch QEMU: %s", cmdline) - vm =3D QEMUMachine(binary=3Dbinary, args=3Dargs) + vm =3D QEMUMachine(binary=3Dbinary, args=3Dargs, qmp_timer=3D15) =20 exc =3D None exc_traceback =3D None --=20 2.31.1 From nobody Sat May 18 18:58:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637268768987989.6631429506226; Thu, 18 Nov 2021 12:52:48 -0800 (PST) Received: from localhost ([::1]:60020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnoOl-00050X-Tq for importer@patchew.org; Thu, 18 Nov 2021 15:52:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIk-0001t0-0I for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnoIi-0000P4-Gj for qemu-devel@nongnu.org; Thu, 18 Nov 2021 15:46:33 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-465-V7a0XKELOiC2ci91ZProCA-1; Thu, 18 Nov 2021 15:46:29 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5477A804143 for ; Thu, 18 Nov 2021 20:46:28 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D559604CC; Thu, 18 Nov 2021 20:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637268391; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DJy2EjSWQLAZm/tVfcEWnbYi3E9ud6fpWr0gyivyG/c=; b=EM+LFbOwP4c9xIg0m95Q4rLeRMABUTtn/RGQ1P9vGZ/qIHwevm7yNnKiBBMpDL2glXcD72 dS6KmoFOs+X24GjHrUZMlTOsScfghxv/1KBji8bCKoIQs/8NsbeVLai3YXs8zkCPTrCTFu gwQBSB0pDDDbH5ycFffaq86RbPWZPgk= X-MC-Unique: V7a0XKELOiC2ci91ZProCA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 7/7] python/aqmp: fix send_fd_scm for python 3.6.x Date: Thu, 18 Nov 2021 15:46:20 -0500 Message-Id: <20211118204620.1897674-8-jsnow@redhat.com> In-Reply-To: <20211118204620.1897674-1-jsnow@redhat.com> References: <20211118204620.1897674-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637268769722100001 Content-Type: text/plain; charset="utf-8" 3.6 doesn't play keepaway with the socket object, so we don't need to go fishing for it on this version. In fact, so long as 'sendmsg' is still available, it's probably preferable to just use that method and only go fishing for forbidden details when we absolutely have to. Reported-by: Thomas Huth Signed-off-by: John Snow Reviewed-by: Willian Rampazzo --- python/qemu/aqmp/qmp_client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python/qemu/aqmp/qmp_client.py b/python/qemu/aqmp/qmp_client.py index f987da02eb..8105e29fa8 100644 --- a/python/qemu/aqmp/qmp_client.py +++ b/python/qemu/aqmp/qmp_client.py @@ -639,9 +639,12 @@ def send_fd_scm(self, fd: int) -> None: if sock.family !=3D socket.AF_UNIX: raise AQMPError("Sending file descriptors requires a UNIX sock= et.") =20 - # Void the warranty sticker. - # Access to sendmsg in asyncio is scheduled for removal in Python = 3.11. - sock =3D sock._sock # pylint: disable=3Dprotected-access + if not hasattr(sock, 'sendmsg'): + # We need to void the warranty sticker. + # Access to sendmsg is scheduled for removal in Python 3.11. + # Find the real backing socket to use it anyway. + sock =3D sock._sock # pylint: disable=3Dprotected-access + sock.sendmsg( [b' '], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, struct.pack('@i', fd))] --=20 2.31.1