summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorPranith Kumar K <pkarampu@redhat.com>2015-02-25 11:37:57 +0530
committerVijay Bellur <vbellur@redhat.com>2015-02-27 01:28:35 -0800
commitd5624b2d4baf509ad8d6037a0d9cabf9cd5ab1c5 (patch)
treea5f257e370606282a1f9c98418e48c466077e5f3 /libglusterfs
parent6a77db6d19dba5367c02cbf2a5883ac49cef94e2 (diff)
libglusterfs: Moved common functions as utils in syncop/common-utils
These will be used by both afr and ec. Moved syncop_dirfd, syncop_ftw, syncop_dir_scan functions also into syncop-utils.c Change-Id: I467253c74a346e1e292d36a8c1a035775c3aa670 BUG: 1177601 Signed-off-by: Pranith Kumar K <pkarampu@redhat.com> Reviewed-on: http://review.gluster.org/9740 Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com> Reviewed-by: Anuradha Talur <atalur@redhat.com> Reviewed-by: Ravishankar N <ravishankar@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/Makefile.am3
-rw-r--r--libglusterfs/src/common-utils.c51
-rw-r--r--libglusterfs/src/common-utils.h3
-rw-r--r--libglusterfs/src/inode.c4
-rw-r--r--libglusterfs/src/syncop-utils.c265
-rw-r--r--libglusterfs/src/syncop-utils.h33
-rw-r--r--libglusterfs/src/syncop.c166
-rw-r--r--libglusterfs/src/syncop.h13
8 files changed, 356 insertions, 182 deletions
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 */