diff options
-rw-r--r-- | heal/src/glfs-heal.c | 40 | ||||
-rw-r--r-- | libglusterfs/src/Makefile.am | 3 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.c | 51 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 3 | ||||
-rw-r--r-- | libglusterfs/src/inode.c | 4 | ||||
-rw-r--r-- | libglusterfs/src/syncop-utils.c | 265 | ||||
-rw-r--r-- | libglusterfs/src/syncop-utils.h | 33 | ||||
-rw-r--r-- | libglusterfs/src/syncop.c | 166 | ||||
-rw-r--r-- | libglusterfs/src/syncop.h | 13 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-common.c | 58 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heald.c | 88 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.h | 3 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix.c | 12 |
13 files changed, 378 insertions, 361 deletions
diff --git a/heal/src/glfs-heal.c b/heal/src/glfs-heal.c index 3ea3f430e3b..7e8673a65ac 100644 --- a/heal/src/glfs-heal.c +++ b/heal/src/glfs-heal.c @@ -16,6 +16,7 @@ #include "glfs-internal.h" #include "protocol-common.h" #include "syncop.h" +#include "syncop-utils.h" #include <string.h> #include <time.h> @@ -124,43 +125,6 @@ glfsh_index_purge (xlator_t *subvol, inode_t *inode, char *name) return ret; } -int -glfsh_gfid_to_path (xlator_t *this, xlator_t *subvol, uuid_t gfid, char **path_p) -{ - int ret = 0; - char *path = NULL; - loc_t loc = {0,}; - dict_t *xattr = NULL; - - uuid_copy (loc.gfid, gfid); - loc.inode = inode_new (this->itable); - - ret = syncop_getxattr (subvol, &loc, &xattr, GFID_TO_PATH_KEY, NULL); - if (ret) - goto out; - - ret = dict_get_str (xattr, GFID_TO_PATH_KEY, &path); - if (ret || !path) { - ret = -EINVAL; - goto out; - } - - *path_p = gf_strdup (path); - if (!*path_p) { - ret = -ENOMEM; - goto out; - } - - ret = 0; - -out: - if (xattr) - dict_unref (xattr); - loc_wipe (&loc); - - return ret; -} - void glfsh_print_spb_status (dict_t *dict, char *path, uuid_t gfid, uint64_t *num_entries) @@ -275,7 +239,7 @@ glfsh_process_entries (xlator_t *xl, fd_t *fd, gf_dirent_t *entries, if (ret) continue; - ret = glfsh_gfid_to_path (this, xl, gfid, &path); + ret = syncop_gfid_to_path (this->itable, xl, gfid, &path); if (ret == -ENOENT || ret == -ESTALE) { glfsh_index_purge (xl, fd->inode, entry->d_name); diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index d117cc17605..b403f2c3bf7 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -26,6 +26,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \ $(CONTRIBDIR)/uuid/isnull.c $(CONTRIBDIR)/uuid/unpack.c syncop.c \ graph-print.c trie.c run.c options.c fd-lk.c circ-buff.c \ event-history.c gidcache.c ctx.c client_t.c event-poll.c event-epoll.c \ + syncop-utils.c \ $(CONTRIBDIR)/libgen/basename_r.c $(CONTRIBDIR)/libgen/dirname_r.c \ $(CONTRIBDIR)/stdlib/gf_mkostemp.c strfd.c \ $(CONTRIBDIR)/mount/mntent.c $(CONTRIBDIR)/libexecinfo/execinfo.c @@ -44,7 +45,7 @@ noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h timespec. $(CONTRIB_BUILDDIR)/uuid/uuid_types.h syncop.h graph-utils.h trie.h \ run.h options.h lkowner.h fd-lk.h circ-buff.h event-history.h \ gidcache.h client_t.h glusterfs-acl.h glfs-message-id.h \ - template-component-messages.h strfd.h \ + template-component-messages.h strfd.h syncop-utils.h \ $(CONTRIBDIR)/mount/mntent_compat.h lvm-defaults.h \ $(CONTRIBDIR)/libexecinfo/execinfo_compat.h diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 39da27d83dd..cfbf3191eef 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3648,3 +3648,54 @@ gf_get_index_by_elem (char **array, char *elem) return -1; } + +static int +get_pathinfo_host (char *pathinfo, char *hostname, size_t size) +{ + char *start = NULL; + char *end = NULL; + int ret = -1; + int i = 0; + + if (!pathinfo) + goto out; + + start = strchr (pathinfo, ':'); + if (!start) + goto out; + + end = strrchr (pathinfo, ':'); + if (start == end) + goto out; + + memset (hostname, 0, size); + i = 0; + while (++start != end) + hostname[i++] = *start; + ret = 0; +out: + return ret; +} + +/*Note: 'pathinfo' should be gathered only from one brick*/ +int +glusterfs_is_local_pathinfo (char *pathinfo, gf_boolean_t *is_local) +{ + int ret = 0; + char pathinfohost[1024] = {0}; + char localhost[1024] = {0}; + + *is_local = _gf_false; + ret = get_pathinfo_host (pathinfo, pathinfohost, sizeof (pathinfohost)); + if (ret) + goto out; + + ret = gethostname (localhost, sizeof (localhost)); + if (ret) + goto out; + + if (!strcmp (localhost, pathinfohost)) + *is_local = _gf_true; +out: + return ret; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 69b1e277861..6e1669912cd 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -679,4 +679,7 @@ recursive_rmdir (const char *delete_path); int gf_get_index_by_elem (char **array, char *elem); + +int +glusterfs_is_local_pathinfo (char *pathinfo, gf_boolean_t *local); #endif /* _COMMON_UTILS_H */ diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index e0079524e2d..2189a032afe 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -1185,7 +1185,7 @@ __inode_path (inode_t *inode, const char *name, char **bufp) if (!inode || uuid_is_null (inode->gfid)) { GF_ASSERT (0); gf_log_callingfn (THIS->name, GF_LOG_WARNING, "invalid inode"); - return -1; + return -EINVAL; } table = inode->table; @@ -1276,7 +1276,7 @@ inode_path (inode_t *inode, const char *name, char **bufp) int ret = -1; if (!inode) - return -1; + return -EINVAL; table = inode->table; diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c new file mode 100644 index 00000000000..53768acd0ac --- /dev/null +++ b/libglusterfs/src/syncop-utils.c @@ -0,0 +1,265 @@ +/* + Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "syncop.h" +#include "common-utils.h" + +int +syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid) +{ + int ret = 0; + fd_t *dirfd = NULL; + + if (!fd) + return -EINVAL; + + dirfd = fd_create (loc->inode, pid); + if (!dirfd) { + gf_log (subvol->name, GF_LOG_ERROR, + "fd_create of %s failed: %s", + uuid_utoa (loc->gfid), strerror(errno)); + ret = -errno; + goto out; + } + + ret = syncop_opendir (subvol, loc, dirfd); + if (ret) { + /* + * On Linux, if the brick was not updated, opendir will + * fail. We therefore use backward compatible code + * that violate the standards by reusing offsets + * in seekdir() from different DIR *, but it works on Linux. + * + * On other systems it never worked, hence we do not need + * to provide backward-compatibility. + */ +#ifdef GF_LINUX_HOST_OS + fd_unref (dirfd); + dirfd = fd_anonymous (loc->inode); + if (!dirfd) { + gf_log(subvol->name, GF_LOG_ERROR, + "fd_anonymous of %s failed: %s", + uuid_utoa (loc->gfid), strerror(errno)); + ret = -errno; + goto out; + } + ret = 0; +#else /* GF_LINUX_HOST_OS */ + fd_unref (dirfd); + gf_log (subvol->name, GF_LOG_ERROR, + "opendir of %s failed: %s", + uuid_utoa (loc->gfid), strerror(errno)); + goto out; +#endif /* GF_LINUX_HOST_OS */ + } +out: + if (ret == 0) + *fd = dirfd; + return ret; +} + +int +syncop_ftw (xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, + void *data)) +{ + loc_t child_loc = {0, }; + fd_t *fd = NULL; + uint64_t offset = 0; + gf_dirent_t *entry = NULL; + int ret = 0; + gf_dirent_t entries; + + ret = syncop_dirfd (subvol, loc, &fd, pid); + if (ret) + goto out; + + INIT_LIST_HEAD (&entries.list); + + while ((ret = syncop_readdirp (subvol, fd, 131072, offset, 0, + &entries))) { + if (ret < 0) + break; + + if (ret > 0) { + /* If the entries are only '.', and '..' then ret + * value will be non-zero. so set it to zero here. */ + ret = 0; + } + list_for_each_entry (entry, &entries.list, list) { + offset = entry->d_off; + + if (!strcmp (entry->d_name, ".") || + !strcmp (entry->d_name, "..")) + continue; + + gf_link_inode_from_dirent (NULL, fd->inode, entry); + + ret = fn (subvol, entry, loc, data); + if (ret) + break; + + if (entry->d_stat.ia_type == IA_IFDIR) { + child_loc.inode = inode_ref (entry->inode); + uuid_copy (child_loc.gfid, entry->inode->gfid); + ret = syncop_ftw (subvol, &child_loc, + pid, data, fn); + loc_wipe (&child_loc); + if (ret) + break; + } + } + + gf_dirent_free (&entries); + if (ret) + break; + } + +out: + if (fd) + fd_unref (fd); + return ret; +} + +int +syncop_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, + void *data)) +{ + fd_t *fd = NULL; + uint64_t offset = 0; + gf_dirent_t *entry = NULL; + int ret = 0; + gf_dirent_t entries; + + ret = syncop_dirfd (subvol, loc, &fd, pid); + if (ret) + goto out; + + INIT_LIST_HEAD (&entries.list); + + while ((ret = syncop_readdir (subvol, fd, 131072, offset, &entries))) { + if (ret < 0) + break; + + if (ret > 0) { + /* If the entries are only '.', and '..' then ret + * value will be non-zero. so set it to zero here. */ + ret = 0; + } + + list_for_each_entry (entry, &entries.list, list) { + offset = entry->d_off; + + if (!strcmp (entry->d_name, ".") || + !strcmp (entry->d_name, "..")) + continue; + + ret = fn (subvol, entry, loc, data); + if (ret) + break; + } + gf_dirent_free (&entries); + if (ret) + break; + } + +out: + if (fd) + fd_unref (fd); + return ret; +} + +int +syncop_is_subvol_local (xlator_t *this, loc_t *loc, gf_boolean_t *is_local) +{ + char *pathinfo = NULL; + dict_t *xattr = NULL; + int ret = 0; + + if (!this || !this->type || !is_local) + return -EINVAL; + + if (strcmp (this->type, "protocol/client") != 0) + return -EINVAL; + + *is_local = _gf_false; + + ret = syncop_getxattr (this, loc, &xattr, GF_XATTR_PATHINFO_KEY, NULL); + if (ret < 0) { + ret = -1; + goto out; + } + + if (!xattr) { + ret = -EINVAL; + goto out; + } + + ret = dict_get_str (xattr, GF_XATTR_PATHINFO_KEY, &pathinfo); + if (ret) + goto out; + + ret = glusterfs_is_local_pathinfo (pathinfo, is_local); + + gf_log (this->name, GF_LOG_DEBUG, "subvol %s is %slocal", + this->name, is_local ? "" : "not "); + +out: + if (xattr) + dict_unref (xattr); + + return ret; +} + +int +syncop_gfid_to_path (inode_table_t *itable, xlator_t *subvol, uuid_t gfid, + char **path_p) +{ + int ret = 0; + char *path = NULL; + loc_t loc = {0,}; + dict_t *xattr = NULL; + + uuid_copy (loc.gfid, gfid); + loc.inode = inode_new (itable); + + ret = syncop_getxattr (subvol, &loc, &xattr, GFID_TO_PATH_KEY, NULL); + if (ret < 0) + goto out; + + ret = dict_get_str (xattr, GFID_TO_PATH_KEY, &path); + if (ret || !path) { + ret = -EINVAL; + goto out; + } + + if (path_p) { + *path_p = gf_strdup (path); + if (!*path_p) { + ret = -ENOMEM; + goto out; + } + } + + ret = 0; + +out: + if (xattr) + dict_unref (xattr); + loc_wipe (&loc); + + return ret; +} diff --git a/libglusterfs/src/syncop-utils.h b/libglusterfs/src/syncop-utils.h new file mode 100644 index 00000000000..918b3b7c666 --- /dev/null +++ b/libglusterfs/src/syncop-utils.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2015, Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef _SYNCOP_UTILS_H +#define _SYNCOP_UTILS_H + +int +syncop_ftw (xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, + void *data)); + +int +syncop_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, + void *data)); + +int +syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid); + +int +syncop_is_subvol_local (xlator_t *this, loc_t *loc, gf_boolean_t *is_local); + +int +syncop_gfid_to_path (inode_table_t *itable, xlator_t *subvol, uuid_t gfid, + char **path_p); +#endif /* _SYNCOP_H */ diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index f571a2ae8bd..a4250330dfd 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -2422,169 +2422,3 @@ syncop_inodelk (xlator_t *subvol, const char *volume, loc_t *loc, int32_t cmd, return args.op_ret; } - -int -syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid) -{ - int ret = 0; - fd_t *dirfd = NULL; - - if (!fd) - return -EINVAL; - - dirfd = fd_create (loc->inode, pid); - if (!dirfd) { - gf_log (subvol->name, GF_LOG_ERROR, - "fd_create of %s failed: %s", - uuid_utoa (loc->gfid), strerror(errno)); - ret = -errno; - goto out; - } - - ret = syncop_opendir (subvol, loc, dirfd); - if (ret) { - /* - * On Linux, if the brick was not updated, opendir will - * fail. We therefore use backward compatible code - * that violate the standards by reusing offsets - * in seekdir() from different DIR *, but it works on Linux. - * - * On other systems it never worked, hence we do not need - * to provide backward-compatibility. - */ -#ifdef GF_LINUX_HOST_OS - fd_unref (dirfd); - dirfd = fd_anonymous (loc->inode); - if (!dirfd) { - gf_log(subvol->name, GF_LOG_ERROR, - "fd_anonymous of %s failed: %s", - uuid_utoa (loc->gfid), strerror(errno)); - ret = -errno; - goto out; - } - ret = 0; -#else /* GF_LINUX_HOST_OS */ - fd_unref (dirfd); - gf_log (subvol->name, GF_LOG_ERROR, - "opendir of %s failed: %s", - uuid_utoa (loc->gfid), strerror(errno)); - goto out; -#endif /* GF_LINUX_HOST_OS */ - } -out: - if (ret == 0) - *fd = dirfd; - return ret; -} - -int -syncop_ftw (xlator_t *subvol, loc_t *loc, int pid, void *data, - int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, - void *data)) -{ - loc_t child_loc = {0, }; - fd_t *fd = NULL; - uint64_t offset = 0; - gf_dirent_t *entry = NULL; - int ret = 0; - gf_dirent_t entries; - - ret = syncop_dirfd (subvol, loc, &fd, pid); - if (ret) - goto out; - - INIT_LIST_HEAD (&entries.list); - - while ((ret = syncop_readdirp (subvol, fd, 131072, offset, 0, - &entries))) { - if (ret < 0) - break; - - if (ret > 0) { - /* If the entries are only '.', and '..' then ret - * value will be non-zero. so set it to zero here. */ - ret = 0; - } - list_for_each_entry (entry, &entries.list, list) { - offset = entry->d_off; - - if (!strcmp (entry->d_name, ".") || - !strcmp (entry->d_name, "..")) - continue; - - gf_link_inode_from_dirent (NULL, fd->inode, entry); - - ret = fn (subvol, entry, loc, data); - if (ret) - break; - - if (entry->d_stat.ia_type == IA_IFDIR) { - child_loc.inode = inode_ref (entry->inode); - uuid_copy (child_loc.gfid, entry->inode->gfid); - ret = syncop_ftw (subvol, &child_loc, - pid, data, fn); - loc_wipe (&child_loc); - if (ret) - break; - } - } - - gf_dirent_free (&entries); - if (ret) - break; - } - -out: - if (fd) - fd_unref (fd); - return ret; -} - -int -syncop_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data, - int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, - void *data)) -{ - fd_t *fd = NULL; - uint64_t offset = 0; - gf_dirent_t *entry = NULL; - int ret = 0; - gf_dirent_t entries; - - ret = syncop_dirfd (subvol, loc, &fd, pid); - if (ret) - goto out; - - INIT_LIST_HEAD (&entries.list); - - while ((ret = syncop_readdir (subvol, fd, 131072, offset, &entries))) { - if (ret < 0) - break; - - if (ret > 0) { - /* If the entries are only '.', and '..' then ret - * value will be non-zero. so set it to zero here. */ - ret = 0; - } - - list_for_each_entry (entry, &entries.list, list) { - offset = entry->d_off; - - if (!strcmp (entry->d_name, ".") || - !strcmp (entry->d_name, "..")) - continue; - - ret = fn (subvol, entry, loc, data); - if (ret) - break; - } - gf_dirent_free (&entries); - if (ret) - break; - } - -out: - if (fd) - fd_unref (fd); - return ret; -} diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h index 3f751de6da5..e3b51018307 100644 --- a/libglusterfs/src/syncop.h +++ b/libglusterfs/src/syncop.h @@ -432,17 +432,4 @@ int syncop_lk (xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock); int syncop_inodelk (xlator_t *subvol, const char *volume, loc_t *loc, int32_t cmd, struct gf_flock *lock, dict_t *xdata_req, dict_t **xdata_rsp); - -int -syncop_ftw (xlator_t *subvol, loc_t *loc, int pid, void *data, - int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, - void *data)); - -int -syncop_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data, - int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, - void *data)); - -int -syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid); #endif /* _SYNCOP_H */ diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c index 333c2bda556..04a90aae4c6 100644 --- a/xlators/cluster/afr/src/afr-common.c +++ b/xlators/cluster/afr/src/afr-common.c @@ -1442,62 +1442,6 @@ afr_final_errno (afr_local_t *local, afr_private_t *priv) return op_errno; } -static int -get_pathinfo_host (char *pathinfo, char *hostname, size_t size) -{ - char *start = NULL; - char *end = NULL; - int ret = -1; - int i = 0; - - if (!pathinfo) - goto out; - - start = strchr (pathinfo, ':'); - if (!start) - goto out; - end = strrchr (pathinfo, ':'); - if (start == end) - goto out; - - memset (hostname, 0, size); - i = 0; - while (++start != end) - hostname[i++] = *start; - ret = 0; -out: - return ret; -} - -int -afr_local_pathinfo (char *pathinfo, gf_boolean_t *local) -{ - int ret = 0; - char pathinfohost[1024] = {0}; - char localhost[1024] = {0}; - xlator_t *this = THIS; - - *local = _gf_false; - ret = get_pathinfo_host (pathinfo, pathinfohost, sizeof (pathinfohost)); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Invalid pathinfo: %s", - pathinfo); - goto out; - } - - ret = gethostname (localhost, sizeof (localhost)); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "gethostname() failed, " - "reason: %s", strerror (errno)); - goto out; - } - - if (!strcmp (localhost, pathinfohost)) - *local = _gf_true; -out: - return ret; -} - static int32_t afr_local_discovery_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, dict_t *dict, @@ -1521,7 +1465,7 @@ afr_local_discovery_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } - ret = afr_local_pathinfo (pathinfo, &is_local); + ret = glusterfs_is_local_pathinfo (pathinfo, &is_local); if (ret) { goto out; } diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c index f979f992660..707c12b7565 100644 --- a/xlators/cluster/afr/src/afr-self-heald.c +++ b/xlators/cluster/afr/src/afr-self-heald.c @@ -18,6 +18,7 @@ #include "afr-self-heal.h" #include "afr-self-heald.h" #include "protocol-common.h" +#include "syncop-utils.h" #define SHD_INODE_LRU_LIMIT 2048 #define AFR_EH_SPLIT_BRAIN_LIMIT 1024 @@ -76,46 +77,15 @@ afr_destroy_shd_event_data (void *data) gf_boolean_t afr_shd_is_subvol_local (xlator_t *this, int subvol) { - char *pathinfo = NULL; - afr_private_t *priv = NULL; - dict_t *xattr = NULL; - int ret = 0; - gf_boolean_t is_local = _gf_false; - loc_t loc = {0, }; + afr_private_t *priv = NULL; + gf_boolean_t is_local = _gf_false; + loc_t loc = {0, }; + loc.inode = this->itable->root; + uuid_copy (loc.gfid, loc.inode->gfid); priv = this->private; - - loc.inode = this->itable->root; - uuid_copy (loc.gfid, loc.inode->gfid); - - ret = syncop_getxattr (priv->children[subvol], &loc, &xattr, - GF_XATTR_PATHINFO_KEY, NULL); - if (ret) { - is_local = _gf_false; - goto out; - } - - if (!xattr) { - is_local = _gf_false; - goto out; - } - - ret = dict_get_str (xattr, GF_XATTR_PATHINFO_KEY, &pathinfo); - if (ret) { - is_local = _gf_false; - goto out; - } - - afr_local_pathinfo (pathinfo, &is_local); - - gf_log (this->name, GF_LOG_DEBUG, "subvol %s is %slocal", - priv->children[subvol]->name, is_local? "" : "not "); - -out: - if (xattr) - dict_unref (xattr); - - return is_local; + syncop_is_subvol_local(priv->children[subvol], &loc, &is_local); + return is_local; } @@ -301,7 +271,7 @@ afr_shd_selfheal (struct subvol_healer *healer, int child, uuid_t gfid) subvol = priv->children[child]; //If this fails with ENOENT/ESTALE index is stale - ret = afr_shd_gfid_to_path (this, subvol, gfid, &path); + ret = syncop_gfid_to_path (this->itable, subvol, gfid, &path); if (ret < 0) return ret; @@ -805,44 +775,6 @@ out: return ret; } - -int -afr_shd_gfid_to_path (xlator_t *this, xlator_t *subvol, uuid_t gfid, char **path_p) -{ - int ret = 0; - char *path = NULL; - loc_t loc = {0,}; - dict_t *xattr = NULL; - - uuid_copy (loc.gfid, gfid); - loc.inode = inode_new (this->itable); - - ret = syncop_getxattr (subvol, &loc, &xattr, GFID_TO_PATH_KEY, NULL); - if (ret) - goto out; - - ret = dict_get_str (xattr, GFID_TO_PATH_KEY, &path); - if (ret || !path) { - ret = -EINVAL; - goto out; - } - - *path_p = gf_strdup (path); - if (!*path_p) { - ret = -ENOMEM; - goto out; - } - - ret = 0; - -out: - if (xattr) - dict_unref (xattr); - loc_wipe (&loc); - - return ret; -} - int afr_shd_gather_entry (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, void *data) @@ -872,7 +804,7 @@ afr_shd_gather_entry (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, if (child == priv->child_count) return 0; - ret = afr_shd_gfid_to_path (this, subvol, gfid, &path); + ret = syncop_gfid_to_path (this->itable, subvol, gfid, &path); if (ret == -ENOENT || ret == -ESTALE) { afr_shd_index_purge (subvol, parent->inode, entry->d_name); diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index d9233eedadc..8156eaa995e 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -1003,9 +1003,6 @@ afr_inodelk_init (afr_inodelk_t *lk, char *dom, size_t child_count); void afr_handle_open_fd_count (call_frame_t *frame, xlator_t *this); -int -afr_local_pathinfo (char *pathinfo, gf_boolean_t *is_local); - void afr_remove_eager_lock_stub (afr_local_t *local); diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index ea9cb3def62..8ac3c5d4b68 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -3737,8 +3737,8 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, dyn_rpath = gf_strdup (host_buf); if (!dyn_rpath) { - ret = -1; - goto done; + op_errno = ENOMEM; + goto out; } size = strlen (dyn_rpath) + 1; @@ -3749,6 +3749,8 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, "could not set value (%s) in dictionary", dyn_rpath); GF_FREE (dyn_rpath); + op_errno = -ret; + goto out; } goto done; } @@ -3757,17 +3759,21 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, (strcmp (name, GFID_TO_PATH_KEY) == 0)) { ret = inode_path (loc->inode, NULL, &path); if (ret < 0) { + op_errno = -ret; gf_log (this->name, GF_LOG_WARNING, "%s: could not get " "inode path", uuid_utoa (loc->inode->gfid)); - goto done; + goto out; } + size = ret; ret = dict_set_dynstr (dict, GFID_TO_PATH_KEY, path); if (ret < 0) { + op_errno = ENOMEM; gf_log (this->name, GF_LOG_WARNING, "could not set value (%s) in dictionary", host_buf); GF_FREE (path); + goto out; } goto done; } |