From nobody Thu May 15 01:40:17 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1513751809324482.2432154337595; Tue, 19 Dec 2017 22:36:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40E24C049D43; Wed, 20 Dec 2017 06:36:47 +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 9BA7317C59; Wed, 20 Dec 2017 06:36:46 +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 EC3354BB78; Wed, 20 Dec 2017 06:36:41 +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 vBK6acGG016309 for ; Wed, 20 Dec 2017 01:36:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id E125E5EDE8; Wed, 20 Dec 2017 06:36:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB59162660 for ; Wed, 20 Dec 2017 06:36:37 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCEF1356D1 for ; Wed, 20 Dec 2017 06:36:34 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBJ9IkWj001510 for ; Tue, 19 Dec 2017 12:18:47 +0300 (MSK) From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Wed, 20 Dec 2017 09:35:37 +0300 Message-Id: <1513751738-772066-6-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1513751738-772066-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1513751738-772066-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.30]); Wed, 20 Dec 2017 06:36:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 20 Dec 2017 06:36:35 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/6] port allocator: remove release functionality from set used 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 20 Dec 2017 06:36:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let's use virPortAllocatorRelease instead of virPortAllocatorSetUsed(false). --- src/bhyve/bhyve_command.c | 2 +- src/bhyve/bhyve_process.c | 2 +- src/qemu/qemu_process.c | 16 ++++++++-------- src/util/virportallocator.c | 22 ++++++---------------- src/util/virportallocator.h | 2 +- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 9d21788..d723cc2 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -411,7 +411,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def, return -1; graphics->data.vnc.port =3D port; } else { - if (virPortAllocatorSetUsed(graphics->data.vnc.port, true)= < 0) + if (virPortAllocatorSetUsed(graphics->data.vnc.port) < 0) VIR_WARN("Failed to mark VNC port '%d' as used by '%s'= ", graphics->data.vnc.port, def->name); } diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 5e682fa..4ff6257 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -424,7 +424,7 @@ virBhyveProcessReconnect(virDomainObjPtr vm, if (vm->def->ngraphics =3D=3D 1 && vm->def->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYP= E_VNC) { int vnc_port =3D vm->def->graphics[0]->data.vnc.port; - if (virPortAllocatorSetUsed(vnc_port, true) < 0) { + if (virPortAllocatorSetUsed(vnc_port) < 0) { VIR_WARN("Failed to mark VNC port '%d' as used by '%s= '", vnc_port, vm->def->name); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0777922..6f4ccd9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4171,12 +4171,12 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDe= fPtr graphics, case VIR_DOMAIN_GRAPHICS_TYPE_VNC: if (!graphics->data.vnc.autoport || reconnect) { - if (virPortAllocatorSetUsed(graphics->data.vnc.port, true) < 0) + if (virPortAllocatorSetUsed(graphics->data.vnc.port) < 0) return -1; graphics->data.vnc.portReserved =3D true; } if (graphics->data.vnc.websocket > 0 && - virPortAllocatorSetUsed(graphics->data.vnc.websocket, true) < = 0) + virPortAllocatorSetUsed(graphics->data.vnc.websocket) < 0) return -1; break; =20 @@ -4185,13 +4185,13 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDe= fPtr graphics, return 0; =20 if (graphics->data.spice.port > 0) { - if (virPortAllocatorSetUsed(graphics->data.spice.port, true) <= 0) + if (virPortAllocatorSetUsed(graphics->data.spice.port) < 0) return -1; graphics->data.spice.portReserved =3D true; } =20 if (graphics->data.spice.tlsPort > 0) { - if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort, true= ) < 0) + if (virPortAllocatorSetUsed(graphics->data.spice.tlsPort) < 0) return -1; graphics->data.spice.tlsPortReserved =3D true; } @@ -6541,7 +6541,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, if (graphics->data.vnc.autoport) { virPortAllocatorRelease(graphics->data.vnc.port); } else if (graphics->data.vnc.portReserved) { - virPortAllocatorSetUsed(graphics->data.spice.port, false); + virPortAllocatorRelease(graphics->data.spice.port); graphics->data.vnc.portReserved =3D false; } if (graphics->data.vnc.websocketGenerated) { @@ -6549,7 +6549,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, graphics->data.vnc.websocketGenerated =3D false; graphics->data.vnc.websocket =3D -1; } else if (graphics->data.vnc.websocket) { - virPortAllocatorSetUsed(graphics->data.vnc.websocket, fals= e); + virPortAllocatorRelease(graphics->data.vnc.websocket); } } if (graphics->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { @@ -6558,12 +6558,12 @@ void qemuProcessStop(virQEMUDriverPtr driver, virPortAllocatorRelease(graphics->data.spice.tlsPort); } else { if (graphics->data.spice.portReserved) { - virPortAllocatorSetUsed(graphics->data.spice.port, fal= se); + virPortAllocatorRelease(graphics->data.spice.port); graphics->data.spice.portReserved =3D false; } =20 if (graphics->data.spice.tlsPortReserved) { - virPortAllocatorSetUsed(graphics->data.spice.tlsPort, = false); + virPortAllocatorRelease(graphics->data.spice.tlsPort); graphics->data.spice.tlsPortReserved =3D false; } } diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 76fac49..565715c 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -279,8 +279,7 @@ int virPortAllocatorRelease(unsigned short port) return ret; } =20 -int virPortAllocatorSetUsed(unsigned short port, - bool value) +int virPortAllocatorSetUsed(unsigned short port) { int ret =3D -1; virPortAllocatorPtr pa =3D virPortAllocatorGet(); @@ -290,20 +289,11 @@ int virPortAllocatorSetUsed(unsigned short port, =20 virObjectLock(pa); =20 - if (value) { - if (virBitmapIsBitSet(pa->bitmap, port) || - virBitmapSetBit(pa->bitmap, port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to reserve port %d"), port); - goto cleanup; - } - } else { - if (virBitmapClearBit(pa->bitmap, port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to release port %d"), - port); - goto cleanup; - } + if (virBitmapIsBitSet(pa->bitmap, port) || + virBitmapSetBit(pa->bitmap, port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to reserve port %d"), port); + goto cleanup; } =20 ret =3D 0; diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h index bddeadd..3bc3ef2 100644 --- a/src/util/virportallocator.h +++ b/src/util/virportallocator.h @@ -39,6 +39,6 @@ int virPortAllocatorAcquire(virPortRangePtr range, =20 int virPortAllocatorRelease(unsigned short port); =20 -int virPortAllocatorSetUsed(unsigned short port, bool value); +int virPortAllocatorSetUsed(unsigned short port); =20 #endif /* __VIR_PORT_ALLOCATOR_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list