summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2015-01-13 09:31:18 +0000
committerKaushal M <kaushal@redhat.com>2015-01-26 23:25:55 -0800
commitbf227251eadcc35a102fc9db0c39e36b7336954d (patch)
treec380673b36607caee3d14ac7140180729d6016bc /xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
parentbecdb76238c45ebe3edc967376f4aee87c0cb6e3 (diff)
glusterd/snap: Fix restore cleanup
If restore commit is successful on the originator and a few nodes, but fails on some other node, restore cleanup should restate the volume and the snapshot in question as it was before the command was run. Change-Id: I7bb0becc7f052f55bc818018bc84770944e76c80 BUG: 1181418 Signed-off-by: Avra Sengupta <asengupt@redhat.com> Reviewed-on: http://review.gluster.org/9441 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com> Reviewed-by: Kaushal M <kaushal@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
index 8603e9e950c..33bcf6e7df0 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
@@ -867,14 +867,15 @@ out:
int32_t
glusterd_perform_missed_op (glusterd_snap_t *snap, int32_t op)
{
- dict_t *dict = NULL;
- int32_t ret = -1;
- glusterd_conf_t *priv = NULL;
- glusterd_volinfo_t *snap_volinfo = NULL;
- glusterd_volinfo_t *volinfo = NULL;
- glusterd_volinfo_t *tmp = NULL;
- xlator_t *this = NULL;
- uuid_t null_uuid = {0};
+ dict_t *dict = NULL;
+ int32_t ret = -1;
+ glusterd_conf_t *priv = NULL;
+ glusterd_volinfo_t *snap_volinfo = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_volinfo_t *tmp = NULL;
+ xlator_t *this = NULL;
+ uuid_t null_uuid = {0};
+ char *parent_volname = NULL;
this = THIS;
GF_ASSERT (this);
@@ -903,13 +904,16 @@ glusterd_perform_missed_op (glusterd_snap_t *snap, int32_t op)
case GF_SNAP_OPTION_TYPE_RESTORE:
list_for_each_entry_safe (snap_volinfo, tmp,
&snap->volumes, vol_list) {
- ret = glusterd_volinfo_find
- (snap_volinfo->parent_volname,
- &volinfo);
+ parent_volname = gf_strdup
+ (snap_volinfo->parent_volname);
+ if (!parent_volname)
+ goto out;
+
+ ret = glusterd_volinfo_find (parent_volname, &volinfo);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"Could not get volinfo of %s",
- snap_volinfo->parent_volname);
+ parent_volname);
goto out;
}
@@ -933,15 +937,38 @@ glusterd_perform_missed_op (glusterd_snap_t *snap, int32_t op)
goto out;
}
- ret = glusterd_snapshot_restore_cleanup (dict, volinfo,
+ /* Restore is successful therefore delete the original
+ * volume's volinfo. If the volinfo is already restored
+ * then we should delete the backend LVMs */
+ if (!uuid_is_null (volinfo->restored_from_snap)) {
+ ret = glusterd_lvm_snapshot_remove (dict,
+ volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to remove LVM backend");
+ goto out;
+ }
+ }
+
+ /* Detach the volinfo from priv->volumes, so that no new
+ * command can ref it any more and then unref it.
+ */
+ list_del_init (&volinfo->vol_list);
+ glusterd_volinfo_unref (volinfo);
+
+ ret = glusterd_snapshot_restore_cleanup (dict,
+ parent_volname,
snap);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"Failed to perform snapshot restore "
"cleanup for %s volume",
- snap_volinfo->parent_volname);
+ parent_volname);
goto out;
}
+
+ GF_FREE (parent_volname);
+ parent_volname = NULL;
}
break;
@@ -956,6 +983,11 @@ glusterd_perform_missed_op (glusterd_snap_t *snap, int32_t op)
out:
dict_unref (dict);
+ if (parent_volname) {
+ GF_FREE (parent_volname);
+ parent_volname = NULL;
+ }
+
gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret);
return ret;
}