b51a1f
From 23ab7175e64ab4d75fbcb6874008843cc78b65b8 Mon Sep 17 00:00:00 2001
b51a1f
From: Ashish Pandey <aspandey@redhat.com>
b51a1f
Date: Fri, 16 Apr 2021 18:48:56 +0530
b51a1f
Subject: [PATCH 541/542] glusterd-volgen: Add functionality to accept any
b51a1f
 custom xlator
b51a1f
b51a1f
Add new function which allow users to insert any custom xlators.
b51a1f
It makes to provide a way to add any processing into file operations.
b51a1f
b51a1f
Users can deploy the plugin(xlator shared object) and integrate it to glusterfsd.
b51a1f
b51a1f
If users want to enable a custom xlator, do the follows:
b51a1f
b51a1f
1. put xlator object(.so file) into "XLATOR_DIR/user/"
b51a1f
2. set the option user.xlator.<xlator> to the existing xlator-name to specify of the position in graph
b51a1f
3. restart gluster volume
b51a1f
b51a1f
Options for custom xlator are able to set in "user.xlator.<xlator>.<optkey>".
b51a1f
b51a1f
Backport of :
b51a1f
>https://github.com/gluster/glusterfs/commit/ea86b664f3b1f54901ce1b7d7fba7d80456f2089
b51a1f
>Fixes: https://github.com/gluster/glusterfs/issues/1943
b51a1f
>Change-Id: Ife3ae1514ea474f5dae2897223012f9d04b64674
b51a1f
>Signed-off-by:Ryo Furuhashi <ryo.furuhashi.nh@hitachi.com>
b51a1f
>Co-authored-by: Yaniv Kaul <ykaul@redhat.com>
b51a1f
>Co-authored-by: Xavi Hernandez <xhernandez@users.noreply.github.com>
b51a1f
b51a1f
Change-Id: Ic8f28bfcfde67213eb1092b0ebf4822c874d37bb
b51a1f
BUG: 1927235
b51a1f
Signed-off-by: Ashish Pandey <aspandey@redhat.com>
b51a1f
Reviewed-on: https://code.engineering.redhat.com/gerrit/236830
b51a1f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
b51a1f
Reviewed-by: Ravishankar Narayanankutty <ravishankar@redhat.com>
b51a1f
Reviewed-by: Xavi Hernandez Juan <xhernandez@redhat.com>
b51a1f
---
b51a1f
 cli/src/cli-rpc-ops.c                       | 148 ++++++++++++++++++++------
b51a1f
 cli/src/cli.h                               |   2 -
b51a1f
 tests/basic/user-xlator.t                   |  65 ++++++++++++
b51a1f
 tests/env.rc.in                             |   3 +
b51a1f
 xlators/mgmt/glusterd/src/glusterd-volgen.c | 155 ++++++++++++++++++++++++++++
b51a1f
 5 files changed, 342 insertions(+), 31 deletions(-)
b51a1f
 create mode 100755 tests/basic/user-xlator.t
b51a1f
b51a1f
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
b51a1f
index 4e91265..51b5447 100644
b51a1f
--- a/cli/src/cli-rpc-ops.c
b51a1f
+++ b/cli/src/cli-rpc-ops.c
b51a1f
@@ -2269,49 +2269,131 @@ out:
b51a1f
     return ret;
b51a1f
 }
b51a1f
 
