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