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

[Xen-changelog] [xen-unstable] libxenlight: fix name to domid conversion.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1263462160 0
# Node ID ab5845cfa62dd612d629d16cbaff9748d911981f
# Parent  7a412f9f6aae72add9d1e68530064b4b911e9425
libxenlight: fix name to domid conversion.

also simplify massively the function that iterate over all domains to
find the corresponding domid to a name.

Signed-off-by: Vincent Hanquez <vincent.hanquez@xxxxxxxxxxxxx>
---
 tools/libxl/libxl_utils.c |   33 +++++++++++----------------------
 tools/libxl/xl.c          |    4 +---
 2 files changed, 12 insertions(+), 25 deletions(-)

diff -r 7a412f9f6aae -r ab5845cfa62d tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Thu Jan 14 09:42:06 2010 +0000
+++ b/tools/libxl/libxl_utils.c Thu Jan 14 09:42:40 2010 +0000
@@ -56,34 +56,23 @@ char *libxl_domid_to_name(struct libxl_c
 
 int libxl_name_to_domid(struct libxl_ctx *ctx, char *name, uint32_t *domid)
 {
-    unsigned int num, len;
-    char path[strlen("/local/domain") + 12];
-    int i, j, nb_domains;
-    char *domname, **l;
+    int i, nb_domains;
+    char *domname;
     struct libxl_dominfo *dominfo;
 
     dominfo = libxl_domain_list(ctx, &nb_domains);
+    if (!dominfo)
+        return ERROR_NOMEM;
 
-    l = xs_directory(ctx->xsh, XBT_NULL, "/local/domain", &num);
-    for (i = 0; i < num; i++) {
-        snprintf(path, sizeof(path), "/local/domain/%s/name", l[i]);
-        domname = xs_read(ctx->xsh, XBT_NULL, path, &len);
-        if (domname != NULL && len == strlen(name) && !strncmp(domname, name, 
len)) {
-            int domid_i = atoi(l[i]);
-            for (j = 0; j < nb_domains; j++) {
-                if (dominfo[j].domid == domid_i) {
-                    *domid = domid_i;
-                    free(dominfo);
-                    free(l);
-                    free(domname);
-                    return 0;
-                }
-            }
+    for (i = 0; i < nb_domains; i++) {
+        domname = libxl_domid_to_name(ctx, dominfo[i].domid);
+        if (!domname)
+            continue;
+        if (strcmp(domname, name) == 0) {
+            *domid = dominfo[i].domid;
+            return 0;
         }
-        free(domname);
     }
-    free(dominfo);
-    free(l);
     return -1;
 }
 
diff -r 7a412f9f6aae -r ab5845cfa62d tools/libxl/xl.c
--- a/tools/libxl/xl.c  Thu Jan 14 09:42:06 2010 +0000
+++ b/tools/libxl/xl.c  Thu Jan 14 09:42:40 2010 +0000
@@ -59,9 +59,7 @@ static int domain_qualifier_to_domid(str
         }
     }
 
-    if (i == 0)
-        return -1;
-    if (alldigit) {
+    if (i > 0 && alldigit) {
         *domid = strtoul(p, NULL, 10);
         return 0;
     } else {

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.