From 112691a0d5a539b71c642228e197764248174f5d Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Wed, 4 Dec 2013 09:48:10 +0530 Subject: mgmt/glusterd: snapshot related cleanup Change-Id: I277a70f732666d047ba5dff7a7e6925e0679741b Signed-off-by: Raghavendra Bhat --- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 57 ++++++++++++++++----------- xlators/mgmt/glusterd/src/glusterd-utils.c | 14 ++++++- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 5ea36dde3..b5859faaf 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -750,25 +750,27 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, volname); goto out; } - } - if (!is_cg) - snprintf (snapname, sizeof (snapname), "%s", name); + tmpstr = gf_strdup (name); + if (!tmpstr) { + gf_log (this->name, GF_LOG_ERROR, "Out Of Memory"); + ret = -1; + goto out; + } - tmpstr = gf_strdup (name); - if (!tmpstr) { - gf_log (this->name, GF_LOG_ERROR, "Out Of Memory"); - ret = -1; - goto out; - } - ret = dict_set_dynstr (dict, "snap-name", tmpstr); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Unable to set snap-name"); - ret = -1; - goto out; + if (!is_cg) + ret = dict_set_dynstr (dict, "snap-name", tmpstr); + else + ret = dict_set_dynstr (dict, "cg-name", tmpstr); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Unable to set %s", + is_cg?"cg name":"snap name"); + ret = -1; + goto out; + } } - tmpstr = NULL; + snprintf (snapname, sizeof (snapname), "%s", name); for (i = 0; i < volume_count; i++) { snprintf (volname_buf, sizeof (volname_buf), @@ -946,6 +948,9 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, ret = 0; out: + if (ret) + GF_FREE (tmpstr); + gf_log ("", GF_LOG_TRACE, "Returning %d", ret); return ret; } @@ -3293,18 +3298,26 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snap-name", &name); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Unable to fetch snap-name"); - goto out; + if (volume_count == 1) { + ret = dict_get_str (dict, "snap-name", &name); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Unable to fetch snap-name"); + goto out; + } + } else { + ret = dict_get_str (dict, "cg-name", &name); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Unable to fetch cg-name"); + goto out; + } } ret = dict_get_bin (dict, "cg-id", (void **)&cg_id); if (ret) - gf_log (this->name, GF_LOG_DEBUG, "Not a cg."); + gf_log (this->name, GF_LOG_DEBUG, "Not a cg."); else { - is_cg = _gf_true; - gf_log (this->name, GF_LOG_DEBUG, "cg-id = %s", uuid_utoa(*cg_id)); + is_cg = _gf_true; + gf_log (this->name, GF_LOG_DEBUG, "cg-id = %s", uuid_utoa(*cg_id)); } if (volume_count > 1) { diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 50d6232ef..9492baf3a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -4431,6 +4431,10 @@ glusterd_restart_bricks (glusterd_conf_t *conf) int ret = 0; glusterd_snap_t *snap = NULL; glusterd_volinfo_t *snap_volume = NULL; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT (this); list_for_each_entry (volinfo, &conf->volumes, vol_list) { if (volinfo->status != GLUSTERD_STATUS_STARTED) @@ -4438,7 +4442,7 @@ glusterd_restart_bricks (glusterd_conf_t *conf) if (volinfo->is_snap_volume) continue; start_nodesvcs = _gf_true; - gf_log (THIS->name, GF_LOG_DEBUG, "starting the volume %s", + gf_log (this->name, GF_LOG_DEBUG, "starting the volume %s", volinfo->volname); list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { glusterd_brick_start (volinfo, brickinfo, _gf_false); @@ -4450,7 +4454,13 @@ glusterd_restart_bricks (glusterd_conf_t *conf) continue; list_for_each_entry (snap, &volinfo->snaps, snap_list) { snap_volume = snap->snap_volume; - GF_ASSERT (snap_volume); + //GF_ASSERT (snap_volume); + if (!snap_volume) { + gf_log (this->name, GF_LOG_WARNING, "volinfo " + "for the snap %s is NULL", + snap->snap_name); + continue; + } list_for_each_entry (brickinfo, &snap_volume->bricks, brick_list) { glusterd_snap_brick_start (volinfo, snap_volume, -- cgit