libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR
authorPaul Durrant <paul.durrant@citrix.com>
Wed, 25 Nov 2015 14:51:00 +0000 (14:51 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 1 Dec 2015 12:02:13 +0000 (12:02 +0000)
This patch modifies the implentation of libxl__xs_mknod() to use XS_WRITE
rather than XS_MKDIR since passing an empty value to the former will
ensure that the path is both existent and empty upon return, rather than
merely existent. The function return type is also changed to a libxl
error value rather than a boolean, it's declaration is accordingly moved
into the 'checked' section in libxl_internal.h, and a comment is added to
clarify its semantics.

This patch also contains as small whitespace fix in the definition of
libxl__xs_mknod() and the addition of 'ok' to CODING_STYLE as the
canonical variable name for holding return values from boolean functions.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/CODING_STYLE
tools/libxl/libxl_internal.h
tools/libxl/libxl_xshelp.c

index 919bcc636cf36f98d3dc836963d130c889124ea8..522d1c98b4a021628c038fcdd7b8a6564f480899 100644 (file)
@@ -35,6 +35,7 @@ The following local variable names should be used where applicable:
 
   int rc;    /* a libxl error code - and not anything else */
   int r;     /* the return value from a system call (or libxc call) */
+  bool ok;   /* the success return value from a boolean function */
 
   uint32_t domid;
   libxl__gc *gc;
index a671a61665098f827bd6a2b7e9c39ce7e7a9cfc6..d2bda0af0afee5836c769a4d9bd6d68b62c13927 100644 (file)
@@ -680,10 +680,6 @@ _hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t,
 _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_mknod(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);
 
 
@@ -692,6 +688,11 @@ _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
  * fails it logs and returns ERROR_FAIL.
  */
 
+/* On success, path will exist and will have an empty value */
+int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t,
+                    const char *path, struct xs_permissions *perms,
+                    unsigned int num_perms);
+
 /* On success, *result_out came from the gc.
  * On error, *result_out is undefined.
  * ENOENT counts as success but sets *result_out=0
index cb6a559f3c9b9bb987da7d499bb789061579bd61..8554ee54df40875ae16e4b2cd2e65870737bc233 100644 (file)
@@ -147,14 +147,26 @@ char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
     return ret;
 }
 
-bool libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t,
-                     const char *path, struct xs_permissions *perms,
-                                unsigned int num_perms)
+int libxl__xs_mknod(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);
+    bool ok;
+
+    ok = xs_write(ctx->xsh, t, path, "", 0);
+    if (!ok) {
+        LOGE(ERROR, "xenstore write failed: `%s' = ''", path);
+        return ERROR_FAIL;
+    }
+
+    ok = xs_set_permissions(ctx->xsh, t, path, perms, num_perms);
+    if (!ok) {
+        LOGE(ERROR, "xenstore set permissions failed on `%s'", path);
+        return ERROR_FAIL;
+    }
+
+    return 0;
 }
 
 char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)