summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-05-12 07:54:59 +0530
committerKaushal M <kaushal@redhat.com>2014-05-13 22:33:50 -0700
commit7d22fca1f5c9d792b148bae15e8d26a9c5d63efa (patch)
tree9d5fe26bb43b84d015c4b2f4fe1919a4f071d068
parentba9aec54be5b8f00125ad018618a86de769fb6b5 (diff)
glusterd/snapshot : Quorum check should not be made if we
perform snapshot status command. Problem : Snapshot status command used to fail as it used to hit the quorum check path. Solution : The condition checking where snapname is fetched based on the presence of snap_volume is moved inside create switch case. And also moved the chunk of code which does the actual quorum check to new function to make the code more readable. Change-Id: Idda2d7c576cdfab3a7d087bfa74bfa616372c20e BUG: 1096700 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/7737 Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-by: Kaushal M <kaushal@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c288
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h4
2 files changed, 163 insertions, 129 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index bb44b255dd4..32761d8fe88 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -12538,16 +12538,9 @@ out:
}
int32_t
-glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume, char **op_errstr)
+glusterd_snap_quorum_check_for_create (dict_t *dict, gf_boolean_t snap_volume,
+ char **op_errstr)
{
- int64_t i = 0;
- int32_t ret = 0;
- glusterd_volinfo_t *volinfo = NULL;
- char *volname = NULL;
- int64_t volcount = 0;
- char key[PATH_MAX] = {0, };
- xlator_t *this = NULL;
- int32_t snap_command = 0;
int8_t snap_force = 0;
int32_t force = 0;
char err_str[PATH_MAX] = {0, };
@@ -12557,6 +12550,13 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume, char **op_er
char key_prefix[PATH_MAX] = {0, };
char *snapname = NULL;
glusterd_snap_t *snap = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ char *volname = NULL;
+ int64_t volcount = 0;
+ char key[PATH_MAX] = {0, };
+ int64_t i = 0;
+ int32_t ret = 0;
+ xlator_t *this = NULL;
this = THIS;
GF_ASSERT (this);
@@ -12567,154 +12567,184 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume, char **op_er
}
if (snap_volume) {
- ret = dict_get_str (dict, "snapname", &snapname);
+ ret = dict_get_str (dict, "snapname", &snapname);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "failed to get snapname");
+ gf_log (this->name, GF_LOG_ERROR, "failed to "
+ "get snapname");
goto out;
}
snap = glusterd_find_snap_by_name (snapname);
if (!snap) {
- gf_log (this->name, GF_LOG_ERROR, "failed to get the "
- "snapshot %s", snapname);
+ gf_log (this->name, GF_LOG_ERROR, "failed to "
+ "get the snapshot %s", snapname);
goto out;
}
}
- ret = dict_get_int32 (dict, "type", &snap_command);
+ ret = dict_get_int32 (dict, "flags", &force);
+ if (!ret && (force & GF_CLI_FLAG_OP_FORCE))
+ snap_force = 1;
+ if (!snap_force) {
+ /* Do a quorum check of glusterds also. Because,
+ the missed snapshot information will be saved
+ by glusterd and if glusterds are not in
+ quorum, then better fail the snapshot
+ */
+ if (!does_gd_meet_server_quorum (this)) {
+ snprintf (err_str, sizeof (err_str),
+ "glusterds are not in quorum");
+ gf_log (this->name, GF_LOG_WARNING, "%s",
+ err_str);
+ *op_errstr = gf_strdup (err_str);
+ goto out;
+ }
+
+ gf_log (this->name, GF_LOG_DEBUG, "glusterds are in "
+ "quorum");
+ }
+
+ ret = dict_get_int64 (dict, "volcount", &volcount);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "unable to get the type of "
- "the snapshot command");
+ gf_log (this->name, GF_LOG_ERROR, "failed to get "
+ "volcount");
goto out;
}
- switch (snap_command) {
- case GF_SNAP_OPTION_TYPE_CREATE:
- ret = dict_get_int32 (dict, "flags", &force);
- if (!ret && (force & GF_CLI_FLAG_OP_FORCE))
- snap_force = 1;
- if (!snap_force) {
- /* Do a quorum check of glusterds also. Because,
- the missed snapshot information will be saved
- by glusterd and if glusterds are not in
- quorum, then better fail the snapshot
- */
- if (!does_gd_meet_server_quorum (this)) {
- snprintf (err_str, sizeof (err_str),
- "glusterds are not in quorum");
- gf_log (this->name, GF_LOG_WARNING, "%s",
- err_str);
- *op_errstr = gf_strdup (err_str);
- goto out;
- }
-
- gf_log (this->name, GF_LOG_DEBUG, "glusterds are in "
- "quorum");
- }
-
- ret = dict_get_int64 (dict, "volcount", &volcount);
+ for (i = 1; i <= volcount; i++) {
+ snprintf (key, sizeof (key), "%s%ld",
+ snap_volume?"snap-volname":"volname", i);
+ ret = dict_get_str (dict, key, &volname);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "failed to get "
- "volcount");
+ gf_log (this->name, GF_LOG_ERROR, "failed to "
+ "get volname");
goto out;
}
- for (i = 1; i <= volcount; i++) {
- snprintf (key, sizeof (key), "%s%ld",
- snap_volume?"snap-volname":"volname", i);
- ret = dict_get_str (dict, key, &volname);
+ if (snap_volume) {
+ ret = glusterd_snap_volinfo_find (volname, snap,
+ &volinfo);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "failed to "
- "get volname");
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to get snap volume %s "
+ "for snap %s", volname,
+ snapname);
goto out;
}
-
- if (snap_volume) {
- ret = glusterd_snap_volinfo_find (volname, snap,
- &volinfo);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get snap volume %s "
- "for snap %s", volname,
- snapname);
- goto out;
- }
- } else {
- ret = glusterd_volinfo_find (volname, &volinfo);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to find the volume %s",
- volname);
- goto out;
- }
+ } else {
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to find the volume %s",
+ volname);
+ goto out;
}
+ }
- /* for replicate volumes with replica count equal to or
- greater than 3, do quorum check by getting what type
- of quorum rule has been set by getting the volume
- option set. If getting the option fails, then assume
- default.
- AFR does this:
- if quorum type is "auto":
- - for odd numner of bricks (n), n/2 + 1
- bricks should be present
- - for even number of bricks n, n/2 bricks
- should be present along with the 1st
- subvolume
- if quorum type is not "auto":
- - get the quorum count from dict with the
- help of the option "cluster.quorum-count"
- if the option is not there in the dict,
- then assume quorum type is auto and follow
- the above method.
- For non replicate volumes quorum is met only if all
- the bricks of the volume are online
+ /* for replicate volumes with replica count equal to or
+ greater than 3, do quorum check by getting what type
+ of quorum rule has been set by getting the volume
+ option set. If getting the option fails, then assume
+ default.
+ AFR does this:
+ if quorum type is "auto":
+ - for odd numner of bricks (n), n/2 + 1
+ bricks should be present
+ - for even number of bricks n, n/2 bricks
+ should be present along with the 1st
+ subvolume
+ if quorum type is not "auto":
+ - get the quorum count from dict with the
+ help of the option "cluster.quorum-count"
+ if the option is not there in the dict,
+ then assume quorum type is auto and follow
+ the above method.
+ For non replicate volumes quorum is met only if all
+ the bricks of the volume are online
+ */
+
+ if (GF_CLUSTER_TYPE_REPLICATE == volinfo->type) {
+ if (volinfo->replica_count %2 == 0)
+ quorum_count = volinfo->replica_count/2;
+ else
+ quorum_count =
+ volinfo->replica_count/2 + 1;
+ } else {
+ quorum_count = volinfo->brick_count;
+ }
+
+ ret = dict_get_str (volinfo->dict,
+ "cluster.quorum-type",
+ &quorum_type);
+ if (!ret && !strcmp (quorum_type, "fixed")) {
+ ret = dict_get_int32 (volinfo->dict,
+ "cluster.quorum-count",
+ &tmp);
+ /* if quorum-type option is not found in the
+ dict assume auto quorum type. i.e n/2 + 1.
+ The same assumption is made when quorum-count
+ option cannot be obtained from the dict (even
+ if the quorum-type option is not set to auto,
+ the behavior is set to the default behavior)
*/
+ if (!ret)
+ quorum_count = tmp;
+ else
+ quorum_type = NULL;
+ }
- if (GF_CLUSTER_TYPE_REPLICATE == volinfo->type) {
- if (volinfo->replica_count %2 == 0)
- quorum_count = volinfo->replica_count/2;
- else
- quorum_count =
- volinfo->replica_count/2 + 1;
- } else {
- quorum_count = volinfo->brick_count;
- }
+ snprintf (key_prefix, sizeof (key_prefix),
+ "%s", snap_volume?"snap-vol":"vol");
- ret = dict_get_str (volinfo->dict,
- "cluster.quorum-type",
- &quorum_type);
- if (!ret && !strcmp (quorum_type, "fixed")) {
- ret = dict_get_int32 (volinfo->dict,
- "cluster.quorum-count",
- &tmp);
- /* if quorum-type option is not found in the
- dict assume auto quorum type. i.e n/2 + 1.
- The same assumption is made when quorum-count
- option cannot be obtained from the dict (even
- if the quorum-type option is not set to auto,
- the behavior is set to the default behavior)
- */
- if (!ret)
- quorum_count = tmp;
- else
- quorum_type = NULL;
- }
+ ret = glusterd_volume_quorum_check (volinfo, i, dict,
+ key_prefix,
+ snap_force,
+ quorum_count,
+ quorum_type,
+ op_errstr);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING, "volume %s "
+ "is not in quorum", volinfo->volname);
+ goto out;
+ }
+ }
+out:
+ return ret;
+}
- snprintf (key_prefix, sizeof (key_prefix),
- "%s", snap_volume?"snap-vol":"vol");
+int32_t
+glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
+ char **op_errstr)
+{
+ int32_t ret = 0;
+ xlator_t *this = NULL;
+ int32_t snap_command = 0;
+ char err_str[PATH_MAX] = {0, };
- ret = glusterd_volume_quorum_check (volinfo, i, dict,
- key_prefix,
- snap_force,
- quorum_count,
- quorum_type,
- op_errstr);
- if (ret) {
- gf_log (this->name, GF_LOG_WARNING, "volume %s "
- "is not in quorum", volinfo->volname);
- goto out;
- }
+ this = THIS;
+ GF_ASSERT (this);
+
+ if (!dict) {
+ gf_log (this->name, GF_LOG_ERROR, "dict is NULL");
+ goto out;
+ }
+
+
+ ret = dict_get_int32 (dict, "type", &snap_command);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "unable to get the type of "
+ "the snapshot command");
+ goto out;
+ }
+
+ switch (snap_command) {
+ case GF_SNAP_OPTION_TYPE_CREATE:
+ ret = glusterd_snap_quorum_check_for_create (dict, snap_volume,
+ op_errstr);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING, "Quorum check"
+ "failed during snapshot create command");
+ goto out;
}
break;
case GF_SNAP_OPTION_TYPE_DELETE:
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index a0fdb196418..6d65b1ffab5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -800,6 +800,10 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
char **op_errstr);
int32_t
+glusterd_snap_quorum_check_for_create (dict_t *dict, gf_boolean_t snap_volume,
+ char **op_errstr);
+
+int32_t
glusterd_volume_quorum_check (glusterd_volinfo_t *volinfo, int64_t index,
dict_t *dict, char *key_prefix,
int8_t snap_force, int32_t quorum_count,