From nobody Wed May 14 19:07:04 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; 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 1517908458148348.7184331435593; Tue, 6 Feb 2018 01:14:18 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 15C88C036744; Tue, 6 Feb 2018 09:14:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6B216135B; Tue, 6 Feb 2018 09:14:16 +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 7B52F18033DE; Tue, 6 Feb 2018 09:14:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w169DrUN023615 for ; Tue, 6 Feb 2018 04:13:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 402716A02F; Tue, 6 Feb 2018 09:13:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33BE7608F3 for ; Tue, 6 Feb 2018 09:13:50 +0000 (UTC) Received: from new-relay.sw.ru (new-relay.sw.ru [195.214.232.40]) (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 8ECDAC052505 for ; Tue, 6 Feb 2018 09:13:48 +0000 (UTC) Received: from msk-vpn.virtuozzo.com ([195.214.232.6] helo=dim-vz7.qa.sw.ru) by new-relay.sw.ru with esmtp (Exim 4.89) (envelope-from ) id 1eizJy-0006tL-6A for libvir-list@redhat.com; Tue, 06 Feb 2018 12:13:46 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 6 Feb 2018 12:09:08 +0300 Message-Id: <1517908151-337420-4-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1517908151-337420-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1517908151-337420-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.31]); Tue, 06 Feb 2018 09:13:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 06 Feb 2018 09:13:49 +0000 (UTC) for IP:'195.214.232.40' DOMAIN:'new-relay.sw.ru' HELO:'new-relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.40 new-relay.sw.ru 195.214.232.40 new-relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/6] port allocator: remove range check in release function 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 06 Feb 2018 09:14:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Range check in virPortAllocatorSetUsed is not useful anymore when we manage ports for entire unsigned short range values. --- src/bhyve/bhyve_process.c | 3 +-- src/libxl/libxl_domain.c | 3 +-- src/libxl/libxl_migration.c | 4 ++-- src/qemu/qemu_migration.c | 12 ++++++------ src/qemu/qemu_process.c | 14 +++++--------- src/util/virportallocator.c | 10 +--------- src/util/virportallocator.h | 3 +-- tests/bhyvexml2argvtest.c | 2 +- tests/libxlxml2domconfigtest.c | 2 +- tests/virportallocatortest.c | 23 +++++++++++------------ 10 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index e215f6a..5e682fa 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -296,8 +296,7 @@ virBhyveProcessStop(bhyveConnPtr driver, /* VNC autoport cleanup */ if ((vm->def->ngraphics =3D=3D 1) && vm->def->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - if (virPortAllocatorRelease(driver->remotePorts, - vm->def->graphics[0]->data.vnc.port) <= 0) { + if (virPortAllocatorRelease(vm->def->graphics[0]->data.vnc.port) <= 0) { VIR_WARN("Failed to release VNC port for '%s'", vm->def->name); } diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 395c8a9..f69d60a 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -778,8 +778,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, vm->def->graphics[0]->data.vnc.autoport) { vnc_port =3D vm->def->graphics[0]->data.vnc.port; if (vnc_port >=3D LIBXL_VNC_PORT_MIN) { - if (virPortAllocatorRelease(driver->reservedGraphicsPorts, - vnc_port) < 0) + if (virPortAllocatorRelease(vnc_port) < 0) VIR_DEBUG("Could not mark port %d as unused", vnc_port); } } diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index a7a578c..ccf2dae 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -805,7 +805,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn, } VIR_FREE(socks); virObjectUnref(args); - virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort); + virPortAllocatorRelease(priv->migrationPort); priv->migrationPort =3D 0; =20 /* Remove virDomainObj from domain list */ @@ -1262,7 +1262,7 @@ libxlDomainMigrationFinish(virConnectPtr dconn, virObjectEventPtr event =3D NULL; virDomainPtr dom =3D NULL; =20 - virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort); + virPortAllocatorRelease(priv->migrationPort); priv->migrationPort =3D 0; =20 if (cancelled) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index ea8b275..fee3163 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -552,7 +552,7 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver, cleanup: VIR_FREE(diskAlias); if (ret < 0 && nbdPort =3D=3D 0) - virPortAllocatorRelease(driver->migrationPorts, port); + virPortAllocatorRelease(port); return ret; =20 exit_monitor: @@ -580,7 +580,7 @@ qemuMigrationStopNBDServer(virQEMUDriverPtr driver, if (qemuDomainObjExitMonitor(driver, vm) < 0) return -1; =20 - virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort); + virPortAllocatorRelease(priv->nbdPort); priv->nbdPort =3D 0; return 0; } @@ -2229,7 +2229,7 @@ qemuMigrationPrepareCleanup(virQEMUDriverPtr driver, qemuDomainJobTypeToString(priv->job.active), qemuDomainAsyncJobTypeToString(priv->job.asyncJob)); =20 - virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort); + virPortAllocatorRelease(priv->migrationPort); priv->migrationPort =3D 0; =20 if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_IN)) @@ -2909,7 +2909,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, * it is given in parameters */ if (nbdPort =3D=3D 0) - virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort); + virPortAllocatorRelease(priv->nbdPort); priv->nbdPort =3D 0; virDomainObjRemoveTransientDef(vm); qemuDomainRemoveInactiveJob(driver, vm); @@ -3152,7 +3152,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (ret !=3D 0) { VIR_FREE(*uri_out); if (autoPort) - virPortAllocatorRelease(driver->migrationPorts, port); + virPortAllocatorRelease(port); } return ret; } @@ -5514,7 +5514,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver, =20 cleanup: VIR_FREE(jobInfo); - virPortAllocatorRelease(driver->migrationPorts, port); + virPortAllocatorRelease(port); if (priv->mon) qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL); VIR_FREE(priv->origname); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2a0690b..ddb699c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6455,7 +6455,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, } } =20 - virPortAllocatorRelease(driver->migrationPorts, priv->nbdPort); + virPortAllocatorRelease(priv->nbdPort); priv->nbdPort =3D 0; =20 if (priv->agent) { @@ -6616,15 +6616,13 @@ void qemuProcessStop(virQEMUDriverPtr driver, virDomainGraphicsDefPtr graphics =3D vm->def->graphics[i]; if (graphics->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { if (graphics->data.vnc.autoport) { - virPortAllocatorRelease(driver->remotePorts, - graphics->data.vnc.port); + virPortAllocatorRelease(graphics->data.vnc.port); } else if (graphics->data.vnc.portReserved) { virPortAllocatorSetUsed(graphics->data.spice.port, false); graphics->data.vnc.portReserved =3D false; } if (graphics->data.vnc.websocketGenerated) { - virPortAllocatorRelease(driver->webSocketPorts, - graphics->data.vnc.websocket); + virPortAllocatorRelease(graphics->data.vnc.websocket); graphics->data.vnc.websocketGenerated =3D false; graphics->data.vnc.websocket =3D -1; } else if (graphics->data.vnc.websocket) { @@ -6633,10 +6631,8 @@ void qemuProcessStop(virQEMUDriverPtr driver, } if (graphics->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { if (graphics->data.spice.autoport) { - virPortAllocatorRelease(driver->remotePorts, - graphics->data.spice.port); - virPortAllocatorRelease(driver->remotePorts, - graphics->data.spice.tlsPort); + virPortAllocatorRelease(graphics->data.spice.port); + virPortAllocatorRelease(graphics->data.spice.tlsPort); } else { if (graphics->data.spice.portReserved) { virPortAllocatorSetUsed(graphics->data.spice.port, fal= se); diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 23c7af1..040d823 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -266,8 +266,7 @@ virPortAllocatorAcquire(virPortAllocatorRangePtr range, } =20 int -virPortAllocatorRelease(virPortAllocatorRangePtr range, - unsigned short port) +virPortAllocatorRelease(unsigned short port) { int ret =3D -1; virPortAllocatorPtr pa =3D virPortAllocatorGet(); @@ -280,13 +279,6 @@ virPortAllocatorRelease(virPortAllocatorRangePtr range, =20 virObjectLock(pa); =20 - if (port < range->start || - port > range->end) { - virReportInvalidArg(port, "port %d must be in range (%d, %d)", - port, range->start, range->end); - goto cleanup; - } - if (virBitmapClearBit(pa->bitmap, port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to release port %d"), diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h index ea816bc..2e0ba46 100644 --- a/src/util/virportallocator.h +++ b/src/util/virportallocator.h @@ -43,8 +43,7 @@ void virPortAllocatorRangeFree(virPortAllocatorRangePtr r= ange); int virPortAllocatorAcquire(virPortAllocatorRangePtr range, unsigned short *port); =20 -int virPortAllocatorRelease(virPortAllocatorRangePtr range, - unsigned short port); +int virPortAllocatorRelease(unsigned short port); =20 int virPortAllocatorSetUsed(unsigned short port, bool value); =20 diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index e8089b8..a7d5ce4 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -95,7 +95,7 @@ static int testCompareXMLToArgvFiles(const char *xml, vmdef->ngraphics =3D=3D 1 && vmdef->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { if (vmdef->graphics[0]->data.vnc.autoport) - virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.p= ort); + virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); else virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, fal= se); } diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index b146eb5..d5ff596 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -116,7 +116,7 @@ testCompareXMLToDomConfig(const char *xmlfile, vmdef->ngraphics =3D=3D 1 && vmdef->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { if (vmdef->graphics[0]->data.vnc.autoport) - virPortAllocatorRelease(gports, vmdef->graphics[0]->data.vnc.p= ort); + virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port); else virPortAllocatorSetUsed(vmdef->graphics[0]->data.vnc.port, fal= se); } diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c index 0a967d1..86dd3bc 100644 --- a/tests/virportallocatortest.c +++ b/tests/virportallocatortest.c @@ -98,13 +98,13 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUS= ED) =20 ret =3D 0; cleanup: - virPortAllocatorRelease(ports, p1); - virPortAllocatorRelease(ports, p2); - virPortAllocatorRelease(ports, p3); - virPortAllocatorRelease(ports, p4); - virPortAllocatorRelease(ports, p5); - virPortAllocatorRelease(ports, p6); - virPortAllocatorRelease(ports, p7); + virPortAllocatorRelease(p1); + virPortAllocatorRelease(p2); + virPortAllocatorRelease(p3); + virPortAllocatorRelease(p4); + virPortAllocatorRelease(p5); + virPortAllocatorRelease(p6); + virPortAllocatorRelease(p7); =20 virPortAllocatorRangeFree(ports); return ret; @@ -142,8 +142,7 @@ static int testAllocReuse(const void *args ATTRIBUTE_UN= USED) goto cleanup; } =20 - - if (virPortAllocatorRelease(ports, p2) < 0) + if (virPortAllocatorRelease(p2) < 0) goto cleanup; =20 if (virPortAllocatorAcquire(ports, &p4) < 0) @@ -155,9 +154,9 @@ static int testAllocReuse(const void *args ATTRIBUTE_UN= USED) =20 ret =3D 0; cleanup: - virPortAllocatorRelease(ports, p1); - virPortAllocatorRelease(ports, p3); - virPortAllocatorRelease(ports, p4); + virPortAllocatorRelease(p1); + virPortAllocatorRelease(p3); + virPortAllocatorRelease(p4); =20 virPortAllocatorRangeFree(ports); return ret; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list