summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/basic/distribute/debug-xattrs.t54
-rw-r--r--xlators/cluster/dht/src/dht-common.c58
-rw-r--r--xlators/cluster/dht/src/dht-common.h3
3 files changed, 87 insertions, 28 deletions
diff --git a/tests/basic/distribute/debug-xattrs.t b/tests/basic/distribute/debug-xattrs.t
new file mode 100644
index 00000000000..6d87c0e8671
--- /dev/null
+++ b/tests/basic/distribute/debug-xattrs.t
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+. $(dirname $0)/../../nfs.rc
+. $(dirname $0)/../../common-utils.rc
+
+# Test overview: Test the virtual xattrs dht provides for debugging
+
+# Test 1 : "dht.file.hashed-subvol.<filename>"
+# Get the hashed subvolume for file1 in dir1 using xattr
+# Create file1 in dir1
+# Check if the file is created in the brick returned by xattr
+
+hashdebugxattr="dht.file.hashed-subvol."
+
+cleanup
+
+TEST glusterd
+TEST pidof glusterd
+
+TEST $CLI volume create $V0 $H0:$B0/$V0-{0..3}
+TEST $CLI volume start $V0
+
+# Mount using FUSE and create a file
+TEST glusterfs -s $H0 --volfile-id $V0 $M0
+
+# Test 1 : "dht.file.hashed-subvol.<filename>"
+# Get the hashed subvolume for file1 in dir1 using xattr
+# Create file1 in dir1
+# Check if the file is created in the brick returned by xattr
+# Create a directory on $M0
+
+TEST mkdir $M0/dir1
+
+xattrname=$hashdebugxattr"file1"
+
+hashed=$(getfattr --only-values -n "$xattrname" $M0/dir1)
+
+# Get the brick path for $hashed
+brickpath=$(cat "$M0/.meta/graphs/active/$hashed/options/remote-subvolume")
+brickpath=$brickpath"/dir1/file1"
+
+# Create the file for which we checked the xattr
+TEST touch $M0/dir1/file1
+TEST stat $brickpath
+
+# Non-existent directory
+TEST ! getfattr --only-values -n "$xattrname" $M0/dir2
+
+
+# Cleanup
+cleanup
+
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 5f64d5c254d..434584e1a34 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -131,7 +131,7 @@ char *xattrs_to_heal[] = {
char *dht_dbg_vxattrs[] = {
- DHT_DBG_HASHED_SUBVOL_KEY,
+ DHT_DBG_HASHED_SUBVOL_PATTERN,
NULL
};
@@ -5042,6 +5042,20 @@ dht_marker_populate_args (call_frame_t *frame, int type, int *gauge,
}
+int
+dht_is_debug_xattr_key (char **array, char *key)
+{
+ int i = 0;
+
+ for (i = 0; array[i]; i++) {
+ if (fnmatch (array[i], key, FNM_NOESCAPE) == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+
/* Note we already have frame->local initialised here*/
int
@@ -5051,8 +5065,9 @@ dht_handle_debug_getxattr (call_frame_t *frame, xlator_t *this,
dht_local_t *local = NULL;
int ret = -1;
int op_errno = ENODATA;
- ia_type_t type = 0;
char *value = NULL;
+ loc_t file_loc = {0};
+ const char *name = NULL;
local = frame->local;
if (!key) {
@@ -5060,44 +5075,32 @@ dht_handle_debug_getxattr (call_frame_t *frame, xlator_t *this,
goto out;
}
- if (gf_get_index_by_elem (dht_dbg_vxattrs, (char *)key) == -1) {
+ if (dht_is_debug_xattr_key (dht_dbg_vxattrs, (char *)key) == -1) {
goto out;
}
- /* getxattr does not set the parent inode*/
- if (!loc->parent) {
- loc->parent =
- inode_parent(local->loc.inode, NULL, NULL);
- }
- if (!loc->parent) {
- op_errno = EINVAL;
- goto out;
- }
-
- gf_uuid_copy (loc->pargfid, loc->parent->gfid);
-
- if (!loc->name && loc->path) {
- loc->name = strrchr (loc->path, '/');
- if (loc->name) {
- ++(loc->name);
- }
- }
-
local->xattr = dict_new ();
if (!local->xattr) {
op_errno = ENOMEM;
goto out;
}
- type = loc->inode->ia_type;
+ if (strncmp (key, DHT_DBG_HASHED_SUBVOL_KEY,
+ SLEN (DHT_DBG_HASHED_SUBVOL_KEY)) == 0) {
- if (strcmp (key, DHT_DBG_HASHED_SUBVOL_KEY) == 0) {
- if (IA_ISDIR (type)) {
+ name = key + strlen(DHT_DBG_HASHED_SUBVOL_KEY);
+ if (strlen(name) == 0) {
op_errno = EINVAL;
goto out;
}
- local->hashed_subvol = dht_subvol_get_hashed (this, loc);
+ ret = dht_build_child_loc (this, &file_loc, loc, (char *)name);
+ if (ret) {
+ op_errno = ENOMEM;
+ goto out;
+ }
+
+ local->hashed_subvol = dht_subvol_get_hashed (this, &file_loc);
if (local->hashed_subvol == NULL) {
op_errno = ENODATA;
goto out;
@@ -5120,6 +5123,7 @@ dht_handle_debug_getxattr (call_frame_t *frame, xlator_t *this,
}
out:
+ loc_wipe (&file_loc);
DHT_STACK_UNWIND (getxattr, frame, ret, op_errno, local->xattr, NULL);
return 0;
}
@@ -5317,7 +5321,7 @@ no_dht_is_dir:
return 0;
}
- if (gf_get_index_by_elem (dht_dbg_vxattrs, (char *)key) >= 0) {
+ if (dht_is_debug_xattr_key (dht_dbg_vxattrs, (char *)key) >= 0) {
dht_handle_debug_getxattr (frame, this, loc, key);
return 0;
}
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
index 2520671e35d..86b3eb3cbd2 100644
--- a/xlators/cluster/dht/src/dht-common.h
+++ b/xlators/cluster/dht/src/dht-common.h
@@ -48,7 +48,8 @@
/* Virtual xattrs for debugging */
-#define DHT_DBG_HASHED_SUBVOL_KEY "dht.file.hashed-subvol"
+#define DHT_DBG_HASHED_SUBVOL_PATTERN "dht.file.hashed-subvol.*"
+#define DHT_DBG_HASHED_SUBVOL_KEY "dht.file.hashed-subvol."
/* Array to hold custom xattr keys