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

Re: [Libvir] [QEMU 1/3] hook up driver methods for inactive domains



Attaching the patch this time :-)

Dan.

On Mon, Aug 28, 2006 at 12:15:40AM +0100, Daniel P. Berrange wrote:
> 
> The attached patch prepares the driver method API to support inactive
> domains. The following methods are hooked up:
> 
>  * virConnectListDefinedDomains
>  * virConnectNumOfDefinedDomains
>  * virDomainDefineXML
>  * virDomainUndefine
>  * virDomainCreate
> 
> It sets all existing drivers to have NULL in these fields.
> 
> The existing code in virDomainDefineXML was ripped out since it was found
> to be more trouble than it was worth - the backend driver needed to repeat
> most of the logic anyway - so better just to delegate the whole lot.
> 
> Regards,
> 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  -=| 
> 
> --
> Libvir-list mailing list
> Libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list

-- 
|=- 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  -=| 
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/include/libvirt/libvirt.h libvirt-new/include/libvirt/libvirt.h
--- libvirt-orig/include/libvirt/libvirt.h	2006-08-27 18:25:35.000000000 -0400
+++ libvirt-new/include/libvirt/libvirt.h	2006-08-27 18:25:25.000000000 -0400
@@ -297,7 +297,8 @@
 virDomainPtr		virDomainDefineXML	(virConnectPtr conn,
 						 const char *xml);
 int			virDomainUndefine	(virDomainPtr domain);
