]> xenbits.xensource.com Git - libvirt.git/commitdiff
* include/libxen.h src/libxen.c src/libxen_sym.version: adding
authorDaniel Veillard <veillard@redhat.com>
Fri, 2 Dec 2005 14:16:21 +0000 (14:16 +0000)
committerDaniel Veillard <veillard@redhat.com>
Fri, 2 Dec 2005 14:16:21 +0000 (14:16 +0000)
  xenConnectListDomains() to list active domains
* src/xensh.c: integrated a basic test for xenConnectListDomains()
Daniel

ChangeLog
include/libxen.h
src/libxen.c
src/libxen_sym.version
src/xensh.c

index 72d45c31b674e489ebc0a46ee20357d9e0bc53b9..83d1b7f4b7e23276d8f2216317a183411437ed40 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Dec  2 15:15:26 CET 2005 Daniel Veillard <veillard@redhat.com>
+
+       * include/libxen.h src/libxen.c src/libxen_sym.version: adding
+         xenConnectListDomains() to list active domains
+       * src/xensh.c: integrated a basic test for xenConnectListDomains()
+
 Fri Dec  2 13:10:04 CET 2005 Daniel Veillard <veillard@redhat.com>
 
        * configure.in src/Makefile.am: more warnings from compiler and
index af0e6545dddeb4c87a18f94450dc31db8bb1af46..b30f3996b8bc5c3c241527140a52ecbbc7565762 100644 (file)
@@ -65,6 +65,13 @@ xenConnectPtr                xenConnectOpenReadOnly  (const char *name);
 int                    xenConnectClose         (xenConnectPtr conn);
 unsigned long          xenConnectGetVersion    (xenConnectPtr conn);
 
+/*
+ * Gather list of running domains
+ */
+int                    xenConnectListDomains   (xenConnectPtr conn,
+                                                int *ids,
+                                                int maxids);
+
 /*
  * Domain creation and destruction
  */
index 7e4de49acd1744197b472b45ef69d55d2f288b00..bd1eacaade8600f579b7058e4de8477a077c6e16 100644 (file)
@@ -122,7 +122,6 @@ failed:
 xenConnectPtr
 xenConnectOpenReadOnly(const char *name) {
     xenConnectPtr ret = NULL;
-    int handle = -1;
     struct xs_handle *xshandle = NULL;
 
     /* we can only talk to the local Xen supervisor ATM */
@@ -205,6 +204,56 @@ unsigned long
 xenConnectGetVersion(xenConnectPtr conn) {
     if (conn == NULL)
         return(-1);
+    TODO
+    return(-1);
+}
+
+/**
+ * xenConnectListDomains:
+ * @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
+ *
+ * Returns the number of domain found or -1 in case of error
+ */
+int
+xenConnectListDomains(xenConnectPtr conn, int *ids, int maxids) {
+    struct xs_transaction_handle* t;
+    int ret = -1;
+    unsigned int num, i;
+    long id;
+    char **idlist = NULL, *endptr;
+
+    if ((conn == NULL) || (conn->magic != XEN_CONNECT_MAGIC) ||
+        (ids == NULL) || (maxids <= 0))
+        return(-1);
+    
+    t = xs_transaction_start(conn->xshandle);
+    if (t == NULL)
+        goto done;
+
+    idlist = xs_directory(conn->xshandle, t, "/local/domain", &num);
+    if (idlist == NULL)
+        goto done;
+
+    for (ret = 0,i = 0;(i < num) && (ret < maxids);i++) {
+        id = strtol(idlist[i], &endptr, 10);
+       if ((endptr == idlist[i]) || (*endptr != 0)) {
+           ret = -1;
+           goto done;
+       }
+       ids[ret++] = (int) id;
+    }
+
+done:
+    if (t != NULL)
+       xs_transaction_end(conn->xshandle, t, 0);
+    if (idlist != NULL)
+        free(idlist);
+
+    return(ret);
 }
 
 /**
@@ -260,7 +309,6 @@ xenDomainLookupByName(xenConnectPtr conn, const char *name) {
 static char *
 xenConnectDoStoreQuery(xenConnectPtr conn, const char *path) {
     struct xs_transaction_handle* t;
-    char s[256];
     char *ret = NULL;
     unsigned int len = 0;
 
index a015bb258f209b888ae32472af7494d0d34ac826..7d36508c7ed120678b798ce47717c34ef766f91b 100644 (file)
@@ -5,6 +5,7 @@
        xenConnectClose;
        xenConnectGetVersion;
        xenDomainCreateLinux;
+       xenConnectListDomains;
        xenDomainLookupByName;
        xenDomainLookupByID;
        xenDomainDestroy;
index ea6f24ebb1dbbc95d8b5881802a28dfbf592a1c1..c6712663c98df731af016e4acff9fedf14c4a063 100644 (file)
 #include <unistd.h>
 #include <sys/types.h>
 
+#define MAX_DOM 100
 int errcode = 0;
 xenConnectPtr conn;
 xenDomainPtr dom0;
+int ids[MAX_DOM];
+
+static void printDomain(xenDomainPtr dom) {
+    printf("id %d: name %s\n", xenDomainGetID(dom), xenDomainGetName(dom));
+}
 
 int main(int argc, char **argv) {
-    int ret;
+    int ret, i;
+    xenDomainPtr dom;
     
     if (getuid() == 0) {
        conn = xenConnectOpen(NULL);
@@ -36,9 +43,29 @@ int main(int argc, char **argv) {
        errcode = 2;
        goto done;
     }
-    printf("Dom0: name %s, id %d\n", xenDomainGetName(dom0),
-           xenDomainGetID(dom0));
 
+    printf("Dom0: ");
+    printDomain(dom0);
+
+    ret = xenConnectListDomains(conn, &ids[0], MAX_DOM);
+    if (ret < 0) {
+        fprintf(stderr, "Failed to list active domains\n");
+       errcode = 3;
+       goto done;
+    }
+    printf("Found %d more active domains\n", ret - 1);
+    for (i = 0;i < ret;i++) {
+        if (ids[i] == 0)
+           continue;
+        printf("  ");
+       dom = xenDomainLookupByID(conn, ids[i]);
+       if (dom == NULL) {
+           printf("domain %d disapeared\n", ids[i]);
+       } else {
+           printDomain(dom);
+       }
+    }
+    
 done:
     if (conn != NULL) {
         ret = xenConnectClose(conn);