diff options
author | Sunny Kumar <sunkumar@redhat.com> | 2018-08-28 11:34:40 +0530 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2018-08-29 04:18:42 +0000 |
commit | 043932a4d81c38d88487c2709eceaf8d5b91be35 (patch) | |
tree | 04ef6f9c6ca02372c716474443540f0b5a5effad /xlators | |
parent | ccaad48f51d4e8d3de001dc3907df68c69f8792b (diff) |
snapshot : fixed coverity issue in glusterd-snapshot.c
This patch fixes CID 1395253 and indentation.
Change-Id: Iffcd992d3d49765c7e47b864724f83c7c5d57579
updates: bz#789278
Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 166 |
1 files changed, 88 insertions, 78 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 9e9a3d26ad7..1f292ae405c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -6903,87 +6903,97 @@ glusterd_snapshot_clone_commit (dict_t *dict, char **op_errstr, tmp_name = NULL; - ret = dict_get_str (dict, "snapname", &volname); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_DICT_GET_FAILED, - "failed to get snap name"); - goto out; - } - snap_parent = glusterd_find_snap_by_name (volname); - /* TODO : As of now there is only one volume in snapshot. - * Change this when multiple volume snapshot is introduced - */ - origin_vol = cds_list_entry (snap_parent->volumes.next, - glusterd_volinfo_t, vol_list); - if (!origin_vol) { - gf_msg ("glusterd", GF_LOG_ERROR, 0, - GD_MSG_VOLINFO_GET_FAIL, "Failed to get snap " - "volinfo %s", snap_parent->snapname); - goto out; - } - snap = glusterd_create_snap_object_for_clone (dict, rsp_dict); - if (!snap) { - gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_SNAP_OBJ_NEW_FAIL, "creating the" - "snap object %s failed", snapname); - ret = -1; - goto out; - } - - snap_vol = glusterd_do_snap_vol (origin_vol, snap, dict, - rsp_dict, 1, 1); - if (!snap_vol) { - ret = -1; - gf_msg (this->name, GF_LOG_WARNING, 0, - GD_MSG_SNAP_CREATION_FAIL, "taking the " - "snapshot of the volume %s failed", volname); - goto out; - } - volcount = 1; - ret = dict_set_int64 (rsp_dict, "volcount", volcount); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_DICT_SET_FAILED, "Failed to set volcount"); - goto out; - } - - ret = glusterd_schedule_brick_snapshot (dict, rsp_dict, snap); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_SNAP_BACKEND_MAKE_FAIL, "Failed to take backend " - "snapshot %s", snap->snapname); - goto out; - } - - cds_list_del_init (&snap_vol->vol_list); - ret = dict_set_dynstr_with_alloc (rsp_dict, "snapuuid", - uuid_utoa (snap_vol->volume_id)); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_DICT_SET_FAILED, "Failed to set snap " - "uuid in response dictionary for %s snapshot", - snap->snapname); - goto out; - } - - glusterd_list_add_order (&snap_vol->vol_list, &priv->volumes, - glusterd_compare_volume_name); - - ret = 0; + ret = dict_get_str (dict, "snapname", &volname); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, + "failed to get snap name"); + goto out; + } + + snap_parent = glusterd_find_snap_by_name (volname); + if (!snap_parent) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_SNAP_NOT_FOUND, "Failed to " + "fetch snap %s", volname); + goto out; + } + + /* TODO : As of now there is only one volume in snapshot. + * Change this when multiple volume snapshot is introduced + */ + origin_vol = cds_list_entry (snap_parent->volumes.next, + glusterd_volinfo_t, vol_list); + if (!origin_vol) { + gf_msg ("glusterd", GF_LOG_ERROR, 0, + GD_MSG_VOLINFO_GET_FAIL, "Failed to get snap " + "volinfo %s", snap_parent->snapname); + goto out; + } + + snap = glusterd_create_snap_object_for_clone (dict, rsp_dict); + if (!snap) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_SNAP_OBJ_NEW_FAIL, "creating the" + "snap object %s failed", snapname); + ret = -1; + goto out; + } + + snap_vol = glusterd_do_snap_vol (origin_vol, snap, dict, + rsp_dict, 1, 1); + if (!snap_vol) { + ret = -1; + gf_msg (this->name, GF_LOG_WARNING, 0, + GD_MSG_SNAP_CREATION_FAIL, "taking the " + "snapshot of the volume %s failed", volname); + goto out; + } + + volcount = 1; + ret = dict_set_int64 (rsp_dict, "volcount", volcount); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_SET_FAILED, "Failed to set volcount"); + goto out; + } + + ret = glusterd_schedule_brick_snapshot (dict, rsp_dict, snap); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_SNAP_BACKEND_MAKE_FAIL, "Failed to take backend " + "snapshot %s", snap->snapname); + goto out; + } + + cds_list_del_init (&snap_vol->vol_list); + ret = dict_set_dynstr_with_alloc (rsp_dict, "snapuuid", + uuid_utoa (snap_vol->volume_id)); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_SET_FAILED, "Failed to set snap " + "uuid in response dictionary for %s snapshot", + snap->snapname); + goto out; + } + + glusterd_list_add_order (&snap_vol->vol_list, &priv->volumes, + glusterd_compare_volume_name); + + ret = 0; out: - if (ret) { - if (snap) - glusterd_snap_remove (rsp_dict, snap, - _gf_true, _gf_true, - _gf_true); - snap = NULL; - } - - gf_msg_trace (this->name, 0, "Returning %d", ret); - return ret; + if (ret) { + if (snap) + glusterd_snap_remove (rsp_dict, snap, + _gf_true, _gf_true, + _gf_true); + snap = NULL; + } + + gf_msg_trace (this->name, 0, "Returning %d", ret); + return ret; } |