From nobody Wed May 15 19:16:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695876704; cv=none; d=zohomail.com; s=zohoarc; b=Pdtd9JamByru6u4eiw9oPuXXSzIiW3nFt+SbwByODyekjoxbVdgSKj2rnUrsO55V8t5DS/E+Vv6Y47QiFP/BvtkQMoTP0J8Jus3LBs8EIGAWLWU907YtBBgiwHMyUCscMRbPdvxVH8EYIVwFRZ+mck6QNw6XMJ1Cjk/242PBvL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695876704; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dy8Zz5j929cTC/y/42t0TFxD3CDCAcfegC9aBb/EUvQ=; b=d0BNyzoxH6wu4NGT7nTNGXaJiMPocIu1t9xFLwjmoYOchWKWFYo2SN6+wNy3YaNd3GIlJ+24trJ+oV8qG4ShMvPHVBclD4zBOXtPtMqH52zdm8xaveVAcUEWUQbyMll7FZyrsNxIH3o5ugGn3IU4cEukd3U4BGqtBqgssekv928= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695876704031730.733729021107; Wed, 27 Sep 2023 21:51:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qliyP-0002I8-II; Thu, 28 Sep 2023 00:50:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyH-0002Gy-Iv for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:49:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyE-0006gB-Ms for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:49:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-491-ZE-PBl7uN4KUi-Sdc_ECEA-1; Thu, 28 Sep 2023 00:49:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D107802C1A; Thu, 28 Sep 2023 04:49:45 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54A661004145; Thu, 28 Sep 2023 04:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695876586; 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=dy8Zz5j929cTC/y/42t0TFxD3CDCAcfegC9aBb/EUvQ=; b=BRjUIrglI11JIQqxwI6kOvh48NSUFnNSCb9pCr91ah9i23JWAWlemXObFXQ4Nbmr3XL3Sn VkJQTzZkh3XgNwD6n1RPzgmceTVjUkqcsULaqCwHnFPttdXiHMh56j/6KYvNxpNLDSc8Xx PleM0l6f57nKaPw4b3YMYUSeXrQmsto= X-MC-Unique: ZE-PBl7uN4KUi-Sdc_ECEA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Beraldo Leal , Cleber Rosa , qemu-block@nongnu.org, Hanna Reitz , "Michael S. Tsirkin" , John Snow , qemu-arm@nongnu.org, Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Andrew Jeffery , Daniel Berrange , Ani Sinha , Peter Maydell Subject: [PATCH v3 1/6] python/machine: move socket setup out of _base_args property Date: Thu, 28 Sep 2023 00:49:38 -0400 Message-ID: <20230928044943.849073-2-jsnow@redhat.com> In-Reply-To: <20230928044943.849073-1-jsnow@redhat.com> References: <20230928044943.849073-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695876705584100005 This property isn't meant to do much else besides return a list of strings, so move this setup back out into _pre_launch(). Signed-off-by: John Snow Reviewed-by: Ani Sinha Reviewed-by: Daniel P. Berrang=C3=A9 --- python/qemu/machine/machine.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 35d5a672dbb..345610d6e46 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -301,9 +301,7 @@ def _base_args(self) -> List[str]: =20 if self._qmp_set: if self._sock_pair: - fd =3D self._sock_pair[0].fileno() - os.set_inheritable(fd, True) - moncdev =3D f"socket,id=3Dmon,fd=3D{fd}" + moncdev =3D f"socket,id=3Dmon,fd=3D{self._sock_pair[0].fil= eno()}" elif isinstance(self._monitor_address, tuple): moncdev =3D "socket,id=3Dmon,host=3D{},port=3D{}".format( *self._monitor_address @@ -340,6 +338,7 @@ def _pre_launch(self) -> None: if self._qmp_set: if self._monitor_address is None: self._sock_pair =3D socket.socketpair() + os.set_inheritable(self._sock_pair[0].fileno(), True) sock =3D self._sock_pair[1] if isinstance(self._monitor_address, str): self._remove_files.append(self._monitor_address) --=20 2.41.0 From nobody Wed May 15 19:16:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695876694; cv=none; d=zohomail.com; s=zohoarc; b=gf7wZTGbiE8fwRCaADZug2s5GbflmL+AIDmtvpTArzVQqH2qdSyQXH9TEZ+4KsNscBYtMRpUovGrXxUXkhRBuNsMhEJxIz0YUjFCsDwje/7a6f+e+/+/XscHzoiGec4ON6d3BrjSfRRoKUwBoEYPjFdjwfXkbxrjOD6lopb7Yz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695876694; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TmGgHENgntSbtlCsa0BEcNYq7zJ9XbDM4SQJ++ZpvxA=; b=aPn6H2NaA+3r0yYFu9my0s3XSIK+kKbIi00wkPI0o32hZqEZjxuk1gSSRw3Jm9PsFmfZxXcqzyih4+O+WYY1qp/p72MXSu9zaUvlhgIYGRfR1tpHlhRNa8gbexHnu6GdJ2wBgfF2KwrdhqK5IOcNAkUBk7dxRw2U7x49vaYCyw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169587669417221.934972979555596; Wed, 27 Sep 2023 21:51:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qliyP-0002JZ-QN; Thu, 28 Sep 2023 00:50:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyM-0002I2-NC for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:49:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyE-0006gO-Ny for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:49:55 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-97-vCZji-f5P2SDuUOpVMFcpg-1; Thu, 28 Sep 2023 00:49:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF15B80349B; Thu, 28 Sep 2023 04:49:45 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D1111004145; Thu, 28 Sep 2023 04:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695876588; 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=TmGgHENgntSbtlCsa0BEcNYq7zJ9XbDM4SQJ++ZpvxA=; b=XWiOJIPsDUP1opqGfiNOOq/TTMXqNfrvDkzy+F9M+a3cmF818iu4m0MLWWMOhPMZ1qwYnd lK0zLyq7zsw2FQ0tn5td9cFBmgcAvW9KawH44rkj33dpe6I8Mfbt6z3BgaB9J3g+ZOyuE1 IayoK4LnRBTU2TIfTsBxhqqCLiw0A/I= X-MC-Unique: vCZji-f5P2SDuUOpVMFcpg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Beraldo Leal , Cleber Rosa , qemu-block@nongnu.org, Hanna Reitz , "Michael S. Tsirkin" , John Snow , qemu-arm@nongnu.org, Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Andrew Jeffery , Daniel Berrange , Ani Sinha , Peter Maydell Subject: [PATCH v3 2/6] python/machine: close sock_pair in cleanup path Date: Thu, 28 Sep 2023 00:49:39 -0400 Message-ID: <20230928044943.849073-3-jsnow@redhat.com> In-Reply-To: <20230928044943.849073-1-jsnow@redhat.com> References: <20230928044943.849073-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695876694990100005 If everything has gone smoothly, we'll already have closed the socket we gave to the child during post_launch. The other half of the pair that we gave to the QMP connection should, likewise, be definitively closed by now. However, in the cleanup path, it's possible we've created the socketpair but flubbed the launch and need to clean up resources. These resources *would* be handled by the garbage collector, but that can happen at unpredictable times. Nicer to just clean them up synchronously on the exit path, here. Signed-off-by: John Snow Reviewed-by: Ani Sinha Reviewed-by: Daniel P. Berrang=C3=A9 --- python/qemu/machine/machine.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 345610d6e46..e26109e6f0e 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -396,6 +396,11 @@ def _post_shutdown(self) -> None: finally: assert self._qmp_connection is None =20 + if self._sock_pair: + self._sock_pair[0].close() + self._sock_pair[1].close() + self._sock_pair =3D None + self._close_qemu_log_file() =20 self._load_io_log() --=20 2.41.0 From nobody Wed May 15 19:16:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695876662; cv=none; d=zohomail.com; s=zohoarc; b=nH4yJz7lASJhDBmogyuaNFDxhRI1+esK66rB4mJqGHYPfB9Db2KnQjrfMAD45XLp2COpkL1nz1hr4e0zkSL8zhfWFJLuifwK+ouSrBpkDqvF1ATvf36m3HC0D8+WDJmv4STVxTBhk4Gl7gJqFyjt/smWoJ9ADYvxCgLT60n59pM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695876662; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QDTWUCIHz3dqe+Gzqb0XXM9jjnjigiSgYGh8iEUpzD4=; b=WnOy0ub9VjADMuxAaaPggMYxhaip5fkpl1jCKY0KPEW1gFabnK8M7/5F2A9rBYgK3W1+pJaNM3bHdJ5VfCc7OTS25U+AmWqVRdPl4lx8gpMou4s0J/b7bTLlhQvC6bhTmgTflhtkJTQrneBUgvBUeJeqyQr1ehQ+b16HsJPRoZs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695876662003377.4890746756728; Wed, 27 Sep 2023 21:51:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qliyd-0002PO-EJ; Thu, 28 Sep 2023 00:50:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyY-0002OC-Lf for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyH-0006gv-J9 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:10 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-182-cbR3O425M7aqqS4n_fgw-A-1; Thu, 28 Sep 2023 00:49:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C1982101A58B; Thu, 28 Sep 2023 04:49:46 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA63C1054FC1; Thu, 28 Sep 2023 04:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695876590; 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=QDTWUCIHz3dqe+Gzqb0XXM9jjnjigiSgYGh8iEUpzD4=; b=Uf+U0/G86rHzyqCmzcb5Wx4IkzrBahphz9aEGxCisr+VVEh75NqJk8fIson2r4wnXBP50f cQpg0GIW8tqaYK+zZSJ0xxRKZhL0a3cXbYxFKbFkWEt2x5lku458fhw8qzXR2mdmPxEgQ9 rDkLt3GS4tJEAszNu9ZUenIWRq3X6bU= X-MC-Unique: cbR3O425M7aqqS4n_fgw-A-1 From: John Snow To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Beraldo Leal , Cleber Rosa , qemu-block@nongnu.org, Hanna Reitz , "Michael S. Tsirkin" , John Snow , qemu-arm@nongnu.org, Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Andrew Jeffery , Daniel Berrange , Ani Sinha , Peter Maydell Subject: [PATCH v3 3/6] python/console_socket: accept existing FD in initializer Date: Thu, 28 Sep 2023 00:49:40 -0400 Message-ID: <20230928044943.849073-4-jsnow@redhat.com> In-Reply-To: <20230928044943.849073-1-jsnow@redhat.com> References: <20230928044943.849073-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695876663715100001 Useful if we want to use ConsoleSocket() for a socket created by socketpair(). Signed-off-by: John Snow Reviewed-by: Ani Sinha Reviewed-by: Daniel P. Berrang=C3=A9 --- python/qemu/machine/console_socket.py | 29 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/python/qemu/machine/console_socket.py b/python/qemu/machine/co= nsole_socket.py index 4e28ba9bb23..0a4e09ffc73 100644 --- a/python/qemu/machine/console_socket.py +++ b/python/qemu/machine/console_socket.py @@ -24,19 +24,32 @@ class ConsoleSocket(socket.socket): """ ConsoleSocket represents a socket attached to a char device. =20 - Optionally (if drain=3D=3DTrue), drains the socket and places the bytes - into an in memory buffer for later processing. - - Optionally a file path can be passed in and we will also - dump the characters to this file for debugging purposes. + :param address: An AF_UNIX path or address. + :param sock_fd: Optionally, an existing socket file descriptor. + One of address or sock_fd must be specified. + :param file: Optionally, a filename to log to. + :param drain: Optionally, drains the socket and places the bytes + into an in memory buffer for later processing. """ - def __init__(self, address: str, file: Optional[str] =3D None, + def __init__(self, + address: Optional[str] =3D None, + sock_fd: Optional[int] =3D None, + file: Optional[str] =3D None, drain: bool =3D False): + if address is None and sock_fd is None: + raise ValueError("one of 'address' or 'sock_fd' must be specif= ied") + if address is not None and sock_fd is not None: + raise ValueError("can't specify both 'address' and 'sock_fd'") + self._recv_timeout_sec =3D 300.0 self._sleep_time =3D 0.5 self._buffer: Deque[int] =3D deque() - socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREAM) - self.connect(address) + if address is not None: + socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREA= M) + self.connect(address) + else: + assert sock_fd is not None + socket.socket.__init__(self, fileno=3Dsock_fd) self._logfile =3D None if file: # pylint: disable=3Dconsider-using-with --=20 2.41.0 From nobody Wed May 15 19:16:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695876702; cv=none; d=zohomail.com; s=zohoarc; b=h2UP3hZZD5rSryXmp5lpkUgKcitnnOdICSF6kFiisoOb9aN6yKDdn1HAKR7AzqlJJZmBED7ibUFRgsg61lDRQJH97xC0TBtSEDyzPLvUwksxTeezcNEi9T89haFErNadMm12ExOcY51Bmeb/k3riI/ht5N9eWPmLr8KV8DzoYsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695876702; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3O/UX3IJX3ftQTm9VfwmH6srYggBUXaw1R2A+RoY+rg=; b=CXkj7AdXTphx4DhTohu+r00UiB2IhlbzriykbVpu4zeA0swrFd3623eT8a5KlBYQp8/gJ9BMOKXHiCKqddx52stoLu5l35kC/jFO+SCWKx8Dv8CFd1lglcOK/I3PdamLaMVDOqhoNxCzQB4Gd17YAaqC+eyb46UdRXoYe8sArpg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695876702538412.6868434163729; Wed, 27 Sep 2023 21:51:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qliya-0002Ok-BC; Thu, 28 Sep 2023 00:50:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyY-0002OD-O1 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyH-0006hB-Gi for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:10 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-oEIkfVumNtOl9-9rl1TSAQ-1; Thu, 28 Sep 2023 00:49:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7643F3C108DA; Thu, 28 Sep 2023 04:49:47 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE4F51054FC1; Thu, 28 Sep 2023 04:49:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695876591; 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=3O/UX3IJX3ftQTm9VfwmH6srYggBUXaw1R2A+RoY+rg=; b=MvJhrVfDOsFwjcZGGk+DbbpSVlshiWsNer84DJwrFoR3w+lNXUNEaSSQptmwZjHXV1Y5lb uvCT5Go9HuVL7JdfASrhsCaenLPttrvBfgC5kiAY/vejCJjgM9fK0wynPGlI1vnO59L3cp ut06WSQv0+VZP3pZp+/79df6k0SBmPE= X-MC-Unique: oEIkfVumNtOl9-9rl1TSAQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Beraldo Leal , Cleber Rosa , qemu-block@nongnu.org, Hanna Reitz , "Michael S. Tsirkin" , John Snow , qemu-arm@nongnu.org, Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Andrew Jeffery , Daniel Berrange , Ani Sinha , Peter Maydell Subject: [PATCH v3 4/6] python/machine: use socketpair() for console connections Date: Thu, 28 Sep 2023 00:49:41 -0400 Message-ID: <20230928044943.849073-5-jsnow@redhat.com> In-Reply-To: <20230928044943.849073-1-jsnow@redhat.com> References: <20230928044943.849073-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695876704012100001 Create a socketpair for the console output. This should help eliminate race conditions around console text early in the boot process that might otherwise have been dropped on the floor before being able to connect to QEMU under "server,nowait". Signed-off-by: John Snow Reviewed-by: Ani Sinha Reviewed-by: Daniel P. Berrang=C3=A9 --- python/qemu/machine/machine.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index e26109e6f0e..4156b8cf7d4 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -159,6 +159,8 @@ def __init__(self, =20 self._name =3D name or f"{id(self):x}" self._sock_pair: Optional[Tuple[socket.socket, socket.socket]] =3D= None + self._cons_sock_pair: Optional[ + Tuple[socket.socket, socket.socket]] =3D None self._temp_dir: Optional[str] =3D None self._base_temp_dir =3D base_temp_dir self._sock_dir =3D sock_dir @@ -316,8 +318,9 @@ def _base_args(self) -> List[str]: for _ in range(self._console_index): args.extend(['-serial', 'null']) if self._console_set: - chardev =3D ('socket,id=3Dconsole,path=3D%s,server=3Don,wait= =3Doff' % - self._console_address) + assert self._cons_sock_pair is not None + fd =3D self._cons_sock_pair[0].fileno() + chardev =3D f"socket,id=3Dconsole,fd=3D{fd}" args.extend(['-chardev', chardev]) if self._console_device_type is None: args.extend(['-serial', 'chardev:console']) @@ -352,6 +355,10 @@ def _pre_launch(self) -> None: nickname=3Dself._name ) =20 + if self._console_set: + self._cons_sock_pair =3D socket.socketpair() + os.set_inheritable(self._cons_sock_pair[0].fileno(), True) + # NOTE: Make sure any opened resources are *definitely* freed in # _post_shutdown()! # pylint: disable=3Dconsider-using-with @@ -369,6 +376,9 @@ def _pre_launch(self) -> None: def _post_launch(self) -> None: if self._sock_pair: self._sock_pair[0].close() + if self._cons_sock_pair: + self._cons_sock_pair[0].close() + if self._qmp_connection: if self._sock_pair: self._qmp.connect() @@ -524,6 +534,11 @@ def _early_cleanup(self) -> None: self._console_socket.close() self._console_socket =3D None =20 + if self._cons_sock_pair: + self._cons_sock_pair[0].close() + self._cons_sock_pair[1].close() + self._cons_sock_pair =3D None + def _hard_shutdown(self) -> None: """ Perform early cleanup, kill the VM, and wait for it to terminate. @@ -885,10 +900,19 @@ def console_socket(self) -> socket.socket: """ if self._console_socket is None: LOG.debug("Opening console socket") + if not self._console_set: + raise QEMUMachineError( + "Attempt to access console socket with no connection") + assert self._cons_sock_pair is not None + # os.dup() is used here for sock_fd because otherwise we'd + # have two rich python socket objects that would each try to + # close the same underlying fd when either one gets garbage + # collected. self._console_socket =3D console_socket.ConsoleSocket( - self._console_address, + sock_fd=3Dos.dup(self._cons_sock_pair[1].fileno()), file=3Dself._console_log_path, drain=3Dself._drain_console) + self._cons_sock_pair[1].close() return self._console_socket =20 @property --=20 2.41.0 From nobody Wed May 15 19:16:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695876686; cv=none; d=zohomail.com; s=zohoarc; b=NJZsP+l7dChKOKCiig/jyyzEArU0J/kGnVI4e7ZXg2bpvRNUUvDt0hHoBmIQ9mYunBq5uzek1VWPcgD7BOiJa+RW+JocGcRq8AscRfXA5fSk7r1SiJRkTdQlaSd17bYJT1FboZElfAMQHD7+xLT5DXgKXza6s6d3TaNJxKD11qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695876686; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=newj1SHRr9285zC79EiG28M0Dw6Um2uVn/exXcSlR40=; b=eMp8idJO8QvUGa1EkWYvv+/Pr+9GTssT3nKO/01gR0j1+WtupsAtcYhsDsHXbV9mtNDawRhxHCyriyGuhtOFpnncUOXwHp7dp69RLuNqMRaIzE3QKYa3bQ00fx7zdiK/sNzztrEWHUxIm/9wkqCtp4BAQKgo6uQ85XsLkNRmHyE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695876685864649.7473587313982; Wed, 27 Sep 2023 21:51:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qliyj-0002SA-FU; Thu, 28 Sep 2023 00:50:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliye-0002QG-J1 for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyI-0006hk-Kc for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:15 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643--PqM27coNNmNiDNRjod5ZA-1; Thu, 28 Sep 2023 00:49:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F0BD8039D1; Thu, 28 Sep 2023 04:49:48 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 832471054FC1; Thu, 28 Sep 2023 04:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695876593; 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=newj1SHRr9285zC79EiG28M0Dw6Um2uVn/exXcSlR40=; b=bUbUnvVz91LNIIRUGBZyBn+DStX6CwoF3H0MsWiX73unduM3h8aldp6UuZIirfAuMppM1Z 30UILkeExkrwVLM8N9kxGVqmBQjWvik1Yu8n+DmQXXozrE2oGBaJCXk8Zg7b81icFK9+WK vHgP9HjgMn9A8wq4SqMRDfQy1Uk4jZs= X-MC-Unique: -PqM27coNNmNiDNRjod5ZA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Beraldo Leal , Cleber Rosa , qemu-block@nongnu.org, Hanna Reitz , "Michael S. Tsirkin" , John Snow , qemu-arm@nongnu.org, Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Andrew Jeffery , Daniel Berrange , Ani Sinha , Peter Maydell Subject: [PATCH v3 5/6] python/machine: use socketpair() for qtest connection Date: Thu, 28 Sep 2023 00:49:42 -0400 Message-ID: <20230928044943.849073-6-jsnow@redhat.com> In-Reply-To: <20230928044943.849073-1-jsnow@redhat.com> References: <20230928044943.849073-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695876687098100003 Like the QMP and console sockets, begin using socketpairs for the qtest connection, too. After this patch, we'll be able to remove the vestigial sock_dir argument, but that cleanup is best done in its own patch. Signed-off-by: John Snow Reviewed-by: Daniel P. Berrang=C3=A9 --- python/qemu/machine/qtest.py | 49 +++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py index 1c46138bd0c..8180d3ab017 100644 --- a/python/qemu/machine/qtest.py +++ b/python/qemu/machine/qtest.py @@ -24,6 +24,7 @@ Optional, Sequence, TextIO, + Tuple, ) =20 from qemu.qmp import SocketAddrT @@ -38,23 +39,41 @@ class QEMUQtestProtocol: :param address: QEMU address, can be either a unix socket path (string) or a tuple in the form ( address, port ) for a TCP connection - :param server: server mode, listens on the socket (bool) + :param sock: An existing socket can be provided as an alternative to + an address. One of address or sock must be provided. + :param server: server mode, listens on the socket. Only meaningful + in conjunction with an address and not an existing + socket. + :raise socket.error: on socket connection errors =20 .. note:: No connection is established by __init__(), this is done by the connect() or accept() methods. """ - def __init__(self, address: SocketAddrT, + def __init__(self, + address: Optional[SocketAddrT] =3D None, + sock: Optional[socket.socket] =3D None, server: bool =3D False): + if address is None and sock is None: + raise ValueError("Either 'address' or 'sock' must be specified= ") + if address is not None and sock is not None: + raise ValueError( + "Either 'address' or 'sock' must be specified, but not bot= h") + if sock is not None and server: + raise ValueError("server=3DTrue is meaningless when passing so= cket") + self._address =3D address - self._sock =3D self._get_sock() + self._sock =3D sock or self._get_sock() self._sockfile: Optional[TextIO] =3D None + if server: + assert self._address is not None self._sock.bind(self._address) self._sock.listen(1) =20 def _get_sock(self) -> socket.socket: + assert self._address is not None if isinstance(self._address, tuple): family =3D socket.AF_INET else: @@ -67,7 +86,8 @@ def connect(self) -> None: =20 @raise socket.error on socket connection errors """ - self._sock.connect(self._address) + if self._address is not None: + self._sock.connect(self._address) self._sockfile =3D self._sock.makefile(mode=3D'r') =20 def accept(self) -> None: @@ -127,29 +147,40 @@ def __init__(self, base_temp_dir=3Dbase_temp_dir, sock_dir=3Dsock_dir, qmp_timer=3Dqmp_timer) self._qtest: Optional[QEMUQtestProtocol] =3D None - self._qtest_path =3D os.path.join(sock_dir, name + "-qtest.sock") + self._qtest_sock_pair: Optional[ + Tuple[socket.socket, socket.socket]] =3D None =20 @property def _base_args(self) -> List[str]: args =3D super()._base_args + assert self._qtest_sock_pair is not None + fd =3D self._qtest_sock_pair[0].fileno() args.extend([ - '-qtest', f"unix:path=3D{self._qtest_path}", + '-chardev', f"socket,id=3Dqtest,fd=3D{fd}", + '-qtest', 'chardev:qtest', '-accel', 'qtest' ]) return args =20 def _pre_launch(self) -> None: + self._qtest_sock_pair =3D socket.socketpair() + os.set_inheritable(self._qtest_sock_pair[0].fileno(), True) super()._pre_launch() - self._qtest =3D QEMUQtestProtocol(self._qtest_path, server=3DTrue) + self._qtest =3D QEMUQtestProtocol(sock=3Dself._qtest_sock_pair[1]) =20 def _post_launch(self) -> None: assert self._qtest is not None super()._post_launch() - self._qtest.accept() + if self._qtest_sock_pair: + self._qtest_sock_pair[0].close() + self._qtest.connect() =20 def _post_shutdown(self) -> None: + if self._qtest_sock_pair: + self._qtest_sock_pair[0].close() + self._qtest_sock_pair[1].close() + self._qtest_sock_pair =3D None super()._post_shutdown() - self._remove_if_exists(self._qtest_path) =20 def qtest(self, cmd: str) -> str: """ --=20 2.41.0 From nobody Wed May 15 19:16:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695876691; cv=none; d=zohomail.com; s=zohoarc; b=KFMX/j5kp33Y0twWDN+xb3eMPvXxSu11/NkyhPY7LK9l4WWDhig0w8lZoS/v7Op+BtirQVqg/2RpLY+t3GQ4cRnivGYw5NoKaRVlWDLWIIrsr38QKNpcz85yrtHU3jMuOzjy0xVmlVsR6szfwHTiH4WowaK3PPzI7RwWSqeTLaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695876691; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dj/G0l/PjOAgLYIgp96JjSaLbQejk9X6fez+h8qPl+Y=; b=NIWrOsYfCBtx1czOsL++O39X3OGLpRgSjahIevXZdnlI5yuMnLS/XB34yG4aBDylUYr7g4j2v50N4iHMsIWZfH/q7nD1nN7J210al8g9MN/eyehdwLXt31Xwej++8fHlD29OfQfMmItdfK6OPXZF/IJ7S6/x3i41zILfIjjI4eI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695876691698548.7159443014584; Wed, 27 Sep 2023 21:51:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qliyR-0002L6-NY; Thu, 28 Sep 2023 00:50:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyO-0002Ir-PU for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qliyH-0006hE-Gb for qemu-devel@nongnu.org; Thu, 28 Sep 2023 00:50:00 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-125-AIp7RXELMdeCdWTmZvjCBA-1; Thu, 28 Sep 2023 00:49:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D75DE280D207; Thu, 28 Sep 2023 04:49:48 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BB2D1054FC1; Thu, 28 Sep 2023 04:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695876591; 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=Dj/G0l/PjOAgLYIgp96JjSaLbQejk9X6fez+h8qPl+Y=; b=MQhGoScb/tHrFQ3uh5uYYVOOrbmaEG90Jt6HRNT1VWD20/tAFBxAm2G3L67JNmOxJRYhgZ W9g9aunBrxDepaSS0ERLWYJ/jGHHseG6RMi25GxFdHMe2fqUcXG+Ly31AQ7c/CISy2dMN4 DCJ+h5saGx3g70d9G0B1gMwEZneDT1U= X-MC-Unique: AIp7RXELMdeCdWTmZvjCBA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Beraldo Leal , Cleber Rosa , qemu-block@nongnu.org, Hanna Reitz , "Michael S. Tsirkin" , John Snow , qemu-arm@nongnu.org, Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Andrew Jeffery , Daniel Berrange , Ani Sinha , Peter Maydell Subject: [PATCH v3 6/6] python/machine: remove unused sock_dir argument Date: Thu, 28 Sep 2023 00:49:43 -0400 Message-ID: <20230928044943.849073-7-jsnow@redhat.com> In-Reply-To: <20230928044943.849073-1-jsnow@redhat.com> References: <20230928044943.849073-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695876693950100003 By using a socketpair for all of the sockets managed by the VM class and its extensions, we don't need the sock_dir argument anymore, so remove it. We only added this argument so that we could specify a second, shorter temporary directory for cases where the temp/log dirs were "too long" as a socket name on macOS. We don't need it for this class now. In one case, avocado testing takes over responsibility for creating an appropriate sockdir. Signed-off-by: John Snow Reviewed-by: Daniel P. Berrang=C3=A9 --- python/qemu/machine/machine.py | 18 ------------------ python/qemu/machine/qtest.py | 5 +---- tests/avocado/acpi-bits.py | 5 +---- tests/avocado/avocado_qemu/__init__.py | 2 +- tests/avocado/machine_aspeed.py | 5 ++++- tests/qemu-iotests/iotests.py | 2 +- tests/qemu-iotests/tests/copy-before-write | 3 +-- 7 files changed, 9 insertions(+), 31 deletions(-) diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 4156b8cf7d4..d539e91268a 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -127,7 +127,6 @@ def __init__(self, name: Optional[str] =3D None, base_temp_dir: str =3D "/var/tmp", monitor_address: Optional[SocketAddrT] =3D None, - sock_dir: Optional[str] =3D None, drain_console: bool =3D False, console_log: Optional[str] =3D None, log_dir: Optional[str] =3D None, @@ -141,7 +140,6 @@ def __init__(self, @param name: prefix for socket and log file names (default: qemu-P= ID) @param base_temp_dir: default location where temp files are created @param monitor_address: address for QMP monitor - @param sock_dir: where to create socket (defaults to base_temp_dir) @param drain_console: (optional) True to drain console socket to b= uffer @param console_log: (optional) path to console log file @param log_dir: where to create and keep log files @@ -163,7 +161,6 @@ def __init__(self, Tuple[socket.socket, socket.socket]] =3D None self._temp_dir: Optional[str] =3D None self._base_temp_dir =3D base_temp_dir - self._sock_dir =3D sock_dir self._log_dir =3D log_dir =20 self._monitor_address =3D monitor_address @@ -189,9 +186,6 @@ def __init__(self, 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}.con" - ) self._console_socket: Optional[socket.socket] =3D None self._console_file: Optional[socket.SocketIO] =3D None self._remove_files: List[str] =3D [] @@ -335,9 +329,6 @@ def args(self) -> List[str]: return self._args =20 def _pre_launch(self) -> None: - if self._console_set: - self._remove_files.append(self._console_address) - if self._qmp_set: if self._monitor_address is None: self._sock_pair =3D socket.socketpair() @@ -937,15 +928,6 @@ 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: """ diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py index 8180d3ab017..4f5ede85b23 100644 --- a/python/qemu/machine/qtest.py +++ b/python/qemu/machine/qtest.py @@ -135,17 +135,14 @@ def __init__(self, wrapper: Sequence[str] =3D (), name: Optional[str] =3D None, base_temp_dir: str =3D "/var/tmp", - sock_dir: Optional[str] =3D None, qmp_timer: Optional[float] =3D None): # pylint: disable=3Dtoo-many-arguments =20 if name is None: name =3D "qemu-%d" % os.getpid() - if sock_dir is None: - sock_dir =3D base_temp_dir super().__init__(binary, args, wrapper=3Dwrapper, name=3Dname, base_temp_dir=3Dbase_temp_dir, - sock_dir=3Dsock_dir, qmp_timer=3Dqmp_timer) + qmp_timer=3Dqmp_timer) self._qtest: Optional[QEMUQtestProtocol] =3D None self._qtest_sock_pair: Optional[ Tuple[socket.socket, socket.socket]] =3D None diff --git a/tests/avocado/acpi-bits.py b/tests/avocado/acpi-bits.py index bb3f8186899..eca13dc5181 100644 --- a/tests/avocado/acpi-bits.py +++ b/tests/avocado/acpi-bits.py @@ -92,17 +92,14 @@ def __init__(self, base_temp_dir: str =3D "/var/tmp", debugcon_log: str =3D "debugcon-log.txt", debugcon_addr: str =3D "0x403", - sock_dir: Optional[str] =3D None, qmp_timer: Optional[float] =3D None): # pylint: disable=3Dtoo-many-arguments =20 if name is None: name =3D "qemu-bits-%d" % os.getpid() - if sock_dir is None: - sock_dir =3D base_temp_dir super().__init__(binary, args, wrapper=3Dwrapper, name=3Dname, base_temp_dir=3Dbase_temp_dir, - sock_dir=3Dsock_dir, qmp_timer=3Dqmp_timer) + qmp_timer=3Dqmp_timer) self.debugcon_log =3D debugcon_log self.debugcon_addr =3D debugcon_addr self.base_temp_dir =3D base_temp_dir diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado= _qemu/__init__.py index 0172a359b71..0589534f28a 100644 --- a/tests/avocado/avocado_qemu/__init__.py +++ b/tests/avocado/avocado_qemu/__init__.py @@ -322,7 +322,7 @@ def require_multiprocess(self): def _new_vm(self, name, *args): self._sd =3D tempfile.TemporaryDirectory(prefix=3D"qemu_") vm =3D QEMUMachine(self.qemu_bin, base_temp_dir=3Dself.workdir, - sock_dir=3Dself._sd.name, log_dir=3Dself.logdir) + log_dir=3Dself.logdir) self.log.debug('QEMUMachine "%s" created', name) self.log.debug('QEMUMachine "%s" temp_dir: %s', name, vm.temp_dir) self.log.debug('QEMUMachine "%s" log_dir: %s', name, vm.log_dir) diff --git a/tests/avocado/machine_aspeed.py b/tests/avocado/machine_aspeed= .py index 90f1b7cb77a..f691ee3fb82 100644 --- a/tests/avocado/machine_aspeed.py +++ b/tests/avocado/machine_aspeed.py @@ -247,7 +247,10 @@ def test_arm_ast2600_evb_buildroot_tpm(self): image_path =3D self.fetch_asset(image_url, asset_hash=3Dimage_hash, algorithm=3D'sha256') =20 - socket =3D os.path.join(self.vm.sock_dir, 'swtpm-socket') + # force creation of VM object, which also defines self._sd + vm =3D self.vm + + socket =3D os.path.join(self._sd.name, 'swtpm-socket') =20 subprocess.run(['swtpm', 'socket', '-d', '--tpm2', '--tpmstate', f'dir=3D{self.vm.temp_dir}', diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index ef66fbd62b0..145c6827138 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -823,7 +823,7 @@ def __init__(self, path_suffix=3D''): super().__init__(qemu_prog, qemu_opts, wrapper=3Dwrapper, name=3Dname, base_temp_dir=3Dtest_dir, - sock_dir=3Dsock_dir, qmp_timer=3Dtimer) + qmp_timer=3Dtimer) self._num_drives =3D 0 =20 def _post_shutdown(self) -> None: diff --git a/tests/qemu-iotests/tests/copy-before-write b/tests/qemu-iotest= s/tests/copy-before-write index 2ffe092b318..d3987db9421 100755 --- a/tests/qemu-iotests/tests/copy-before-write +++ b/tests/qemu-iotests/tests/copy-before-write @@ -44,8 +44,7 @@ class TestCbwError(iotests.QMPTestCase): =20 opts =3D ['-nodefaults', '-display', 'none', '-machine', 'none'] self.vm =3D QEMUMachine(iotests.qemu_prog, opts, - base_temp_dir=3Diotests.test_dir, - sock_dir=3Diotests.sock_dir) + base_temp_dir=3Diotests.test_dir) self.vm.launch() =20 def do_cbw_error(self, on_cbw_error): --=20 2.41.0