From 9b1fe5a0625e39f71332feb2e4c097995b5e8e7d Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 25 Jan 2012 11:27:42 +0000 Subject: [PATCH] Thin clear stacked message for thin pool Before removing thin pool LV always make sure, stacked message for previous run are cleared - but allow to remove any device that should have been created (i.e. creation of snapshot failed - so the message for snapshot creation may be replaced with delete message within unfinished transaction). Also commit messages after lv remove - so free space is released in pool. --- lib/metadata/lv_manip.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index a5e63a14d..400e446bf 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -527,10 +527,6 @@ static int _lv_reduce(struct logical_volume *lv, uint32_t extents, int delete) return_0; if (seg->pool_lv) { - /* For now, clear stacked messages here */ - if (!update_pool_lv(seg->pool_lv, 1)) - return_0; - if (!detach_pool_lv(seg)) return_0; } @@ -3142,6 +3138,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, struct logical_volume *format1_origin = NULL; int format1_reload_required = 0; int visible; + struct logical_volume *pool_lv = NULL; vg = lv->vg; @@ -3176,7 +3173,8 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, log_error("Can't remove logical volume %s used by a thin pool.", lv->name); return 0; - } + } else if (lv_is_thin_volume(lv)) + pool_lv = first_seg(lv)->pool_lv; if (lv->status & LOCKED) { log_error("Can't remove locked LV %s", lv->name); @@ -3222,6 +3220,13 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, return 0; } + /* Clear thin pool stacked messages */ + if (pool_lv && !pool_has_message(first_seg(pool_lv), lv, 0) && + !update_pool_lv(pool_lv, 1)) { + log_error("Failed to update thin pool %s.", pool_lv->name); + return 0; + } + visible = lv_is_visible(lv); log_verbose("Releasing logical volume \"%s\"", lv->name); @@ -3256,6 +3261,13 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, return 0; } + /* Release unneeded blocks in thin pool */ + /* TODO: defer when multiple LVs relased at once */ + if (pool_lv && !update_pool_lv(pool_lv, 1)) { + log_error("Failed to update thin pool %s.", pool_lv->name); + return 0; + } + backup(vg); if (visible)