[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 2/2] libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR
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@xxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> --- v2: - Add logging should libxl__xs_mknod() fail - Clarify semantics of libxl__xs_mknod() in libxl_internal.h - Re-word use ok 'ok' in libxl/CODING_STYLE --- tools/libxl/CODING_STYLE | 1 + tools/libxl/libxl_internal.h | 9 +++++---- tools/libxl/libxl_xshelp.c | 24 ++++++++++++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/tools/libxl/CODING_STYLE b/tools/libxl/CODING_STYLE index 919bcc6..522d1c9 100644 --- a/tools/libxl/CODING_STYLE +++ b/tools/libxl/CODING_STYLE @@ -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; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index a671a61..d2bda0a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -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 diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index cb6a559..8554ee5 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -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) -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |