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