diff options
author | Roger Pau Monne <roger.pau@citrix.com> | 2012-05-23 11:06:48 +0100 |
---|---|---|
committer | Roger Pau Monne <roger.pau@citrix.com> | 2012-05-23 11:06:48 +0100 |
commit | 6aab68ff43c5e4714d3a36eee19b69f14a9ad555 (patch) | |
tree | c7044ee8527c435aa5e2fe5094aff693ec81e492 /tools/libxl/libxl_xshelp.c | |
parent | 145d12a5d284b892875e040f3ccaae68a6df8499 (diff) | |
download | xen-6aab68ff43c5e4714d3a36eee19b69f14a9ad555.tar.gz xen-6aab68ff43c5e4714d3a36eee19b69f14a9ad555.tar.bz2 xen-6aab68ff43c5e4714d3a36eee19b69f14a9ad555.zip |
libxl: add libxl__xs_path_cleanup
Add a function which behaves like "xenstore-rm -t", and which will be
used to clean xenstore after unplug since we will be no longer
executing xen-hotplug-cleanup script, that used to do that for us.
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/libxl/libxl_xshelp.c')
-rw-r--r-- | tools/libxl/libxl_xshelp.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index 6ca1afe632..c5b5364c56 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -135,6 +135,44 @@ char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid) return s; } +int libxl__xs_path_cleanup(libxl__gc *gc, xs_transaction_t t, char *user_path) +{ + unsigned int nb = 0; + char *path, *last, *val; + int rc; + + /* A path and transaction must be provided by the caller */ + assert(user_path && t); + + path = libxl__strdup(gc, user_path); + if (!xs_rm(CTX->xsh, t, path)) { + LOGE(DEBUG, "unable to remove path %s", path); + rc = ERROR_FAIL; + goto out; + } + + for (last = strrchr(path, '/'); last != NULL; last = strrchr(path, '/')) { + *last = '\0'; + + if (!strlen(path)) break; + + val = libxl__xs_read(gc, t, path); + if (!val || strlen(val) != 0) break; + + if (!libxl__xs_directory(gc, t, path, &nb) || nb != 0) break; + + if (!xs_rm(CTX->xsh, t, path)) { + LOGE(DEBUG, "unable to remove path %s", path); + rc = ERROR_FAIL; + goto out; + } + } + rc = 0; + +out: + return rc; +} + /* * Local variables: * mode: C |