From 312b339190b7b8f2e38cdd210bf2ee71e53b287e Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Wed, 3 Sep 2014 10:50:31 +0530 Subject: glusterd: Prevent rebalance starting with old clients Glusterd will prevent rebalance from starting when clients older than glusterfs-v3.6.0 are connected to a volume. This is needed as running rebalance with old clients connected could lead to data loss in some cases. The DHT xlator on newer clients (>= 3.6.0) has been fixed to prevent the data loss issues. Change-Id: If58640236382a2fc13f73f6b43777f01713859f7 BUG: 1136201 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.org/8583 Tested-by: Gluster Build System Reviewed-by: Atin Mukherjee Reviewed-by: Krishnan Parthasarathi Tested-by: Krishnan Parthasarathi --- xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 19 +++++++++++++ xlators/mgmt/glusterd/src/glusterd-op-sm.c | 38 ------------------------- xlators/mgmt/glusterd/src/glusterd-rebalance.c | 20 +++++++++++++ xlators/mgmt/glusterd/src/glusterd-utils.c | 39 ++++++++++++++++++++++++++ xlators/mgmt/glusterd/src/glusterd-utils.h | 3 ++ 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index efaefe7b761..951e733b4db 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -1577,6 +1577,25 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) goto out; } + /* Check if the connected clients are all of version + * glusterfs-3.6 and higher. This is needed to prevent some data + * loss issues that could occur when older clients are connected + * when rebalance is run. + */ + ret = glusterd_check_client_op_version_support + (volname, GD_OP_VERSION_3_6_0, NULL); + if (ret) { + ret = gf_asprintf (op_errstr, "Volume %s has one or " + "more connected clients of a version" + " lower than GlusterFS-v3.6.0. " + "Starting remove-brick in this state " + "could lead to data loss.\nPlease " + "disconnect those clients before " + "attempting this command again.", + volname); + goto out; + } + if (is_origin_glusterd (dict)) { ret = glusterd_generate_and_set_task_id (dict, GF_REMOVE_BRICK_TID_KEY); diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 9694a8454ef..c3ef67e0c5c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -638,44 +638,6 @@ out: return ret; } -static int -glusterd_check_client_op_version_support (char *volname, uint32_t op_version, - char **op_errstr) -{ - int ret = 0; - xlator_t *this = NULL; - glusterd_conf_t *priv = NULL; - rpc_transport_t *xprt = NULL; - - this = THIS; - GF_ASSERT(this); - priv = this->private; - GF_ASSERT(priv); - - pthread_mutex_lock (&priv->xprt_lock); - list_for_each_entry (xprt, &priv->xprt_list, list) { - if ((!strcmp(volname, xprt->peerinfo.volname)) && - ((op_version > xprt->peerinfo.max_op_version) || - (op_version < xprt->peerinfo.min_op_version))) { - ret = -1; - break; - } - } - pthread_mutex_unlock (&priv->xprt_lock); - - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "One or more clients " - "don't support the required op-version"); - ret = gf_asprintf (op_errstr, "One or more connected clients " - "cannot support the feature being set. " - "These clients need to be upgraded or " - "disconnected before running this command" - " again"); - return -1; - } - return 0; -} - static int glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) { diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c index f2e7338a80e..dac36d4bf1f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c +++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c @@ -554,6 +554,26 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) switch (cmd) { case GF_DEFRAG_CMD_START: case GF_DEFRAG_CMD_START_LAYOUT_FIX: + /* Check if the connected clients are all of version + * glusterfs-3.6 and higher. This is needed to prevent some data + * loss issues that could occur when older clients are connected + * when rebalance is run. This check can be bypassed by using + * 'force' + */ + ret = glusterd_check_client_op_version_support + (volname, GD_OP_VERSION_3_6_0, NULL); + if (ret) { + ret = gf_asprintf (op_errstr, "Volume %s has one or " + "more connected clients of a version" + " lower than GlusterFS-v3.6.0. " + "Starting rebalance in this state " + "could lead to data loss.\nPlease " + "disconnect those clients before " + "attempting this command again.", + volname); + goto out; + } + case GF_DEFRAG_CMD_START_FORCE: if (is_origin_glusterd (dict)) { op_ctx = glusterd_op_get_ctx (); diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index d8ad209caab..375e58e3e87 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -13905,3 +13905,42 @@ out: gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); return ret; } + +int +glusterd_check_client_op_version_support (char *volname, uint32_t op_version, + char **op_errstr) +{ + int ret = 0; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + rpc_transport_t *xprt = NULL; + + this = THIS; + GF_ASSERT(this); + priv = this->private; + GF_ASSERT(priv); + + pthread_mutex_lock (&priv->xprt_lock); + list_for_each_entry (xprt, &priv->xprt_list, list) { + if ((!strcmp(volname, xprt->peerinfo.volname)) && + ((op_version > xprt->peerinfo.max_op_version) || + (op_version < xprt->peerinfo.min_op_version))) { + ret = -1; + break; + } + } + pthread_mutex_unlock (&priv->xprt_lock); + + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "One or more clients " + "don't support the required op-version"); + if (op_errstr) + ret = gf_asprintf (op_errstr, "One or more connected " + "clients cannot support the feature " + "being set. These clients need to be" + " upgraded or disconnected before " + "running this command again"); + return -1; + } + return 0; +} diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index fe89e15aaf6..887e89661f4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -909,4 +909,7 @@ glusterd_get_default_val_for_volopt (dict_t *dict, gf_boolean_t all_opts, char *key, char *orig_key, dict_t *vol_dict, char **err_str); +int +glusterd_check_client_op_version_support (char *volname, uint32_t op_version, + char **op_errstr); #endif -- cgit