Skip to contentSkip to conversation

Test that all snapshots are not open before deactivating volume.

PATCH New Mike Snitzer 2 participants 2 messages Sep 29, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Test that all snapshots are not open before deactivating volume.

Test that all snapshots are not open before deactivating volume.

This prevents very weird misbehavior when we have closed origin, open snapshot and deactivate the origin with lvchange -an or vgchange -an command --- the origin is closed, the snapshot remains open and cannot be deactivated.

There is still race condition if the snapshot is open immediately after the test, but it is inevitable --- and the patch prevents misbehavior in most common case.

---
 lib/activate/activate.c |   26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
lib/activate/activate.c +22 -4
Index: lvm2/lib/activate/activate.c
===================================================================
@@ -1001,10 +1001,28 @@ int lv_deactivate(struct cmd_context *cm
 		goto out;
 	}
 
-	if (info.open_count && lv_is_visible(lv)) {
-		log_error("LV %s/%s in use: not deactivating", lv->vg->name,
-			  lv->name);
-		goto out;
+	if (lv_is_visible(lv)) {
+		if (info.open_count) {
+			log_error("LV %s/%s in use: not deactivating",
+				  lv->vg->name, lv->name);
+			goto out;
+		}
+		if (lv_is_origin(lv)) {
+			struct lv_segment *snap_seg;
+			dm_list_iterate_items_gen(snap_seg, &lv->snapshot_segs,
+						  origin_list) {
+				struct logical_volume *snap = snap_seg->cow;
+				if (!lv_info(cmd, snap, &info, 1, 0))
+					goto out;
+
+				if (info.exists && info.open_count) {
+					log_error("LV %s/%s has open snapshot %s: "
+						  "not deactivating",
+						  lv->vg->name, lv->name, snap->name);
+					goto out;
+				}
+			}
+		}
 	}
 
 	lv_calculate_readahead(lv, NULL);
#1 lore raw

PATCH 1/1 Test that all snapshots are not open before deactivating volume.

Quoted 1 line · Mike Snitzer

Test that all snapshots are not open before deactivating volume.

Moved the new checks into a separate function and applied.

Alasdair