[Patch 3/4]: Xen inactive domains: stop xend/xs/xen using inactive domains

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

 



The existing xend, xs, xen, proxy driver backends all assume that if they're
given a virDomainPtr object, the handle member is non-zero (ie its a running
domain). With the addition of inactive domain support this assumption is no
longer value. Thus this patch modifies all these drivers, so that if the
handle is -1, then they return without doing any work. This lets the operation
be correctly delegated to the new driver for inactive domains.

In addition, the XenD driver assumed that if XenD returns a 404 when looking
up a domain based on its name, this was a fatal error condition. Since inative
domains are not known to XenD, this assumption is also now false. The attached
patch modifies xend_internal so that if a 404 is returned, the error is not
propagated to the libvirt error handlers. Instead the methods in question
simply return -1, and control continues to the new backend for managing 
inactive domains.

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
Index: src/proxy_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/proxy_internal.c,v
retrieving revision 1.10
diff -u -r1.10 proxy_internal.c
--- src/proxy_internal.c	30 Aug 2006 14:21:03 -0000	1.10
+++ src/proxy_internal.c	4 Sep 2006 01:15:08 -0000
@@ -694,6 +694,8 @@
 	    virProxyError(domain->conn, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
         return (0);
     }
+    if (domain->handle < 0)
+        return(-1);
     return(xenProxyDomainGetDomMaxMemory(domain->conn, domain->handle));
 }
 
@@ -719,8 +721,10 @@
 	    virProxyError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 	else
 	    virProxyError(domain->conn, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        return (0);
+        return (-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     if (info == NULL) {
         virProxyError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 	return (-1);
@@ -739,7 +743,6 @@
 	return (-1);
     }
     memmove(info, &ans.extra.dinfo, sizeof(virDomainInfo));
-
     return(0);
 }
 
@@ -959,6 +962,8 @@
 	    virProxyError(domain->conn, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
         return (NULL);
     }
+    if (domain->handle < 0)
+        return(NULL);
     memset(&req, 0, sizeof(req));
     req.command = VIR_PROXY_DOMAIN_XML;
     req.data.arg = domain->handle;
Index: src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.36
diff -u -r1.36 xen_internal.c
--- src/xen_internal.c	2 Sep 2006 21:27:09 -0000	1.36
+++ src/xen_internal.c	4 Sep 2006 01:15:08 -0000
@@ -1194,7 +1194,7 @@
 xenHypervisorGetMaxMemory(virDomainPtr domain)
 {
     if ((domain == NULL) || (domain->conn == NULL) ||
-        (domain->conn->handle < 0))
+        (domain->conn->handle < 0) || (domain->handle < 0))
         return (0);
 
     return(xenHypervisorGetDomMaxMemory(domain->conn, domain->handle));
@@ -1277,7 +1277,6 @@
 	(domain->handle < 0))
         return (-1);
     return(xenHypervisorGetDomInfo(domain->conn, domain->handle, info));
-
 }
 
 #ifndef PROXY
@@ -1295,7 +1294,7 @@
     int ret;
 
     if ((domain == NULL) || (domain->conn == NULL) ||
-        (domain->conn->handle < 0))
+        (domain->conn->handle < 0) || (domain->handle < 0))
         return (-1);
 
     ret = virXen_pausedomain(domain->conn->handle, domain->handle);
@@ -1318,7 +1317,7 @@
     int ret;
 
     if ((domain == NULL) || (domain->conn == NULL) ||
-        (domain->conn->handle < 0))
+        (domain->conn->handle < 0) || (domain->handle < 0))
         return (-1);
 
     ret = virXen_unpausedomain(domain->conn->handle, domain->handle);
@@ -1341,7 +1340,7 @@
     int ret;
 
     if ((domain == NULL) || (domain->conn == NULL) ||
-        (domain->conn->handle < 0))
+        (domain->conn->handle < 0) || (domain->handle < 0))
         return (-1);
 
     ret = virXen_destroydomain(domain->conn->handle, domain->handle);
@@ -1365,7 +1364,7 @@
     int ret;
 
     if ((domain == NULL) || (domain->conn == NULL) ||
-        (domain->conn->handle < 0))
+        (domain->conn->handle < 0) || (domain->handle < 0))
         return (-1);
 
     ret = virXen_setmaxmem(domain->conn->handle, domain->handle, memory);
@@ -1392,7 +1391,8 @@
     int ret;
 
     if ((domain == NULL) || (domain->conn == NULL) ||
-        (domain->conn->handle < 0) || (nvcpus < 1))
+        (domain->conn->handle < 0) || (domain->handle < 0) ||
+        (nvcpus < 1))
         return (-1);
 
     ret = virXen_setmaxvcpus(domain->conn->handle, domain->handle, nvcpus);
@@ -1420,7 +1420,9 @@
     int ret;
 
     if ((domain == NULL) || (domain->conn == NULL) ||
-        (domain->conn->handle < 0) || (cpumap == NULL) || (maplen < 1))
+        (domain->conn->handle < 0) || (domain->handle < 0) ||
+        (cpumap == NULL) || (maplen < 1))
+      return -1;
     ret = virXen_setvcpumap(domain->conn->handle, domain->handle, vcpu,
                             cpumap, maplen);
     if (ret < 0)
@@ -1460,9 +1462,9 @@
     unsigned char *cpumap;
     int vcpu, cpu;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->conn->handle < 0)
-     || (info == NULL) || (maxinfo < 1)
-     || (sizeof(cpumap_t) & 7))
+    if ((domain == NULL) || (domain->conn == NULL) ||
+        (domain->conn->handle < 0) || (domain->handle < 0) ||
+        (info == NULL) || (maxinfo < 1) || (sizeof(cpumap_t) & 7))
         return (-1);
     if (cpumaps != NULL && maplen < 1)
 	return -1;
@@ -1502,4 +1504,5 @@
     }
     return nbinfo;
 #endif
+    return -1;
 }
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.60
diff -u -r1.60 xend_internal.c
--- src/xend_internal.c	30 Aug 2006 14:21:03 -0000	1.60
+++ src/xend_internal.c	4 Sep 2006 01:15:11 -0000
@@ -36,6 +36,7 @@
 #include "xend_internal.h"
 #include "xen_internal.h" /* for DOM0_INTERFACE_VERSION */
 #include "xs_internal.h" /* To extract VNC port & Serial console TTY */
+#include "conf.h"
 
 #ifndef PROXY
 static const char * xenDaemonGetType(virConnectPtr conn);
@@ -183,6 +184,7 @@
         foreach(iterator, start) \
             if (sexpr_lookup(iterator, path))
 