b51a1f
-char *
b51a1f
-is_server_debug_xlator(void *myframe)
b51a1f
+/*
b51a1f
+ * returns
b51a1f
+ *   1 : is server debug xlator
b51a1f
+ *   0 : is not server debug xlator
b51a1f
+ *  <0 : error
b51a1f
+ */
b51a1f
+static int
b51a1f
+is_server_debug_xlator(char *key, char *value)
b51a1f
+{
b51a1f
+    if (!key || !value)
b51a1f
+        return -1;
b51a1f
+
b51a1f
+    if (strcmp("debug.trace", key) == 0 ||
b51a1f
+        strcmp("debug.error-gen", key) == 0) {
b51a1f
+        if (strcmp("client", value) == 0)
b51a1f
+            return 0;
b51a1f
+        else
b51a1f
+            return 1;
b51a1f
+    }
b51a1f
+
b51a1f
+    return 0;
b51a1f
+}
b51a1f
+
b51a1f
+/*
b51a1f
+ * returns
b51a1f
+ *   1 : is user xlator
b51a1f
+ *   0 : is not user xlator
b51a1f
+ *  <0 : error
b51a1f
+ */
b51a1f
+static int
b51a1f
+is_server_user_xlator(char *key, char *value)
b51a1f
+{
b51a1f
+    int ret = 0;
b51a1f
+
b51a1f
+    if (!key || !value)
b51a1f
+        return -1;
b51a1f
+
b51a1f
+    ret = fnmatch("user.xlator.*", key, 0);
b51a1f
+    if (ret < 0) {
b51a1f
+        ret = -1;
b51a1f
+        goto out;
b51a1f
+    } else if (ret == FNM_NOMATCH) {
b51a1f
+        ret = 0;
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
+
b51a1f
+    ret = fnmatch("user.xlator.*.*", key, 0);
b51a1f
+    if (ret < 0) {
b51a1f
+        ret = -1;
b51a1f
+        goto out;
b51a1f
+    } else if (ret != FNM_NOMATCH) {  // this is user xlator's option key
b51a1f
+        ret = 0;
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
+
b51a1f
+    ret = 1;
b51a1f
+
b51a1f
+out:
b51a1f
+    return ret;
b51a1f
+}
b51a1f
+
b51a1f
+static int
b51a1f
+added_server_xlator(void *myframe, char **added_xlator)
b51a1f
 {
b51a1f
     call_frame_t *frame = NULL;
b51a1f
     cli_local_t *local = NULL;
b51a1f
     char **words = NULL;
b51a1f
     char *key = NULL;
b51a1f
     char *value = NULL;
b51a1f
-    char *debug_xlator = NULL;
b51a1f
+    int ret = 0;
b51a1f
 
b51a1f
     frame = myframe;
b51a1f
     local = frame->local;
b51a1f
     words = (char **)local->words;
b51a1f
 
b51a1f
     while (*words != NULL) {
b51a1f
-        if (strstr(*words, "trace") == NULL &&
b51a1f
-            strstr(*words, "error-gen") == NULL) {
b51a1f
-            words++;
b51a1f
-            continue;
b51a1f
-        }
b51a1f
-
b51a1f
         key = *words;
b51a1f
         words++;
b51a1f
         value = *words;
b51a1f
-        if (value == NULL)
b51a1f
+
b51a1f
+        if (!value) {
b51a1f
             break;
b51a1f
-        if (strstr(value, "client")) {
b51a1f
-            words++;
b51a1f
-            continue;
b51a1f
-        } else {
b51a1f
-            if (!(strstr(value, "posix") || strstr(value, "acl") ||
b51a1f
-                  strstr(value, "locks") || strstr(value, "io-threads") ||
b51a1f
-                  strstr(value, "marker") || strstr(value, "index"))) {
b51a1f
-                words++;
b51a1f
-                continue;
b51a1f
-            } else {
b51a1f
-                debug_xlator = gf_strdup(key);
b51a1f
-                break;
b51a1f
+        }
b51a1f
+
b51a1f
+        ret = is_server_debug_xlator(key, value);
b51a1f
+        if (ret < 0) {
b51a1f
+            gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
b51a1f
+                   "failed to check that debug xlator was added");
b51a1f
+            ret = -1;
b51a1f
+            goto out;
b51a1f
+        }
b51a1f
+
b51a1f
+        if (ret) {
b51a1f
+            *added_xlator = gf_strdup(key);
b51a1f
+            if (!*added_xlator) {
b51a1f
+                gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
b51a1f
+                       "Out of memory");
b51a1f
+                ret = -1;
b51a1f
+                goto out;
b51a1f
+            }
b51a1f
+            break;
b51a1f
+        }
b51a1f
+
b51a1f
+        ret = is_server_user_xlator(key, value);
b51a1f
+        if (ret < 0) {
b51a1f
+            gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
b51a1f
+                   "failed to check that user xlator was added");
b51a1f
+            ret = -1;
b51a1f
+            goto out;
b51a1f
+        }
b51a1f
+
b51a1f
+        if (ret) {
b51a1f
+            *added_xlator = gf_strdup(key);
b51a1f
+            if (!*added_xlator) {
b51a1f
+                gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
b51a1f
+                       "Out of memory");
b51a1f
+                ret = -1;
b51a1f
+                goto out;
b51a1f
             }
b51a1f
+            break;
b51a1f
         }
b51a1f
     }
b51a1f
 
b51a1f
-    return debug_xlator;
b51a1f
+out:
b51a1f
+    return ret;
b51a1f
 }
