libxl: change libxl__xs_mkdir() to libxl__xs_mknod()
cover libxl: change libxl__xs_mkdir() to libxl__xs_mknod()
Patch #1 is purely a search and replace
Patch #2 changes the underlying implementation
PATCH 1/2 libxl: replace libxl__xs_mkdir() with libxl__xs_mknod()
This patch is purely cosmetic, it contains no functional change. A change in the implementation of libxl__xs_mknod() will be made in a subsequent patch.
--- tools/libxl/libxl_create.c | 26 +++++++++++++------------- tools/libxl/libxl_internal.h | 2 +- tools/libxl/libxl_xshelp.c | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-)
tools/libxl/libxl_create.c +13 -13
@@ -583,43 +583,43 @@ retry_transaction: t =xs_transaction_start (ctx->xsh);xs_rm (ctx->xsh, t, dom_path); -libxl__xs_mkdir (gc, t, dom_path, roperm,ARRAY_SIZE (roperm)); +libxl__xs_mknod (gc, t, dom_path, roperm,ARRAY_SIZE (roperm));xs_rm (ctx->xsh, t, vm_path); -libxl__xs_mkdir (gc, t, vm_path, roperm,ARRAY_SIZE (roperm)); +libxl__xs_mknod (gc, t, vm_path, roperm,ARRAY_SIZE (roperm));xs_rm (ctx->xsh, t, libxl_path); -libxl__xs_mkdir (gc, t, libxl_path, noperm,ARRAY_SIZE (noperm)); +libxl__xs_mknod (gc, t, libxl_path, noperm,ARRAY_SIZE (noperm));xs_write (ctx->xsh, t,GCSPRINTF ("%s/vm" , dom_path), vm_path,strlen (vm_path)); rc =libxl__domain_rename (gc, *domid,0 , info->name, t);if (rc) goto out; -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/cpu" , dom_path), roperm,ARRAY_SIZE (roperm)); -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/memory" , dom_path), roperm,ARRAY_SIZE (roperm)); -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/device" , dom_path), roperm,ARRAY_SIZE (roperm)); -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/control" , dom_path), roperm,ARRAY_SIZE (roperm));if (info->type ==LIBXL_DOMAIN_TYPE_HVM ) -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/hvmloader" , dom_path), roperm,ARRAY_SIZE (roperm)); -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/control/shutdown" , dom_path), rwperm,ARRAY_SIZE (rwperm)); -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/device/suspend/event-channel" , dom_path), rwperm,ARRAY_SIZE (rwperm)); -libxl__xs_mkdir (gc, t, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/data" , dom_path), rwperm,ARRAY_SIZE (rwperm));
@@ -628,13 +628,13 @@ retry_transaction:* Create a local "libxl" directory for each guest, since we might want * to use libxl from inside the guest */ -libxl__xs_mkdir (gc, t,GCSPRINTF ("%s/libxl" , dom_path), rwperm, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/libxl" , dom_path), rwperm,ARRAY_SIZE (rwperm));/* * Create a local "device-model" directory for each guest, since we * might want to use Qemu from inside the guest */ -libxl__xs_mkdir (gc, t,GCSPRINTF ("%s/device-model" , dom_path), rwperm, +libxl__xs_mknod (gc, t,GCSPRINTF ("%s/device-model" , dom_path), rwperm,ARRAY_SIZE (rwperm)); }
tools/libxl/libxl_internal.h +1 -1
@@ -680,7 +680,7 @@ _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_mkdir(libxl__gc *gc, xs_transaction_t t, +_hidden bool libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t,const char *path,struct xs_permissions *perms,unsigned int num_perms);
tools/libxl/libxl_xshelp.c +1 -1
@@ -147,7 +147,7 @@ char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,return ret; } -bool libxl__xs_mkdir (libxl__gc *gc,xs_transaction_t t, +bool libxl__xs_mknod (libxl__gc *gc,xs_transaction_t t,const char *path,struct xs_permissions *perms,unsigned int num_perms) {
Signature · 1 line
2.1.4
PATCH 2/2 libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR
In reply to Paul DurrantThis 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.
--- tools/libxl/CODING_STYLE | 1 + tools/libxl/libxl_internal.h | 9 +++++---- tools/libxl/libxl_xshelp.c | 20 ++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-)
tools/libxl/CODING_STYLE +1 -0
@@ -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 return value from a boolean function */ uint32_t domid; libxl__gc *gc;
tools/libxl/libxl_internal.h +5 -4
@@ -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 be empty */ +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
tools/libxl/libxl_xshelp.c +14 -6
@@ -147,14 +147,22 @@ 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) +return ERROR_FAIL ; + + ok =xs_set_permissions (ctx->xsh, t, path, perms, num_perms); +if (!ok) +return ERROR_FAIL ; + +return 0 ; }char *libxl__xs_libxl_path (libxl__gc *gc,uint32_t domid)
Signature · 1 line
2.1.4
Re: [PATCH 1/2] libxl: replace libxl__xs_mkdir() with libxl__xs_mknod()
In reply to Paul DurrantPaul Durrant writes ("[PATCH 1/2] libxl: replace libxl__xs_mkdir() with libxl__xs_mknod()"):
Quoted 3 lines
This patch is purely cosmetic, it contains no functional change. A change in the implementation of
libxl__xs_mknod()will be made in a subsequent patch.
Re: [PATCH 2/2] libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR
In reply to Paul DurrantPaul Durrant writes ("[PATCH 2/2] libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR"):
Quoted 7 lines
This patch modifies the implentation of
libxl__xs_mknod()to useXS_WRITErather thanXS_MKDIRsince 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 inlibxl_internal.h, and a comment is added to clarify its semantics.
...
tools/libxl/libxl_internal.h _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid); · line 694
Quoted 4 lines
tools/libxl/libxl_internal.h +4
-0+/* On success, path will exist and will be empty */ +int libxl__xs_mknod (libxl__gc *gc,xs_transaction_t t, +const char *path,struct xs_permissions *perms, +unsigned int num_perms);
I like the idea of making this function a `checked' one, but:
/*----- "checked" xenstore access functions -----*/ /* Each of these functions will check that it succeeded; if it
* fails it logs and returns ERROR_FAIL.
*/
but your implementation does not log anything.
I think it's probably correct to add the logging but it would perhaps be worth checking the call sites.
While I am here, you maybe want to adjust the wording of a couple of comments:
Quoted 1 line
+/* On success, path will exist and will be empty */
You mean `will have an empty value'. WRITE does not delete any subtrees (and libxl__xs_mknod shouldn't IMO).
Quoted 1 line
+ bool ok; /* the return value from a boolean function */
Maybe say `the success return value from a boolean function' ?
Ian.
Re: [PATCH 2/2] libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR
Quoted 26 lines
-----Original Message-----
From: Ian Jackson [mailto:[email protected]]
Sent: 25 November 2015 14:04
To: Paul Durrant
Cc: [email protected]; Stefano Stabellini; Ian Campbell; Wei Liu
Subject: Re: [PATCH 2/2] libxl: implementlibxl__xs_mknodusingXS_WRITErather thanXS_MKDIRPaul Durrant writes ("[PATCH 2/2] libxl: implement
libxl__xs_mknodusingXS_WRITErather thanXS_MKDIR"):Quoted 1 line
This patch modifies the implentation of
libxl__xs_mknod()to use
XS_WRITEQuoted 6 lines
rather than
XS_MKDIRsince 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 inlibxl_internal.h, and a comment is added to clarify its semantics....
tools/libxl/libxl_internal.h _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid); · line 694
Quoted 4 lines
tools/libxl/libxl_internal.h +4
-0+/* On success, path will exist and will be empty */ +int libxl__xs_mknod (libxl__gc *gc,xs_transaction_t t, +const char *path,struct xs_permissions *perms, +unsigned int num_perms);I like the idea of making this function a `checked' one, but:
Quoted 6 lines
/*----- "checked" xenstore access functions -----*/ /* Each of these functions will check that it succeeded; if it
* fails it logs and returnsERROR_FAIL.
*/but your implementation does not log anything.
Damn. I meant to add that too.
Quoted 4 lines
I think it's probably correct to add the logging but it would perhaps be worth checking the call sites.
Sure.
Quoted 9 lines
While I am here, you maybe want to adjust the wording of a couple of comments:
Quoted 1 line
+/* On success, path will exist and will be empty */
You mean `will have an empty value'. WRITE does not delete any subtrees (and
libxl__xs_mknodshouldn't IMO).
Yes, I'll re-word.
Quoted 5 lines
Quoted 2 lines
+ bool ok; /* the return value from a boolean function */
Maybe say `the success return value from a boolean function' ?
Ok.
Paul
Quoted 1 line
Ian.