+
 /**
  * do_connect:
  * @xend: pointer to the Xen Daemon structure
@@ -424,7 +426,7 @@
  */
 static int
 xend_get(virConnectPtr xend, const char *path,
-         char *content, size_t n_content)
+         char *content, size_t n_content, int quiet404s)
 {
     int ret;
     int s = do_connect(xend);
@@ -444,7 +446,8 @@
     ret = xend_req(s, content, n_content);
     close(s);
 
-    if ((ret < 0) || (ret >= 300)) {
+    if (((ret < 0) || (ret >= 300)) &&
+	((ret != 404) || !quiet404s)) {
         virXendError(NULL, VIR_ERR_GET_FAILED, content);
     }
 
@@ -648,7 +651,7 @@
  * Returns a parsed S-Expression in case of success, NULL in case of failure
  */
 static struct sexpr *
-sexpr_get(virConnectPtr xend, const char *fmt, ...)
+sexpr_get(virConnectPtr xend, int quiet404s, const char *fmt, ...)
 {
     char buffer[4096];
     char path[1024];
@@ -659,7 +662,7 @@
     vsnprintf(path, sizeof(path), fmt, ap);
     va_end(ap);
 
-    ret = xend_get(xend, path, buffer, sizeof(buffer));
+    ret = xend_get(xend, path, buffer, sizeof(buffer), quiet404s);
     ret = http2unix(ret);
     if (ret == -1)
         return NULL;
@@ -991,7 +994,7 @@
     char *ptr;
     struct sexpr *_for_i, *node;
 
-    root = sexpr_get(xend, "/xend/domain");
+    root = sexpr_get(xend, 0, "/xend/domain");
     if (root == NULL)
         goto error;
 
@@ -1087,7 +1090,7 @@
 
     if (uuid != NULL)
         memset(uuid, 0, 16);
-    root = sexpr_get(xend, "/xend/domain/%s?detail=1", domname);
+    root = sexpr_get(xend, 0, "/xend/domain/%s?detail=1", domname);
     if (root == NULL)
         goto error;
 
@@ -1140,7 +1143,7 @@
 
     memset(uuid, 0, 16);
 
-    root = sexpr_get(xend, "/xend/domain/%d?detail=1", id);
+    root = sexpr_get(xend, 0, "/xend/domain/%d?detail=1", id);
     if (root == NULL)
       goto error;
 
@@ -1189,7 +1192,7 @@
     size_t size;
     char *ptr;
 
-    root = sexpr_get(xend, "/xend/node/");
+    root = sexpr_get(xend, 0, "/xend/node/");
     if (root == NULL)
         goto error;
 
@@ -1302,7 +1305,7 @@
 int
 xend_dmesg(virConnectPtr xend, char *buffer, size_t n_buffer)
 {
-    return http2unix(xend_get(xend, "/xend/node/dmesg", buffer, n_buffer));
+    return http2unix(xend_get(xend, "/xend/node/dmesg", buffer, n_buffer, 0));
 }
 
 /**
@@ -1334,7 +1337,7 @@
 int
 xend_log(virConnectPtr xend, char *buffer, size_t n_buffer)
 {
-    return http2unix(xend_get(xend, "/xend/node/log", buffer, n_buffer));
+    return http2unix(xend_get(xend, "/xend/node/log", buffer, n_buffer, 0));
 }
 #endif /* PROXY */
 
@@ -1941,6 +1944,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     return xend_op(domain->conn, domain->name, "op", "pause", NULL);
 }
 
@@ -1961,6 +1966,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     return xend_op(domain->conn, domain->name, "op", "unpause", NULL);
 }
 
@@ -1982,6 +1989,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     return xend_op(domain->conn, domain->name, "op", "shutdown", "reason", "halt", NULL);
 }
 
@@ -2004,6 +2013,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     return xend_op(domain->conn, domain->name, "op", "shutdown", "reason", "reboot", NULL);
 }
 
@@ -2028,6 +2039,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     return xend_op(domain->conn, domain->name, "op", "destroy", NULL);
 }
 
@@ -2053,6 +2066,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     return xend_op(domain->conn, domain->name, "op", "save", "file", filename, NULL);
 }
 
@@ -2098,9 +2113,11 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
 
     /* can we ask for a subset ? worth it ? */
-    root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
+    root = sexpr_get(domain->conn, 0, "/xend/domain/%s?detail=1", domain->name);
     if (root == NULL)
         return(0);
 
@@ -2132,6 +2149,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     snprintf(buf, sizeof(buf), "%lu", memory >> 10);
     return xend_op(domain->conn, domain->name, "op", "maxmem_set", "memory",
                    buf, NULL);
@@ -2163,6 +2182,8 @@
 	             __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     snprintf(buf, sizeof(buf), "%lu", memory >> 10);
     return xend_op(domain->conn, domain->name, "op", "mem_target_set",
                    "target", buf, NULL);
@@ -2176,7 +2197,7 @@
     char *ret = NULL;
     struct sexpr *root;
 
-    root = sexpr_get(conn, "/xend/domain/%d?detail=1", domid);
+    root = sexpr_get(conn, 0, "/xend/domain/%d?detail=1", domid);
     if (root == NULL)
         return (NULL);
 
@@ -2205,6 +2226,8 @@
 	             __FUNCTION__);
         return(NULL);
     }
+    if (domain->handle < 0)
+        return(NULL);
 
     return xenDaemonDomainDumpXMLByID(domain->conn, domain->handle);
 }
@@ -2233,13 +2256,16 @@
         return(-1);
     }
 
+    if (domain->handle < 0)
+        return(-1);
 