-int			virConnectListDefinedDomains(virConnectPtr conn,
+int                     virConnectNumOfDefinedDomains  (virConnectPtr conn);
+int			virConnectListDefinedDomains (virConnectPtr conn,
 						 const char **names,
 						 int maxnames);
 int			virDomainCreate		(virDomainPtr domain);
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/include/libvirt/libvirt.h.in libvirt-new/include/libvirt/libvirt.h.in
--- libvirt-orig/include/libvirt/libvirt.h.in	2006-08-16 13:58:23.000000000 -0400
+++ libvirt-new/include/libvirt/libvirt.h.in	2006-08-27 17:11:08.000000000 -0400
@@ -297,7 +297,8 @@
 virDomainPtr		virDomainDefineXML	(virConnectPtr conn,
 						 const char *xml);
 int			virDomainUndefine	(virDomainPtr domain);
-int			virConnectListDefinedDomains(virConnectPtr conn,
+int                     virConnectNumOfDefinedDomains  (virConnectPtr conn);
+int			virConnectListDefinedDomains (virConnectPtr conn,
 						 const char **names,
 						 int maxnames);
 int			virDomainCreate		(virDomainPtr domain);
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/driver.h libvirt-new/src/driver.h
--- libvirt-orig/src/driver.h	2006-08-09 11:21:16.000000000 -0400
+++ libvirt-new/src/driver.h	2006-08-27 17:05:39.000000000 -0400
@@ -107,7 +108,18 @@
 typedef char *
 	(*virDrvDomainDumpXML)		(virDomainPtr dom,
 					 int flags);
-
+typedef int
+	(*virDrvListDefinedDomains)	(virConnectPtr conn,
+					 const char **names,
+					 int maxnames);
+typedef int
+	(*virDrvNumOfDefinedDomains)	(virConnectPtr conn);
+typedef int
+	(*virDrvDomainCreate)	(virDomainPtr dom);
+typedef virDomainPtr
+	(*virDrvDomainDefineXML)(virConnectPtr conn, const char *xml);
+typedef int
+	(*virDrvDomainUndefine) (virDomainPtr dom);
 typedef int
 	(*virDrvDomainSetVcpus)		(virDomainPtr domain,
 					 unsigned int nvcpus);
@@ -168,6 +180,11 @@
 	virDrvDomainPinVcpu		domainPinVcpu;
 	virDrvDomainGetVcpus		domainGetVcpus;
 	virDrvDomainDumpXML		domainDumpXML;
+	virDrvListDefinedDomains	listDefinedDomains;
+	virDrvNumOfDefinedDomains	numOfDefinedDomains;
+	virDrvDomainCreate		domainCreate;
+	virDrvDomainDefineXML           domainDefineXML;
+	virDrvDomainUndefine            domainUndefine;
 };
 
 
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/libvirt.c libvirt-new/src/libvirt.c
--- libvirt-orig/src/libvirt.c	2006-08-16 12:29:46.000000000 -0400
+++ libvirt-new/src/libvirt.c	2006-08-27 17:05:39.000000000 -0400
@@ -1533,10 +1536,7 @@
 virDomainPtr
 virDomainDefineXML(virConnectPtr conn, const char *xml) {
     virDomainPtr ret = NULL;
-    const char *name = NULL;
-    xmlDocPtr doc = NULL;
-    xmlXPathObjectPtr obj = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    int i;
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@@ -1551,72 +1551,16 @@
         return (NULL);
     }
 
-    /*
-     * Check the XML description is at least well formed and extract the
-     * name.
-     * TODO: a full validation based on RNG for example should be done there
-     */
-    doc = xmlReadMemory(xml, strlen(xml), "domain_define.xml", NULL, 0);
-    if (doc == NULL) {
-        virLibConnError(conn, VIR_ERR_XML_ERROR, __FUNCTION__);
-	goto done;
-    }
-    ctxt = xmlXPathNewContext(doc);
-    if (ctxt == NULL) {
-        goto done;
-    }
-    obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
-    if ((obj == NULL) || (obj->type != XPATH_STRING) ||
-        (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
-        virLibConnError(conn, VIR_ERR_NO_NAME, xml);
-        goto done;
+    /* Go though the driver registered entry points */
+    for (i = 0;i < conn->nb_drivers;i++) {
+	if ((conn->drivers[i] != NULL) &&
+	    (conn->drivers[i]->domainDefineXML != NULL)) {
+            ret = conn->drivers[i]->domainDefineXML(conn, xml);
+	    if (ret)
+	        return(ret);
+	}
     }
-    name = (const char *) obj->stringval;
 
-    /*
-     * Now look it up in the domain pool and check it's not an already run
-     * domain.
-     */
-    ret = virGetDomain(conn, name, NULL);
-    if (ret == NULL) {
-        goto done;
-    }
-    /*
-     * TODO: the lifecycle of domains, especially predefined ones need to be
-     *       explicitely written down
-     */
-    if (ret->handle != -1) {
-        virLibConnError(conn, VIR_ERR_DOM_EXIST, name);
-        virFreeDomain(conn, ret);
-	ret = NULL;
-	goto done;
-    }
-    if ((ret->uses > 1) && (!(ret->flags & DOMAIN_IS_DEFINED))) {
-        virLibConnError(conn, VIR_ERR_DOM_EXIST, name);
-        virFreeDomain(conn, ret);
-	ret = NULL;
-	goto done;
-    }
-    ret->flags |= DOMAIN_IS_DEFINED;
-    if (ret->xml != NULL) {
-        free(ret->xml);
-    }
-    ret->xml = strdup(xml);
-    if (ret->xml == NULL) {
-        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
-	virFreeDomain(conn, ret);
-	ret = NULL;
-	goto done;
-    }
-    /* TODO shall we keep a list of defined domains there ? */
-
-done:
-    if (obj != NULL)
-	xmlXPathFreeObject(obj);
-    if (ctxt != NULL)
-        xmlXPathFreeContext(ctxt);
-    if (doc != NULL)
-        xmlFreeDoc(doc);
     return(ret);
 }
 
@@ -1630,23 +1574,62 @@
  */
 int
 virDomainUndefine(virDomainPtr domain) {
-    int ret;
+    int ret, i;
+    virConnectPtr conn;
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
         return (-1);
     }
-    if (domain->conn->flags & VIR_CONNECT_RO) {
+    conn = domain->conn;
+    if (conn->flags & VIR_CONNECT_RO) {
         virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 	return (-1);
     }
 
-    /* TODO shall we keep a list of defined domains there ? */
+    /* Go though the driver registered entry points */
+    for (i = 0;i < conn->nb_drivers;i++) {
+	if ((conn->drivers[i] != NULL) &&
+	    (conn->drivers[i]->domainUndefine != NULL)) {
+	    ret = conn->drivers[i]->domainUndefine(domain);
+	    if (ret >= 0)
+	        return(ret);
+	}
+    }
 
-    ret = virFreeDomain(domain->conn, domain);
-    if (ret < 0)
-        return(-1);
-    return(0);
+    return(-1);
+}
+
+/**
+ * virConnectNumOfDefinedDomains:
+ * @conn: pointer to the hypervisor connection
+ *
+ * Provides the number of active domains.
+ *
+ * Returns the number of domain found or -1 in case of error
+ */
+int
+virConnectNumOfDefinedDomains(virConnectPtr conn)
+{
+    int ret = -1;
+    int i;
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
+        return (-1);
+    }
+
+    /* Go though the driver registered entry points */
+    for (i = 0;i < conn->nb_drivers;i++) {
+	if ((conn->drivers[i] != NULL) &&
+	    (conn->drivers[i]->numOfDefinedDomains != NULL)) {
+	    ret = conn->drivers[i]->numOfDefinedDomains(conn);
+	    if (ret >= 0)
+	        return(ret);
+	}
+    }
+
+    return(-1);
 }
 
 /**
@@ -1662,8 +1645,30 @@
 int
 virConnectListDefinedDomains(virConnectPtr conn, const char **names,
                              int maxnames) {
-    TODO
-    return(-1);
+    int ret = -1;
+    int i;
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
+        return (-1);
+    }
+
+    if ((names == NULL) || (maxnames <= 0)) {
+        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return (-1);
+    }
+
+    /* Go though the driver registered entry points */
+    for (i = 0;i < conn->nb_drivers;i++) {
+	if ((conn->drivers[i] != NULL) &&
+	    (conn->drivers[i]->listDefinedDomains != NULL)) {
+	    ret = conn->drivers[i]->listDefinedDomains(conn, names, maxnames);
+	    if (ret >= 0)
+	        return(ret);
+	}
+    }
+
+    return (-1);
 }
 
 /**
@@ -1677,16 +1682,31 @@
  */
 int
 virDomainCreate(virDomainPtr domain) {
-    
+    int i, ret = -1;
+    virConnectPtr conn;
+    if (domain == NULL) {
+        TODO
+	return (-1);
+    }
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
         return (-1);
     }
