diff options
author | Kotresh HR <khiremat@redhat.com> | 2015-01-06 20:26:39 +0530 |
---|---|---|
committer | Krishnan Parthasarathi <kparthas@redhat.com> | 2015-02-16 04:22:18 -0800 |
commit | 8618abaaf07a96c0384db9bd1e7dbbe663f4f24c (patch) | |
tree | 8982056824e7e084f84e2a6bfebdf8e7ac8ca5cd | |
parent | 04c4ec96b88ee6392812a511de32b48bbe63a421 (diff) |
glusterd/geo-rep: Allow replace/remove brick if geo-rep is stopped.
Replace brick:
If geo-replication was configured on a volume, replace brick
used to fail. This patch allows replace brick to go through
if all geo-rep sessions corresponding to that volume is stopped.
Remove brick:
There was no check for geo-replication for remove brick. Enforce
'remove brick commit' to fail if geo-rep session corresponding
to volume is running. Allow 'remove brick commit' only if all of
the geo-rep sessions corresponding to that volume is stopped.
Code is re-organized for better readability.
Change-Id: I02282c2764d8b81e319489c977847e6e437511a4
BUG: 1179638
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Reviewed-on: http://review.gluster.org/9402
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Aravinda VK <avishwan@redhat.com>
Reviewed-by: ajeet jha <ajha@redhat.com>
Reviewed-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
Tested-by: Krishnan Parthasarathi <kparthas@redhat.com>
-rw-r--r-- | xlators/mgmt/glusterd/src/Makefile.am | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 12 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 65 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.h | 45 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.h | 20 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 63 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 1 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 10 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 33 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.c | 1 |
10 files changed, 156 insertions, 96 deletions
diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am index 4d14858343e..2215af71065 100644 --- a/xlators/mgmt/glusterd/src/Makefile.am +++ b/xlators/mgmt/glusterd/src/Makefile.am @@ -26,7 +26,7 @@ noinst_HEADERS = glusterd.h glusterd-utils.h glusterd-op-sm.h \ glusterd-pmap.h glusterd-volgen.h glusterd-mountbroker.h \ glusterd-syncop.h glusterd-hooks.h glusterd-locks.h \ glusterd-mgmt.h glusterd-messages.h glusterd-peer-utils.h \ - glusterd-statedump.h glusterd-snapshot-utils.h + glusterd-statedump.h glusterd-snapshot-utils.h glusterd-geo-rep.h AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ -I$(rpclibdir) -I$(CONTRIBDIR)/rbtree \ diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index 951e733b4db..72aaff58ffc 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -17,6 +17,7 @@ #include "xdr-generic.h" #include "glusterd.h" #include "glusterd-op-sm.h" +#include "glusterd-geo-rep.h" #include "glusterd-store.h" #include "glusterd-utils.h" #include "glusterd-volgen.h" @@ -1467,6 +1468,7 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) char key[256] = {0,}; char *brick = NULL; glusterd_brickinfo_t *brickinfo = NULL; + gsync_status_param_t param = {0,}; this = THIS; GF_ASSERT (this); @@ -1658,6 +1660,16 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) } } + /* If geo-rep is configured, for this volume, it should be + * stopped. + */ + param.volinfo = volinfo; + ret = glusterd_check_geo_rep_running (¶m, op_errstr); + if (ret || param.is_active) { + ret = -1; + goto out; + } + break; case GF_OP_CMD_COMMIT_FORCE: diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index c53f027def1..31dd5a481d4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -17,6 +17,7 @@ #include "xdr-generic.h" #include "glusterd.h" #include "glusterd-op-sm.h" +#include "glusterd-geo-rep.h" #include "glusterd-store.h" #include "glusterd-utils.h" #include "glusterd-volgen.h" @@ -1327,8 +1328,9 @@ out: return ret; } -int -glusterd_check_gsync_running (glusterd_volinfo_t *volinfo, gf_boolean_t *flag) +void +glusterd_check_geo_rep_configured (glusterd_volinfo_t *volinfo, + gf_boolean_t *flag) { GF_ASSERT (volinfo); @@ -1339,7 +1341,7 @@ glusterd_check_gsync_running (glusterd_volinfo_t *volinfo, gf_boolean_t *flag) else *flag = _gf_false; - return 0; + return; } /* @@ -1497,6 +1499,63 @@ out: return ret; } +/* glusterd_check_geo_rep_running: + * Checks if any geo-rep session is running for the volume. + * + * RETURN VALUE: + * Sets param.active to true if any geo-rep session is active. + * This function sets op_errstr during some error and when any geo-rep + * session is active. It is caller's responsibility to free op_errstr + * in above cases. + */ + +int +glusterd_check_geo_rep_running (gsync_status_param_t *param, char **op_errstr) +{ + char msg[2048] = {0,}; + gf_boolean_t enabled = _gf_false; + int ret = 0; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT (this); + GF_ASSERT (param); + GF_ASSERT (param->volinfo); + GF_ASSERT (op_errstr); + + glusterd_check_geo_rep_configured (param->volinfo, &enabled); + + if (enabled) { + ret = dict_foreach (param->volinfo->gsync_slaves, + _get_slave_status, param); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "_get_slave_satus failed"); + snprintf (msg, sizeof(msg), GEOREP" Unable to" + " get the status of active "GEOREP"" + " session for the volume '%s'.\n" + " Please check the log file for" + " more info.", param->volinfo->volname); + *op_errstr = gf_strdup (msg); + ret = -1; + goto out; + } + + if (param->is_active) { + snprintf (msg, sizeof(msg), GEOREP" sessions" + " are active for the volume %s.\nStop" + " "GEOREP " sessions involved in this" + " volume. Use 'volume "GEOREP + " status' command for more info.", + param->volinfo->volname); + *op_errstr = gf_strdup (msg); + goto out; + } + } + out: + return ret; +} + static int glusterd_op_verify_gsync_running (glusterd_volinfo_t *volinfo, char *slave, char *conf_path, diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.h b/xlators/mgmt/glusterd/src/glusterd-geo-rep.h new file mode 100644 index 00000000000..2543b9482c1 --- /dev/null +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.h @@ -0,0 +1,45 @@ +/* + Copyright (c) 2006-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ +#ifndef _GLUSTERD_GEO_REP_H_ +#define _GLUSTERD_GEO_REP_H_ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#ifndef GSYNC_CONF_TEMPLATE +#define GSYNC_CONF_TEMPLATE GEOREP"/gsyncd_template.conf" +#endif + +typedef struct glusterd_gsync_status_temp { + dict_t *rsp_dict; + glusterd_volinfo_t *volinfo; + char *node; +} glusterd_gsync_status_temp_t; + +typedef struct gsync_status_param { + int is_active; + glusterd_volinfo_t *volinfo; +} gsync_status_param_t; + +int +gsync_status (char *master, char *slave, char *conf_path, + int *status, gf_boolean_t *is_template_in_use); + +void +glusterd_check_geo_rep_configured (glusterd_volinfo_t *volinfo, + gf_boolean_t *flag); +int +_get_slave_status (dict_t *dict, char *key, data_t *value, void *data); +int +glusterd_check_geo_rep_running (gsync_status_param_t *param, char **op_errstr); +#endif + diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 88fe9ef4c04..e306ccc6bde 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -15,9 +15,6 @@ #include "config.h" #endif -#ifndef GSYNC_CONF_TEMPLATE -#define GSYNC_CONF_TEMPLATE GEOREP"/gsyncd_template.conf" -#endif #include <pthread.h> #include "uuid.h" @@ -160,16 +157,6 @@ typedef struct glusterd_status_rsp_conv_ { dict_t *dict; } glusterd_status_rsp_conv_t; -typedef struct glusterd_gsync_status_temp { - dict_t *rsp_dict; - glusterd_volinfo_t *volinfo; - char *node; -}glusterd_gsync_status_temp_t; - -typedef struct gsync_status_param { - int is_active; - glusterd_volinfo_t *volinfo; -}gsync_status_param_t; typedef struct glusterd_txn_opinfo_object_ { glusterd_op_info_t opinfo; @@ -285,13 +272,6 @@ glusterd_are_all_volumes_stopped (); int glusterd_stop_bricks (glusterd_volinfo_t *volinfo); int -gsync_status (char *master, char *slave, char *conf_path, - int *status, gf_boolean_t *is_template_in_use); - -int -glusterd_check_gsync_running (glusterd_volinfo_t *volinfo, gf_boolean_t *flag); - -int glusterd_defrag_volume_node_rsp (dict_t *req_dict, dict_t *rsp_dict, dict_t *op_ctx); #ifdef HAVE_BD_XLATOR diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c index 11e15c55f46..ad89d159b46 100644 --- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c @@ -18,6 +18,7 @@ #include "glusterfs.h" #include "glusterd.h" #include "glusterd-op-sm.h" +#include "glusterd-geo-rep.h" #include "glusterd-store.h" #include "glusterd-utils.h" #include "glusterd-volgen.h" @@ -200,28 +201,29 @@ int glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) { - int ret = 0; - int32_t port = 0; - char *src_brick = NULL; - char *dst_brick = NULL; - char *volname = NULL; - int replace_op = 0; - glusterd_volinfo_t *volinfo = NULL; - glusterd_brickinfo_t *src_brickinfo = NULL; - char *host = NULL; - char *path = NULL; - char msg[2048] = {0}; - char *dup_dstbrick = NULL; - glusterd_peerinfo_t *peerinfo = NULL; - glusterd_brickinfo_t *dst_brickinfo = NULL; - gf_boolean_t is_run = _gf_false; - dict_t *ctx = NULL; - glusterd_conf_t *priv = NULL; - char *savetok = NULL; - char pidfile[PATH_MAX] = {0}; - char *task_id_str = NULL; - xlator_t *this = NULL; - gf_boolean_t is_force = _gf_false; + int ret = 0; + int32_t port = 0; + char *src_brick = NULL; + char *dst_brick = NULL; + char *volname = NULL; + int replace_op = 0; + glusterd_volinfo_t *volinfo = NULL; + glusterd_brickinfo_t *src_brickinfo = NULL; + char *host = NULL; + char *path = NULL; + char msg[2048] = {0}; + char *dup_dstbrick = NULL; + glusterd_peerinfo_t *peerinfo = NULL; + glusterd_brickinfo_t *dst_brickinfo = NULL; + gf_boolean_t enabled = _gf_false; + dict_t *ctx = NULL; + glusterd_conf_t *priv = NULL; + char *savetok = NULL; + char pidfile[PATH_MAX] = {0}; + char *task_id_str = NULL; + xlator_t *this = NULL; + gf_boolean_t is_force = _gf_false; + gsync_status_param_t param = {0,}; this = THIS; GF_ASSERT (this); @@ -288,19 +290,10 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr, goto out; } - ret = glusterd_check_gsync_running (volinfo, &is_run); - if (ret && (is_run == _gf_false)) - gf_log (this->name, GF_LOG_WARNING, "Unable to get the status" - " of active "GEOREP" session"); - if (is_run) { - gf_log (this->name, GF_LOG_WARNING, GEOREP" sessions active" - "for the volume %s ", volname); - snprintf (msg, sizeof(msg), GEOREP" sessions are active " - "for the volume %s.\nStop "GEOREP " sessions " - "involved in this volume. Use 'volume "GEOREP - " status' command for more info.", - volname); - *op_errstr = gf_strdup (msg); + /* If geo-rep is configured, for this volume, it should be stopped. */ + param.volinfo = volinfo; + ret = glusterd_check_geo_rep_running (¶m, op_errstr); + if (ret || param.is_active) { ret = -1; goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index e1b0681c29a..9ff7bf2347b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -42,6 +42,7 @@ #include "glusterd-mem-types.h" #include "glusterd.h" #include "glusterd-op-sm.h" +#include "glusterd-geo-rep.h" #include "glusterd-sm.h" #include "glusterd-utils.h" #include "glusterd-store.h" diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 5310e72070e..29b34883a81 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -30,7 +30,7 @@ #include "glusterd-mem-types.h" #include "cli1-xdr.h" #include "glusterd-volgen.h" -#include "glusterd-op-sm.h" +#include "glusterd-geo-rep.h" #include "glusterd-utils.h" #include "run.h" #include "options.h" @@ -1315,7 +1315,7 @@ server_check_marker_off (volgen_graph_t *graph, struct volopt_map_entry *vme, if (ret) { enabled = _gf_false; - ret = glusterd_check_gsync_running (volinfo, &enabled); + glusterd_check_geo_rep_configured (volinfo, &enabled); if (enabled) { gf_log ("", GF_LOG_WARNING, GEOREP" sessions active" @@ -1327,12 +1327,6 @@ server_check_marker_off (volgen_graph_t *graph, struct volopt_map_entry *vme, ret = -1; goto out; } - - if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get the status" - " of active gsync session"); - goto out; - } } ret = 0; diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index 4c2c895decb..b90518e1c9a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -22,6 +22,7 @@ #include "xdr-generic.h" #include "glusterd.h" #include "glusterd-op-sm.h" +#include "glusterd-geo-rep.h" #include "glusterd-store.h" #include "glusterd-utils.h" #include "glusterd-volgen.h" @@ -39,9 +40,6 @@ #define glusterd_op_start_volume_args_get(dict, volname, flags) \ glusterd_op_stop_volume_args_get (dict, volname, flags) -extern int -_get_slave_status (dict_t *this, char *key, data_t *value, void *data); - gf_ai_compare_t glusterd_compare_addrinfo (struct addrinfo *first, struct addrinfo *next) { @@ -1452,7 +1450,6 @@ glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr) char *volname = NULL; int flags = 0; gf_boolean_t exists = _gf_false; - gf_boolean_t is_run = _gf_false; glusterd_volinfo_t *volinfo = NULL; char msg[2048] = {0}; xlator_t *this = NULL; @@ -1496,33 +1493,11 @@ glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr) ret = -1; goto out; } - ret = glusterd_check_gsync_running (volinfo, &is_run); - if (ret && (is_run == _gf_false)) - gf_log (this->name, GF_LOG_WARNING, "Unable to get the status" - " of active "GEOREP" session"); + /* If geo-rep is configured, for this volume, it should be stopped. */ param.volinfo = volinfo; - ret = dict_foreach (volinfo->gsync_slaves, _get_slave_status, ¶m); - - if (ret) { - gf_log (this->name, GF_LOG_WARNING, "_get_slave_satus failed"); - snprintf (msg, sizeof(msg), GEOREP" Unable to get the status " - "of active "GEOREP" session for the volume '%s'.\n" - "Please check the log file for more info. Use " - "'force' option to ignore and stop the volume.", - volname); - ret = -1; - goto out; - } - - if (is_run && param.is_active) { - gf_log (this->name, GF_LOG_WARNING, GEOREP" sessions active " - "for the volume %s ", volname); - snprintf (msg, sizeof(msg), GEOREP" sessions are active " - "for the volume '%s'.\nUse 'volume "GEOREP" " - "status' command for more info. Use 'force' " - "option to ignore and stop the volume.", - volname); + ret = glusterd_check_geo_rep_running (¶m, op_errstr); + if (ret || param.is_active) { ret = -1; goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index 1efe7d08a0f..ce312066379 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -39,6 +39,7 @@ #include "glusterd-utils.h" #include "glusterd-locks.h" #include "common-utils.h" +#include "glusterd-geo-rep.h" #include "run.h" #include "rpc-clnt-ping.h" |