-    root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
+    root = sexpr_get(domain->conn, 0, "/xend/domain/%s?detail=1", domain->name);
     if (root == NULL)
         return (-1);
 
     ret = sexpr_to_xend_domain_info(root, info);
     sexpr_free(root);
+
     return (ret);
 }
 
@@ -2265,7 +2291,7 @@
         virXendError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 	return(NULL);
     }
-    root = sexpr_get(conn, "/xend/domain/%s?detail=1", domname);
+    root = sexpr_get(conn, 1, "/xend/domain/%s?detail=1", domname);
     if (root == NULL)
         goto error;
 
@@ -2300,7 +2326,7 @@
         return (-1);
     }
 
-    root = sexpr_get(conn, "/xend/node/");
+    root = sexpr_get(conn, 0, "/xend/node/");
     if (root == NULL)
         return (-1);
 
@@ -2360,7 +2386,7 @@
 	const char *extra;
 	int major, minor, release = 0;
         
-	root = sexpr_get(conn, "/xend/node/");
+	root = sexpr_get(conn, 0, "/xend/node/");
 	if (root == NULL)
 	    return(-1);
 
@@ -2404,7 +2430,7 @@
 
     if ((ids == NULL) || (maxids <= 0))
         goto error;
-    root = sexpr_get(conn, "/xend/domain");
+    root = sexpr_get(conn, 0, "/xend/domain");
     if (root == NULL)
         goto error;
 
@@ -2440,7 +2466,7 @@
     int ret = -1;
     struct sexpr *_for_i, *node;
 
-    root = sexpr_get(conn, "/xend/domain");
+    root = sexpr_get(conn, 0, "/xend/domain");
     if (root == NULL)
         goto error;
 
@@ -2515,6 +2541,8 @@
 	             __FUNCTION__);
         return (-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     snprintf(buf, sizeof(buf), "%d", vcpus);
     return(xend_op(domain->conn, domain->name, "op", "set_vcpus", "vcpus",
                    buf, NULL));
@@ -2544,6 +2572,8 @@
 	             __FUNCTION__);
         return (-1);
     }
+    if (domain->handle < 0)
+        return(-1);
 
     /* from bit map, build character string of mapped CPU numbers */
     for (i = 0; i < maplen; i++) for (j = 0; j < 8; j++)
@@ -2597,7 +2627,9 @@
 	             __FUNCTION__);
         return (-1);
     }
-    root = sexpr_get(domain->conn, "/xend/domain/%s?op=vcpuinfo", domain->name);
+    if (domain->handle < 0)
+        return(-1);
+    root = sexpr_get(domain->conn, 0, "/xend/domain/%s?op=vcpuinfo", domain->name);
     if (root == NULL)
         return (-1);
 
@@ -2778,5 +2810,7 @@
         free(name);
     return (NULL);
 }
+
+
 #endif /* ! PROXY */
 
Index: src/xs_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.c,v
retrieving revision 1.18
diff -u -r1.18 xs_internal.c
--- src/xs_internal.c	2 Sep 2006 21:23:14 -0000	1.18
+++ src/xs_internal.c	4 Sep 2006 01:15:11 -0000
@@ -368,6 +368,8 @@
 	                 __FUNCTION__);
 	return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     if (domain->conn->xshandle == NULL)
         return(-1);
 
@@ -428,6 +430,8 @@
 	                 __FUNCTION__);
 	return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     snprintf(value, 19, "%lu", memory);
     value[19] = 0;
     ret = virDomainDoStoreWrite(domain, "memory/target", &value[0]);
@@ -452,6 +456,8 @@
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain))
         return (ret);
+    if (domain->handle < 0)
+        return(-1);
 
     tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "memory/target");
     if (tmp != NULL) {
@@ -624,6 +630,8 @@
 	                 __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     /*
      * this is very hackish, the domU kernel probes for a special 
      * node in the xenstore and launch the shutdown command if found.
@@ -650,6 +658,8 @@
 	                 __FUNCTION__);
         return(-1);
     }
+    if (domain->handle < 0)
+        return(-1);
     /*
      * this is very hackish, the domU kernel probes for a special 
      * node in the xenstore and launch the shutdown command if found.

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]