-    if (domain->conn->flags & VIR_CONNECT_RO) {
+    conn = domain->conn;
+    if (conn->flags & VIR_CONNECT_RO) {
         virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 	return (-1);
     }
-    return(-1);
+
+    for (i = 0;i < conn->nb_drivers;i++) {
+	if ((conn->drivers[i] != NULL) &&
+	    (conn->drivers[i]->domainCreate != NULL)) {
+	    ret = conn->drivers[i]->domainCreate(domain);
+	    if (ret == 0)
+	        return(ret);
+	}
+    }
+    return(ret);
 }
 
 /**
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/libvirt_sym.version libvirt-new/src/libvirt_sym.version
--- libvirt-orig/src/libvirt_sym.version	2006-08-04 06:41:05.000000000 -0400
+++ libvirt-new/src/libvirt_sym.version	2006-08-27 17:05:39.000000000 -0400
@@ -33,7 +33,9 @@
 	virDomainShutdown;
 	virDomainReboot;
 	virDomainSuspend;
-        virDomainUndefine;
+	virConnectListDefinedDomains;
+	virConnectNumOfDefinedDomains;
+	virDomainUndefine;
 	virGetVersion;
 	virCopyLastError;
 	virConnSetErrorFunc;
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/proxy_internal.c libvirt-new/src/proxy_internal.c
--- libvirt-orig/src/proxy_internal.c	2006-08-16 13:58:23.000000000 -0400
+++ libvirt-new/src/proxy_internal.c	2006-08-27 17:05:39.000000000 -0400
@@ -77,6 +77,11 @@
     NULL, /* domainPinVcpu */
     NULL, /* domainGetVcpus */
     xenProxyDomainDumpXML, /* domainDumpXML */
+    NULL, /* listDefinedDomains */
+    NULL, /* numOfDefinedDomains */
+    NULL, /* domainCreate */
+    NULL, /* domainDefineXML */
+    NULL, /* domainUndefine */
 };
 
 /**
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/test.c libvirt-new/src/test.c
--- libvirt-orig/src/test.c	2006-08-16 13:58:23.000000000 -0400
+++ libvirt-new/src/test.c	2006-08-27 17:05:39.000000000 -0400
@@ -58,6 +58,11 @@
   NULL, /* domainPinVcpu */
   NULL, /* domainGetVcpus */
   testDomainDumpXML, /* domainDumpXML */
+  NULL, /* listDefinedDomains */
+  NULL, /* numOfDefinedDomains */
+  NULL, /* domainCreate */
+  NULL, /* domainDefineXML */
+  NULL, /* domainUndefine */
 };
 
 /* Amount of time it takes to shutdown */
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/xend_internal.c libvirt-new/src/xend_internal.c
--- libvirt-orig/src/xend_internal.c	2006-08-26 11:30:44.000000000 -0400
+++ libvirt-new/src/xend_internal.c	2006-08-27 17:05:39.000000000 -0400
@@ -88,6 +88,11 @@
     xenDaemonDomainPinVcpu, /* domainPinVcpu */
     xenDaemonDomainGetVcpus, /* domainGetVcpus */
     xenDaemonDomainDumpXML, /* domainDumpXML */
+    NULL, /* listDefinedDomains */
+    NULL, /* numOfDefinedDomains */
+    NULL, /* domainCreate */
+    NULL, /* domainDefineXML */
+    NULL, /* domainUndefine */
 };
 
 /**
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/xen_internal.c libvirt-new/src/xen_internal.c
--- libvirt-orig/src/xen_internal.c	2006-08-09 11:21:16.000000000 -0400
+++ libvirt-new/src/xen_internal.c	2006-08-27 17:06:37.000000000 -0400
@@ -94,6 +94,11 @@
     xenHypervisorPinVcpu, /* domainPinVcpu */
     xenHypervisorGetVcpus, /* domainGetVcpus */
     NULL, /* domainDumpXML */
+    NULL, /* listDefinedDomains */
+    NULL, /* numOfDefinedDomains */
+    NULL, /* domainCreate */
+    NULL, /* domainDefineXML */
+    NULL, /* domainUndefine */
 };
 #endif /* !PROXY */
 
diff --exclude docs --exclude .deps --exclude CVS -ruN libvirt-orig/src/xs_internal.c libvirt-new/src/xs_internal.c
--- libvirt-orig/src/xs_internal.c	2006-08-24 11:05:19.000000000 -0400
+++ libvirt-new/src/xs_internal.c	2006-08-27 17:05:39.000000000 -0400
@@ -70,6 +70,11 @@
     NULL, /* domainPinVcpu */
     NULL, /* domainGetVcpus */
     NULL, /* domainDumpXML */
+    NULL, /* listDefinedDomains */
+    NULL, /* numOfDefinedDomains */
+    NULL, /* domainCreate */
+    NULL, /* domainDefineXML */
+    NULL, /* domainUndefine */
 };
 
 /**

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