Test that all snapshots are not open before we deactivate 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 immediatelly after the test, but it is inevitable --- and the patch prevents misbehavior in most common case. Signed-off-by: Mikulas Patocka --- lib/activate/activate.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) Index: LVM2.2.02.45/lib/activate/activate.c =================================================================== --- LVM2.2.02.45.orig/lib/activate/activate.c 2009-02-28 01:54:06.000000000 +0100 +++ LVM2.2.02.45/lib/activate/activate.c 2009-05-11 13:08:18.000000000 +0200 @@ -974,10 +974,25 @@ int lv_deactivate(struct cmd_context *cm if (!info.exists) return 1; - if (info.open_count && (lv->status & VISIBLE_LV)) { - log_error("LV %s/%s in use: not deactivating", lv->vg->name, - lv->name); - return 0; + if (lv->status & VISIBLE_LV) { + if (info.open_count) { + log_error("LV %s/%s in use: not deactivating", lv->vg->name, + lv->name); + return 0; + } + 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)) + return_0; + + if (info.exists && info.open_count) { + log_error("LV %s/%s has open snapshot %s: not deactivating", lv->vg->name, lv->name, snap->name); + return 0; + } + } + } } if (!monitor_dev_for_events(cmd, lv, 0))