From 1a2f51144fcbd920a6f3769d6b2f3ceeefdc220d Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Thu, 14 Nov 2013 17:10:09 +0530 Subject: core: add dht_is_linkfile helper procedure. components other than distribute (like marker to exclude linkfiles from being accounted) also need awareness of what constitutes a linkfile. Hence its good to separate out this functionality into core. Change-Id: Ib944eeacc991bb1de464c9e73ee409fc7a689ff1 BUG: 1022995 Signed-off-by: Raghavendra G Reviewed-on: http://review.gluster.org/6152 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfs/src/common-utils.c | 31 +++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 7 +++++++ libglusterfs/src/glusterfs.h | 10 ++++++++++ xlators/cluster/dht/src/dht-common.h | 7 +------ xlators/cluster/dht/src/dht-shared.c | 3 ++- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index cb51dd175..08efb5c9f 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3111,3 +3111,34 @@ out: fclose (file); return running; } + +static inline int +dht_is_linkfile_key (dict_t *this, char *key, data_t *value, void *data) +{ + gf_boolean_t *linkfile_key_found = NULL; + + if (!data) + goto out; + + linkfile_key_found = data; + + *linkfile_key_found = _gf_true; +out: + return 0; +} + + +inline gf_boolean_t +dht_is_linkfile (struct iatt *buf, dict_t *dict) +{ + gf_boolean_t linkfile_key_found = _gf_false; + + if (!IS_DHT_LINKFILE_MODE (buf)) + return _gf_false; + + dict_foreach_fnmatch (dict, "*."DHT_LINKFILE_STR, dht_is_linkfile_key, + &linkfile_key_found); + + return linkfile_key_found; +} + diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index b50d3ac38..05e4d5b34 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -619,4 +619,11 @@ gf_boolean_t gf_is_service_running (char *pidfile, int *pid); int gf_skip_header_section (int fd, int header_len); + +struct iatt; +struct _dict; + +inline gf_boolean_t +dht_is_linkfile (struct iatt *buf, struct _dict *dict); + #endif /* _COMMON_UTILS_H */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 8f05a222d..997097384 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -171,6 +171,16 @@ */ #define DEFAULT_GLUSTERD_SOCKFILE DATADIR "/run/glusterd.socket" +/* features/marker-quota also needs to have knowledge of link-files so as to + * exclude them from accounting. + */ +#define DHT_LINKFILE_MODE (S_ISVTX) + +#define IS_DHT_LINKFILE_MODE(iabuf) ((st_mode_from_ia ((iabuf)->ia_prot, \ + (iabuf)->ia_type) & ~S_IFMT)\ + == DHT_LINKFILE_MODE) +#define DHT_LINKFILE_STR "linkto" + /* NOTE: add members ONLY at the end (just before _MAXVALUE) */ typedef enum { GF_FOP_NULL = 0, diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h index 9e4bde1a5..81e4cc175 100644 --- a/xlators/cluster/dht/src/dht-common.h +++ b/xlators/cluster/dht/src/dht-common.h @@ -332,12 +332,7 @@ typedef enum { #define DHT_MIGRATION_IN_PROGRESS 1 #define DHT_MIGRATION_COMPLETED 2 -#define DHT_LINKFILE_MODE (S_ISVTX) - -#define check_is_linkfile(i,s,x,n) ( \ - ((st_mode_from_ia ((s)->ia_prot, (s)->ia_type) & ~S_IFMT) \ - == DHT_LINKFILE_MODE) && \ - dict_get (x, n)) +#define check_is_linkfile(i,s,x,n) (IS_DHT_LINKFILE_MODE (s) && dict_get (x, n)) #define IS_DHT_MIGRATION_PHASE2(buf) ( \ IA_ISREG ((buf)->ia_type) && \ diff --git a/xlators/cluster/dht/src/dht-shared.c b/xlators/cluster/dht/src/dht-shared.c index 70aac7710..674297c71 100644 --- a/xlators/cluster/dht/src/dht-shared.c +++ b/xlators/cluster/dht/src/dht-shared.c @@ -607,7 +607,8 @@ dht_init (xlator_t *this) } GF_OPTION_INIT ("xattr-name", conf->xattr_name, str, err); - gf_asprintf (&conf->link_xattr_name, "%s.linkto", conf->xattr_name); + gf_asprintf (&conf->link_xattr_name, "%s."DHT_LINKFILE_STR, + conf->xattr_name); gf_asprintf (&conf->wild_xattr_name, "%s*", conf->xattr_name); if (!conf->link_xattr_name || !conf->wild_xattr_name) { goto err; -- cgit