[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] PATCH: Allow automatic driver probe for remote TCP connections



When connecting to a local libvirt you can let it automatically probe
the hypervisor URI if you don't know it ahead of time. This doesn't
work with remote URIs because you need to have something to put in
the URI scheme before the hostname

  qemu+ssh://somehost/system
  xen+tcp://somehost/system

This is then translated into the URI

   qemu:///system
   xen:///

It occurred to me that we can trivially enable probing with all existing
libvirtd daemon releases, simply by fixing the client side. All we need
todo is invent a new generic URI scheme, and convert that to empty string

This patch adds a 'remote' URI scheme, usable like this

    remote+ssh://somehost/
    remote+tcp://somehost/
    remote://somehost/
    remote+tls://somehost/
    remote+ext://somehost/

In all these styles, the URI passed to the remote daemon is "", causing
it to probe.

As a demonstration, here's an example using virsh and two hosts I have,
one running Xen, the other QEMU

See it automatically choosing QEMU....

 $ virsh --connect remote+ssh://root lettuce/ version
 Compiled against library: libvir 0.5.0
 Using library: libvir 0.5.0
 Running hypervisor: QEMU 0.9.1

And choosing Xen....

 $ virsh --connect remote+ssh://root pumpkin/ version
 Compiled against library: libvir 0.5.0
 Using library: libvir 0.5.0
 Running hypervisor: Xen 3.1.0


This finally makes the Avahi broadcasts useful - they only include
info on the hostname + data transport (SSH, TCP, TLS), not the HV
type. So letting us use auto-probing remotely is the missing link.

NB. we've got a small problem with the virGetVersion() API - it does not
take a connection URI - just a hypervisor type. It then directly checks
the statically declared 'version' field in the virDriverPtr struct.
This no longer works now that some drivers are linked directly into the
libvirt daemon. 

I'm thinking that perhaps we can just change the virGetVersion() apis
so that instead of looking in virDriverPtr struct, we just include the
version numbers directly in virGetVersion as a static const lookup 
table. Meanwhile, this patch also includes a change to virsh to stop
it calling virGetVersion(), though this hunk instead intended to apply
to CVS.

Daniel

Index: remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.108
diff -u -p -r1.108 remote_internal.c
--- remote_internal.c	21 Nov 2008 12:31:04 -0000	1.108
+++ remote_internal.c	26 Nov 2008 21:58:47 -0000
@@ -430,28 +430,40 @@ doRemoteOpen (virConnectPtr conn,
 
         /* Construct the original name. */
         if (!name) {
-            xmlURI tmpuri = {
-                .scheme = conn->uri->scheme,
+            if (STREQ(conn->uri->scheme, "remote") ||
+                STRPREFIX(conn->uri->scheme, "remote+")) {
+                /* Allow remote serve to probe */
+                name = strdup("");
+            } else {
+                xmlURI tmpuri = {
+                    .scheme = conn->uri->scheme,
 #ifdef HAVE_XMLURI_QUERY_RAW
-                .query_raw = qparam_get_query (vars),
+                    .query_raw = qparam_get_query (vars),
 #else
-                .query = qparam_get_query (vars),
+                    .query = qparam_get_query (vars),
 #endif
-                .path = conn->uri->path,
-                .fragment = conn->uri->fragment,
-            };
-
-            /* Evil, blank out transport scheme temporarily */
-            if (transport_str) {
-                assert (transport_str[-1] == '+');
-                transport_str[-1] = '\0';
-            }
+                    .path = conn->uri->path,
+                    .fragment = conn->uri->fragment,
+                };
+
+                /* Evil, blank out transport scheme temporarily */
+                if (transport_str) {
+                    assert (transport_str[-1] == '+');
+                    transport_str[-1] = '\0';
+                }
+
+                name = (char *) xmlSaveUri (&tmpuri);
 
-            name = (char *) xmlSaveUri (&tmpuri);
+#ifdef HAVE_XMLURI_QUERY_RAW
+                VIR_FREE(tmpuri.query_raw);
+#else
+                VIR_FREE(tmpuri.query);
+#endif
 
-            /* Restore transport scheme */
-            if (transport_str)
-                transport_str[-1] = '+';
+                /* Restore transport scheme */
+                if (transport_str)
+                    transport_str[-1] = '+';
+            }
         }
 
         free_qparam_set (vars);
Index: virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.175
diff -u -p -r1.175 virsh.c
--- virsh.c	24 Nov 2008 07:13:30 -0000	1.175
+++ virsh.c	26 Nov 2008 21:58:51 -0000
@@ -4357,7 +4357,6 @@ cmdVersion(vshControl *ctl, const vshCmd
     const char *hvType;
     unsigned long libVersion;
     unsigned long includeVersion;
-    unsigned long apiVersion;
     int ret;
     unsigned int major;
     unsigned int minor;
@@ -4380,7 +4379,8 @@ cmdVersion(vshControl *ctl, const vshCmd
     vshPrint(ctl, _("Compiled against library: libvir %d.%d.%d\n"),
              major, minor, rel);
 
-    ret = virGetVersion(&libVersion, hvType, &apiVersion);
+
+    ret = virGetVersion(&libVersion, NULL, NULL);
     if (ret < 0) {
         vshError(ctl, FALSE, "%s", _("failed to get the library version"));
         return FALSE;
@@ -4392,13 +4392,6 @@ cmdVersion(vshControl *ctl, const vshCmd
     vshPrint(ctl, _("Using library: libvir %d.%d.%d\n"),
              major, minor, rel);
 
-    major = apiVersion / 1000000;
-    apiVersion %= 1000000;
-    minor = apiVersion / 1000;
-    rel = apiVersion % 1000;
-    vshPrint(ctl, _("Using API: %s %d.%d.%d\n"), hvType,
-             major, minor, rel);
-
     ret = virConnectGetVersion(ctl->conn, &hvVersion);
     if (ret < 0) {
         vshError(ctl, FALSE, "%s", _("failed to get the hypervisor version"));

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]