]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Explicitly error on uri=qemu://system
authorCole Robinson <crobinso@redhat.com>
Sat, 16 Apr 2016 12:59:08 +0000 (08:59 -0400)
committerCole Robinson <crobinso@redhat.com>
Wed, 20 Apr 2016 13:31:25 +0000 (09:31 -0400)
It's a fairly common error that a user tries to connect to a URI
like qemu://system or qemu://session (missing a slash). This errors
like:

$ virsh --connect qemu://session
error: failed to connect to the hypervisor
error: Unable to resolve address 'session' service '16514': No address associated with hostname

If you already know that the standard qemu URI has 3 slashes, that
error will make it obvious enough. But new user's may not get it.
There's even a RHEL support page explicitly mentioning it!:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/sect-Troubleshooting-Common_libvirt_errors_and_troubleshooting.html

Catch this error early in libvirt.c virConnectOpen for qemu (and vbox
which has similar rules

https://bugzilla.redhat.com/show_bug.cgi?id=1038304
(cherry picked from commit 0d1579572a864c33621da4d01408f8bcb6de5d4a)

src/libvirt.c

index dd58e9c23d14cdf6bcaed7ab0b65395a2dba67ba..8f665ee4858f6f23399256718504619f78287d05 100644 (file)
@@ -935,6 +935,35 @@ virConnectGetDefaultURI(virConfPtr conf,
 }
 
 
+/*
+ * Check to see if an invalid URI like qemu://system (missing /) was passed,
+ * offer the suggested fix.
+ */
+static int
+virConnectCheckURIMissingSlash(const char *uristr, virURIPtr uri)
+{
+    /* To avoid false positives, only check drivers that mandate
+       a path component in the URI, like /system or /session */
+    if (STRNEQ(uri->scheme, "qemu") &&
+        STRNEQ(uri->scheme, "vbox") &&
+        STRNEQ(uri->scheme, "vz"))
+        return 0;
+
+    if (uri->path != NULL)
+        return 0;
+
+    if (STREQ(uri->server, "session") ||
+        STREQ(uri->server, "system")) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("invalid URI %s (maybe you want %s:///%s)"),
+                       uristr, uri->scheme, uri->server);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static virConnectPtr
 do_open(const char *name,
         virConnectAuthPtr auth,
@@ -1002,6 +1031,12 @@ do_open(const char *name,
                   NULLSTR(ret->uri->user), ret->uri->port,
                   NULLSTR(ret->uri->path));
 
+        if (virConnectCheckURIMissingSlash(alias ? alias : name,
+                                           ret->uri) < 0) {
+            VIR_FREE(alias);
+            goto failed;
+        }
+
         VIR_FREE(alias);
     } else {
         VIR_DEBUG("no name, allowing driver auto-select");