b51a1f
 
b51a1f
 int
b51a1f
@@ -2327,7 +2409,7 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
b51a1f
     char msg[1024] = {
b51a1f
         0,
b51a1f
     };
b51a1f
-    char *debug_xlator = NULL;
b51a1f
+    char *added_xlator = NULL;
b51a1f
     char tmp_str[512] = {
b51a1f
         0,
b51a1f
     };
b51a1f
@@ -2365,18 +2447,26 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
b51a1f
      * The process has to be restarted. So this is a check from the
b51a1f
      * volume set option such that if debug xlators such as trace/errorgen
b51a1f
      * are provided in the set command, warn the user.
b51a1f
+     * volume set option such that if user custom xlators or debug
b51a1f
+     * xlators such as trace/errorgen are provided in the set command,
b51a1f
+     * warn the user.
b51a1f
      */
b51a1f
-    debug_xlator = is_server_debug_xlator(myframe);
b51a1f
+    ret = added_server_xlator(myframe, &added_xlator);
b51a1f
+    if (ret < 0) {
b51a1f
+        gf_log("cli", GF_LOG_ERROR,
b51a1f
+               "failed to check that server graph has been changed");
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
 
b51a1f
     if (dict_get_str(dict, "help-str", &help_str) && !msg[0])
b51a1f
         snprintf(msg, sizeof(msg), "Set volume %s",
b51a1f
                  (rsp.op_ret) ? "unsuccessful" : "successful");
b51a1f
-    if (rsp.op_ret == 0 && debug_xlator) {
b51a1f
+    if (rsp.op_ret == 0 && added_xlator) {
b51a1f
         snprintf(tmp_str, sizeof(tmp_str),
b51a1f
                  "\n%s translator has been "
b51a1f
                  "added to the server volume file. Please restart the"
b51a1f
                  " volume for enabling the translator",
b51a1f
-                 debug_xlator);
b51a1f
+                 added_xlator);
b51a1f
     }
b51a1f
 
b51a1f
     if ((global_state->mode & GLUSTER_MODE_XML) && (help_str == NULL)) {
b51a1f
@@ -2394,7 +2484,7 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
b51a1f
             cli_err("volume set: failed");
b51a1f
     } else {
b51a1f
         if (help_str == NULL) {
b51a1f
-            if (debug_xlator == NULL)
b51a1f
+            if (added_xlator == NULL)
b51a1f
                 cli_out("volume set: success");
b51a1f
             else
b51a1f
                 cli_out("volume set: success%s", tmp_str);
b51a1f
@@ -2408,7 +2498,7 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
b51a1f
 out:
b51a1f
     if (dict)
b51a1f
         dict_unref(dict);
b51a1f
-    GF_FREE(debug_xlator);
b51a1f
+    GF_FREE(added_xlator);
b51a1f
     cli_cmd_broadcast_response(ret);
b51a1f
     gf_free_xdr_cli_rsp(rsp);
b51a1f
     return ret;
b51a1f
diff --git a/cli/src/cli.h b/cli/src/cli.h
b51a1f
index 7b4f446..b5b69ea 100644
b51a1f
--- a/cli/src/cli.h
b51a1f
+++ b/cli/src/cli.h
b51a1f
@@ -502,8 +502,6 @@ cli_xml_output_snapshot(int cmd_type, dict_t *dict, int op_ret, int op_errno,
b51a1f
 int
b51a1f
 cli_xml_snapshot_status_single_snap(cli_local_t *local, dict_t *dict,
b51a1f
                                     char *key);
b51a1f
-char *
b51a1f
-is_server_debug_xlator(void *myframe);
b51a1f
 
b51a1f
 int32_t
b51a1f
 cli_cmd_snapshot_parse(const char **words, int wordcount, dict_t **options,
b51a1f
diff --git a/tests/basic/user-xlator.t b/tests/basic/user-xlator.t
b51a1f
new file mode 100755
b51a1f
index 0000000..a711f9f
b51a1f
--- /dev/null
b51a1f
+++ b/tests/basic/user-xlator.t
b51a1f
@@ -0,0 +1,65 @@
b51a1f
+#!/bin/bash
b51a1f
+
b51a1f
+. $(dirname $0)/../include.rc
b51a1f
+. $(dirname $0)/../volume.rc
b51a1f
+
b51a1f
+#### patchy.dev.d-backends-patchy1.vol
b51a1f
+brick=${B0//\//-}
b51a1f
+SERVER_VOLFILE="/var/lib/glusterd/vols/${V0}/${V0}.${H0}.${brick:1}-${V0}1.vol"
b51a1f
+
b51a1f
+cleanup;
b51a1f
+
b51a1f
+TEST mkdir -p $B0/single-brick
b51a1f
+TEST mkdir -p ${GLUSTER_XLATOR_DIR}/user
b51a1f
+
b51a1f
+## deploy dummy user xlator
b51a1f
+TEST cp ${GLUSTER_XLATOR_DIR}/playground/template.so ${GLUSTER_XLATOR_DIR}/user/hoge.so
b51a1f
+
b51a1f
+TEST glusterd
b51a1f
+TEST $CLI volume create $V0 replica 3  $H0:$B0/${V0}{1,2,3,4,5,6};
b51a1f
+TEST $CLI volume set $V0 user.xlator.hoge posix
b51a1f
+TEST grep -q 'user/hoge' ${SERVER_VOLFILE}
b51a1f
+
b51a1f
+TEST $CLI volume set $V0 user.xlator.hoge.opt1 10
b51a1f
+TEST grep -q '"option opt1 10"' ${SERVER_VOLFILE}
b51a1f
+TEST $CLI volume set $V0 user.xlator.hoge.opt2 hogehoge
b51a1f
+TEST grep -q '"option opt2 hogehoge"' ${SERVER_VOLFILE}
b51a1f
+TEST $CLI volume set $V0 user.xlator.hoge.opt3 true
b51a1f
+TEST grep -q '"option opt3 true"' ${SERVER_VOLFILE}
b51a1f
+
b51a1f
+TEST $CLI volume start $V0
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}1
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}2
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}3
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}4
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}5
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}6
b51a1f
+
b51a1f
+TEST $CLI volume set $V0 user.xlator.hoge trash
b51a1f
+TEST grep -q 'user/hoge' ${SERVER_VOLFILE}
b51a1f
+
b51a1f
+TEST $CLI volume stop $V0
b51a1f
+TEST $CLI volume start $V0
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}1
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}2
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}3
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}4
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}5
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}6
b51a1f
+
b51a1f
+TEST ! $CLI volume set $V0 user.xlator.hoge unknown
b51a1f
+TEST grep -q 'user/hoge' ${SERVER_VOLFILE} # When the CLI fails, the volfile is not modified.
b51a1f
+
b51a1f
+TEST $CLI volume stop $V0
b51a1f
+TEST $CLI volume start $V0
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}1
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}2
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}3
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}4
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}5
b51a1f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}6
b51a1f
+
b51a1f
+#### teardown
b51a1f
+
b51a1f
+TEST rm -f ${GLUSTER_XLATOR_DIR}/user/hoge.so
b51a1f
+cleanup;
b51a1f
diff --git a/tests/env.rc.in b/tests/env.rc.in
b51a1f
index c7472a7..1f0ca88 100644
b51a1f
--- a/tests/env.rc.in
b51a1f
+++ b/tests/env.rc.in
b51a1f
@@ -40,3 +40,6 @@ export GLUSTER_LIBEXECDIR
b51a1f
 
