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

[Xen-devel] [PATCH 1 of 4] Open code rw and ro path creation



# HG changeset patch
# User Paul Durrant <paul.durrant@xxxxxxxxxx>
# Date 1324044735 0
# Node ID a8c26cdf079cd6e3aa934e5011e554e36f33fce3
# Parent  03138a08366b895d79e143119d4c9c72833cdbcd
Open code rw and ro path creation.

Use a new libxl__xs_mkdir() to do this and also clean up extraneous path 
creation
while in the neighbourhood. Checking 'xenstore-ls -fp' output before and after
shows that, as well as the disappearance of error, drivers, messages and domid, 
the
following perms change is also present:

-device/suspend = ""   (ndomU)
+device/suspend = ""   (n0,rdomU)

I believe the new perms are more desirable than the old ones.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>

diff -r 03138a08366b -r a8c26cdf079c tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Fri Dec 09 16:19:36 2011 +0000
+++ b/tools/libxl/libxl_create.c        Fri Dec 16 14:12:15 2011 +0000
@@ -320,11 +320,8 @@ int libxl__domain_make(libxl__gc *gc, li
   * on exit (even error exit), domid may be valid and refer to a domain */
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    int flags, ret, i, rc;
+    int flags, ret, rc;
     char *uuid_string;
-    char *rw_paths[] = { "control/shutdown", "device", 
"device/suspend/event-channel" , "data"};
-    char *ro_paths[] = { "cpu", "memory", "device", "error", "drivers",
-                         "control", "attr", "messages" };
     char *dom_path, *vm_path, *libxl_path;
     struct xs_permissions roperm[2];
     struct xs_permissions rwperm[1];
@@ -384,6 +381,7 @@ int libxl__domain_make(libxl__gc *gc, li
         rc = ERROR_FAIL;
         goto out;
     }
+
     noperm[0].id = 0;
     noperm[0].perms = XS_PERM_NONE;
 
@@ -391,6 +389,7 @@ int libxl__domain_make(libxl__gc *gc, li
     roperm[0].perms = XS_PERM_NONE;
     roperm[1].id = *domid;
     roperm[1].perms = XS_PERM_READ;
+
     rwperm[0].id = *domid;
     rwperm[0].perms = XS_PERM_NONE;
 
@@ -398,32 +397,42 @@ retry_transaction:
     t = xs_transaction_start(ctx->xsh);
 
     xs_rm(ctx->xsh, t, dom_path);
-    xs_mkdir(ctx->xsh, t, dom_path);
-    xs_set_permissions(ctx->xsh, t, dom_path, roperm, ARRAY_SIZE(roperm));
+    libxl__xs_mkdir(gc, t, dom_path, roperm, ARRAY_SIZE(roperm));
+
 
     xs_rm(ctx->xsh, t, vm_path);
-    xs_mkdir(ctx->xsh, t, vm_path);
-    xs_set_permissions(ctx->xsh, t, vm_path, roperm, ARRAY_SIZE(roperm));
+    libxl__xs_mkdir(gc, t, vm_path, roperm, ARRAY_SIZE(roperm));
 
     xs_rm(ctx->xsh, t, libxl_path);
-    xs_mkdir(ctx->xsh, t, libxl_path);
-    xs_set_permissions(ctx->xsh, t, libxl_path, noperm, ARRAY_SIZE(noperm));
+    libxl__xs_mkdir(gc, t, libxl_path, noperm, ARRAY_SIZE(noperm));
 
     xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/vm", dom_path), vm_path, 
strlen(vm_path));
     rc = libxl__domain_rename(gc, *domid, 0, info->name, t);
     if (rc)
         goto out;
 
-    for (i = 0; i < ARRAY_SIZE(rw_paths); i++) {
-        char *path = libxl__sprintf(gc, "%s/%s", dom_path, rw_paths[i]);
-        xs_mkdir(ctx->xsh, t, path);
-        xs_set_permissions(ctx->xsh, t, path, rwperm, ARRAY_SIZE(rwperm));
-    }
-    for (i = 0; i < ARRAY_SIZE(ro_paths); i++) {
-        char *path = libxl__sprintf(gc, "%s/%s", dom_path, ro_paths[i]);
-        xs_mkdir(ctx->xsh, t, path);
-        xs_set_permissions(ctx->xsh, t, path, roperm, ARRAY_SIZE(roperm));
-    }
+    libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/cpu", dom_path),
+                    roperm, ARRAY_SIZE(roperm));
+    libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/memory", dom_path),
+                    roperm, ARRAY_SIZE(roperm));
+    libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/device", dom_path),
+                    roperm, ARRAY_SIZE(roperm));
+    libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/control", dom_path),
+                    roperm, ARRAY_SIZE(roperm));
+
+    libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/control/shutdown", dom_path),
+                    rwperm, ARRAY_SIZE(rwperm));
+    libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/device/suspend/event-channel", 
dom_path),
+                    rwperm, ARRAY_SIZE(rwperm));
+    libxl__xs_mkdir(gc, t,
+                    libxl__sprintf(gc, "%s/data", dom_path),
+                    rwperm, ARRAY_SIZE(rwperm));
 
     xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/uuid", vm_path), uuid_string, 
strlen(uuid_string));
     xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/name", vm_path), info->name, 
strlen(info->name));
diff -r 03138a08366b -r a8c26cdf079c tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Fri Dec 09 16:19:36 2011 +0000
+++ b/tools/libxl/libxl_internal.h      Fri Dec 16 14:12:15 2011 +0000
@@ -204,6 +204,9 @@ _hidden char *libxl__xs_read(libxl__gc *
 _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
                                    const char *path, unsigned int *nb);
    /* On error: returns NULL, sets errno (no logging) */
+_hidden bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t,
+                             const char *path, struct xs_permissions *perms,
+                            unsigned int num_perms);
 
 _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
 
diff -r 03138a08366b -r a8c26cdf079c tools/libxl/libxl_xshelp.c
--- a/tools/libxl/libxl_xshelp.c        Fri Dec 09 16:19:36 2011 +0000
+++ b/tools/libxl/libxl_xshelp.c        Fri Dec 16 14:12:15 2011 +0000
@@ -122,6 +122,16 @@ char **libxl__xs_directory(libxl__gc *gc
     return ret;
 }
 
+bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t,
+                     const char *path, struct xs_permissions *perms,
+                                unsigned int num_perms)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    if (!xs_mkdir(ctx->xsh, t, path))
+        return false;
+    return xs_set_permissions(ctx->xsh, t, path, perms, num_perms);
+}
+
 char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);

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


 


Rackspace

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