]> xenbits.xensource.com Git - libvirt.git/commitdiff
* src/libvirt.c src/xend_internal.c src/xend_internal.h: cleaned up
authorDaniel Veillard <veillard@redhat.com>
Wed, 14 Jun 2006 15:44:14 +0000 (15:44 +0000)
committerDaniel Veillard <veillard@redhat.com>
Wed, 14 Jun 2006 15:44:14 +0000 (15:44 +0000)
  virConnectListDomains and virConnectNumOfDomains, implemented xend
  driver entry point for them.
daniel

ChangeLog
src/libvirt.c
src/xend_internal.c
src/xend_internal.h

index c2518bc7d6d058849a280ba1733a5b77ebbdd08d..efd59bb0cf2f5f37baf54654ddd5058b3cebcd34 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jun 14 15:51:00 EDT 2006 Daniel Veillard <veillard@redhat.com>
+
+       * src/libvirt.c src/xend_internal.c src/xend_internal.h: cleaned up
+         virConnectListDomains and virConnectNumOfDomains, implemented xend
+         driver entry point for them.
+
 Wed Jun 14 13:10:03 EDT 2006 Daniel Veillard <veillard@redhat.com>
 
        * src/libvirt.c: Daniel P. Berrange pointed out a bug in virConnectOpen
index 5be855580e8ea8e97b37aa077c39cde9803dd5c3..65e9ae768b2c3ba0e7408ac7846bd15cfd9d5685 100644 (file)
@@ -345,8 +345,14 @@ failed:
 int
 virConnectClose(virConnectPtr conn)
 {
+    int i;
+
     if (!VIR_IS_CONNECT(conn))
         return (-1);
+    for (i = 0;i < conn->nb_drivers;i++) {
+       if ((conn->drivers[i] != NULL) && (conn->drivers[i]->close != NULL))
+           conn->drivers[i]->close(conn);
+    }
     if (virFreeConnect(conn) < 0)
         return (-1);
     return (0);
@@ -415,8 +421,6 @@ virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
         return (-1);
     }
 
-    *hvVer = 0;
-
     for (i = 0;i < conn->nb_drivers;i++) {
        if ((conn->drivers[i] != NULL) &&
            (conn->drivers[i]->version != NULL)) {
@@ -443,8 +447,6 @@ virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
 {
     int ret = -1;
     int i;
-    long id;
-    char **idlist = NULL;
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@@ -466,25 +468,7 @@ virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
        }
     }
 
-    /*
-     * try then though the Xen Daemon
-     */
-    idlist = xenDaemonListDomains(conn);
-    if (idlist != NULL) {
-        for (ret = 0, i = 0; (idlist[i] != NULL) && (ret < maxids); i++) {
-            id = xenDaemonDomainLookupByName_ids(conn, idlist[i], NULL);
-            if (id >= 0)
-                ids[ret++] = (int) id;
-        }
-       free(idlist);
-        return(ret);
-    }
-
-    /*
-     * Then fallback to the XenStore
-     */
-    ret = xenStoreListDomains(conn, ids, maxids);
-    return (ret);
+    return (-1);
 }
 
 /**
@@ -500,7 +484,6 @@ virConnectNumOfDomains(virConnectPtr conn)
 {
     int ret = -1;
     int i;
-    char **idlist = NULL;
 
     if (!VIR_IS_CONNECT(conn)) {
         virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@@ -517,23 +500,7 @@ virConnectNumOfDomains(virConnectPtr conn)
        }
     }
 
-    /* 
-     * try then with Xend interface
-     */
-    idlist = xenDaemonListDomains(conn);
-    if (idlist != NULL) {
-        char **tmp = idlist;
-
-        ret = 0;
-        while (*tmp != NULL) {
-            tmp++;
-            ret++;
-        }
-       free(idlist);
-       return(ret);
-    }
-    /* Then Xen Store */
-    return(xenStoreNumOfDomains(conn));
+    return(-1);
 }
 
 /**
@@ -659,7 +626,7 @@ virDomainLookupByID(virConnectPtr conn, int id)
     }
 
     /* path does not contain name, use xend API to retrieve name */
-    names = xenDaemonListDomains(conn);
+    names = xenDaemonListDomainsOld(conn);
     tmp = names;
 
     if (names != NULL) {
@@ -734,7 +701,7 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
        }
     }
 
-    names = xenDaemonListDomains(conn);
+    names = xenDaemonListDomainsOld(conn);
     tmp = names;
 
     if (names == NULL) {
index a682705e406286c5c059bba75791ffdedbb37713..7d21960d651993e44faff208f2c01a67ffa65868 100644 (file)
@@ -39,6 +39,8 @@
 static const char * xenDaemonGetType(virConnectPtr conn);
 static int xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
 static int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer);
