summaryrefslogtreecommitdiff
path: root/lib/metadata/snapshot_manip.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/metadata/snapshot_manip.c')
-rw-r--r--lib/metadata/snapshot_manip.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index cb5df6b..5766d0b 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -81,7 +81,9 @@ struct lv_segment *find_cow(const struct logical_volume *lv)
/* Given a cow LV, return its origin */
struct logical_volume *origin_from_cow(const struct logical_volume *lv)
{
- return lv->snapshot->origin;
+ if (lv->snapshot)
+ return lv->snapshot->origin;
+ return NULL;
}
void init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin,
@@ -172,7 +174,7 @@ int vg_add_snapshot(struct logical_volume *origin,
int vg_remove_snapshot(struct logical_volume *cow)
{
- int preload_origin = 0;
+ int merging_snapshot = 0;
struct logical_volume *origin = origin_from_cow(cow);
dm_list_del(&cow->snapshot->origin_list);
@@ -193,7 +195,7 @@ int vg_remove_snapshot(struct logical_volume *cow)
* when transitioning from "snapshot-merge" to
* "snapshot-origin after a merge completes.
*/
- preload_origin = 1;
+ merging_snapshot = 1;
}
}
@@ -206,20 +208,26 @@ int vg_remove_snapshot(struct logical_volume *cow)
cow->snapshot = NULL;
lv_set_visible(cow);
- if (preload_origin) {
- if (!vg_write(origin->vg))
- return_0;
- if (!suspend_lv(origin->vg->cmd, origin)) {
- log_error("Failed to refresh %s without snapshot.",
- origin->name);
- return 0;
- }
- if (!vg_commit(origin->vg))
- return_0;
- if (!resume_lv(origin->vg->cmd, origin)) {
- log_error("Failed to resume %s.", origin->name);
- return 0;
- }
+ /* format1 must do the change in one step, with the commit last. */
+ if (!(origin->vg->fid->fmt->features & FMT_MDAS))
+ return 1;
+
+ if (!vg_write(origin->vg))
+ return_0;
+ if (!suspend_lv(origin->vg->cmd, origin)) {
+ log_error("Failed to refresh %s without snapshot.",
+ origin->name);
+ return 0;
+ }
+ if (!vg_commit(origin->vg))
+ return_0;
+ if (!merging_snapshot && !resume_lv(origin->vg->cmd, cow)) {
+ log_error("Failed to resume %s.", cow->name);
+ return 0;
+ }
+ if (!resume_lv(origin->vg->cmd, origin)) {
+ log_error("Failed to resume %s.", origin->name);
+ return 0;
}
return 1;