From nobody Mon Feb 9 14:38:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530702307551123.1180043098069; Wed, 4 Jul 2018 04:05:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6035E821C7; Wed, 4 Jul 2018 11:05:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 18DEB1001643; Wed, 4 Jul 2018 11:05:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A3B814A460; Wed, 4 Jul 2018 11:05:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w64B51ER013519 for ; Wed, 4 Jul 2018 07:05:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id A86DC5B682; Wed, 4 Jul 2018 11:05:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9ED335D761 for ; Wed, 4 Jul 2018 11:04:57 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B78F73082A26 for ; Wed, 4 Jul 2018 11:04:55 +0000 (UTC) Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=dim-vz7.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fafaf-000096-EU for libvir-list@redhat.com; Wed, 04 Jul 2018 14:04:53 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Wed, 4 Jul 2018 14:03:38 +0300 Message-Id: <1530702221-451603-3-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1530702221-451603-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1530702221-451603-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Sender passed SPF test, ACL 227 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 04 Jul 2018 11:04:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 04 Jul 2018 11:04:56 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] qemu: simplify graphics port releasing X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Jul 2018 11:05:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Originally port allocator have 2 functions to release ports: one for for manually reserved ports and one for autoallocated ports. Thus a bit complicated code of port releasing. Now we have only one releasing function. Let's use *reserved flag whenever we manually/automatically allocate port so that we can use it later for releasing. Actually we set *reserved flag on autoallocation already on reconnection, which lead to uncleared flag on stop. So this step looks natural. qemuProcessGraphicsReservePorts is called on reconnect. As a result portReserved is set not only for manual ports but autoports too. Now due to the way port releasing is written in qemuProcessStop portReserved stays set for autoports after domain stop. Now imagine one redefine Signed-off-by: Nikolay Shirokovskiy --- src/conf/domain_conf.h | 1 + src/qemu/qemu_process.c | 48 ++++++++++++++++++++++-----------------------= --- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 41d2748..1da6b8f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1610,6 +1610,7 @@ struct _virDomainGraphicsDef { int port; bool portReserved; int websocket; + bool websocketReserved; bool websocketGenerated; bool autoport; char *keymap; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index da5656d..de2e84b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3628,12 +3628,14 @@ qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver, if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0) return -1; graphics->data.vnc.port =3D port; + graphics->data.vnc.portReserved =3D true; } =20 if (graphics->data.vnc.websocket =3D=3D -1) { if (virPortAllocatorAcquire(driver->webSocketPorts, &port) < 0) return -1; graphics->data.vnc.websocket =3D port; + graphics->data.vnc.websocketReserved =3D true; graphics->data.vnc.websocketGenerated =3D true; } =20 @@ -3705,9 +3707,7 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver, goto cleanup; =20 graphics->data.spice.port =3D port; - - if (!graphics->data.spice.autoport) - graphics->data.spice.portReserved =3D true; + graphics->data.spice.portReserved =3D true; } =20 if (needTLSPort || graphics->data.spice.tlsPort =3D=3D -1) { @@ -3722,9 +3722,7 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver, goto cleanup; =20 graphics->data.spice.tlsPort =3D tlsPort; - - if (!graphics->data.spice.autoport) - graphics->data.spice.tlsPortReserved =3D true; + graphics->data.spice.tlsPortReserved =3D true; } =20 ret =3D 0; @@ -4328,9 +4326,11 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDef= Ptr graphics, return -1; graphics->data.vnc.portReserved =3D true; } - if (graphics->data.vnc.websocket > 0 && - virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0) - return -1; + if (graphics->data.vnc.websocket > 0) { + if (virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0) + return -1; + graphics->data.vnc.websocketReserved =3D true; + } break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: @@ -6974,34 +6974,30 @@ void qemuProcessStop(virQEMUDriverPtr driver, for (i =3D 0; i < vm->def->ngraphics; ++i) { virDomainGraphicsDefPtr graphics =3D vm->def->graphics[i]; if (graphics->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - if (graphics->data.vnc.autoport) { - virPortAllocatorRelease(graphics->data.vnc.port); - } else if (graphics->data.vnc.portReserved) { + if (graphics->data.vnc.portReserved) { virPortAllocatorRelease(graphics->data.vnc.port); graphics->data.vnc.portReserved =3D false; } + + if (graphics->data.vnc.websocketReserved) { + virPortAllocatorRelease(graphics->data.vnc.websocket); + graphics->data.vnc.websocketReserved =3D false; + } + if (graphics->data.vnc.websocketGenerated) { - virPortAllocatorRelease(graphics->data.vnc.websocket); graphics->data.vnc.websocketGenerated =3D false; graphics->data.vnc.websocket =3D -1; - } else if (graphics->data.vnc.websocket) { - virPortAllocatorRelease(graphics->data.vnc.websocket); } } if (graphics->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - if (graphics->data.spice.autoport) { + if (graphics->data.spice.portReserved) { virPortAllocatorRelease(graphics->data.spice.port); + graphics->data.spice.portReserved =3D false; + } + + if (graphics->data.spice.tlsPortReserved) { virPortAllocatorRelease(graphics->data.spice.tlsPort); - } else { - if (graphics->data.spice.portReserved) { - virPortAllocatorRelease(graphics->data.spice.port); - graphics->data.spice.portReserved =3D false; - } - - if (graphics->data.spice.tlsPortReserved) { - virPortAllocatorRelease(graphics->data.spice.tlsPort); - graphics->data.spice.tlsPortReserved =3D false; - } + graphics->data.spice.tlsPortReserved =3D false; } } } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list