From nobody Wed May 14 19:09:49 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 151790843711443.9304309223794; Tue, 6 Feb 2018 01:13:57 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD5EAC03677B; Tue, 6 Feb 2018 09:13:55 +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 1244350DF2; Tue, 6 Feb 2018 09:13:55 +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 3C24B18033DA; Tue, 6 Feb 2018 09:13:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w169DpNQ023590 for ; Tue, 6 Feb 2018 04:13:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46681609B4; Tue, 6 Feb 2018 09:13:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F1CF60E39 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 89CA16E769 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-9X 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:09 +0300 Message-Id: <1517908151-337420-5-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.25]); Tue, 06 Feb 2018 09:13:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); 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.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/6] port allocator: drop skip bind check flag 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.13 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:13:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This flag is only used for tests. Let's instead overload bind syscall in mocks where it is not done yet. --- src/bhyve/bhyve_driver.c | 2 +- src/libxl/libxl_driver.c | 5 ++--- src/qemu/qemu_driver.c | 9 +++------ src/util/virportallocator.c | 14 ++++---------- src/util/virportallocator.h | 7 +------ tests/bhyvexml2argvmock.c | 7 +++++++ tests/bhyvexml2argvtest.c | 3 +-- tests/libxlxml2domconfigtest.c | 3 +-- tests/virmocklibxl.c | 7 +++++++ tests/virportallocatortest.c | 4 ++-- 10 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 913c7b1..849d3ab 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1268,7 +1268,7 @@ bhyveStateInitialize(bool privileged, goto cleanup; =20 if (!(bhyve_driver->remotePorts =3D virPortAllocatorRangeNew(_("displa= y"), - 5900, 65535= , 0))) + 5900, 65535= ))) goto cleanup; =20 bhyve_driver->hostsysinfo =3D virSysinfoRead(); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 5da9378..2a6bfc6 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -659,15 +659,14 @@ libxlStateInitialize(bool privileged, if (!(libxl_driver->reservedGraphicsPorts =3D virPortAllocatorRangeNew(_("VNC"), LIBXL_VNC_PORT_MIN, - LIBXL_VNC_PORT_MAX, - 0))) + LIBXL_VNC_PORT_MAX))) goto error; =20 /* Allocate bitmap for migration port reservation */ if (!(libxl_driver->migrationPorts =3D virPortAllocatorRangeNew(_("migration"), LIBXL_MIGRATION_PORT_MIN, - LIBXL_MIGRATION_PORT_MAX, 0))) + LIBXL_MIGRATION_PORT_MAX))) goto error; =20 if (!(libxl_driver->domains =3D virDomainObjListNew())) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9f0bab5..26ff03a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -750,22 +750,19 @@ qemuStateInitialize(bool privileged, if ((qemu_driver->remotePorts =3D virPortAllocatorRangeNew(_("display"), cfg->remotePortMin, - cfg->remotePortMax, - 0)) =3D=3D NULL) + cfg->remotePortMax)) =3D=3D NULL) goto error; =20 if ((qemu_driver->webSocketPorts =3D virPortAllocatorRangeNew(_("webSocket"), cfg->webSocketPortMin, - cfg->webSocketPortMax, - 0)) =3D=3D NULL) + cfg->webSocketPortMax)) =3D=3D NULL) goto error; =20 if ((qemu_driver->migrationPorts =3D virPortAllocatorRangeNew(_("migration"), cfg->migrationPortMin, - cfg->migrationPortMax, - 0)) =3D=3D NULL) + cfg->migrationPortMax)) =3D=3D NULL) goto error; =20 if (qemuSecurityInit(qemu_driver) < 0) diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 040d823..d800fdf 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -47,8 +47,6 @@ struct _virPortAllocatorRange { =20 unsigned short start; unsigned short end; - - unsigned int flags; }; =20 static virClassPtr virPortAllocatorClass; @@ -99,8 +97,7 @@ VIR_ONCE_GLOBAL_INIT(virPortAllocator) virPortAllocatorRangePtr virPortAllocatorRangeNew(const char *name, unsigned short start, - unsigned short end, - unsigned int flags) + unsigned short end) { virPortAllocatorRangePtr range; =20 @@ -113,7 +110,6 @@ virPortAllocatorRangeNew(const char *name, if (VIR_ALLOC(range) < 0) return NULL; =20 - range->flags =3D flags; range->start =3D start; range->end =3D end; =20 @@ -237,11 +233,9 @@ virPortAllocatorAcquire(virPortAllocatorRangePtr range, if (virBitmapIsBitSet(pa->bitmap, i)) continue; =20 - if (!(range->flags & VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)) { - if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 || - virPortAllocatorBindToPort(&used, i, AF_INET) < 0) - goto cleanup; - } + if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 || + virPortAllocatorBindToPort(&used, i, AF_INET) < 0) + goto cleanup; =20 if (!used && !v6used) { /* Add port to bitmap of reserved ports */ diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h index 2e0ba46..1d7505f 100644 --- a/src/util/virportallocator.h +++ b/src/util/virportallocator.h @@ -28,15 +28,10 @@ typedef struct _virPortAllocatorRange virPortAllocatorRange; typedef virPortAllocatorRange *virPortAllocatorRangePtr; =20 -typedef enum { - VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK =3D (1 << 0), -} virPortAllocatorFlags; - virPortAllocatorRangePtr virPortAllocatorRangeNew(const char *name, unsigned short start, - unsigned short end, - unsigned int flags); + unsigned short end); =20 void virPortAllocatorRangeFree(virPortAllocatorRangePtr range); =20 diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c index bec7f90..ebcaff4 100644 --- a/tests/bhyvexml2argvmock.c +++ b/tests/bhyvexml2argvmock.c @@ -54,3 +54,10 @@ int virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUS= ED, { return 0; } + +int bind(int sockfd ATTRIBUTE_UNUSED, + const struct sockaddr *addr ATTRIBUTE_UNUSED, + socklen_t addrlen ATTRIBUTE_UNUSED) +{ + return 0; +} diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index a7d5ce4..eb0f548 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -154,8 +154,7 @@ mymain(void) if ((driver.xmlopt =3D virBhyveDriverCreateXMLConf(&driver)) =3D=3D NU= LL) return EXIT_FAILURE; =20 - if (!(driver.remotePorts =3D virPortAllocatorRangeNew("display", 5900,= 65535, - VIR_PORT_ALLOCATOR= _SKIP_BIND_CHECK))) + if (!(driver.remotePorts =3D virPortAllocatorRangeNew("display", 5900,= 65535))) return EXIT_FAILURE; =20 =20 diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index d5ff596..0dc5709 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -74,8 +74,7 @@ testCompareXMLToDomConfig(const char *xmlfile, if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0) goto cleanup; =20 - if (!(gports =3D virPortAllocatorRangeNew("vnc", 5900, 6000, - VIR_PORT_ALLOCATOR_SKIP_BIND_C= HECK))) + if (!(gports =3D virPortAllocatorRangeNew("vnc", 5900, 6000))) goto cleanup; =20 if (!(xmlopt =3D libxlCreateXMLConf())) diff --git a/tests/virmocklibxl.c b/tests/virmocklibxl.c index 747f9f8..9735956 100644 --- a/tests/virmocklibxl.c +++ b/tests/virmocklibxl.c @@ -29,6 +29,7 @@ # include # include # include +# include =20 VIR_MOCK_IMPL_RET_VOID(xs_daemon_open, struct xs_handle *) @@ -68,6 +69,12 @@ VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames, VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close, struct xs_handle *, handle) =20 +VIR_MOCK_STUB_RET_ARGS(bind, + int, 0, + int, sockfd, + const struct sockaddr *, addr, + socklen_t, addrlen) + VIR_MOCK_IMPL_RET_ARGS(__xstat, int, int, ver, const char *, path, diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c index 86dd3bc..5e30b41 100644 --- a/tests/virportallocatortest.c +++ b/tests/virportallocatortest.c @@ -42,7 +42,7 @@ VIR_LOG_INIT("tests.portallocatortest"); =20 static int testAllocAll(const void *args ATTRIBUTE_UNUSED) { - virPortAllocatorRangePtr ports =3D virPortAllocatorRangeNew("test", 59= 00, 5909, 0); + virPortAllocatorRangePtr ports =3D virPortAllocatorRangeNew("test", 59= 00, 5909); int ret =3D -1; unsigned short p1 =3D 0, p2 =3D 0, p3 =3D 0, p4 =3D 0, p5 =3D 0, p6 = =3D 0, p7 =3D 0; =20 @@ -114,7 +114,7 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUS= ED) =20 static int testAllocReuse(const void *args ATTRIBUTE_UNUSED) { - virPortAllocatorRangePtr ports =3D virPortAllocatorRangeNew("test", 59= 00, 5910, 0); + virPortAllocatorRangePtr ports =3D virPortAllocatorRangeNew("test", 59= 00, 5910); int ret =3D -1; unsigned short p1 =3D 0, p2 =3D 0, p3 =3D 0, p4 =3D 0; =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list