+static int xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids);
+static int xenDaemonNumOfDomains(virConnectPtr conn);
 
 static virDriver xenDaemonDriver = {
     "XenDaemon",
@@ -51,8 +53,8 @@ static virDriver xenDaemonDriver = {
     xenDaemonGetType, /* type */
     xenDaemonGetVersion, /* version */
     xenDaemonNodeGetInfo, /* nodeGetInfo */
-    NULL, /* listDomains */
-    NULL, /* numOfDomains */
+    xenDaemonListDomains, /* listDomains */
+    xenDaemonNumOfDomains, /* numOfDomains */
     NULL, /* domainCreateLinux */
     NULL, /* domainLookupByID */
     NULL, /* domainLookupByUUID */
@@ -997,7 +999,7 @@ xend_sysrq(virConnectPtr xend, const char *name, const char *key)
 }
 
 /**
- * xenDaemonListDomains:
+ * xenDaemonListDomainsOld:
  * @xend: pointer to the Xem Daemon block
  *
  * This method will return an array of names of currently running
@@ -1006,7 +1008,7 @@ xend_sysrq(virConnectPtr xend, const char *name, const char *key)
  * Returns a list of names or NULL in case of error.
  */
 char **
-xenDaemonListDomains(virConnectPtr xend)
+xenDaemonListDomainsOld(virConnectPtr xend)
 {
     size_t extra = 0;
     struct sexpr *root = NULL;
@@ -1609,7 +1611,7 @@ sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
     if (name == NULL)
         goto error;
 
-    ret = virGetDomain(conn, name, &uuid[0]);
+    ret = virGetDomain(conn, name, (const unsigned char *) &uuid[0]);
     if (ret == NULL) {
         virXendError(conn, VIR_ERR_NO_MEMORY, "Allocating domain");
        return(NULL);
@@ -2146,3 +2148,80 @@ xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer)
     *hvVer = version;
     return(0);
 }
+
+/**
+ * xenDaemonListDomains:
+ * @conn: pointer to the hypervisor connection
+ * @ids: array to collect the list of IDs of active domains
+ * @maxids: size of @ids
+ *
+ * Collect the list of active domains, and store their ID in @maxids
+ * TODO: this is quite expensive at the moment since there isn't one
+ *       xend RPC providing both name and id for all domains.
+ *
+ * Returns the number of domain found or -1 in case of error
+ */
+static int
+xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids)
+{
+    struct sexpr *root = NULL;
+    int ret = -1;
+    struct sexpr *_for_i, *node;
+    long id;
+
+    if ((ids == NULL) || (maxids <= 0))
+        goto error;
+    root = sexpr_get(conn, "/xend/domain");
+    if (root == NULL)
+        goto error;
+
+    ret = 0;
+
+    for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
+         _for_i = _for_i->cdr, node = _for_i->car) {
+        if (node->kind != SEXPR_VALUE)
+            continue;
+        id = xenDaemonDomainLookupByName_ids(conn, node->value, NULL);
+        if (id >= 0)
+           ids[ret++] = (int) id;
+    }
+
+error:
+    if (root != NULL)
+       sexpr_free(root);
+    return(ret);
+}
+
+/**
+ * xenDaemonNumOfDomains:
+ * @conn: pointer to the hypervisor connection
+ *
+ * Provides the number of active domains.
+ *
+ * Returns the number of domain found or -1 in case of error
+ */
+static int
+xenDaemonNumOfDomains(virConnectPtr conn)
+{
+    struct sexpr *root = NULL;
+    int ret = -1;
+    struct sexpr *_for_i, *node;
+
+    root = sexpr_get(conn, "/xend/domain");
+    if (root == NULL)
+        goto error;
+
+    ret = 0;
+
+    for (_for_i = root, node = root->car; _for_i->kind == SEXPR_CONS;
+         _for_i = _for_i->cdr, node = _for_i->car) {
+        if (node->kind != SEXPR_VALUE)
+            continue;
+       ret++;
+    }
+
+error:
+    if (root != NULL)
+       sexpr_free(root);
+    return(ret);
+}
index e00c482d966316478279f3fff13b6dfec60c110b..dba8617e03772720e98587f79acda47242bba9af 100644 (file)
@@ -517,7 +517,7 @@ int xenDaemonOpen_unix(virConnectPtr xend, const char *path);
  * This method will return an array of names of currently running
  * domains.  The memory should be released will a call to free().
  */
-    char **xenDaemonListDomains(virConnectPtr xend);
+    char **xenDaemonListDomainsOld(virConnectPtr xend);
 
 /**
  * \brief Create a new domain