[libvirt] [PATCH 0/8] Simplify & standarize more parts of driver URI handling

The motivating goal of this series was/is to make it possible to answer whether there is any driver registered to handle a given URI scheme without having to call into the drivers. Ultimately this ended up being a nice simplification and cleanup of driver URI opening code, removing repetative logic from all drivers. Daniel P. Berrangé (8): xen: encourage use of xen:///system URI as preferred format lxc: allow use of lxc:///system URI as preferred format driver: introduce a driver method for probing default URIs driver: allow drivers to indicate if they permit remote connections driver: declare supported URI schemes in virConnectDriver struct driver: ensure NULL URI isn't passed to drivers with whitelisted URIs driver: enforce a non-NULL URI scheme driver: ensure URI path is non-NULL to simplify drivers docs/drvlxc.html.in | 34 ++++++------- docs/drvxen.html.in | 14 +++--- docs/hvsupport.pl | 6 +-- docs/remote.html.in | 6 +-- docs/uri.html.in | 16 +++---- examples/lxcconvert/virt-lxc-convert | 2 +- src/bhyve/bhyve_driver.c | 48 +++++++++---------- src/driver-hypervisor.h | 4 ++ src/driver.h | 8 ++++ src/esx/esx_driver.c | 31 +----------- src/hyperv/hyperv_driver.c | 24 +--------- src/interface/interface_backend_netcf.c | 47 +++++++----------- src/interface/interface_backend_udev.c | 47 +++++++----------- src/libvirt.c | 69 +++++++++++++++++++++++--- src/libxl/libxl_driver.c | 58 +++++++++++----------- src/lxc/lxc_driver.c | 56 ++++++++++------------ src/lxc/lxc_process.c | 4 +- src/network/bridge_driver.c | 47 +++++++----------- src/node_device/node_device_driver.c | 45 +++++++---------- src/node_device/node_device_hal.c | 2 + src/node_device/node_device_udev.c | 2 + src/nwfilter/nwfilter_driver.c | 35 +++++--------- src/openvz/openvz_driver.c | 70 +++++++++++++-------------- src/phyp/phyp_driver.c | 9 +--- src/qemu/qemu_driver.c | 85 +++++++++++++++------------------ src/remote/remote_driver.c | 74 +++++++++++++--------------- src/secret/secret_driver.c | 47 +++++++----------- src/storage/storage_driver.c | 47 +++++++----------- src/test/test_driver.c | 18 ++----- src/uml/uml_driver.c | 71 +++++++++++++-------------- src/vbox/vbox_common.c | 26 ++++------ src/vbox/vbox_driver.c | 18 ++----- src/vmware/vmware_driver.c | 29 ++++------- src/vz/vz_driver.c | 25 ++-------- src/xenapi/xenapi_driver.c | 6 +-- tools/libvirt-guests.sysconf | 2 +- tools/virsh.pod | 4 +- tools/virt-login-shell.c | 2 +- 38 files changed, 489 insertions(+), 649 deletions(-) -- 2.14.3

Historically we have used a bare xen:/// URI for connecting to the legacy Xen driver. The new libxl Xen driver follows the new practice of allowing '/system' as a path, as well as bare '/' for compat with the old Xen driver. This documents xen:///system as the preferred format for Xen, leaving xen:/// as an undocumented feature just for back-compat. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- docs/drvxen.html.in | 14 +++++++------- docs/remote.html.in | 6 +++--- docs/uri.html.in | 16 ++++++++-------- src/libvirt.c | 8 ++++---- src/libxl/libxl_driver.c | 4 ++-- tools/libvirt-guests.sysconf | 2 +- tools/virsh.pod | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/drvxen.html.in b/docs/drvxen.html.in index b8d190c942..2e45e09527 100644 --- a/docs/drvxen.html.in +++ b/docs/drvxen.html.in @@ -43,11 +43,11 @@ </p> <pre> -xen:/// (local access, direct) -xen+unix:/// (local access, via daemon) -xen://example.com/ (remote access, TLS/x509) -xen+tcp://example.com/ (remote access, SASl/Kerberos) -xen+ssh://root@example.com/ (remote access, SSH tunnelled) +xen:///system (local access, direct) +xen+unix:///system (local access, via daemon) +xen://example.com/system (remote access, TLS/x509) +xen+tcp://example.com/system (remote access, SASl/Kerberos) +xen+ssh://root@example.com/system (remote access, SSH tunnelled) </pre> <h2><a id="imex">Import and export of libvirt domain XML configs</a></h2> @@ -76,7 +76,7 @@ xen+ssh://root@example.com/ (remote access, SSH tunnelled) which can then be used by libvirt. </p> - <pre>$ virsh -c xen:/// domxml-from-native xen-xm rhel5.cfg + <pre>$ virsh -c xen:///system domxml-from-native xen-xm rhel5.cfg <domain type='xen'> <name>rhel5pv</name> <uuid>8f07fe28-753f-2729-d76d-bdbd892f949a</uuid> @@ -122,7 +122,7 @@ xen+ssh://root@example.com/ (remote access, SSH tunnelled) format. </p> - <pre>$ virsh -c xen:/// domxml-to-native xen-xm rhel5pv.xml + <pre>$ virsh -c xen:///system domxml-to-native xen-xm rhel5pv.xml name = "rhel5pv" uuid = "8f07fe28-753f-2729-d76d-bdbd892f949a" maxmem = 2500 diff --git a/docs/remote.html.in b/docs/remote.html.in index 8c22778f53..de09975039 100644 --- a/docs/remote.html.in +++ b/docs/remote.html.in @@ -130,14 +130,14 @@ to distinguish this from a local URI. Some examples: </p> <ul> - <li><code>xen+ssh://rjones@towada/</code><br/> — Connect to a + <li><code>xen+ssh://rjones@towada/system</code><br/> — Connect to a remote Xen hypervisor on host <code>towada</code> using ssh transport and ssh username <code>rjones</code>. </li> - <li><code>xen://towada/</code><br/> — Connect to a + <li><code>xen://towada/system</code><br/> — Connect to a remote Xen hypervisor on host <code>towada</code> using TLS. </li> - <li><code>xen://towada/?no_verify=1</code><br/> — Connect to a + <li><code>xen://towada/system?no_verify=1</code><br/> — Connect to a remote Xen hypervisor on host <code>towada</code> using TLS. Do not verify the server's certificate. </li> diff --git a/docs/uri.html.in b/docs/uri.html.in index 5df73613ae..6da9eb9746 100644 --- a/docs/uri.html.in +++ b/docs/uri.html.in @@ -107,7 +107,7 @@ In virt-install use the <code>--connect=</code><i>URI</i> option: virt-install <b>--connect=test:///default</b> <i>[other options]</i> </pre> <h2> - <a id="URI_xen">xen:/// URI</a> + <a id="URI_xen">xen:///system URI</a> </h2> <p> <i>This section describes a feature which is new in libvirt > @@ -115,7 +115,7 @@ virt-install <b>--connect=test:///default</b> <i>[other options]</i> </p> <p> To access a Xen hypervisor running on the local machine -use the URI <code>xen:///</code>. +use the URI <code>xen:///system</code>. </p> <h2> <a id="URI_qemu">qemu:///... QEMU and KVM URIs</a> @@ -167,10 +167,10 @@ a NULL URI for a local connection. For example: </tr> <tr> <td> - <code>xen:///</code> + <code>xen:///system</code> </td> <td> - <code>xen://oirase/</code> + <code>xen://oirase/system</code> </td> <td> Connect to the Xen hypervisor running on host <code>oirase</code> using TLS. </td> @@ -187,10 +187,10 @@ a NULL URI for a local connection. For example: </tr> <tr> <td> - <code>xen:///</code> + <code>xen:///system</code> </td> <td> - <code>xen+ssh://oirase/</code> + <code>xen+ssh://oirase/system</code> </td> <td> Connect to the Xen hypervisor running on host <code>oirase</code> by going over an <code>ssh</code> connection. </td> @@ -251,7 +251,7 @@ In any case applications linked to libvirt can continue to pass user to override the URI, either by constructing one or by allowing the user to type a URI in directly (if that is appropriate). If your application wishes to connect specifically to a Xen hypervisor, then -for future proofing it should choose a full <a href="#URI_xen"><code>xen:///</code> URI</a>. +for future proofing it should choose a full <a href="#URI_xen"><code>xen:///system</code> URI</a>. </p> <h3> <a id="URI_legacy_xen">Legacy: <code>"xen"</code></a> @@ -259,7 +259,7 @@ for future proofing it should choose a full <a href="#URI_xen"><code>xen:///</co <p> Another legacy URI is to specify name as the string <code>"xen"</code>. This will continue to refer to the Xen -hypervisor. However you should prefer a full <a href="#URI_xen"><code>xen:///</code> URI</a> in all future code. +hypervisor. However you should prefer a full <a href="#URI_xen"><code>xen:///system</code> URI</a> in all future code. </p> </body> </html> diff --git a/src/libvirt.c b/src/libvirt.c index b7bcf80224..51acbbf83e 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -954,15 +954,15 @@ virConnectOpenInternal(const char *name, goto failed; } - /* Convert xen -> xen:/// for back compat */ + /* Convert xen -> xen:///system for back compat */ if (name && STRCASEEQ(name, "xen")) - name = "xen:///"; + name = "xen:///system"; - /* Convert xen:// -> xen:/// because xmlParseURI cannot parse the + /* Convert xen:// -> xen:///system because xmlParseURI cannot parse the * former. This allows URIs such as xen://localhost to work. */ if (name && STREQ(name, "xen://")) - name = "xen:///"; + name = "xen:///system"; /* * If no URI is passed, then check for an environment string if not diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index de70abaaae..c559bf6514 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -839,7 +839,7 @@ libxlConnectOpen(virConnectPtr conn, if (libxl_driver == NULL) return VIR_DRV_OPEN_DECLINED; - if (!(conn->uri = virURIParse("xen:///"))) + if (!(conn->uri = virURIParse("xen:///system"))) return VIR_DRV_OPEN_ERROR; } else { /* Only xen scheme */ @@ -863,7 +863,7 @@ libxlConnectOpen(virConnectPtr conn, STRNEQ(conn->uri->path, "/") && STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected Xen URI path '%s', try xen:///"), + _("unexpected Xen URI path '%s', try xen:///system"), NULLSTR(conn->uri->path)); return VIR_DRV_OPEN_ERROR; } diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf index 08204ca039..4e11464d2d 100644 --- a/tools/libvirt-guests.sysconf +++ b/tools/libvirt-guests.sysconf @@ -1,5 +1,5 @@ # URIs to check for running guests -# example: URIS='default xen:/// vbox+tcp://host/system lxc:///' +# example: URIS='default xen:///system vbox+tcp://host/system lxc:///' #URIS=default # action taken on host boot diff --git a/tools/virsh.pod b/tools/virsh.pod index 9d69a75244..4d25ac5d9b 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -254,7 +254,7 @@ common are: =over 4 -=item xen:/// +=item xen:///system this is used to connect to the local Xen hypervisor -- 2.14.3

