From 73bce15b61755509de23d32646135254d369a2f6 Mon Sep 17 00:00:00 2001 From: Kaushik BV Date: Thu, 27 Jan 2011 05:23:30 +0000 Subject: adding libxlator, to ensure proper client side aggregation of marks by clustering translators Signed-off-by: Kaushik BV Signed-off-by: Csaba Henk Signed-off-by: Anand V. Avati BUG: 2310 (georeplication) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2310 --- xlators/cluster/afr/src/Makefile.am | 7 +- xlators/cluster/afr/src/afr-inode-read.c | 74 ++++++++++++++++++++- xlators/cluster/afr/src/afr.h | 10 +++ xlators/cluster/dht/src/Makefile.am | 10 +-- xlators/cluster/dht/src/dht-common.c | 71 ++++++++++++++++++-- xlators/cluster/dht/src/dht-common.h | 5 ++ xlators/cluster/stripe/src/Makefile.am | 7 +- xlators/cluster/stripe/src/stripe.c | 108 +++++++++++++++++++++++++++++++ xlators/cluster/stripe/src/stripe.h | 5 ++ 9 files changed, 278 insertions(+), 19 deletions(-) (limited to 'xlators/cluster') diff --git a/xlators/cluster/afr/src/Makefile.am b/xlators/cluster/afr/src/Makefile.am index 4e4b4c752..e192b599b 100644 --- a/xlators/cluster/afr/src/Makefile.am +++ b/xlators/cluster/afr/src/Makefile.am @@ -1,7 +1,7 @@ xlator_LTLIBRARIES = afr.la pump.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster -afr_common_source = afr-dir-read.c afr-dir-write.c afr-inode-read.c afr-inode-write.c afr-open.c afr-transaction.c afr-self-heal-data.c afr-self-heal-common.c afr-self-heal-metadata.c afr-self-heal-entry.c afr-self-heal-algorithm.c afr-lk-common.c +afr_common_source = afr-dir-read.c afr-dir-write.c afr-inode-read.c afr-inode-write.c afr-open.c afr-transaction.c afr-self-heal-data.c afr-self-heal-common.c afr-self-heal-metadata.c afr-self-heal-entry.c afr-self-heal-algorithm.c afr-lk-common.c $(top_builddir)/xlators/lib/src/libxlator.c afr_la_LDFLAGS = -module -avoidversion afr_la_SOURCES = $(afr_common_source) afr.c @@ -11,10 +11,11 @@ pump_la_LDFLAGS = -module -avoidversion pump_la_SOURCES = $(afr_common_source) pump.c pump_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -noinst_HEADERS = afr.h afr-transaction.h afr-inode-write.h afr-inode-read.h afr-dir-read.h afr-dir-write.h afr-self-heal.h afr-self-heal-common.h afr-self-heal-algorithm.h pump.h afr-mem-types.h afr-common.c +noinst_HEADERS = afr.h afr-transaction.h afr-inode-write.h afr-inode-read.h afr-dir-read.h afr-dir-write.h afr-self-heal.h afr-self-heal-common.h afr-self-heal-algorithm.h pump.h afr-mem-types.h afr-common.c $(top_builddir)/xlators/lib/src/libxlator.h AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/contrib/md5 -shared -nostartfiles $(GF_CFLAGS) + -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/contrib/md5 -shared -nostartfiles $(GF_CFLAGS) \ + -I$(top_srcdir)/xlators/lib/src CLEANFILES = diff --git a/xlators/cluster/afr/src/afr-inode-read.c b/xlators/cluster/afr/src/afr-inode-read.c index 399860767..ce6a6a363 100644 --- a/xlators/cluster/afr/src/afr-inode-read.c +++ b/xlators/cluster/afr/src/afr-inode-read.c @@ -656,6 +656,15 @@ out: return 0; } +int32_t +afr_getxattr_unwind (void *arg, call_frame_t *frame, + int op_ret, int op_errno, dict_t *dict) + +{ + AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict); + return 0; +} + int32_t afr_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name) @@ -664,8 +673,11 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, xlator_t ** children = NULL; int call_child = 0; afr_local_t * local = NULL; + xlator_list_t * trav = NULL; + xlator_t ** sub_volumes= NULL; int read_child = -1; + int i = 0; int32_t op_ret = -1; int32_t op_errno = 0; @@ -683,6 +695,11 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, ALLOC_OR_GOTO (local, afr_local_t, out); frame->local = local; + loc_copy (&local->loc, loc); + if (name) + local->cont.getxattr.name = gf_strdup (name); + + if (name) { if (!strncmp (name, AFR_XATTR_PREFIX, strlen (AFR_XATTR_PREFIX))) { @@ -690,6 +707,60 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, op_errno = ENODATA; goto out; } + if ((strcmp (GF_XATTR_MARKER_KEY, name) == 0) + && (-1 == frame->root->pid)) { + + local->marker.call_count = priv->child_count; + + sub_volumes = alloca ( priv->child_count * sizeof (xlator_t *)); + for (i = 0, trav = this->children; trav ; + trav = trav->next, i++) { + + *(sub_volumes + i) = trav->xlator; + } + + if (cluster_getmarkerattr (frame, this, loc, name, + local, afr_getxattr_unwind, + sub_volumes, + priv->child_count, + MARKER_UUID_TYPE, + priv->vol_uuid)) { + + op_errno = EINVAL; + goto out; + } + + return 0; + } + + if (*priv->vol_uuid) { + if ((match_uuid_local (name, priv->vol_uuid) == 0) + && (-1 == frame->root->pid)) { + + local->marker.call_count = priv->child_count; + + sub_volumes = alloca ( priv->child_count * sizeof (xlator_t *)); + for (i = 0, trav = this->children; trav ; + trav = trav->next, i++) { + + *(sub_volumes + i) = trav->xlator; + + } + + if (cluster_getmarkerattr (frame, this, loc, + name, local, + afr_getxattr_unwind, + sub_volumes, + priv->child_count, + MARKER_XTIME_TYPE, + priv->vol_uuid)) { + op_errno = EINVAL; + goto out; + } + + return 0; + } + } } @@ -712,9 +783,6 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, local->cont.getxattr.last_tried = call_child; } - loc_copy (&local->loc, loc); - if (name) - local->cont.getxattr.name = gf_strdup (name); STACK_WIND_COOKIE (frame, afr_getxattr_cbk, (void *) (long) call_child, diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index a7359f269..b0e434142 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -30,6 +30,8 @@ #include "compat-errno.h" #include "afr-mem-types.h" +#include "libxlator.h" + #define AFR_XATTR_PREFIX "trusted.afr" struct _pump_private; @@ -89,6 +91,8 @@ typedef struct _afr_private { pthread_mutex_t mutex; struct list_head saved_fds; /* list of fds on which locks have succeeded */ gf_boolean_t optimistic_change_log; + + char vol_uuid[UUID_SIZE + 1]; } afr_private_t; typedef struct { @@ -616,6 +620,8 @@ typedef struct _afr_local { } transaction; afr_self_heal_t self_heal; + + struct marker_str marker; } afr_local_t; @@ -927,4 +933,8 @@ afr_transaction_local_init (afr_local_t *local, afr_private_t *priv) return 0; } +int32_t +afr_marker_getxattr (call_frame_t *frame, xlator_t *this, + loc_t *loc, const char *name,afr_local_t *local, afr_private_t *priv ); + #endif /* __AFR_H__ */ diff --git a/xlators/cluster/dht/src/Makefile.am b/xlators/cluster/dht/src/Makefile.am index 4b69aa071..8ebcab044 100644 --- a/xlators/cluster/dht/src/Makefile.am +++ b/xlators/cluster/dht/src/Makefile.am @@ -4,7 +4,8 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster dht_common_source = dht-layout.c dht-helper.c dht-linkfile.c \ - dht-selfheal.c dht-rename.c dht-hashfn.c dht-diskusage.c + dht-selfheal.c dht-rename.c dht-hashfn.c dht-diskusage.c \ + $(top_builddir)/xlators/lib/src/libxlator.c dht_la_SOURCES = $(dht_common_source) dht.c @@ -20,10 +21,11 @@ nufa_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la switch_la_LDFLAGS = -module -avoidversion switch_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -noinst_HEADERS = dht-common.h dht-common.c dht-mem-types.h +noinst_HEADERS = dht-common.h dht-common.c dht-mem-types.h $(top_builddir)/xlators/lib/src/libxlator.h AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) + -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ + -I$(top_srcdir)/xlators/lib/src CLEANFILES = @@ -31,4 +33,4 @@ uninstall-local: rm -f $(DESTDIR)$(xlatordir)/distribute.so install-data-hook: - ln -sf dht.so $(DESTDIR)$(xlatordir)/distribute.so \ No newline at end of file + ln -sf dht.so $(DESTDIR)$(xlatordir)/distribute.so diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c index e20472646..cca09927c 100644 --- a/xlators/cluster/dht/src/dht-common.c +++ b/xlators/cluster/dht/src/dht-common.c @@ -27,12 +27,14 @@ #include "glusterfs.h" #include "xlator.h" +#include "libxlator.h" #include "dht-common.h" #include "defaults.h" #include #include + /* TODO: - use volumename in xattr instead of "dht" - use NS locks @@ -1834,6 +1836,14 @@ out: return 0; } +int32_t +dht_getxattr_unwind (void *getxattr, call_frame_t *frame, + int op_ret, int op_errno, dict_t *dict) +{ + DHT_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict); + return 0; +} + int dht_getxattr (call_frame_t *frame, xlator_t *this, @@ -1845,6 +1855,7 @@ dht_getxattr (call_frame_t *frame, xlator_t *this, dht_conf_t *conf = NULL; dht_local_t *local = NULL; dht_layout_t *layout = NULL; + xlator_t **sub_volumes = NULL; int op_errno = -1; int ret = 0; int flag = 0; @@ -1867,6 +1878,14 @@ dht_getxattr (call_frame_t *frame, xlator_t *this, goto err; } + local = dht_local_init (frame); + if (!local) { + op_errno = ENOMEM; + gf_log (this->name, GF_LOG_ERROR, + "Out of memory"); + goto err; + } + if (key && (strcmp (key, GF_XATTR_PATHINFO_KEY) == 0)) { hashed_subvol = dht_subvol_get_hashed (this, loc); cached_subvol = dht_subvol_get_cached (this, loc->inode); @@ -1959,12 +1978,52 @@ dht_getxattr (call_frame_t *frame, xlator_t *this, goto err; } - local = dht_local_init (frame); - if (!local) { - op_errno = ENOMEM; - gf_log (this->name, GF_LOG_ERROR, - "Out of memory"); - goto err; + if (key && (!strcmp (GF_XATTR_MARKER_KEY, key)) + && (-1 == frame->root->pid)) { + + if (loc->inode-> ia_type == IA_IFDIR) { + cnt = layout->cnt; + } else { + cnt = 1; + } + sub_volumes = alloca ( cnt * sizeof (xlator_t *)); + for (i = 0; i < cnt; i++) + *(sub_volumes + i) = layout->list[i].xlator; + + if (cluster_getmarkerattr (frame, this, loc, key, + local, dht_getxattr_unwind, + sub_volumes, cnt, + MARKER_UUID_TYPE, conf->vol_uuid)) { + op_errno = EINVAL; + goto err; + } + + return 0; + } + + if (key && *conf->vol_uuid) { + if ((match_uuid_local (key, conf->vol_uuid) == 0) && + (-1 == frame->root->pid)) { + if (loc->inode-> ia_type == IA_IFDIR) { + cnt = layout->cnt; + } else { + cnt = 1; + } + sub_volumes = alloca ( cnt * sizeof (xlator_t *)); + for (i = 0; i < cnt; i++) + sub_volumes[i] = layout->list[i].xlator; + + if (cluster_getmarkerattr (frame, this, loc, key, + local, dht_getxattr_unwind, + sub_volumes, cnt, + MARKER_XTIME_TYPE, + conf->vol_uuid)) { + op_errno = EINVAL; + goto err; + } + + return 0; + } } ret = loc_dup (loc, &local->loc); diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h index becc8d9c8..6a4daa65e 100644 --- a/xlators/cluster/dht/src/dht-common.h +++ b/xlators/cluster/dht/src/dht-common.h @@ -23,6 +23,7 @@ #endif #include "dht-mem-types.h" +#include "libxlator.h" #ifndef _DHT_H #define _DHT_H @@ -128,6 +129,9 @@ struct dht_local { /* gfid related */ uuid_t gfid; + + /*Marker Related*/ + struct marker_str marker; }; typedef struct dht_local dht_local_t; @@ -160,6 +164,7 @@ struct dht_conf { void *private; /* Can be used by wrapper xlators over dht */ gf_boolean_t use_readdirp; + char vol_uuid[UUID_SIZE + 1]; }; typedef struct dht_conf dht_conf_t; diff --git a/xlators/cluster/stripe/src/Makefile.am b/xlators/cluster/stripe/src/Makefile.am index 6d4fae4d2..0db3c9eeb 100644 --- a/xlators/cluster/stripe/src/Makefile.am +++ b/xlators/cluster/stripe/src/Makefile.am @@ -4,13 +4,14 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster stripe_la_LDFLAGS = -module -avoidversion -stripe_la_SOURCES = stripe.c +stripe_la_SOURCES = stripe.c $(top_builddir)/xlators/lib/src/libxlator.c stripe_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -noinst_HEADERS = stripe.h stripe-mem-types.h +noinst_HEADERS = stripe.h stripe-mem-types.h $(top_builddir)/xlators/lib/src/libxlator.h AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ - -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) + -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ + -I$(top_srcdir)/xlators/lib/src CLEANFILES = diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c index 639fbfd8b..cc34a8468 100644 --- a/xlators/cluster/stripe/src/stripe.c +++ b/xlators/cluster/stripe/src/stripe.c @@ -34,6 +34,7 @@ */ #include "stripe.h" +#include "libxlator.h" void stripe_local_wipe (stripe_local_t *local) @@ -3896,6 +3897,7 @@ init (xlator_t *this) priv->nodes_down = priv->child_count; this->private = priv; + ret = 0; out: if (ret) { @@ -3942,6 +3944,110 @@ out: return; } +int32_t +stripe_getxattr_unwind (void *getxattr, call_frame_t *frame, + int op_ret, int op_errno, dict_t *dict) + +{ + STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict); + return 0; +} + +int32_t +stripe_getxattr (call_frame_t *frame, xlator_t *this, + loc_t *loc, const char *name) +{ + stripe_local_t *local = NULL; + xlator_list_t *trav = NULL; + stripe_private_t *priv = NULL; + int32_t op_errno = EINVAL; + int i = 0; + xlator_t **sub_volumes; + + VALIDATE_OR_GOTO (frame, err); + VALIDATE_OR_GOTO (this, err); + VALIDATE_OR_GOTO (loc, err); + VALIDATE_OR_GOTO (loc->path, err); + VALIDATE_OR_GOTO (loc->inode, err); + + priv = this->private; + trav = this->children; + + /* Initialization */ + local = GF_CALLOC (1, sizeof (stripe_local_t), + gf_stripe_mt_stripe_local_t); + if (!local) { + op_errno = ENOMEM; + goto err; + } + local->op_ret = -1; + frame->local = local; + loc_copy (&local->loc, loc); + + + if (name && (strcmp (GF_XATTR_MARKER_KEY, name) == 0) + && (-1 == frame->root->pid)) { + local->marker.call_count = priv->child_count; + + sub_volumes = alloca ( priv->child_count * + sizeof (xlator_t *)); + for (i = 0, trav = this->children; trav ; + trav = trav->next, i++) { + + *(sub_volumes + i) = trav->xlator; + + } + + if (cluster_getmarkerattr (frame, this, loc, name, + local, stripe_getxattr_unwind, + sub_volumes, priv->child_count, + MARKER_UUID_TYPE, priv->vol_uuid)) { + op_errno = EINVAL; + goto err; + } + + return 0; + } + + if (*priv->vol_uuid) { + if ((match_uuid_local (name, priv->vol_uuid) == 0) + && (-1 == frame->root->pid)) { + local->marker.call_count = priv->child_count; + + sub_volumes = alloca ( priv->child_count * + sizeof (xlator_t *)); + for (i = 0, trav = this->children; trav ; + trav = trav->next, i++) { + + *(sub_volumes + i) = trav->xlator; + + } + + if (cluster_getmarkerattr (frame, this, loc, name, + local, stripe_getxattr_unwind, + sub_volumes, + priv->child_count, + MARKER_XTIME_TYPE, + priv->vol_uuid)) { + op_errno = EINVAL; + goto err; + } + return 0; + } + } + + + STACK_WIND (frame, default_getxattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->getxattr, loc, name); + + return 0; + +err: + STACK_UNWIND_STRICT (getxattr, frame, -1, op_errno, NULL); + return 0; +} + + struct xlator_fops fops = { .stat = stripe_stat, @@ -3967,6 +4073,8 @@ struct xlator_fops fops = { .fsetattr = stripe_fsetattr, .lookup = stripe_lookup, .mknod = stripe_mknod, + + .getxattr = stripe_getxattr, }; struct xlator_cbks cbks = { diff --git a/xlators/cluster/stripe/src/stripe.h b/xlators/cluster/stripe/src/stripe.h index 6199c0061..86555144f 100644 --- a/xlators/cluster/stripe/src/stripe.h +++ b/xlators/cluster/stripe/src/stripe.h @@ -33,6 +33,7 @@ #include "compat.h" #include "compat-errno.h" #include "stripe-mem-types.h" +#include "libxlator.h" #include #include @@ -84,6 +85,7 @@ struct stripe_private { int8_t child_count; int8_t *state; /* Current state of child node */ gf_boolean_t xattr_supported; /* default yes */ + char vol_uuid[UUID_SIZE + 1]; }; /** @@ -163,6 +165,8 @@ struct stripe_local { /* For File I/O fops */ dict_t *dict; + struct marker_str marker; + /* General usage */ off_t offset; off_t stripe_size; @@ -180,4 +184,5 @@ struct stripe_local { typedef struct stripe_local stripe_local_t; typedef struct stripe_private stripe_private_t; + #endif /* _STRIPE_H_ */ -- cgit