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

[Libvir] [PATCH] Add support for virConnectGetHostname and virConnectGetURI for qemu



Specifically this just adds support for virConnectGetHostname on qemu:/// URIs.

Because of the way that the qemu driver now works, calls to virConnectGetURI are answered by the remote driver before the qemu driver ever sees them, so they have worked all along.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: src/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.23
diff -u -p -r1.23 qemu_driver.c
--- src/qemu_driver.c	21 Aug 2007 10:08:12 -0000	1.23
+++ src/qemu_driver.c	20 Sep 2007 13:53:44 -0000
@@ -1369,12 +1369,12 @@ static virDrvOpenStatus qemudOpen(virCon
     if (qemu_driver == NULL)
         return VIR_DRV_OPEN_DECLINED;
 
-    if (uid) {
-        if (strcmp(name, "qemu:///session"))
+    if (uid != 0) {
+        if (STRNEQ (name, "qemu:///session"))
             return VIR_DRV_OPEN_DECLINED;
-    } else {
-        if (strcmp(name, "qemu:///system") &&
-            strcmp(name, "qemu:///session"))
+    } else { /* root */
+        if (STRNEQ (name, "qemu:///system") &&
+            STRNEQ (name, "qemu:///session"))
             return VIR_DRV_OPEN_DECLINED;
     }
 
@@ -1698,6 +1698,28 @@ static int qemudGetVersion(virConnectPtr
     return 0;
 }
 
+static char *
+qemudGetHostname (virConnectPtr conn)
+{
+    int r;
+    char hostname[HOST_NAME_MAX+1], *str;
+
+    r = gethostname (hostname, HOST_NAME_MAX+1);
+    if (r == -1) {
+        qemudReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
+                          "%s", strerror (errno));
+        return NULL;
+    }
+    /* Caller frees this string. */
+    str = strdup (hostname);
+    if (str == NULL) {
+        qemudReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
+                         "%s", strerror (errno));
+        return NULL;
+    }
+    return str;
+}
+
 static int qemudListDomains(virConnectPtr conn, int *ids, int nids) {
     struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
     struct qemud_vm *vm = driver->vms;
@@ -2621,8 +2643,8 @@ static virDriver qemuDriver = {
     NULL, /* supports_feature */
     qemudGetType, /* type */
     qemudGetVersion, /* version */
-    NULL, /* hostname */
-    NULL, /* uri */
+    qemudGetHostname, /* hostname */
+    NULL, /* URI - never called because remote_internal.c answers this */
     qemudGetMaxVCPUs, /* getMaxVcpus */
     qemudGetNodeInfo, /* nodeGetInfo */
     qemudGetCapabilities, /* getCapabilities */
Index: src/remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.24
diff -u -p -r1.24 remote_internal.c
--- src/remote_internal.c	19 Sep 2007 21:44:32 -0000	1.24
+++ src/remote_internal.c	20 Sep 2007 13:53:46 -0000
@@ -693,9 +693,9 @@ remoteOpen (virConnectPtr conn, const ch
         rflags |= VIR_DRV_OPEN_REMOTE_RO;
 
     if (uri_str) {
-        if (!strcmp(uri_str, "qemu:///system")) {
+        if (STREQ (uri_str, "qemu:///system")) {
             rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-        } else if (!strcmp(uri_str, "qemu:///session")) {
+        } else if (STREQ (uri_str, "qemu:///session")) {
             rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
             if (getuid() > 0) {
                 rflags |= VIR_DRV_OPEN_REMOTE_USER;

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


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