From 1bfb0a750c6fcd0bbf4d68a1890704f0aefe6337 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Sun, 17 Nov 2019 11:00:50 +0530 Subject: debug/io-stats: add an option to set volume-id 'volume-id' is good to have for a graph for uniquely identifying it. Add it to graph->volume_id while generating volfile itself. This can be further used in many other places. Updates: #763 Change-Id: I80516d62d28a284e8ff4707841570ced97a37e73 Signed-off-by: Amar Tumballi --- libglusterfs/src/glusterfs/globals.h | 1 + xlators/debug/io-stats/src/io-stats.c | 13 +++++++++++ xlators/mgmt/glusterd/src/glusterd-volgen.c | 9 ++++++++ xlators/protocol/client/src/client-handshake.c | 7 ++++-- xlators/protocol/server/src/server-handshake.c | 31 ++++++++++++++------------ xlators/storage/posix/src/posix-common.c | 6 ----- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/libglusterfs/src/glusterfs/globals.h b/libglusterfs/src/glusterfs/globals.h index f398f71766a..781ea04e121 100644 --- a/libglusterfs/src/glusterfs/globals.h +++ b/libglusterfs/src/glusterfs/globals.h @@ -116,6 +116,7 @@ #define GD_OP_VERSION_6_0 60000 /* Op-version for GlusterFS 6.0 */ #define GD_OP_VERSION_7_0 70000 /* Op-version for GlusterFS 7.0 */ +#define GD_OP_VERSION_7_1 70100 /* Op-version for GlusterFS 7.1 */ #define GD_OP_VERSION_8_0 80000 /* Op-version for GlusterFS 8.0 */ diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index 71bd03c0123..9d3a9638d0c 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -3895,6 +3895,7 @@ int init(xlator_t *this) { struct ios_conf *conf = NULL; + char *volume_id = NULL; char *sys_log_str = NULL; char *logger_str = NULL; char *log_format_str = NULL; @@ -3935,6 +3936,11 @@ init(xlator_t *this) conf->unique_id = this->name; } + ret = dict_get_strn(this->options, "volume-id", SLEN("volume-id"), + &volume_id); + if (!ret) { + strncpy(this->graph->volume_id, volume_id, GF_UUID_BUF_SIZE); + } /* * Init it just after calloc, so that we are sure the lock is inited * in case of error paths. @@ -4484,6 +4490,13 @@ struct volume_options options[] = { .tags = {"io-stats", "threading"}, .description = "When global threading is used, this value determines the " "maximum amount of threads that can be created on clients"}, + {.key = {"volume-id"}, + .type = GF_OPTION_TYPE_STR, + .op_version = {GD_OP_VERSION_7_1}, + .tags = {"global", "volume-id"}, + .description = + "This option points to the 'unique' UUID particular to this " + "volume, which would be set in 'graph->volume_id'"}, {.key = {NULL}}, }; diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index b93c7b84c90..f872c207b66 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -2216,6 +2216,8 @@ brick_graph_add_io_stats(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, { int ret = -1; xlator_t *xl = NULL; + xlator_t *this = THIS; + glusterd_conf_t *priv = this->private; if (!graph || !set_dict || !brickinfo) goto out; @@ -2228,6 +2230,13 @@ brick_graph_add_io_stats(volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (ret) goto out; + if (priv->op_version >= GD_OP_VERSION_7_1) { + ret = xlator_set_fixed_option(xl, "volume-id", + uuid_utoa(volinfo->volume_id)); + if (ret) + goto out; + } + ret = 0; out: return ret; diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c index e6a5e84f422..0437f1f272d 100644 --- a/xlators/protocol/client/src/client-handshake.c +++ b/xlators/protocol/client/src/client-handshake.c @@ -836,8 +836,7 @@ client_setvolume_cbk(struct rpc_req *req, struct iovec *iov, int count, goto out; } } else { - strncpy(ctx->volume_id, volume_id, - min(strlen(volume_id), GF_UUID_BUF_SIZE)); + strncpy(ctx->volume_id, volume_id, GF_UUID_BUF_SIZE); } } @@ -1036,6 +1035,10 @@ client_setvolume(xlator_t *this, struct rpc_clnt *rpc) if (strncmp("snapd", remote_subvol, 5)) { /* If any value is set, the first element will be non-0. It would be '0', but not '\0' :-) */ + if (!this->ctx->volume_id[0]) { + strncpy(this->ctx->volume_id, this->graph->volume_id, + GF_UUID_BUF_SIZE); + } if (this->ctx->volume_id[0]) { ret = dict_set_str(options, "volume-id", this->ctx->volume_id); if (ret < 0) { diff --git a/xlators/protocol/server/src/server-handshake.c b/xlators/protocol/server/src/server-handshake.c index 1f347db4f77..dda58b60ca0 100644 --- a/xlators/protocol/server/src/server-handshake.c +++ b/xlators/protocol/server/src/server-handshake.c @@ -409,22 +409,25 @@ server_setvolume(rpcsvc_request_t *req) client_name = "unknown"; } - ret = dict_get_str_sizen(params, "volume-id", &volume_id); - if (!ret && strcmp(xl->graph->volume_id, volume_id)) { - ret = dict_set_str(reply, "ERROR", - "Volume-ID different, possible case " - "of same brick re-used in another volume"); - if (ret < 0) - gf_msg_debug(this->name, 0, "failed to set error msg"); + /* If any value is set, the first element will be non-0. + It would be '0', but not '\0' :-) */ + if (xl->graph->volume_id[0]) { + ret = dict_get_str_sizen(params, "volume-id", &volume_id); + if (!ret && strcmp(xl->graph->volume_id, volume_id)) { + ret = dict_set_str(reply, "ERROR", + "Volume-ID different, possible case " + "of same brick re-used in another volume"); + if (ret < 0) + gf_msg_debug(this->name, 0, "failed to set error msg"); - op_ret = -1; - op_errno = EINVAL; - goto fail; + op_ret = -1; + op_errno = EINVAL; + goto fail; + } + ret = dict_set_str(reply, "volume-id", tmp->volume_id); + if (ret) + gf_msg_debug(this->name, 0, "failed to set 'volume-id'"); } - ret = dict_set_str(reply, "volume-id", tmp->volume_id); - if (ret) - gf_msg_debug(this->name, 0, "failed to set 'volume-id'"); - client = gf_client_get(this, &req->cred, client_uid, subdir_mount); if (client == NULL) { op_ret = -1; diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c index 13b70da4d64..e95bc652944 100644 --- a/xlators/storage/posix/src/posix-common.c +++ b/xlators/storage/posix/src/posix-common.c @@ -145,12 +145,6 @@ posix_notify(xlator_t *this, int32_t event, void *data, ...) switch (event) { case GF_EVENT_PARENT_UP: { /* Notify the parent that posix xlator is up */ - char *volume_id; - int ret = dict_get_str(this->options, "volume-id", &volume_id); - if (!ret) { - strncpy(this->graph->volume_id, volume_id, - min(strlen(volume_id), GF_UUID_BUF_SIZE)); - } default_notify(this, GF_EVENT_CHILD_UP, data); } break; -- cgit