Historically we have used a bare lxc:/// URI for connecting to LXC. This is different from our practice with QEMU, UML, Parallels, Libxl, BHyve and VirtualBox drivers, which all use a path of '/system' or '/session' or both. By making LXC allow '/system', we have fully standardized on the use of either '/system' or '/session' for all the stateful drivers that run inside libvirtd. Support for lxc:/// is of course maintained for back-compat. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- docs/drvlxc.html.in | 34 +++++++++++++++++----------------- examples/lxcconvert/virt-lxc-convert | 2 +- src/lxc/lxc_driver.c | 7 ++++--- src/lxc/lxc_process.c | 4 ++-- tools/libvirt-guests.sysconf | 2 +- tools/virsh.pod | 2 +- tools/virt-login-shell.c | 2 +- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/docs/drvlxc.html.in b/docs/drvlxc.html.in index 58a336ed30..44c49609d9 100644 --- a/docs/drvlxc.html.in +++ b/docs/drvlxc.html.in @@ -308,8 +308,8 @@ unit file specifies how systemd will start the libvirt LXC container Description=My little container [Service] -ExecStart=/usr/bin/virsh -c lxc:/// start --pass-fds 3 mycontainer -ExecStop=/usr/bin/virsh -c lxc:/// destroy mycontainer +ExecStart=/usr/bin/virsh -c lxc:///system start --pass-fds 3 mycontainer +ExecStop=/usr/bin/virsh -c lxc:///system destroy mycontainer Type=oneshot RemainAfterExit=yes KillMode=none @@ -621,9 +621,9 @@ The use of namespace passthrough requires libvirt >= 1.2.19 As with any libvirt virtualization driver, LXC containers can be managed via a wide variety of libvirt based tools. At the lowest level the <code>virsh</code> command can be used to perform many -tasks, by passing the <code>-c lxc:///</code> argument. As an +tasks, by passing the <code>-c lxc:///system</code> argument. As an alternative to repeating the URI with every command, the <code>LIBVIRT_DEFAULT_URI</code> -environment variable can be set to <code>lxc:///</code>. The +environment variable can be set to <code>lxc:///system</code>. The examples that follow outline some common operations with virsh and LXC. For further details about usage of virsh consult its manual page. @@ -637,7 +637,7 @@ document and loads it into libvirt, saving the configuration on disk </p> <pre> -# virsh -c lxc:/// define myguest.xml +# virsh -c lxc:///system define myguest.xml </pre> <h3><a id="usageView">Viewing container configuration</a></h3> @@ -652,7 +652,7 @@ using the <code>--inactive</code> flag </p> <pre> -# virsh -c lxc:/// dumpxml myguest +# virsh -c lxc:///system dumpxml myguest </pre> <h3><a id="usageStart">Starting containers</a></h3> @@ -663,7 +663,7 @@ container from a previously defined persistent configuration </p> <pre> -# virsh -c lxc:/// start myguest +# virsh -c lxc:///system start myguest </pre> <p> @@ -673,7 +673,7 @@ by libvirt, using the <code>virsh create</code> command. </p> <pre> -# virsh -c lxc:/// create myguest.xml +# virsh -c lxc:///system create myguest.xml </pre> @@ -689,7 +689,7 @@ to PID 1 inside the container. </p> <pre> -# virsh -c lxc:/// shutdown myguest +# virsh -c lxc:///system shutdown myguest </pre> <p> @@ -698,7 +698,7 @@ request, it can be forcibly stopped using the <code>virsh destroy</code> </p> <pre> -# virsh -c lxc:/// destroy myguest +# virsh -c lxc:///system destroy myguest </pre> @@ -714,7 +714,7 @@ to PID 1 inside the container. </p> <pre> -# virsh -c lxc:/// reboot myguest +# virsh -c lxc:///system reboot myguest </pre> <h3><a id="usageDelete">Undefining (deleting) a container configuration</a></h3> @@ -726,7 +726,7 @@ running, this will turn it into a "transient" guest. </p> <pre> -# virsh -c lxc:/// undefine myguest +# virsh -c lxc:///system undefine myguest </pre> <h3><a id="usageConnect">Connecting to a container console</a></h3> @@ -737,7 +737,7 @@ to the text console associated with a container. </p> <pre> -# virsh -c lxc:/// console myguest +# virsh -c lxc:///system console myguest </pre> <p> @@ -749,7 +749,7 @@ as 'console0', 'console1', 'console2', etc. </p> <pre> -# virsh -c lxc:/// console myguest --devname console1 +# virsh -c lxc:///system console myguest --devname console1 </pre> <h3><a id="usageEnter">Running commands in a container</a></h3> @@ -761,7 +761,7 @@ and then execute an arbitrary command. </p> <pre> -# virsh -c lxc:/// lxc-enter-namespace myguest -- /bin/ls -al /dev +# virsh -c lxc:///system lxc-enter-namespace myguest -- /bin/ls -al /dev </pre> <h3><a id="usageTop">Monitoring container utilization</a></h3> @@ -773,7 +773,7 @@ host </p> <pre> -# virt-top -c lxc:/// +# virt-top -c lxc:///system </pre> <h3><a id="usageConvert">Converting LXC container configuration</a></h3> @@ -784,7 +784,7 @@ most of the LXC container configuration into a domain XML fragment </p> <pre> -# virsh -c lxc:/// domxml-from-native lxc-tools /var/lib/lxc/myguest/config +# virsh -c lxc:///system domxml-from-native lxc-tools /var/lib/lxc/myguest/config </pre> <p> diff --git a/examples/lxcconvert/virt-lxc-convert b/examples/lxcconvert/virt-lxc-convert index e62172eea4..5260eb708f 100644 --- a/examples/lxcconvert/virt-lxc-convert +++ b/examples/lxcconvert/virt-lxc-convert @@ -123,5 +123,5 @@ if test -z "$mem_limit"; then echo "lxc.cgroup.memory.limit_in_bytes = $memory" >> "$conf_new" fi -virsh -c lxc:/// domxml-from-native lxc-tools $conf_new +virsh -c lxc:///system domxml-from-native lxc-tools $conf_new exit $? diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4f600f3df7..cb481bf20a 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -164,7 +164,7 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, if (lxc_driver == NULL) return VIR_DRV_OPEN_DECLINED; - if (!(conn->uri = virURIParse("lxc:///"))) + if (!(conn->uri = virURIParse("lxc:///system"))) return VIR_DRV_OPEN_ERROR; } else { if (conn->uri->scheme == NULL || @@ -177,9 +177,10 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, /* If path isn't '/' then they typoed, tell them correct path */ if (conn->uri->path != NULL && - STRNEQ(conn->uri->path, "/")) { + STRNEQ(conn->uri->path, "/") && + STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected LXC URI path '%s', try lxc:///"), + _("Unexpected LXC URI path '%s', try lxc:///system"), conn->uri->path); return VIR_DRV_OPEN_ERROR; } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 85c7bcc321..99c41014ee 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -109,7 +109,7 @@ virLXCProcessReboot(virLXCDriverPtr driver, virObjectRef(conn); autodestroy = true; } else { - conn = virConnectOpen("lxc:///"); + conn = virConnectOpen("lxc:///system"); /* Ignoring NULL conn which is mostly harmless here */ } @@ -1629,7 +1629,7 @@ virLXCProcessAutostartAll(virLXCDriverPtr driver) * to lookup the bridge associated with a virtual * network */ - virConnectPtr conn = virConnectOpen("lxc:///"); + virConnectPtr conn = virConnectOpen("lxc:///system"); /* Ignoring NULL conn which is mostly harmless here */ struct virLXCProcessAutostartData data = { driver, conn }; diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf index 4e11464d2d..669b046507 100644 --- a/tools/libvirt-guests.sysconf +++ b/tools/libvirt-guests.sysconf @@ -1,5 +1,5 @@ # URIs to check for running guests -# example: URIS='default xen:///system vbox+tcp://host/system lxc:///' +# example: URIS='default xen:///system vbox+tcp://host/system lxc:///system' #URIS=default # action taken on host boot diff --git a/tools/virsh.pod b/tools/virsh.pod index 4d25ac5d9b..929958a953 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -266,7 +266,7 @@ connect locally as root to the daemon supervising QEMU and KVM domains connect locally as a normal user to his own set of QEMU and KVM domains -=item lxc:/// +=item lxc:///system connect to a local linux container diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c index 016e2b6d4e..b68c393026 100644 --- a/tools/virt-login-shell.c +++ b/tools/virt-login-shell.c @@ -253,7 +253,7 @@ main(int argc, char **argv) if (virConfGetValueBool(conf, "auto_shell", &autoshell) < 0) goto cleanup; - conn = virConnectOpen("lxc:///"); + conn = virConnectOpen("lxc:///system"); if (!conn) goto cleanup; -- 2.14.3