b51a1f
 RUN_NFS_TESTS=@BUILD_GNFS@
b51a1f
 export RUN_NFS_TESTS
b51a1f
+
b51a1f
+GLUSTER_XLATOR_DIR=@libdir@/glusterfs/@PACKAGE_VERSION@/xlator
b51a1f
+export GLUSTER_XLATOR_DIR
b51a1f
\ No newline at end of file
b51a1f
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
b51a1f
index 1920284..a242b5c 100644
b51a1f
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
b51a1f
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
b51a1f
@@ -45,6 +45,11 @@ struct gd_validate_reconf_opts {
b51a1f
 
b51a1f
 extern struct volopt_map_entry glusterd_volopt_map[];
b51a1f
 
b51a1f
+struct check_and_add_user_xlator_t {
b51a1f
+    volgen_graph_t *graph;
b51a1f
+    char *volname;
b51a1f
+};
b51a1f
+
b51a1f
 #define RPC_SET_OPT(XL, CLI_OPT, XLATOR_OPT, ERROR_CMD)                        \
b51a1f
     do {                                                                       \
b51a1f
         char *_value = NULL;                                                   \
b51a1f
@@ -2822,6 +2827,145 @@ out:
b51a1f
     return ret;
b51a1f
 }
b51a1f
 
b51a1f
+static gf_boolean_t
b51a1f
+check_user_xlator_position(dict_t *dict, char *key, data_t *value,
b51a1f
+                           void *prev_xlname)
b51a1f
+{
b51a1f
+    if (strncmp(key, "user.xlator.", SLEN("user.xlator.")) != 0) {
b51a1f
+        return false;
b51a1f
+    }
b51a1f
+
b51a1f
+    if (fnmatch("user.xlator.*.*", key, 0) == 0) {
b51a1f
+        return false;
b51a1f
+    }
b51a1f
+
b51a1f
+    char *value_str = data_to_str(value);
b51a1f
+    if (!value_str) {
b51a1f
+        return false;
b51a1f
+    }
b51a1f
+
b51a1f
+    if (strcmp(value_str, prev_xlname) == 0) {
b51a1f
+        gf_log("glusterd", GF_LOG_INFO,
b51a1f
+               "found insert position of user-xlator(%s)", key);
b51a1f
+        return true;
b51a1f
+    }
b51a1f
+
b51a1f
+    return false;
b51a1f
+}
b51a1f
+
b51a1f
+static int
b51a1f
+set_user_xlator_option(dict_t *set_dict, char *key, data_t *value, void *data)
b51a1f
+{
b51a1f
+    xlator_t *xl = data;
b51a1f
+    char *optname = strrchr(key, '.') + 1;
b51a1f
+
b51a1f
+    gf_log("glusterd", GF_LOG_DEBUG, "set user xlator option %s = %s", key,
b51a1f
+           value->data);
b51a1f
+
b51a1f
+    return xlator_set_option(xl, optname, strlen(optname), data_to_str(value));
b51a1f
+}
b51a1f
+
b51a1f
+static int
b51a1f
+insert_user_xlator_to_graph(dict_t *set_dict, char *key, data_t *value,
b51a1f
+                            void *action_data)
b51a1f
+{
b51a1f
+    int ret = -1;
b51a1f
+
b51a1f
+    struct check_and_add_user_xlator_t *data = action_data;
b51a1f
+
b51a1f
+    char *xlator_name = strrchr(key, '.') + 1;  // user.xlator.<xlator_name>
b51a1f
+    char *xlator_option_matcher = NULL;
b51a1f
+    char *type = NULL;
b51a1f
+    xlator_t *xl = NULL;
b51a1f
+
b51a1f
+    // convert optkey to xlator type
b51a1f
+    if (gf_asprintf(&type, "user/%s", xlator_name) < 0) {
b51a1f
+        gf_log("glusterd", GF_LOG_ERROR, "failed to generate user-xlator type");
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
+
b51a1f
+    gf_log("glusterd", GF_LOG_INFO, "add user xlator=%s to graph", type);
b51a1f
+
b51a1f
+    xl = volgen_graph_add(data->graph, type, data->volname);
b51a1f
+    if (!xl) {
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
+
b51a1f
+    ret = gf_asprintf(&xlator_option_matcher, "user.xlator.%s.*", xlator_name);
b51a1f
+    if (ret < 0) {
b51a1f
+        gf_log("glusterd", GF_LOG_ERROR,
b51a1f
+               "failed to generate user-xlator option matcher");
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
+
b51a1f
+    dict_foreach_fnmatch(set_dict, xlator_option_matcher,
b51a1f
+                         set_user_xlator_option, xl);
b51a1f
+
b51a1f
+out:
b51a1f
+    if (type)
b51a1f
+        GF_FREE(type);
b51a1f
+    if (xlator_option_matcher)
b51a1f
+        GF_FREE(xlator_option_matcher);
b51a1f
+
b51a1f
+    return ret;
b51a1f
+}
b51a1f
+
b51a1f
+static int
b51a1f
+validate_user_xlator_position(dict_t *this, char *key, data_t *value,
b51a1f
+                              void *unused)
b51a1f
+{
b51a1f
+    int ret = -1;
b51a1f
+    int i = 0;
b51a1f
+
b51a1f
+    if (!value)
b51a1f
+        goto out;
b51a1f
+
b51a1f
+    if (fnmatch("user.xlator.*.*", key, 0) == 0) {
b51a1f
+        ret = 0;
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
+
b51a1f
+    char *value_str = data_to_str(value);
b51a1f
+    if (!value_str)
b51a1f
+        goto out;
b51a1f
+
b51a1f
+    int num_xlators = sizeof(server_graph_table) /
b51a1f
+                      sizeof(server_graph_table[0]);
b51a1f
+    for (i = 0; i < num_xlators; i++) {
b51a1f
+        if (server_graph_table[i].dbg_key &&
b51a1f
+            strcmp(value_str, server_graph_table[i].dbg_key) == 0) {
b51a1f
+            ret = 0;
b51a1f
+            goto out;
b51a1f
+        }
b51a1f
+    }
b51a1f
+
b51a1f
+out:
b51a1f
+    if (ret == -1)
b51a1f
+        gf_log("glusterd", GF_LOG_ERROR, "invalid user xlator position %s = %s",
b51a1f
+               key, value->data);
b51a1f
+
b51a1f
+    return ret;
b51a1f
+}
b51a1f
+
b51a1f
+static int
b51a1f
+check_and_add_user_xl(volgen_graph_t *graph, dict_t *set_dict, char *volname,
b51a1f
+                      char *prev_xlname)
b51a1f
+{
b51a1f
+    if (!prev_xlname)
b51a1f
+        goto out;
b51a1f
+
b51a1f
+    struct check_and_add_user_xlator_t data = {.graph = graph,
b51a1f
+                                               .volname = volname};
b51a1f
+
b51a1f
+    if (dict_foreach_match(set_dict, check_user_xlator_position, prev_xlname,
b51a1f
+                           insert_user_xlator_to_graph, &data) < 0) {
b51a1f
+        return -1;
b51a1f
+    }
b51a1f
+
b51a1f
+out:
b51a1f
+    return 0;
b51a1f
+}
b51a1f
+
b51a1f
 static int
b51a1f
 server_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
b51a1f
                      dict_t *set_dict, void *param)
b51a1f
@@ -2831,6 +2975,12 @@ server_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
b51a1f
     char *loglevel = NULL;
b51a1f
     int i = 0;
b51a1f
 
b51a1f
+    if (dict_foreach_fnmatch(set_dict, "user.xlator.*",
b51a1f
+                             validate_user_xlator_position, NULL) < 0) {
b51a1f
+        ret = -EINVAL;
b51a1f
+        goto out;
b51a1f
+    }
b51a1f
+
b51a1f
     i = sizeof(server_graph_table) / sizeof(server_graph_table[0]) - 1;
b51a1f
 
b51a1f
     while (i >= 0) {
b51a1f
@@ -2848,6 +2998,11 @@ server_graph_builder(volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
b51a1f
         if (ret)
b51a1f
             goto out;
b51a1f
 
b51a1f
+        ret = check_and_add_user_xl(graph, set_dict, volinfo->volname,
b51a1f
+                                    server_graph_table[i].dbg_key);
b51a1f
+        if (ret)
b51a1f
+            goto out;
b51a1f
+
b51a1f
         i--;
b51a1f
     }
b51a1f
 
b51a1f
-- 
b51a1f
1.8.3.1
b51a1f