From dec408299ea7a2cb9aa9aa3ea3a3c72ee79169de Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Tue, 5 May 2009 15:58:48 +0530 Subject: libglusterfsclient: Add remove API Signed-off-by: Anand V. Avati --- libglusterfsclient/src/libglusterfsclient.c | 61 +++++++++++++++++++++++++++++ libglusterfsclient/src/libglusterfsclient.h | 25 ++++++++++++ 2 files changed, 86 insertions(+) diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 6d8910fe1..c36d9b4db 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -6140,6 +6140,67 @@ out: return realp; } +int +glusterfs_glh_remove (glusterfs_handle_t handle, const char *path) +{ + loc_t loc = {0, }; + int op_ret = -1; + libglusterfs_client_ctx_t *ctx = handle; + char *name = NULL; + + GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, handle, out); + GF_VALIDATE_ABSOLUTE_PATH_OR_GOTO (LIBGF_XL_NAME, path, out); + + loc.path = libgf_resolve_path_light ((char *)path); + if (!loc.path) + goto out; + + op_ret = libgf_client_path_lookup (&loc, ctx, 1); + if (op_ret == -1) + goto out; + + name = strdup (loc.path); + op_ret = libgf_client_loc_fill (&loc, ctx, 0, loc.parent->ino, + basename (name)); + if (op_ret == -1) + goto out; + + if (S_ISDIR (loc.inode->st_mode)) + op_ret = libgf_client_rmdir (ctx, &loc); + else + op_ret = libgf_client_unlink (ctx, &loc); + +out: + if (name) + FREE (name); + return op_ret; + +} + +int +glusterfs_remove(const char *pathname) +{ + struct vmp_entry *entry = NULL; + int op_ret = -1; + char *vpath = NULL; + + GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, pathname, out); + + entry = libgf_vmp_search_entry ((char *)pathname); + if (!entry) { + errno = ENODEV; + goto out; + } + + vpath = libgf_vmp_virtual_path (entry, pathname); + op_ret = glusterfs_glh_remove (entry->handle, vpath); + +out: + if (vpath) + FREE (vpath); + return op_ret; +} + static struct xlator_fops libgf_client_fops = { }; diff --git a/libglusterfsclient/src/libglusterfsclient.h b/libglusterfsclient/src/libglusterfsclient.h index 7c0c25062..37fcf04dd 100755 --- a/libglusterfsclient/src/libglusterfsclient.h +++ b/libglusterfsclient/src/libglusterfsclient.h @@ -1118,6 +1118,31 @@ glusterfs_glh_rename (glusterfs_handle_t handle, const char *oldpath, */ int glusterfs_rename (const char *oldpath, const char *newpath); + + + +/* Remove a file or directory in the given glusterfs context. + * + * @handle : Handle identifying the glusterfs context. + * @path : Path of the file or directory to be removed. + * + * + * Returns 0 on success and -1 on error with errno set appropriately. + */ +int +glusterfs_glh_remove (glusterfs_handle_t handle, const char *path); + + + +/* Remove a file or directory. + * + * @path : Path of the file or directory to be removed. The + * path must be pre-fixed with the VMP. + * + * Returns 0 on success and -1 on error with errno set appropriately. + */ +int +glusterfs_remove (const char *path); /* FIXME: review the need for these apis */ /* added for log related initialization in booster fork implementation */ void -- cgit