Currently the virDrvConnectOpen method is supposed to handle both opening an explicit URI and auto-probing a driver if no URI is given. Introduce a dedicated virDrvConnectURIProbe method to enable the probing functionality to be split from the driver opening functionality. It is still possible for NULL to be passed to the virDrvConnectOpen method after this change, because the remote driver needs special handling to enable probing of the URI against a remote libvirtd daemon. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- docs/hvsupport.pl | 6 +++--- src/bhyve/bhyve_driver.c | 18 +++++++++++++----- src/driver-hypervisor.h | 4 ++++ src/libvirt.c | 13 +++++++++++++ src/libxl/libxl_driver.c | 17 ++++++++++++----- src/lxc/lxc_driver.c | 17 ++++++++++++----- src/openvz/openvz_driver.c | 24 ++++++++++++++++-------- src/qemu/qemu_driver.c | 30 +++++++++++++++++++++--------- src/uml/uml_driver.c | 20 +++++++++++++------- src/vbox/vbox_common.c | 13 ++++++++++--- 10 files changed, 117 insertions(+), 45 deletions(-) diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl index fc6eb1f152..a2b980c502 100755 --- a/docs/hvsupport.pl +++ b/docs/hvsupport.pl @@ -184,7 +184,7 @@ foreach my $drivertable (@drivertable) { my $api; if (exists $apis{"vir$name"}) { $api = "vir$name"; - } elsif ($name =~ /\w+(Open|Close)/) { + } elsif ($name =~ /\w+(Open|Close|URIProbe)/) { next; } else { die "driver $name does not have a public API"; @@ -241,12 +241,12 @@ foreach my $src (@srcs) { next if $api eq "no" || $api eq "name"; - die "Method $meth in $src is missing version" unless defined $vers; + die "Method $meth in $src is missing version" unless defined $vers || $api eq "connectURIProbe"; die "Driver method for $api is NULL in $src" if $meth eq "NULL"; if (!exists($groups{$ingrp}->{apis}->{$api})) { - next if $api =~ /\w(Open|Close)/; + next if $api =~ /\w(Open|Close|URIProbe)/; die "Found unexpected method $api in $ingrp\n"; } diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 849d3abcd3..a0bc400480 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -180,6 +180,17 @@ bhyveDomObjFromDomain(virDomainPtr domain) return vm; } + +static int +bhyveConnectURIProbe(char **uri) +{ + if (bhyve_driver == NULL) + return 0; + + return VIR_STRDUP(*uri, "bhyve:///system"); +} + + static virDrvOpenStatus bhyveConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, @@ -189,11 +200,7 @@ bhyveConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (conn->uri == NULL) { - if (bhyve_driver == NULL) - return VIR_DRV_OPEN_DECLINED; - - if (!(conn->uri = virURIParse("bhyve:///system"))) - return VIR_DRV_OPEN_ERROR; + return VIR_DRV_OPEN_DECLINED; } else { if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "bhyve")) return VIR_DRV_OPEN_DECLINED; @@ -1689,6 +1696,7 @@ bhyveConnectGetDomainCapabilities(virConnectPtr conn, static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", + .connectURIProbe = bhyveConnectURIProbe, .connectOpen = bhyveConnectOpen, /* 1.2.2 */ .connectClose = bhyveConnectClose, /* 1.2.2 */ .connectGetVersion = bhyveConnectGetVersion, /* 1.2.2 */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index ce0e2b2525..e71a72a441 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -25,6 +25,9 @@ # error "Don't include this file directly, only use driver.h" # endif +typedef int +(*virDrvConnectURIProbe)(char **uri); + typedef virDrvOpenStatus (*virDrvConnectOpen)(virConnectPtr conn, virConnectAuthPtr auth, @@ -1300,6 +1303,7 @@ typedef virHypervisorDriver *virHypervisorDriverPtr; */ struct _virHypervisorDriver { const char *name; /* the name of the driver */ + virDrvConnectURIProbe connectURIProbe; virDrvConnectOpen connectOpen; virDrvConnectClose connectClose; virDrvConnectSupportsFeature connectSupportsFeature; diff --git a/src/libvirt.c b/src/libvirt.c index 51acbbf83e..d87efca625 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -975,6 +975,19 @@ virConnectOpenInternal(const char *name, } else { if (virConnectGetDefaultURI(conf, &uristr) < 0) goto failed; + + if (uristr == NULL) { + VIR_DEBUG("Trying to probe for default URI"); + for (i = 0; i < virConnectDriverTabCount && uristr == NULL; i++) { + if (virConnectDriverTab[i]->hypervisorDriver->connectURIProbe) { + if (virConnectDriverTab[i]->hypervisorDriver->connectURIProbe(&uristr) < 0) + goto failed; + VIR_DEBUG("%s driver URI probe returned '%s'", + virConnectDriverTab[i]->hypervisorDriver->name, + uristr ? uristr : ""); + } + } + } } if (uristr) { diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index c559bf6514..d574fa446e 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -827,6 +827,16 @@ libxlStateReload(void) } +static int +libxlConnectURIProbe(char **uri) +{ + if (libxl_driver == NULL) + return 0; + + return VIR_STRDUP(*uri, "xen:///system"); +} + + static virDrvOpenStatus libxlConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, @@ -836,11 +846,7 @@ libxlConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (conn->uri == NULL) { - if (libxl_driver == NULL) - return VIR_DRV_OPEN_DECLINED; - - if (!(conn->uri = virURIParse("xen:///system"))) - return VIR_DRV_OPEN_ERROR; + return VIR_DRV_OPEN_DECLINED; } else { /* Only xen scheme */ if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "xen")) @@ -6466,6 +6472,7 @@ libxlConnectBaselineCPU(virConnectPtr conn, static virHypervisorDriver libxlHypervisorDriver = { .name = LIBXL_DRIVER_NAME, + .connectURIProbe = libxlConnectURIProbe, .connectOpen = libxlConnectOpen, /* 0.9.0 */ .connectClose = libxlConnectClose, /* 0.9.0 */ .connectGetType = libxlConnectGetType, /* 0.9.0 */ diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index cb481bf20a..7fbeabc994 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -152,6 +152,16 @@ lxcDomObjFromDomain(virDomainPtr domain) /* Functions */ +static int +lxcConnectURIProbe(char **uri) +{ + if (lxc_driver == NULL) + return 0; + + return VIR_STRDUP(*uri, "lxc:///system"); +} + + static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConfPtr conf ATTRIBUTE_UNUSED, @@ -161,11 +171,7 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, /* Verify uri was specified */ if (conn->uri == NULL) { - if (lxc_driver == NULL) - return VIR_DRV_OPEN_DECLINED; - - if (!(conn->uri = virURIParse("lxc:///system"))) - return VIR_DRV_OPEN_ERROR; + return VIR_DRV_OPEN_DECLINED; } else { if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "lxc")) @@ -5533,6 +5539,7 @@ lxcDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) /* Function Tables */ static virHypervisorDriver lxcHypervisorDriver = { .name = LXC_DRIVER_NAME, + .connectURIProbe = lxcConnectURIProbe, .connectOpen = lxcConnectOpen, /* 0.4.2 */ .connectClose = lxcConnectClose, /* 0.4.2 */ .connectSupportsFeature = lxcConnectSupportsFeature, /* 1.2.2 */ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index f1132490e8..f30db8eec3 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1420,6 +1420,20 @@ openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) return openvzDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE); } + +static int +openvzConnectURIProbe(char **uri) +{ + if (!virFileExists("/proc/vz")) + return 0; + + if (access("/proc/vz", W_OK) < 0) + return 0; + + return VIR_STRDUP(*uri, "openvz:///system"); +} + + static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConfPtr conf ATTRIBUTE_UNUSED, @@ -1430,14 +1444,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (conn->uri == NULL) { - if (!virFileExists("/proc/vz")) - return VIR_DRV_OPEN_DECLINED; - - if (access("/proc/vz", W_OK) < 0) - return VIR_DRV_OPEN_DECLINED; - - if (!(conn->uri = virURIParse("openvz:///system"))) - return VIR_DRV_OPEN_ERROR; + return VIR_DRV_OPEN_DECLINED; } else { /* If scheme isn't 'openvz', then its for another driver */ if (conn->uri->scheme == NULL || @@ -2585,6 +2592,7 @@ openvzDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) static virHypervisorDriver openvzHypervisorDriver = { .name = "OPENVZ", + .connectURIProbe = openvzConnectURIProbe, .connectOpen = openvzConnectOpen, /* 0.3.1 */ .connectClose = openvzConnectClose, /* 0.3.1 */ .connectGetType = openvzConnectGetType, /* 0.3.1 */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5c31dfdd58..99ec51f304 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1115,6 +1115,25 @@ qemuStateCleanup(void) } +static int +qemuConnectURIProbe(char **uri) +{ + virQEMUDriverConfigPtr cfg = NULL; + int ret = -1; + + if (qemu_driver == NULL) + return 0; + + cfg = virQEMUDriverGetConfig(qemu_driver); + if (VIR_STRDUP(*uri, cfg->uri) < 0) + goto cleanup; + + ret = 0; + cleanup: + virObjectUnref(cfg); + return ret; +} + static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConfPtr conf ATTRIBUTE_UNUSED, @@ -1125,15 +1144,7 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (conn->uri == NULL) { - if (qemu_driver == NULL) { - ret = VIR_DRV_OPEN_DECLINED; - goto cleanup; - } - - cfg = virQEMUDriverGetConfig(qemu_driver); - - if (!(conn->uri = virURIParse(cfg->uri))) - goto cleanup; + return VIR_DRV_OPEN_DECLINED; } else { /* If URI isn't 'qemu' its definitely not for us */ if (conn->uri->scheme == NULL || @@ -21340,6 +21351,7 @@ qemuDomainSetLifecycleAction(virDomainPtr dom, static virHypervisorDriver qemuHypervisorDriver = { .name = QEMU_DRIVER_NAME, + .connectURIProbe = qemuConnectURIProbe, .connectOpen = qemuConnectOpen, /* 0.2.0 */ .connectClose = qemuConnectClose, /* 0.2.0 */ .connectSupportsFeature = qemuConnectSupportsFeature, /* 0.5.0 */ diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index ab7fa7f273..63350908dd 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1185,6 +1185,17 @@ static void umlShutdownVMDaemon(struct uml_driver *driver, } +static int umlConnectURIProbe(char **uri) +{ + if (uml_driver == NULL) + return 0; + + return VIR_STRDUP(*uri, uml_driver->privileged ? + "uml:///system" : + "uml:///session"); +} + + static virDrvOpenStatus umlConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConfPtr conf ATTRIBUTE_UNUSED, @@ -1193,13 +1204,7 @@ static virDrvOpenStatus umlConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (conn->uri == NULL) { - if (uml_driver == NULL) - return VIR_DRV_OPEN_DECLINED; - - if (!(conn->uri = virURIParse(uml_driver->privileged ? - "uml:///system" : - "uml:///session"))) - return VIR_DRV_OPEN_ERROR; + return VIR_DRV_OPEN_DECLINED; } else { if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "uml")) @@ -2947,6 +2952,7 @@ umlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) static virHypervisorDriver umlHypervisorDriver = { .name = "UML", + .connectURIProbe = umlConnectURIProbe, .connectOpen = umlConnectOpen, /* 0.5.0 */ .connectClose = umlConnectClose, /* 0.5.0 */ .connectGetType = umlConnectGetType, /* 0.5.0 */ diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 3bcca43d32..ef71e650c6 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -499,6 +499,13 @@ vboxAttachStorageControllers(virDomainDefPtr def, } +static int +vboxConnectURIProbe(char **uri) +{ + return VIR_STRDUP(*uri, geteuid() ? "vbox:///session" : "vbox:///system"); +} + + static virDrvOpenStatus vboxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, @@ -510,9 +517,8 @@ vboxConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL && - !(conn->uri = virURIParse(uid ? "vbox:///session" : "vbox:///system"))) - return VIR_DRV_OPEN_ERROR; + if (conn->uri == NULL) + return VIR_DRV_OPEN_DECLINED; if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "vbox")) @@ -7980,6 +7986,7 @@ vboxDomainSendKey(virDomainPtr dom, virHypervisorDriver vboxCommonDriver = { .name = "VBOX", + .connectURIProbe = vboxConnectURIProbe, .connectOpen = vboxConnectOpen, /* 0.6.3 */ .connectClose = vboxConnectClose, /* 0.6.3 */ .connectGetVersion = vboxConnectGetVersion, /* 0.6.3 */ -- 2.14.3

On 04/09/2018 05:45 PM, Daniel P. Berrangé wrote:
Currently the virDrvConnectOpen method is supposed to handle both opening an explicit URI and auto-probing a driver if no URI is given. Introduce a dedicated virDrvConnectURIProbe method to enable the probing functionality to be split from the driver opening functionality.
It is still possible for NULL to be passed to the virDrvConnectOpen method after this change, because the remote driver needs special handling to enable probing of the URI against a remote libvirtd daemon.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- docs/hvsupport.pl | 6 +++--- src/bhyve/bhyve_driver.c | 18 +++++++++++++----- src/driver-hypervisor.h | 4 ++++ src/libvirt.c | 13 +++++++++++++ src/libxl/libxl_driver.c | 17 ++++++++++++----- src/lxc/lxc_driver.c | 17 ++++++++++++----- src/openvz/openvz_driver.c | 24 ++++++++++++++++-------- src/qemu/qemu_driver.c | 30 +++++++++++++++++++++--------- src/uml/uml_driver.c | 20 +++++++++++++------- src/vbox/vbox_common.c | 13 ++++++++++--- 10 files changed, 117 insertions(+), 45 deletions(-)
diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl index fc6eb1f152..a2b980c502 100755 --- a/docs/hvsupport.pl +++ b/docs/hvsupport.pl @@ -184,7 +184,7 @@ foreach my $drivertable (@drivertable) { my $api; if (exists $apis{"vir$name"}) { $api = "vir$name"; - } elsif ($name =~ /\w+(Open|Close)/) { + } elsif ($name =~ /\w+(Open|Close|URIProbe)/) { next; } else { die "driver $name does not have a public API"; @@ -241,12 +241,12 @@ foreach my $src (@srcs) {
next if $api eq "no" || $api eq "name";
- die "Method $meth in $src is missing version" unless defined $vers; + die "Method $meth in $src is missing version" unless defined $vers || $api eq "connectURIProbe";
die "Driver method for $api is NULL in $src" if $meth eq "NULL";
if (!exists($groups{$ingrp}->{apis}->{$api})) { - next if $api =~ /\w(Open|Close)/; + next if $api =~ /\w(Open|Close|URIProbe)/;
die "Found unexpected method $api in $ingrp\n"; } diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 849d3abcd3..a0bc400480 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -180,6 +180,17 @@ bhyveDomObjFromDomain(virDomainPtr domain) return vm; }
+ +static int +bhyveConnectURIProbe(char **uri) +{ + if (bhyve_driver == NULL) + return 0; + + return VIR_STRDUP(*uri, "bhyve:///system"); +}
make check fails because it thinks this function (and others) is missing ACL check.
+ + static virDrvOpenStatus bhyveConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, @@ -189,11 +200,7 @@ bhyveConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
if (conn->uri == NULL) { - if (bhyve_driver == NULL) - return VIR_DRV_OPEN_DECLINED; - - if (!(conn->uri = virURIParse("bhyve:///system"))) - return VIR_DRV_OPEN_ERROR; + return VIR_DRV_OPEN_DECLINED; } else { if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "bhyve")) return VIR_DRV_OPEN_DECLINED; @@ -1689,6 +1696,7 @@ bhyveConnectGetDomainCapabilities(virConnectPtr conn,
static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", + .connectURIProbe = bhyveConnectURIProbe,
s,$, /* 4.3.0 */ Michal

On Wed, Apr 11, 2018 at 02:08:51PM +0200, Michal Privoznik wrote:
On 04/09/2018 05:45 PM, Daniel P. Berrangé wrote:
Currently the virDrvConnectOpen method is supposed to handle both opening an explicit URI and auto-probing a driver if no URI is given. Introduce a dedicated virDrvConnectURIProbe method to enable the probing functionality to be split from the driver opening functionality.
It is still possible for NULL to be passed to the virDrvConnectOpen method after this change, because the remote driver needs special handling to enable probing of the URI against a remote libvirtd daemon.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- docs/hvsupport.pl | 6 +++--- src/bhyve/bhyve_driver.c | 18 +++++++++++++----- src/driver-hypervisor.h | 4 ++++ src/libvirt.c | 13 +++++++++++++ src/libxl/libxl_driver.c | 17 ++++++++++++----- src/lxc/lxc_driver.c | 17 ++++++++++++----- src/openvz/openvz_driver.c | 24 ++++++++++++++++-------- src/qemu/qemu_driver.c | 30 +++++++++++++++++++++--------- src/uml/uml_driver.c | 20 +++++++++++++------- src/vbox/vbox_common.c | 13 ++++++++++--- 10 files changed, 117 insertions(+), 45 deletions(-)
diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl index fc6eb1f152..a2b980c502 100755 --- a/docs/hvsupport.pl +++ b/docs/hvsupport.pl @@ -184,7 +184,7 @@ foreach my $drivertable (@drivertable) { my $api; if (exists $apis{"vir$name"}) { $api = "vir$name"; - } elsif ($name =~ /\w+(Open|Close)/) { + } elsif ($name =~ /\w+(Open|Close|URIProbe)/) { next; } else { die "driver $name does not have a public API"; @@ -241,12 +241,12 @@ foreach my $src (@srcs) {
next if $api eq "no" || $api eq "name";
- die "Method $meth in $src is missing version" unless defined $vers; + die "Method $meth in $src is missing version" unless defined $vers || $api eq "connectURIProbe";
die "Driver method for $api is NULL in $src" if $meth eq "NULL";
if (!exists($groups{$ingrp}->{apis}->{$api})) { - next if $api =~ /\w(Open|Close)/; + next if $api =~ /\w(Open|Close|URIProbe)/;
die "Found unexpected method $api in $ingrp\n"; } diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 849d3abcd3..a0bc400480 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -180,6 +180,17 @@ bhyveDomObjFromDomain(virDomainPtr domain) return vm; }
+ +static int +bhyveConnectURIProbe(char **uri) +{ + if (bhyve_driver == NULL) + return 0; + + return VIR_STRDUP(*uri, "bhyve:///system"); +}
make check fails because it thinks this function (and others) is missing ACL check.
IMHO, we don't need ACLs on this. This isn't doing anything functional, and the caller will trigger the .connectOpen method next which already has an ACL check. So I think we just whitelist it diff --git a/src/check-aclrules.pl b/src/check-aclrules.pl index 5b6c711dc8..8b146d8dba 100755 --- a/src/check-aclrules.pl +++ b/src/check-aclrules.pl @@ -59,6 +59,7 @@ my %whitelist = ( "storageClose" => 1, "interfaceOpen" => 1, "interfaceClose" => 1, + "connectURIProbe" => 1, ); # Temp hack - remove it once xen driver is fixed Heh, and that last comment tells me we've got some stuff that can be purged now :-) Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Add a localOnly flag to the virConnectDriver struct which allows a driver to indicate whether it is local-only, or permits remote connections. Stateful drivers running inside libvirtd are generally local only. This allows us to remote the check for uri->server != NULL from most drivers. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 4 +--- src/driver.h | 2 ++ src/interface/interface_backend_netcf.c | 5 +---- src/interface/interface_backend_udev.c | 5 +---- src/libvirt.c | 5 +++++ src/libxl/libxl_driver.c | 5 +---- src/lxc/lxc_driver.c | 5 +---- src/network/bridge_driver.c | 5 +---- src/node_device/node_device_driver.c | 4 ---- src/node_device/node_device_hal.c | 1 + src/node_device/node_device_udev.c | 1 + src/nwfilter/nwfilter_driver.c | 5 +---- src/openvz/openvz_driver.c | 5 +---- src/qemu/qemu_driver.c | 7 +------ src/secret/secret_driver.c | 5 +---- src/storage/storage_driver.c | 5 +---- src/test/test_driver.c | 5 +---- src/uml/uml_driver.c | 6 +----- src/vbox/vbox_common.c | 4 ---- src/vbox/vbox_driver.c | 8 +++++--- src/vmware/vmware_driver.c | 5 +---- src/vz/vz_driver.c | 5 +---- 22 files changed, 29 insertions(+), 73 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index a0bc400480..cc1d4ba6fb 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -205,9 +205,6 @@ bhyveConnectOpen(virConnectPtr conn, if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "bhyve")) return VIR_DRV_OPEN_DECLINED; - if (conn->uri->server) - return VIR_DRV_OPEN_DECLINED; - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected bhyve URI path '%s', try bhyve:///system"), @@ -1754,6 +1751,7 @@ static virHypervisorDriver bhyveHypervisorDriver = { static virConnectDriver bhyveConnectDriver = { + .localOnly = true, .hypervisorDriver = &bhyveHypervisorDriver, }; diff --git a/src/driver.h b/src/driver.h index c86da85481..5fb0b523c8 100644 --- a/src/driver.h +++ b/src/driver.h @@ -79,6 +79,8 @@ typedef struct _virConnectDriver virConnectDriver; typedef virConnectDriver *virConnectDriverPtr; struct _virConnectDriver { + /* Wether driver permits a server in the URI */ + bool localOnly; virHypervisorDriverPtr hypervisorDriver; virInterfaceDriverPtr interfaceDriver; virNetworkDriverPtr networkDriver; diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index fb75a33280..3da958980f 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -167,10 +167,6 @@ netcfConnectOpen(virConnectPtr conn, if (STRNEQ_NULLABLE(conn->uri->scheme, "interface")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("interface state driver is not active")); @@ -1224,6 +1220,7 @@ static virHypervisorDriver interfaceHypervisorDriver = { static virConnectDriver interfaceConnectDriver = { + .localOnly = true, .hypervisorDriver = &interfaceHypervisorDriver, .interfaceDriver = &interfaceDriver, }; diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 47e850bc2a..2b8a9da682 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -1211,10 +1211,6 @@ udevConnectOpen(virConnectPtr conn, if (STRNEQ_NULLABLE(conn->uri->scheme, "interface")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("interface state driver is not active")); @@ -1295,6 +1291,7 @@ static virHypervisorDriver udevHypervisorDriver = { static virConnectDriver udevConnectDriver = { + .localOnly = true, .hypervisorDriver = &udevHypervisorDriver, .interfaceDriver = &udevIfaceDriver, }; diff --git a/src/libvirt.c b/src/libvirt.c index d87efca625..2b2b3ed425 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1068,6 +1068,11 @@ virConnectOpenInternal(const char *name, VIR_DEBUG("trying driver %zu (%s) ...", i, virConnectDriverTab[i]->hypervisorDriver->name); + if (virConnectDriverTab[i]->localOnly && ret->uri && ret->uri->server) { + VIR_DEBUG("Server present, skipping local only driver"); + continue; + } + ret->driver = virConnectDriverTab[i]->hypervisorDriver; ret->interfaceDriver = virConnectDriverTab[i]->interfaceDriver; ret->networkDriver = virConnectDriverTab[i]->networkDriver; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index d574fa446e..ce4741cf4c 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -852,10 +852,6 @@ libxlConnectOpen(virConnectPtr conn, if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "xen")) return VIR_DRV_OPEN_DECLINED; - /* If server name is given, its for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - /* Error if xen or libxl scheme specified but driver not started. */ if (libxl_driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -6582,6 +6578,7 @@ static virHypervisorDriver libxlHypervisorDriver = { }; static virConnectDriver libxlConnectDriver = { + .localOnly = true, .hypervisorDriver = &libxlHypervisorDriver, }; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 7fbeabc994..7a3e720d16 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -177,10 +177,6 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, STRNEQ(conn->uri->scheme, "lxc")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - /* If path isn't '/' then they typoed, tell them correct path */ if (conn->uri->path != NULL && STRNEQ(conn->uri->path, "/") && @@ -5633,6 +5629,7 @@ static virHypervisorDriver lxcHypervisorDriver = { }; static virConnectDriver lxcConnectDriver = { + .localOnly = true, .hypervisorDriver = &lxcHypervisorDriver, }; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d326923d81..ca48a0358c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -886,10 +886,6 @@ networkConnectOpen(virConnectPtr conn, if (STRNEQ_NULLABLE(conn->uri->scheme, "network")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (network_driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network state driver is not active")); @@ -5616,6 +5612,7 @@ static virHypervisorDriver networkHypervisorDriver = { static virConnectDriver networkConnectDriver = { + .localOnly = true, .hypervisorDriver = &networkHypervisorDriver, .networkDriver = &networkDriver, }; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 1347ce0c86..ad4938fcd6 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -62,10 +62,6 @@ nodeConnectOpen(virConnectPtr conn, if (STRNEQ_NULLABLE(conn->uri->scheme, "nodedev")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nodedev state driver is not active")); diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index 6ad56f4166..4c251da88a 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -783,6 +783,7 @@ static virHypervisorDriver halHypervisorDriver = { static virConnectDriver halConnectDriver = { + .localOnly = true, .hypervisorDriver = &halHypervisorDriver, .nodeDeviceDriver = &halNodeDeviceDriver, }; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index e87eb32a85..d89b5ff7cc 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1957,6 +1957,7 @@ static virHypervisorDriver udevHypervisorDriver = { static virConnectDriver udevConnectDriver = { + .localOnly = true, .hypervisorDriver = &udevHypervisorDriver, .nodeDeviceDriver = &udevNodeDeviceDriver, }; diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 6cc7ca699a..71aca5a968 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -379,10 +379,6 @@ nwfilterConnectOpen(virConnectPtr conn, if (STRNEQ_NULLABLE(conn->uri->scheme, "nwfilter")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nwfilter state driver is not active")); @@ -712,6 +708,7 @@ static virHypervisorDriver nwfilterHypervisorDriver = { static virConnectDriver nwfilterConnectDriver = { + .localOnly = true, .hypervisorDriver = &nwfilterHypervisorDriver, .nwfilterDriver = &nwfilterDriver, }; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index f30db8eec3..a56476475e 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1451,10 +1451,6 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, STRNEQ(conn->uri->scheme, "openvz")) return VIR_DRV_OPEN_DECLINED; - /* If server name is given, its for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - /* If path isn't /system, then they typoed, so tell them correct path */ if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/system")) { @@ -2659,6 +2655,7 @@ static virHypervisorDriver openvzHypervisorDriver = { }; static virConnectDriver openvzConnectDriver = { + .localOnly = true, .hypervisorDriver = &openvzHypervisorDriver, }; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 99ec51f304..ef890916dc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1153,12 +1153,6 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn, goto cleanup; } - /* Allow remote driver to deal with URIs with hostname server */ - if (conn->uri->server != NULL) { - ret = VIR_DRV_OPEN_DECLINED; - goto cleanup; - } - if (qemu_driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qemu state driver is not active")); @@ -21573,6 +21567,7 @@ static virHypervisorDriver qemuHypervisorDriver = { static virConnectDriver qemuConnectDriver = { + .localOnly = true, .hypervisorDriver = &qemuHypervisorDriver, }; diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 23a3c9bdad..06d116f07f 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -532,10 +532,6 @@ secretConnectOpen(virConnectPtr conn, if (STRNEQ_NULLABLE(conn->uri->scheme, "secret")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("secret state driver is not active")); @@ -662,6 +658,7 @@ static virHypervisorDriver secretHypervisorDriver = { static virConnectDriver secretConnectDriver = { + .localOnly = true, .hypervisorDriver = &secretHypervisorDriver, .secretDriver = &secretDriver, }; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 173b91b61b..7eb5fad929 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -392,10 +392,6 @@ storageConnectOpen(virConnectPtr conn, if (STRNEQ_NULLABLE(conn->uri->scheme, "storage")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage state driver is not active")); @@ -2855,6 +2851,7 @@ static virHypervisorDriver storageHypervisorDriver = { }; static virConnectDriver storageConnectDriver = { + .localOnly = true, .hypervisorDriver = &storageHypervisorDriver, .storageDriver = &storageDriver, }; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 856869c9d3..de3943406e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1460,10 +1460,6 @@ testConnectOpen(virConnectPtr conn, if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "test")) return VIR_DRV_OPEN_DECLINED; - /* Remote driver should handle these. */ - if (conn->uri->server) - return VIR_DRV_OPEN_DECLINED; - /* From this point on, the connection is for us. */ if (!conn->uri->path || conn->uri->path[0] == '\0' @@ -7065,6 +7061,7 @@ static virNodeDeviceDriver testNodeDeviceDriver = { }; static virConnectDriver testConnectDriver = { + .localOnly = true, .hypervisorDriver = &testHypervisorDriver, .interfaceDriver = &testInterfaceDriver, .networkDriver = &testNetworkDriver, diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 63350908dd..7fae561aff 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1210,11 +1210,6 @@ static virDrvOpenStatus umlConnectOpen(virConnectPtr conn, STRNEQ(conn->uri->scheme, "uml")) return VIR_DRV_OPEN_DECLINED; - /* Allow remote driver to deal with URIs with hostname server */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - - /* Check path and tell them correct path if they made a mistake */ if (uml_driver->privileged) { if (STRNEQ(conn->uri->path, "/system") && @@ -3018,6 +3013,7 @@ static virHypervisorDriver umlHypervisorDriver = { }; static virConnectDriver umlConnectDriver = { + .localOnly = true, .hypervisorDriver = ¨HypervisorDriver, }; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index ef71e650c6..886b41b0b9 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -524,10 +524,6 @@ vboxConnectOpen(virConnectPtr conn, STRNEQ(conn->uri->scheme, "vbox")) return VIR_DRV_OPEN_DECLINED; - /* Leave for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no VirtualBox driver path specified (try vbox:///session)")); diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index c10c0c492b..e3880b4826 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -60,8 +60,7 @@ static virDrvOpenStatus dummyConnectOpen(virConnectPtr conn, if (conn->uri == NULL || conn->uri->scheme == NULL || - STRNEQ(conn->uri->scheme, "vbox") || - conn->uri->server != NULL) + STRNEQ(conn->uri->scheme, "vbox")) return VIR_DRV_OPEN_DECLINED; if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { @@ -95,7 +94,10 @@ static virHypervisorDriver vboxDriverDummy = { .connectOpen = dummyConnectOpen, /* 0.6.3 */ }; -static virConnectDriver vboxConnectDriver; +static virConnectDriver vboxConnectDriver = { + .localOnly = true, + .hypervisorDriver = NULL, +}; int vboxRegister(void) { diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 8b487c4a7c..435b9ee6ff 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -140,10 +140,6 @@ vmwareConnectOpen(virConnectPtr conn, STRNEQ(conn->uri->scheme, "vmwarefusion"))) return VIR_DRV_OPEN_DECLINED; - /* If server name is given, its for remote driver */ - if (conn->uri->server != NULL) - return VIR_DRV_OPEN_DECLINED; - /* If path isn't /session, then they typoed, so tell them correct path */ if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1271,6 +1267,7 @@ static virHypervisorDriver vmwareHypervisorDriver = { }; static virConnectDriver vmwareConnectDriver = { + .localOnly = true, .hypervisorDriver = &vmwareHypervisorDriver, }; diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index a425bc8552..8842056ea4 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -374,10 +374,6 @@ vzConnectOpen(virConnectPtr conn, if (STREQ(conn->uri->scheme, "parallels") && STRNEQ(conn->driver->name, "Parallels")) return VIR_DRV_OPEN_DECLINED; - /* Remote driver should handle these. */ - if (conn->uri->server) - return VIR_DRV_OPEN_DECLINED; - /* From this point on, the connection is for us. */ if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -4143,6 +4139,7 @@ static virHypervisorDriver vzHypervisorDriver = { }; static virConnectDriver vzConnectDriver = { + .localOnly = true, .hypervisorDriver = &vzHypervisorDriver, }; -- 2.14.3

Declare what URI schemes a driver supports in its virConnectDriver struct. This allows us to skip trying to open the driver entirely if the URI scheme doesn't match. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 4 +--- src/driver.h | 6 ++++++ src/esx/esx_driver.c | 27 ++------------------------- src/hyperv/hyperv_driver.c | 22 ++-------------------- src/interface/interface_backend_netcf.c | 4 +--- src/interface/interface_backend_udev.c | 4 +--- src/libvirt.c | 24 ++++++++++++++++++++++++ src/libxl/libxl_driver.c | 5 +---- src/lxc/lxc_driver.c | 5 +---- src/network/bridge_driver.c | 4 +--- src/node_device/node_device_driver.c | 3 --- src/node_device/node_device_hal.c | 1 + src/node_device/node_device_udev.c | 1 + src/nwfilter/nwfilter_driver.c | 4 +--- src/openvz/openvz_driver.c | 6 +----- src/phyp/phyp_driver.c | 4 +--- src/qemu/qemu_driver.c | 8 +------- src/secret/secret_driver.c | 4 +--- src/storage/storage_driver.c | 4 +--- src/test/test_driver.c | 4 +--- src/uml/uml_driver.c | 5 +---- src/vbox/vbox_common.c | 4 ---- src/vbox/vbox_driver.c | 5 ++--- src/vmware/vmware_driver.c | 7 +------ src/vz/vz_driver.c | 15 ++------------- src/xenapi/xenapi_driver.c | 5 ++--- 26 files changed, 57 insertions(+), 128 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index cc1d4ba6fb..21754dfc10 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -202,9 +202,6 @@ bhyveConnectOpen(virConnectPtr conn, if (conn->uri == NULL) { return VIR_DRV_OPEN_DECLINED; } else { - if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "bhyve")) - return VIR_DRV_OPEN_DECLINED; - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected bhyve URI path '%s', try bhyve:///system"), @@ -1752,6 +1749,7 @@ static virHypervisorDriver bhyveHypervisorDriver = { static virConnectDriver bhyveConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "bhyve", NULL }, .hypervisorDriver = &bhyveHypervisorDriver, }; diff --git a/src/driver.h b/src/driver.h index 5fb0b523c8..b071a3a782 100644 --- a/src/driver.h +++ b/src/driver.h @@ -81,6 +81,12 @@ typedef virConnectDriver *virConnectDriverPtr; struct _virConnectDriver { /* Wether driver permits a server in the URI */ bool localOnly; + /* + * NULL terminated list of supported URI schemes. + * - Single element { NULL } list indicates no supported schemes + * - NULL list indicates wildcard supportnig all schemes + */ + const char **uriSchemes; virHypervisorDriverPtr hypervisorDriver; virInterfaceDriverPtr interfaceDriver; virNetworkDriverPtr networkDriver; diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 927267f1cc..9b6944ba59 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -845,7 +845,6 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) { virDrvOpenStatus result = VIR_DRV_OPEN_ERROR; - char *plus; esxPrivate *priv = NULL; char *potentialVCenterIPAddress = NULL; char vCenterIPAddress[NI_MAXHOST] = ""; @@ -853,32 +852,9 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* Decline if the URI is NULL or the scheme is NULL */ - if (!conn->uri || !conn->uri->scheme) + if (!conn->uri) return VIR_DRV_OPEN_DECLINED; - /* Decline if the scheme is not one of {vpx|esx|gsx} */ - plus = strchr(conn->uri->scheme, '+'); - - if (!plus) { - if (STRCASENEQ(conn->uri->scheme, "vpx") && - STRCASENEQ(conn->uri->scheme, "esx") && - STRCASENEQ(conn->uri->scheme, "gsx")) { - return VIR_DRV_OPEN_DECLINED; - } - } else { - if (plus - conn->uri->scheme != 3 || - (STRCASENEQLEN(conn->uri->scheme, "vpx", 3) && - STRCASENEQLEN(conn->uri->scheme, "esx", 3) && - STRCASENEQLEN(conn->uri->scheme, "gsx", 3))) { - return VIR_DRV_OPEN_DECLINED; - } - - virReportError(VIR_ERR_INVALID_ARG, - _("Transport '%s' in URI scheme is not supported, try again " - "without the transport part"), plus + 1); - return VIR_DRV_OPEN_ERROR; - } - if (STRCASENEQ(conn->uri->scheme, "vpx") && conn->uri->path && STRNEQ(conn->uri->path, "/")) { VIR_WARN("Ignoring unexpected path '%s' for non-vpx scheme '%s'", @@ -5262,6 +5238,7 @@ static virHypervisorDriver esxHypervisorDriver = { static virConnectDriver esxConnectDriver = { + .uriSchemes = (const char *[]){ "vpx", "esx", "gsx", NULL }, .hypervisorDriver = &esxHypervisorDriver, .interfaceDriver = &esxInterfaceDriver, .networkDriver = &esxNetworkDriver, diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index e512b626ea..4ad8855dcc 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -122,7 +122,6 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) { virDrvOpenStatus result = VIR_DRV_OPEN_ERROR; - char *plus; hypervPrivate *priv = NULL; char *username = NULL; char *password = NULL; @@ -130,27 +129,9 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* Decline if the URI is NULL or the scheme is NULL */ - if (conn->uri == NULL || conn->uri->scheme == NULL) + if (conn->uri == NULL) return VIR_DRV_OPEN_DECLINED; - /* Decline if the scheme is not hyperv */ - plus = strchr(conn->uri->scheme, '+'); - - if (plus == NULL) { - if (STRCASENEQ(conn->uri->scheme, "hyperv")) - return VIR_DRV_OPEN_DECLINED; - } else { - if (plus - conn->uri->scheme != 6 || - STRCASENEQLEN(conn->uri->scheme, "hyperv", 6)) { - return VIR_DRV_OPEN_DECLINED; - } - - virReportError(VIR_ERR_INVALID_ARG, - _("Transport '%s' in URI scheme is not supported, try again " - "without the transport part"), plus + 1); - return VIR_DRV_OPEN_ERROR; - } - /* Require server part */ if (conn->uri->server == NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -1685,6 +1666,7 @@ hypervDebugHandler(const char *message, debug_level_e level, static virConnectDriver hypervConnectDriver = { + .uriSchemes = (const char *[]){ "hyperv", NULL }, .hypervisorDriver = &hypervHypervisorDriver, }; diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index 3da958980f..ff3443c8e6 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -164,9 +164,6 @@ netcfConnectOpen(virConnectPtr conn, /* Only hypervisor drivers are permitted to auto-open on NULL uri */ return VIR_DRV_OPEN_DECLINED; } else { - if (STRNEQ_NULLABLE(conn->uri->scheme, "interface")) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("interface state driver is not active")); @@ -1221,6 +1218,7 @@ static virHypervisorDriver interfaceHypervisorDriver = { static virConnectDriver interfaceConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "interface", NULL }, .hypervisorDriver = &interfaceHypervisorDriver, .interfaceDriver = &interfaceDriver, }; diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 2b8a9da682..743aafd8ba 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -1208,9 +1208,6 @@ udevConnectOpen(virConnectPtr conn, /* Only hypervisor drivers are permitted to auto-open on NULL uri */ return VIR_DRV_OPEN_DECLINED; } else { - if (STRNEQ_NULLABLE(conn->uri->scheme, "interface")) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("interface state driver is not active")); @@ -1292,6 +1289,7 @@ static virHypervisorDriver udevHypervisorDriver = { static virConnectDriver udevConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "interface", NULL }, .hypervisorDriver = &udevHypervisorDriver, .interfaceDriver = &udevIfaceDriver, }; diff --git a/src/libvirt.c b/src/libvirt.c index 2b2b3ed425..cc1387341a 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1073,6 +1073,30 @@ virConnectOpenInternal(const char *name, continue; } + /* Filter drivers based on declared URI schemes */ + if (virConnectDriverTab[i]->uriSchemes && ret->uri) { + bool matchScheme = false; + size_t s; + if (!ret->uri->scheme) { + VIR_DEBUG("No URI scheme, skipping driver with URI whitelist"); + continue; + } + VIR_DEBUG("Checking for supported URI schemes"); + for (s = 0; virConnectDriverTab[i]->uriSchemes[s] != NULL; s++) { + if (STREQ(ret->uri->scheme, virConnectDriverTab[i]->uriSchemes[s])) { + VIR_DEBUG("Matched URI scheme '%s'", ret->uri->scheme); + matchScheme = true; + break; + } + } + if (!matchScheme) { + VIR_DEBUG("No matching URI scheme"); + continue; + } + } else { + VIR_DEBUG("Matching any URI scheme for '%s'", ret->uri ? ret->uri->scheme : ""); + } + ret->driver = virConnectDriverTab[i]->hypervisorDriver; ret->interfaceDriver = virConnectDriverTab[i]->interfaceDriver; ret->networkDriver = virConnectDriverTab[i]->networkDriver; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index ce4741cf4c..872790e743 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -848,10 +848,6 @@ libxlConnectOpen(virConnectPtr conn, if (conn->uri == NULL) { return VIR_DRV_OPEN_DECLINED; } else { - /* Only xen scheme */ - if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "xen")) - return VIR_DRV_OPEN_DECLINED; - /* Error if xen or libxl scheme specified but driver not started. */ if (libxl_driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -6579,6 +6575,7 @@ static virHypervisorDriver libxlHypervisorDriver = { static virConnectDriver libxlConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "xen", NULL }, .hypervisorDriver = &libxlHypervisorDriver, }; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 7a3e720d16..8b01abf75f 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -173,10 +173,6 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, if (conn->uri == NULL) { return VIR_DRV_OPEN_DECLINED; } else { - if (conn->uri->scheme == NULL || - STRNEQ(conn->uri->scheme, "lxc")) - return VIR_DRV_OPEN_DECLINED; - /* If path isn't '/' then they typoed, tell them correct path */ if (conn->uri->path != NULL && STRNEQ(conn->uri->path, "/") && @@ -5630,6 +5626,7 @@ static virHypervisorDriver lxcHypervisorDriver = { static virConnectDriver lxcConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "lxc", NULL }, .hypervisorDriver = &lxcHypervisorDriver, }; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ca48a0358c..98754d4471 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -883,9 +883,6 @@ networkConnectOpen(virConnectPtr conn, /* Only hypervisor drivers are permitted to auto-open on NULL uri */ return VIR_DRV_OPEN_DECLINED; } else { - if (STRNEQ_NULLABLE(conn->uri->scheme, "network")) - return VIR_DRV_OPEN_DECLINED; - if (network_driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network state driver is not active")); @@ -5613,6 +5610,7 @@ static virHypervisorDriver networkHypervisorDriver = { static virConnectDriver networkConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "network", NULL }, .hypervisorDriver = &networkHypervisorDriver, .networkDriver = &networkDriver, }; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index ad4938fcd6..a3e3d76dfc 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -59,9 +59,6 @@ nodeConnectOpen(virConnectPtr conn, /* Only hypervisor drivers are permitted to auto-open on NULL uri */ return VIR_DRV_OPEN_DECLINED; } else { - if (STRNEQ_NULLABLE(conn->uri->scheme, "nodedev")) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nodedev state driver is not active")); diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index 4c251da88a..2101101bc6 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -784,6 +784,7 @@ static virHypervisorDriver halHypervisorDriver = { static virConnectDriver halConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "nodedev", NULL }, .hypervisorDriver = &halHypervisorDriver, .nodeDeviceDriver = &halNodeDeviceDriver, }; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index d89b5ff7cc..de01816402 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1958,6 +1958,7 @@ static virHypervisorDriver udevHypervisorDriver = { static virConnectDriver udevConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "nodedev", NULL }, .hypervisorDriver = &udevHypervisorDriver, .nodeDeviceDriver = &udevNodeDeviceDriver, }; diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 71aca5a968..76289265a2 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -376,9 +376,6 @@ nwfilterConnectOpen(virConnectPtr conn, /* Only hypervisor drivers are permitted to auto-open on NULL uri */ return VIR_DRV_OPEN_DECLINED; } else { - if (STRNEQ_NULLABLE(conn->uri->scheme, "nwfilter")) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nwfilter state driver is not active")); @@ -709,6 +706,7 @@ static virHypervisorDriver nwfilterHypervisorDriver = { static virConnectDriver nwfilterConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "nwfilter", NULL }, .hypervisorDriver = &nwfilterHypervisorDriver, .nwfilterDriver = &nwfilterDriver, }; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index a56476475e..3eab3e47df 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1446,11 +1446,6 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, if (conn->uri == NULL) { return VIR_DRV_OPEN_DECLINED; } else { - /* If scheme isn't 'openvz', then its for another driver */ - if (conn->uri->scheme == NULL || - STRNEQ(conn->uri->scheme, "openvz")) - return VIR_DRV_OPEN_DECLINED; - /* If path isn't /system, then they typoed, so tell them correct path */ if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/system")) { @@ -2656,6 +2651,7 @@ static virHypervisorDriver openvzHypervisorDriver = { static virConnectDriver openvzConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "openvz", NULL }, .hypervisorDriver = &openvzHypervisorDriver, }; diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index cce7448abc..ddbd9144bc 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1144,9 +1144,6 @@ phypConnectOpen(virConnectPtr conn, if (!conn || !conn->uri) return VIR_DRV_OPEN_DECLINED; - if (conn->uri->scheme == NULL || STRNEQ(conn->uri->scheme, "phyp")) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->server == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing server name in phyp:// URI")); @@ -3766,6 +3763,7 @@ static virInterfaceDriver phypInterfaceDriver = { }; static virConnectDriver phypConnectDriver = { + .uriSchemes = (const char *[]){ "phyp", NULL }, .hypervisorDriver = &phypHypervisorDriver, .interfaceDriver = &phypInterfaceDriver, .storageDriver = &phypStorageDriver, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ef890916dc..8a6d3f9af0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1146,13 +1146,6 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn, if (conn->uri == NULL) { return VIR_DRV_OPEN_DECLINED; } else { - /* If URI isn't 'qemu' its definitely not for us */ - if (conn->uri->scheme == NULL || - STRNEQ(conn->uri->scheme, "qemu")) { - ret = VIR_DRV_OPEN_DECLINED; - goto cleanup; - } - if (qemu_driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qemu state driver is not active")); @@ -21568,6 +21561,7 @@ static virHypervisorDriver qemuHypervisorDriver = { static virConnectDriver qemuConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "qemu", NULL }, .hypervisorDriver = &qemuHypervisorDriver, }; diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 06d116f07f..aedfa10dcc 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -529,9 +529,6 @@ secretConnectOpen(virConnectPtr conn, /* Only hypervisor drivers are permitted to auto-open on NULL uri */ return VIR_DRV_OPEN_DECLINED; } else { - if (STRNEQ_NULLABLE(conn->uri->scheme, "secret")) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("secret state driver is not active")); @@ -659,6 +656,7 @@ static virHypervisorDriver secretHypervisorDriver = { static virConnectDriver secretConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "secret", NULL }, .hypervisorDriver = &secretHypervisorDriver, .secretDriver = &secretDriver, }; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 7eb5fad929..1a81733842 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -389,9 +389,6 @@ storageConnectOpen(virConnectPtr conn, /* Only hypervisor drivers are permitted to auto-open on NULL uri */ return VIR_DRV_OPEN_DECLINED; } else { - if (STRNEQ_NULLABLE(conn->uri->scheme, "storage")) - return VIR_DRV_OPEN_DECLINED; - if (driver == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("storage state driver is not active")); @@ -2852,6 +2849,7 @@ static virHypervisorDriver storageHypervisorDriver = { static virConnectDriver storageConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "storage", NULL }, .hypervisorDriver = &storageHypervisorDriver, .storageDriver = &storageDriver, }; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index de3943406e..7f9c7f751e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1457,9 +1457,6 @@ testConnectOpen(virConnectPtr conn, if (!conn->uri) return VIR_DRV_OPEN_DECLINED; - if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "test")) - return VIR_DRV_OPEN_DECLINED; - /* From this point on, the connection is for us. */ if (!conn->uri->path || conn->uri->path[0] == '\0' @@ -7062,6 +7059,7 @@ static virNodeDeviceDriver testNodeDeviceDriver = { static virConnectDriver testConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "test", NULL }, .hypervisorDriver = &testHypervisorDriver, .interfaceDriver = &testInterfaceDriver, .networkDriver = &testNetworkDriver, diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 7fae561aff..2315cd4d15 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1206,10 +1206,6 @@ static virDrvOpenStatus umlConnectOpen(virConnectPtr conn, if (conn->uri == NULL) { return VIR_DRV_OPEN_DECLINED; } else { - if (conn->uri->scheme == NULL || - STRNEQ(conn->uri->scheme, "uml")) - return VIR_DRV_OPEN_DECLINED; - /* Check path and tell them correct path if they made a mistake */ if (uml_driver->privileged) { if (STRNEQ(conn->uri->path, "/system") && @@ -3014,6 +3010,7 @@ static virHypervisorDriver umlHypervisorDriver = { static virConnectDriver umlConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "uml", NULL }, .hypervisorDriver = ¨HypervisorDriver, }; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 886b41b0b9..4c4c80d45b 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -520,10 +520,6 @@ vboxConnectOpen(virConnectPtr conn, if (conn->uri == NULL) return VIR_DRV_OPEN_DECLINED; - if (conn->uri->scheme == NULL || - STRNEQ(conn->uri->scheme, "vbox")) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no VirtualBox driver path specified (try vbox:///session)")); diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index e3880b4826..395fa8e3d6 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -58,9 +58,7 @@ static virDrvOpenStatus dummyConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL || - conn->uri->scheme == NULL || - STRNEQ(conn->uri->scheme, "vbox")) + if (conn->uri == NULL) return VIR_DRV_OPEN_DECLINED; if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { @@ -96,6 +94,7 @@ static virHypervisorDriver vboxDriverDummy = { static virConnectDriver vboxConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "vbox", NULL }, .hypervisorDriver = NULL, }; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 435b9ee6ff..6118e6fa13 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -134,12 +134,6 @@ vmwareConnectOpen(virConnectPtr conn, /* @TODO accept */ return VIR_DRV_OPEN_DECLINED; } else { - if (conn->uri->scheme == NULL || - (STRNEQ(conn->uri->scheme, "vmwareplayer") && - STRNEQ(conn->uri->scheme, "vmwarews") && - STRNEQ(conn->uri->scheme, "vmwarefusion"))) - return VIR_DRV_OPEN_DECLINED; - /* If path isn't /session, then they typoed, so tell them correct path */ if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1268,6 +1262,7 @@ static virHypervisorDriver vmwareHypervisorDriver = { static virConnectDriver vmwareConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "vmwareplayer", "vmwarews", "vmwarefusion", NULL }, .hypervisorDriver = &vmwareHypervisorDriver, }; diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 8842056ea4..f3047cad6c 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -361,19 +361,6 @@ vzConnectOpen(virConnectPtr conn, if (!conn->uri) return VIR_DRV_OPEN_DECLINED; - if (!conn->uri->scheme) - return VIR_DRV_OPEN_DECLINED; - - if (STRNEQ(conn->uri->scheme, "vz") && - STRNEQ(conn->uri->scheme, "parallels")) - return VIR_DRV_OPEN_DECLINED; - - if (STREQ(conn->uri->scheme, "vz") && STRNEQ(conn->driver->name, "vz")) - return VIR_DRV_OPEN_DECLINED; - - if (STREQ(conn->uri->scheme, "parallels") && STRNEQ(conn->driver->name, "Parallels")) - return VIR_DRV_OPEN_DECLINED; - /* From this point on, the connection is for us. */ if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -4140,6 +4127,7 @@ static virHypervisorDriver vzHypervisorDriver = { static virConnectDriver vzConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "vz", NULL }, .hypervisorDriver = &vzHypervisorDriver, }; @@ -4209,6 +4197,7 @@ vzRegister(void) parallelsHypervisorDriver.name = "Parallels"; parallelsConnectDriver = vzConnectDriver; parallelsConnectDriver.hypervisorDriver = ¶llelsHypervisorDriver; + parallelsConnectDriver.uriSchemes = (const char *[]){ "parallels", NULL }, if (virRegisterConnectDriver(¶llelsConnectDriver, true) < 0) return -1; diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index fb462cd3a1..86f9e7706d 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -146,10 +146,8 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL || conn->uri->scheme == NULL || - STRCASENEQ(conn->uri->scheme, "XenAPI")) { + if (conn->uri == NULL) return VIR_DRV_OPEN_DECLINED; - } if (conn->uri->server == NULL) { xenapiSessionErrorHandler(conn, VIR_ERR_INVALID_ARG, @@ -2075,6 +2073,7 @@ static virHypervisorDriver xenapiHypervisorDriver = { static virConnectDriver xenapiConnectDriver = { + .uriSchemes = (const char *[]){ "xenapi", NULL }, .hypervisorDriver = &xenapiHypervisorDriver, }; -- 2.14.3

On 04/09/2018 05:45 PM, Daniel P. Berrangé wrote:
Declare what URI schemes a driver supports in its virConnectDriver struct. This allows us to skip trying to open the driver entirely if the URI scheme doesn't match.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 4 +--- src/driver.h | 6 ++++++ src/esx/esx_driver.c | 27 ++------------------------- src/hyperv/hyperv_driver.c | 22 ++-------------------- src/interface/interface_backend_netcf.c | 4 +--- src/interface/interface_backend_udev.c | 4 +--- src/libvirt.c | 24 ++++++++++++++++++++++++ src/libxl/libxl_driver.c | 5 +---- src/lxc/lxc_driver.c | 5 +---- src/network/bridge_driver.c | 4 +--- src/node_device/node_device_driver.c | 3 --- src/node_device/node_device_hal.c | 1 + src/node_device/node_device_udev.c | 1 + src/nwfilter/nwfilter_driver.c | 4 +--- src/openvz/openvz_driver.c | 6 +----- src/phyp/phyp_driver.c | 4 +--- src/qemu/qemu_driver.c | 8 +------- src/secret/secret_driver.c | 4 +--- src/storage/storage_driver.c | 4 +--- src/test/test_driver.c | 4 +--- src/uml/uml_driver.c | 5 +---- src/vbox/vbox_common.c | 4 ---- src/vbox/vbox_driver.c | 5 ++--- src/vmware/vmware_driver.c | 7 +------ src/vz/vz_driver.c | 15 ++------------- src/xenapi/xenapi_driver.c | 5 ++--- 26 files changed, 57 insertions(+), 128 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index cc1d4ba6fb..21754dfc10 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -202,9 +202,6 @@ bhyveConnectOpen(virConnectPtr conn, if (conn->uri == NULL) { return VIR_DRV_OPEN_DECLINED; } else { - if (!conn->uri->scheme || STRNEQ(conn->uri->scheme, "bhyve")) - return VIR_DRV_OPEN_DECLINED; - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected bhyve URI path '%s', try bhyve:///system"), @@ -1752,6 +1749,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
static virConnectDriver bhyveConnectDriver = { .localOnly = true, + .uriSchemes = (const char *[]){ "bhyve", NULL },
Frankly, I don't like this typecast. But at the same time, I'm unable to come up with something better. Apart from some VIR_URI_SCHEMES() macro that would hide typecast in its internals. Michal

Ensuring that we don't call the virDrvConnectOpen method with a NULL URI means that the drivers can drop various checks for NULL URIs. These were not needed anymore since the probe functionality was split Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/bhyve/bhyve_driver.c | 26 +++++++---------- src/esx/esx_driver.c | 4 --- src/hyperv/hyperv_driver.c | 4 --- src/interface/interface_backend_netcf.c | 40 +++++++++++-------------- src/interface/interface_backend_udev.c | 40 +++++++++++-------------- src/libvirt.c | 6 +++- src/libxl/libxl_driver.c | 34 ++++++++++----------- src/lxc/lxc_driver.c | 33 +++++++++------------ src/network/bridge_driver.c | 40 +++++++++++-------------- src/node_device/node_device_driver.c | 40 +++++++++++-------------- src/nwfilter/nwfilter_driver.c | 26 +++++++---------- src/openvz/openvz_driver.c | 38 +++++++++++------------- src/phyp/phyp_driver.c | 3 -- src/qemu/qemu_driver.c | 52 +++++++++++++++------------------ src/secret/secret_driver.c | 40 +++++++++++-------------- src/storage/storage_driver.c | 40 +++++++++++-------------- src/test/test_driver.c | 4 --- src/uml/uml_driver.c | 44 +++++++++++++--------------- src/vbox/vbox_common.c | 3 -- src/vbox/vbox_driver.c | 3 -- src/vmware/vmware_driver.c | 17 ++++------- src/vz/vz_driver.c | 3 -- src/xenapi/xenapi_driver.c | 3 -- 23 files changed, 224 insertions(+), 319 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 21754dfc10..7d6439d79d 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -199,21 +199,17 @@ bhyveConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) { - return VIR_DRV_OPEN_DECLINED; - } else { - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected bhyve URI path '%s', try bhyve:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - - if (bhyve_driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("bhyve state driver is not active")); - return VIR_DRV_OPEN_ERROR; - } + if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected bhyve URI path '%s', try bhyve:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + + if (bhyve_driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("bhyve state driver is not active")); + return VIR_DRV_OPEN_ERROR; } if (virConnectOpenEnsureACL(conn) < 0) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 9b6944ba59..335d9a970d 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -851,10 +851,6 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Decline if the URI is NULL or the scheme is NULL */ - if (!conn->uri) - return VIR_DRV_OPEN_DECLINED; - if (STRCASENEQ(conn->uri->scheme, "vpx") && conn->uri->path && STRNEQ(conn->uri->path, "/")) { VIR_WARN("Ignoring unexpected path '%s' for non-vpx scheme '%s'", diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 4ad8855dcc..d02c0ac373 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -128,10 +128,6 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Decline if the URI is NULL or the scheme is NULL */ - if (conn->uri == NULL) - return VIR_DRV_OPEN_DECLINED; - /* Require server part */ if (conn->uri->server == NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index ff3443c8e6..cc2402febb 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -159,31 +159,25 @@ netcfConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - /* Only hypervisor drivers are permitted to auto-open on NULL uri */ - return VIR_DRV_OPEN_DECLINED; - } else { - if (driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("interface state driver is not active")); + if (driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("interface state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try interface:///system"), + conn->uri->path); return VIR_DRV_OPEN_ERROR; } - - if (driver->privileged) { - if (STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected interface URI path '%s', try interface:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected interface URI path '%s', try interface:///session"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try interface:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } } diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 743aafd8ba..4b975ae4b4 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -1203,31 +1203,25 @@ udevConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - /* Only hypervisor drivers are permitted to auto-open on NULL uri */ - return VIR_DRV_OPEN_DECLINED; - } else { - if (driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("interface state driver is not active")); + if (driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("interface state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try interface:///system"), + conn->uri->path); return VIR_DRV_OPEN_ERROR; } - - if (driver->privileged) { - if (STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected interface URI path '%s', try interface:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected interface URI path '%s', try interface:///session"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try interface:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } } diff --git a/src/libvirt.c b/src/libvirt.c index cc1387341a..30345af10d 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1074,9 +1074,13 @@ virConnectOpenInternal(const char *name, } /* Filter drivers based on declared URI schemes */ - if (virConnectDriverTab[i]->uriSchemes && ret->uri) { + if (virConnectDriverTab[i]->uriSchemes) { bool matchScheme = false; size_t s; + if (!ret->uri) { + VIR_DEBUG("No URI, skipping driver with URI whitelist"); + continue; + } if (!ret->uri->scheme) { VIR_DEBUG("No URI scheme, skipping driver with URI whitelist"); continue; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 872790e743..45d0c99902 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -845,26 +845,22 @@ libxlConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) { - return VIR_DRV_OPEN_DECLINED; - } else { - /* Error if xen or libxl scheme specified but driver not started. */ - if (libxl_driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("libxenlight state driver is not active")); - return VIR_DRV_OPEN_ERROR; - } + /* Error if xen or libxl scheme specified but driver not started. */ + if (libxl_driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("libxenlight state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } - /* /session isn't supported in libxenlight */ - if (conn->uri->path && - 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)); - return VIR_DRV_OPEN_ERROR; - } + /* /session isn't supported in libxenlight */ + if (conn->uri->path && + 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)); + return VIR_DRV_OPEN_ERROR; } if (virConnectOpenEnsureACL(conn) < 0) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8b01abf75f..2079dd0704 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -169,26 +169,21 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - return VIR_DRV_OPEN_DECLINED; - } else { - /* If path isn't '/' then they typoed, tell them correct path */ - if (conn->uri->path != NULL && - STRNEQ(conn->uri->path, "/") && - STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected LXC URI path '%s', try lxc:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + /* If path isn't '/' then they typoed, tell them correct path */ + if (conn->uri->path != NULL && + STRNEQ(conn->uri->path, "/") && + STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected LXC URI path '%s', try lxc:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } - /* URI was good, but driver isn't active */ - if (lxc_driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("lxc state driver is not active")); - return VIR_DRV_OPEN_ERROR; - } + /* URI was good, but driver isn't active */ + if (lxc_driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("lxc state driver is not active")); + return VIR_DRV_OPEN_ERROR; } if (virConnectOpenEnsureACL(conn) < 0) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 98754d4471..2e9191f75d 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -878,31 +878,25 @@ networkConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - /* Only hypervisor drivers are permitted to auto-open on NULL uri */ - return VIR_DRV_OPEN_DECLINED; - } else { - if (network_driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("network state driver is not active")); + if (network_driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("network state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (network_driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected network URI path '%s', try network:///system"), + conn->uri->path); return VIR_DRV_OPEN_ERROR; } - - if (network_driver->privileged) { - if (STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected network URI path '%s', try network:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected network URI path '%s', try network:///session"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected network URI path '%s', try network:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } } diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index a3e3d76dfc..61afa1f8eb 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -54,31 +54,25 @@ nodeConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - /* Only hypervisor drivers are permitted to auto-open on NULL uri */ - return VIR_DRV_OPEN_DECLINED; - } else { - if (driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("nodedev state driver is not active")); + if (driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("nodedev state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected nodedev URI path '%s', try nodedev:///system"), + conn->uri->path); return VIR_DRV_OPEN_ERROR; } - - if (driver->privileged) { - if (STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected nodedev URI path '%s', try nodedev:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected nodedev URI path '%s', try nodedev:///session"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected nodedev URI path '%s', try nodedev:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } } diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 76289265a2..542de03596 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -371,23 +371,17 @@ nwfilterConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - /* Only hypervisor drivers are permitted to auto-open on NULL uri */ - return VIR_DRV_OPEN_DECLINED; - } else { - if (driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("nwfilter state driver is not active")); - return VIR_DRV_OPEN_ERROR; - } + if (driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("nwfilter state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } - if (STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected nwfilter URI path '%s', try nwfilter:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected nwfilter URI path '%s', try nwfilter:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } if (virConnectOpenEnsureACL(conn) < 0) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 3eab3e47df..33893ac009 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1443,29 +1443,25 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) { - return VIR_DRV_OPEN_DECLINED; - } else { - /* If path isn't /system, then they typoed, so tell them correct path */ - if (conn->uri->path == NULL || - STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected OpenVZ URI path '%s', try openvz:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + /* If path isn't /system, then they typoed, so tell them correct path */ + if (conn->uri->path == NULL || + STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected OpenVZ URI path '%s', try openvz:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } - if (!virFileExists("/proc/vz")) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("OpenVZ control file /proc/vz does not exist")); - return VIR_DRV_OPEN_ERROR; - } + if (!virFileExists("/proc/vz")) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("OpenVZ control file /proc/vz does not exist")); + return VIR_DRV_OPEN_ERROR; + } - if (access("/proc/vz", W_OK) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("OpenVZ control file /proc/vz is not accessible")); - return VIR_DRV_OPEN_ERROR; - } + if (access("/proc/vz", W_OK) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("OpenVZ control file /proc/vz is not accessible")); + return VIR_DRV_OPEN_ERROR; } /* We now know the URI is definitely for this driver, so beyond diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index ddbd9144bc..55d459df5c 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1141,9 +1141,6 @@ phypConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (!conn || !conn->uri) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->server == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing server name in phyp:// URI")); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8a6d3f9af0..e677bf13b5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1143,38 +1143,34 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn, virDrvOpenStatus ret = VIR_DRV_OPEN_ERROR; virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) { - return VIR_DRV_OPEN_DECLINED; - } else { - if (qemu_driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qemu state driver is not active")); - goto cleanup; - } + if (qemu_driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("qemu state driver is not active")); + goto cleanup; + } + + cfg = virQEMUDriverGetConfig(qemu_driver); + if (conn->uri->path == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("no QEMU URI path given, try %s"), + cfg->uri); + goto cleanup; + } - cfg = virQEMUDriverGetConfig(qemu_driver); - if (conn->uri->path == NULL) { + if (virQEMUDriverIsPrivileged(qemu_driver)) { + if (STRNEQ(conn->uri->path, "/system") && + STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("no QEMU URI path given, try %s"), - cfg->uri); + _("unexpected QEMU URI path '%s', try qemu:///system"), + conn->uri->path); goto cleanup; } - - if (virQEMUDriverIsPrivileged(qemu_driver)) { - if (STRNEQ(conn->uri->path, "/system") && - STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected QEMU URI path '%s', try qemu:///system"), - conn->uri->path); - goto cleanup; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected QEMU URI path '%s', try qemu:///session"), - conn->uri->path); - goto cleanup; - } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected QEMU URI path '%s', try qemu:///session"), + conn->uri->path); + goto cleanup; } } diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index aedfa10dcc..02fcaece35 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -524,31 +524,25 @@ secretConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - /* Only hypervisor drivers are permitted to auto-open on NULL uri */ - return VIR_DRV_OPEN_DECLINED; - } else { - if (driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("secret state driver is not active")); + if (driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("secret state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected secret URI path '%s', try secret:///system"), + conn->uri->path); return VIR_DRV_OPEN_ERROR; } - - if (driver->privileged) { - if (STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected secret URI path '%s', try secret:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected secret URI path '%s', try secret:///session"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected secret URI path '%s', try secret:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 1a81733842..6104276730 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -384,31 +384,25 @@ storageConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - /* Verify uri was specified */ - if (conn->uri == NULL) { - /* Only hypervisor drivers are permitted to auto-open on NULL uri */ - return VIR_DRV_OPEN_DECLINED; - } else { - if (driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("storage state driver is not active")); + if (driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("storage state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected storage URI path '%s', try storage:///system"), + conn->uri->path); return VIR_DRV_OPEN_ERROR; } - - if (driver->privileged) { - if (STRNEQ(conn->uri->path, "/system")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected storage URI path '%s', try storage:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected storage URI path '%s', try storage:///session"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected storage URI path '%s', try storage:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 7f9c7f751e..56d496a849 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1454,10 +1454,6 @@ testConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (!conn->uri) - return VIR_DRV_OPEN_DECLINED; - - /* From this point on, the connection is for us. */ if (!conn->uri->path || conn->uri->path[0] == '\0' || (conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) { diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 2315cd4d15..ac168ce77b 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1203,35 +1203,31 @@ static virDrvOpenStatus umlConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) { - return VIR_DRV_OPEN_DECLINED; - } else { - /* Check path and tell them correct path if they made a mistake */ - if (uml_driver->privileged) { - if (STRNEQ(conn->uri->path, "/system") && - STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected UML URI path '%s', try uml:///system"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } - } else { - if (STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected UML URI path '%s', try uml:///session"), - conn->uri->path); - return VIR_DRV_OPEN_ERROR; - } + /* Check path and tell them correct path if they made a mistake */ + if (uml_driver->privileged) { + if (STRNEQ(conn->uri->path, "/system") && + STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected UML URI path '%s', try uml:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; } - - /* URI was good, but driver isn't active */ - if (uml_driver == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("uml state driver is not active")); + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected UML URI path '%s', try uml:///session"), + conn->uri->path); return VIR_DRV_OPEN_ERROR; } } + /* URI was good, but driver isn't active */ + if (uml_driver == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("uml state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + if (virConnectOpenEnsureACL(conn) < 0) return VIR_DRV_OPEN_ERROR; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 4c4c80d45b..05cf9ad0de 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -517,9 +517,6 @@ vboxConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no VirtualBox driver path specified (try vbox:///session)")); diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index 395fa8e3d6..9e95ab01c5 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -58,9 +58,6 @@ static virDrvOpenStatus dummyConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no VirtualBox driver path specified (try vbox:///session)")); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 6118e6fa13..de3708aab3 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -130,17 +130,12 @@ vmwareConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) { - /* @TODO accept */ - return VIR_DRV_OPEN_DECLINED; - } else { - /* If path isn't /session, then they typoed, so tell them correct path */ - if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected VMware URI path '%s', try vmwareplayer:///session, vmwarews:///session or vmwarefusion:///session"), - NULLSTR(conn->uri->path)); - return VIR_DRV_OPEN_ERROR; - } + /* If path isn't /session, then they typoed, so tell them correct path */ + if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected VMware URI path '%s', try vmwareplayer:///session, vmwarews:///session or vmwarefusion:///session"), + NULLSTR(conn->uri->path)); + return VIR_DRV_OPEN_ERROR; } /* We now know the URI is definitely for this driver, so beyond diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index f3047cad6c..5867f1c911 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -358,9 +358,6 @@ vzConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (!conn->uri) - return VIR_DRV_OPEN_DECLINED; - /* From this point on, the connection is for us. */ if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 86f9e7706d..42b305d316 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -146,9 +146,6 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri == NULL) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->server == NULL) { xenapiSessionErrorHandler(conn, VIR_ERR_INVALID_ARG, _("Server name not in URI")); -- 2.14.3

Now that the legacy Xen driver has been dropped, we no longer need to support URIs such as "/path/to/xend/socket", and so can mandate that a URI scheme must always be present. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/libvirt.c | 15 ++++++---- src/remote/remote_driver.c | 74 ++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 48 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 30345af10d..600beaa4d5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -905,7 +905,7 @@ virConnectGetDefaultURI(virConfPtr conf, static int virConnectCheckURIMissingSlash(const char *uristr, virURIPtr uri) { - if (!uri->scheme || !uri->path || !uri->server) + if (!uri->path || !uri->server) return 0; /* To avoid false positives, only check drivers that mandate @@ -1018,6 +1018,13 @@ virConnectOpenInternal(const char *name, NULLSTR(ret->uri->user), ret->uri->port, NULLSTR(ret->uri->path)); + if (ret->uri->scheme == NULL) { + virReportError(VIR_ERR_NO_CONNECT, + _("URI '%s' does not include a driver name"), + name); + goto failed; + } + if (virConnectCheckURIMissingSlash(uristr, ret->uri) < 0) { goto failed; @@ -1038,7 +1045,7 @@ virConnectOpenInternal(const char *name, * not being able to connect to libvirtd or not being able to find * certificates. */ if (STREQ(virConnectDriverTab[i]->hypervisorDriver->name, "remote") && - ret->uri != NULL && ret->uri->scheme != NULL && + ret->uri != NULL && ( #ifndef WITH_PHYP STRCASEEQ(ret->uri->scheme, "phyp") || @@ -1081,10 +1088,6 @@ virConnectOpenInternal(const char *name, VIR_DEBUG("No URI, skipping driver with URI whitelist"); continue; } - if (!ret->uri->scheme) { - VIR_DEBUG("No URI scheme, skipping driver with URI whitelist"); - continue; - } VIR_DEBUG("Checking for supported URI schemes"); for (s = 0; virConnectDriverTab[i]->uriSchemes[s] != NULL; s++) { if (STREQ(ret->uri->scheme, virConnectDriverTab[i]->uriSchemes[s])) { diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 901a2ebfbd..ce2ea27cd8 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -771,51 +771,41 @@ doRemoteOpen(virConnectPtr conn, * URIs we don't care about */ if (conn->uri) { - if (!conn->uri->scheme) { - /* This is the ///var/lib/xen/xend-socket local path style */ - if (!conn->uri->path) - return VIR_DRV_OPEN_DECLINED; - if (conn->uri->path[0] != '/') - return VIR_DRV_OPEN_DECLINED; - - transport = trans_unix; - } else { - transport_str = get_transport_from_scheme(conn->uri->scheme); + transport_str = get_transport_from_scheme(conn->uri->scheme); - if (!transport_str) { - if (conn->uri->server) - transport = trans_tls; - else - transport = trans_unix; - } else { - if (STRCASEEQ(transport_str, "tls")) { - transport = trans_tls; - } else if (STRCASEEQ(transport_str, "unix")) { - if (conn->uri->server) { - virReportError(VIR_ERR_INVALID_ARG, - _("using unix socket and remote " - "server '%s' is not supported."), - conn->uri->server); - return VIR_DRV_OPEN_ERROR; - } else { - transport = trans_unix; - } - } else if (STRCASEEQ(transport_str, "ssh")) { - transport = trans_ssh; - } else if (STRCASEEQ(transport_str, "libssh2")) { - transport = trans_libssh2; - } else if (STRCASEEQ(transport_str, "ext")) { - transport = trans_ext; - } else if (STRCASEEQ(transport_str, "tcp")) { - transport = trans_tcp; - } else if (STRCASEEQ(transport_str, "libssh")) { - transport = trans_libssh; - } else { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("remote_open: transport in URL not recognised " - "(should be tls|unix|ssh|ext|tcp|libssh2)")); + if (!transport_str) { + if (conn->uri->server) + transport = trans_tls; + else + transport = trans_unix; + } else { + if (STRCASEEQ(transport_str, "tls")) { + transport = trans_tls; + } else if (STRCASEEQ(transport_str, "unix")) { + if (conn->uri->server) { + virReportError(VIR_ERR_INVALID_ARG, + _("using unix socket and remote " + "server '%s' is not supported."), + conn->uri->server); return VIR_DRV_OPEN_ERROR; + } else { + transport = trans_unix; } + } else if (STRCASEEQ(transport_str, "ssh")) { + transport = trans_ssh; + } else if (STRCASEEQ(transport_str, "libssh2")) { + transport = trans_libssh2; + } else if (STRCASEEQ(transport_str, "ext")) { + transport = trans_ext; + } else if (STRCASEEQ(transport_str, "tcp")) { + transport = trans_tcp; + } else if (STRCASEEQ(transport_str, "libssh")) { + transport = trans_libssh; + } else { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("remote_open: transport in URL not recognised " + "(should be tls|unix|ssh|ext|tcp|libssh2)")); + return VIR_DRV_OPEN_ERROR; } } } else { -- 2.14.3

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é <berrange@redhat.com> --- 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); - 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:///system"), 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 auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); 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; } + /* Avoid need for drivers to worry about NULLs, as + * no one needs to distinguish "" vs NULL */ + if (ret->uri->path == 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); if (ret->uri->scheme == 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, } /* /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; } 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 conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* If path isn't '/' then they typoed, tell them correct path */ - if (conn->uri->path != 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(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* If path isn't /system, then they typoed, so tell them correct path */ - if (conn->uri->path == NULL || - STRNEQ(conn->uri->path, "/system")) { + if (STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected OpenVZ URI path '%s', try openvz:///system"), 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; - if (conn->uri->path) { + if (conn->uri->path[0] != '\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] == '/')) < 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(virConnectPtr conn, } cfg = virQEMUDriverGetConfig(qemu_driver); - if (conn->uri->path == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("no QEMU URI path given, try %s"), - cfg->uri); - goto cleanup; - } 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, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (!conn->uri->path - || conn->uri->path[0] == '\0' - || (conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) { + if (conn->uri->path[0] == '\0' || + (conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("testOpen: supply a path or use test:///default")); 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, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri->path == 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 != 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 conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri->path == 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 != 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); /* If path isn't /session, then they typoed, so tell them correct path */ - if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) { + if (STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected VMware URI path '%s', try vmwareplayer:///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); /* 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:///system"), conn->uri->path); -- 2.14.3

On Mon, Apr 09, 2018 at 04:45:43PM +0100, Daniel P. Berrangé wrote:
The motivating goal of this series was/is to make it possible to answer whether there is any driver registered to handle a given URI scheme without having to call into the drivers.
Ultimately this ended up being a nice simplification and cleanup of driver URI opening code, removing repetative logic from all drivers.
BTW, this is rebased above Jim's v2 patch for killing the XenD driver https://www.redhat.com/archives/libvir-list/2018-April/msg00524.html Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 04/09/2018 05:45 PM, Daniel P. Berrangé wrote:
The motivating goal of this series was/is to make it possible to answer whether there is any driver registered to handle a given URI scheme without having to call into the drivers.
Ultimately this ended up being a nice simplification and cleanup of driver URI opening code, removing repetative logic from all drivers.
Daniel P. Berrangé (8): xen: encourage use of xen:///system URI as preferred format lxc: allow use of lxc:///system URI as preferred format driver: introduce a driver method for probing default URIs driver: allow drivers to indicate if they permit remote connections driver: declare supported URI schemes in virConnectDriver struct driver: ensure NULL URI isn't passed to drivers with whitelisted URIs driver: enforce a non-NULL URI scheme driver: ensure URI path is non-NULL to simplify drivers
docs/drvlxc.html.in | 34 ++++++------- docs/drvxen.html.in | 14 +++--- docs/hvsupport.pl | 6 +-- docs/remote.html.in | 6 +-- docs/uri.html.in | 16 +++---- examples/lxcconvert/virt-lxc-convert | 2 +- src/bhyve/bhyve_driver.c | 48 +++++++++---------- src/driver-hypervisor.h | 4 ++ src/driver.h | 8 ++++ src/esx/esx_driver.c | 31 +----------- src/hyperv/hyperv_driver.c | 24 +--------- src/interface/interface_backend_netcf.c | 47 +++++++----------- src/interface/interface_backend_udev.c | 47 +++++++----------- src/libvirt.c | 69 +++++++++++++++++++++++--- src/libxl/libxl_driver.c | 58 +++++++++++----------- src/lxc/lxc_driver.c | 56 ++++++++++------------ src/lxc/lxc_process.c | 4 +- src/network/bridge_driver.c | 47 +++++++----------- src/node_device/node_device_driver.c | 45 +++++++---------- src/node_device/node_device_hal.c | 2 + src/node_device/node_device_udev.c | 2 + src/nwfilter/nwfilter_driver.c | 35 +++++--------- src/openvz/openvz_driver.c | 70 +++++++++++++-------------- src/phyp/phyp_driver.c | 9 +--- src/qemu/qemu_driver.c | 85 +++++++++++++++------------------ src/remote/remote_driver.c | 74 +++++++++++++--------------- src/secret/secret_driver.c | 47 +++++++----------- src/storage/storage_driver.c | 47 +++++++----------- src/test/test_driver.c | 18 ++----- src/uml/uml_driver.c | 71 +++++++++++++-------------- src/vbox/vbox_common.c | 26 ++++------ src/vbox/vbox_driver.c | 18 ++----- src/vmware/vmware_driver.c | 29 ++++------- src/vz/vz_driver.c | 25 ++-------- src/xenapi/xenapi_driver.c | 6 +-- tools/libvirt-guests.sysconf | 2 +- tools/virsh.pod | 4 +- tools/virt-login-shell.c | 2 +- 38 files changed, 489 insertions(+), 649 deletions(-)
ACK series, but please before pushing: a) read my comments, b) make sure 'make check syntax-check' passes after each patch ;-) Michal
participants (2)
-
Daniel P. Berrangé
-
Michal Privoznik