From nobody Wed May 14 11:32:20 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=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152328878281277.18483949555161; Mon, 9 Apr 2018 08:46:22 -0700 (PDT) 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 664EC9D427; Mon, 9 Apr 2018 15:46:21 +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 2842360930; Mon, 9 Apr 2018 15:46:21 +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 DD7F04CAAF; Mon, 9 Apr 2018 15:46:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w39Fk1wr032446 for ; Mon, 9 Apr 2018 11:46:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 03492202699A; Mon, 9 Apr 2018 15:46:01 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FEC62024CA7; Mon, 9 Apr 2018 15:46:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 9 Apr 2018 16:45:51 +0100 Message-Id: <20180409154551.22604-9-berrange@redhat.com> In-Reply-To: <20180409154551.22604-1-berrange@redhat.com> References: <20180409154551.22604-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] driver: ensure URI path is non-NULL to simplify drivers 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: , Content-Type: text/plain; charset="utf-8" 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.39]); Mon, 09 Apr 2018 15:46:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Avoid the need for the drivers to explicitly check for a NULL path by making sure it is at least the empty string. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/bhyve/bhyve_driver.c | 2 +- src/esx/esx_driver.c | 2 +- src/libvirt.c | 8 +++++++- src/libxl/libxl_driver.c | 5 ++--- src/lxc/lxc_driver.c | 3 +-- src/openvz/openvz_driver.c | 3 +-- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_driver.c | 6 ------ src/test/test_driver.c | 5 ++--- src/vbox/vbox_common.c | 6 ------ src/vbox/vbox_driver.c | 6 ------ src/vmware/vmware_driver.c | 2 +- src/vz/vz_driver.c | 2 +- 13 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 7d6439d79d..8870756ac5 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -199,7 +199,7 @@ bhyveConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { + if (STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected bhyve URI path '%s', try bhyve:///sy= stem"), conn->uri->path); diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 335d9a970d..c682c800ca 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -852,7 +852,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr au= th, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 if (STRCASENEQ(conn->uri->scheme, "vpx") && - conn->uri->path && STRNEQ(conn->uri->path, "/")) { + STRNEQ(conn->uri->path, "/")) { VIR_WARN("Ignoring unexpected path '%s' for non-vpx scheme '%s'", conn->uri->path, conn->uri->scheme); } diff --git a/src/libvirt.c b/src/libvirt.c index 600beaa4d5..0b6bd6666e 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1007,6 +1007,12 @@ virConnectOpenInternal(const char *name, goto failed; } =20 + /* Avoid need for drivers to worry about NULLs, as + * no one needs to distinguish "" vs NULL */ + if (ret->uri->path =3D=3D NULL && + VIR_STRDUP(ret->uri->path, "") < 0) + goto failed; + VIR_DEBUG("Split \"%s\" to URI components:\n" " scheme %s\n" " server %s\n" @@ -1016,7 +1022,7 @@ virConnectOpenInternal(const char *name, uristr, NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->server), NULLSTR(ret->uri->user), ret->uri->port, - NULLSTR(ret->uri->path)); + ret->uri->path); =20 if (ret->uri->scheme =3D=3D NULL) { virReportError(VIR_ERR_NO_CONNECT, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 45d0c99902..8808da8db1 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -853,13 +853,12 @@ libxlConnectOpen(virConnectPtr conn, } =20 /* /session isn't supported in libxenlight */ - if (conn->uri->path && - STRNEQ(conn->uri->path, "") && + if (STRNEQ(conn->uri->path, "") && STRNEQ(conn->uri->path, "/") && STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected Xen URI path '%s', try xen:///system"= ), - NULLSTR(conn->uri->path)); + conn->uri->path); return VIR_DRV_OPEN_ERROR; } =20 diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 2079dd0704..f6041aab43 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -170,8 +170,7 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr co= nn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 /* If path isn't '/' then they typoed, tell them correct path */ - if (conn->uri->path !=3D NULL && - STRNEQ(conn->uri->path, "/") && + if (STRNEQ(conn->uri->path, "/") && STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected LXC URI path '%s', try lxc:///system"= ), diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 33893ac009..5a1446ddda 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1444,8 +1444,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectP= tr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 /* If path isn't /system, then they typoed, so tell them correct path = */ - if (conn->uri->path =3D=3D NULL || - STRNEQ(conn->uri->path, "/system")) { + if (STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected OpenVZ URI path '%s', try openvz:///s= ystem"), conn->uri->path); diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 55d459df5c..ed3d9feb58 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1155,7 +1155,7 @@ phypConnectOpen(virConnectPtr conn, if (VIR_ALLOC(uuid_table) < 0) goto failure; =20 - if (conn->uri->path) { + if (conn->uri->path[0] !=3D '\0') { /* need to shift one byte in order to remove the first "/" of URI = component */ if (VIR_STRDUP(managed_system, conn->uri->path + (conn->uri->path[0] =3D=3D '/')) = < 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e677bf13b5..97d72f6fe8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1150,12 +1150,6 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPt= r conn, } =20 cfg =3D virQEMUDriverGetConfig(qemu_driver); - if (conn->uri->path =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("no QEMU URI path given, try %s"), - cfg->uri); - goto cleanup; - } =20 if (virQEMUDriverIsPrivileged(qemu_driver)) { if (STRNEQ(conn->uri->path, "/system") && diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 56d496a849..eec7a82924 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1454,9 +1454,8 @@ testConnectOpen(virConnectPtr conn, =20 virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 - if (!conn->uri->path - || conn->uri->path[0] =3D=3D '\0' - || (conn->uri->path[0] =3D=3D '/' && conn->uri->path[1] =3D=3D '\0= ')) { + if (conn->uri->path[0] =3D=3D '\0' || + (conn->uri->path[0] =3D=3D '/' && conn->uri->path[1] =3D=3D '\0'))= { virReportError(VIR_ERR_INVALID_ARG, "%s", _("testOpen: supply a path or use test:///def= ault")); return VIR_DRV_OPEN_ERROR; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 05cf9ad0de..ee94931918 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -517,12 +517,6 @@ vboxConnectOpen(virConnectPtr conn, =20 virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 - if (conn->uri->path =3D=3D NULL || STREQ(conn->uri->path, "")) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("no VirtualBox driver path specified (try vbox://= /session)")); - return VIR_DRV_OPEN_ERROR; - } - if (uid !=3D 0) { if (STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index 9e95ab01c5..1f31fa28df 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -58,12 +58,6 @@ static virDrvOpenStatus dummyConnectOpen(virConnectPtr c= onn, =20 virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 - if (conn->uri->path =3D=3D NULL || STREQ(conn->uri->path, "")) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("no VirtualBox driver path specified (try vbox://= /session)")); - return VIR_DRV_OPEN_ERROR; - } - if (uid !=3D 0) { if (STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index de3708aab3..c8a3151faf 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -131,7 +131,7 @@ vmwareConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 /* If path isn't /session, then they typoed, so tell them correct path= */ - if (conn->uri->path =3D=3D NULL || STRNEQ(conn->uri->path, "/session")= ) { + if (STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected VMware URI path '%s', try vmwareplaye= r:///session, vmwarews:///session or vmwarefusion:///session"), NULLSTR(conn->uri->path)); diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 5867f1c911..e51d968f28 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -359,7 +359,7 @@ vzConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 /* From this point on, the connection is for us. */ - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { + if (STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected Virtuozzo URI path '%s', try vz:///sy= stem"), conn->uri->path); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list