diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2015-08-26 15:57:39 +0200 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2016-02-04 16:20:33 +0100 |
commit | fcf96b7c78920b8aa3cc6657b7806abc87cb5dcf (patch) | |
tree | 9ff94a1562af6e67d7c181bf81b6d26fd23c58a5 | |
parent | dbb5f665a524e8a31f9fdb54f1d795d865cb284d (diff) | |
download | lvm2-fcf96b7c78920b8aa3cc6657b7806abc87cb5dcf.tar.gz |
commands: lvremove: recognize -r|--removed switch
When lvremove is used together with -r|--removed switch, dead LVs
are processed as well. This allows for removing dead LVs from history.
For example, we have lvol1 --> lvol2 --> lvol3 thin snapshot chain at
the beginning:
$ lvs -o name,name_removed,full_ancestors,full_descendants -O removed vg
LV RLV FAncestors FDescendants
pool
lvol1 lvol2,lvol3
lvol2 lvol1 lvol3
lvol3 lvol2,lvol1
Then we remove the lvol2 which is then recorded as dead LV -rlvol0:
$ lvremove -ff vg/lvol2
Logical volume "lvol2" successfully removed
$ lvs -r -o name,name_removed,full_ancestors,full_descendants -O removed vg
LV RLV FAncestors FDescendants
pool
lvol1 -rlvol0,lvol3
lvol3 -rlvol0,lvol1
-lvol2 -rlvol0 lvol1 lvol3
Without the -r|--removed switch, removed entities are not processed and
they're simply not visible to the command:
$ lvremove -ff vg/-rlvol0
Failed to find logical volume "vg/-rlvol0"
With lvremove used together with the -r|--removed switch, we can removed
items from history:
$ lvremove -r -ff vg/-rlvol0
Dead logical volume "rlvol0" successfully removed
The indirect origin/indirect users relation is still kept though, we
just don't see the history of what was in between there before:
$ lvs -r -o name,name_removed,full_ancestors,full_descendants -O removed vg
LV RLV FAncestors FDescendants
pool
lvol1 lvol3
lvol3 lvol1
-rw-r--r-- | lib/metadata/lv_manip.c | 19 | ||||
-rw-r--r-- | tools/commands.h | 4 |
2 files changed, 17 insertions, 6 deletions
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 9c448b064..d8bfdecc8 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -5811,7 +5811,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, struct volume_group *vg; struct logical_volume *format1_origin = NULL; int format1_reload_required = 0; - int visible; + int visible, dead; struct logical_volume *pool_lv = NULL; struct logical_volume *lock_lv = lv; struct lv_segment *cache_seg = NULL; @@ -5988,10 +5988,17 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, } visible = lv_is_visible(lv); + dead = lv_is_dead(lv); - log_verbose("Releasing logical volume \"%s\"", lv->name); + if (dead) + log_verbose("Releasing %slogical volume \"%s\"", + dead ? "dead " : "", + dead ? lv->this_glv->dead->dname : lv->name); if (!lv_remove(lv)) { - log_error("Error releasing logical volume \"%s\"", lv->name); + if (dead) + log_error("Error releasing %slogical volume \"%s\"", + dead ? "dead ": "", + dead ? lv->this_glv->dead->dname : lv->name); return 0; } @@ -6054,8 +6061,10 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, lockd_lv(cmd, lock_lv, "un", LDLV_PERSISTENT); lockd_free_lv(cmd, vg, lv->name, &lv->lvid.id[1], lv->lock_args); - if (!suppress_remove_message && visible) - log_print_unless_silent("Logical volume \"%s\" successfully removed", lv->name); + if (!suppress_remove_message && (visible || dead)) + log_print_unless_silent("%sogical volume \"%s\" successfully removed", + dead ? "Dead l" : "L", + dead ? lv->this_glv->dead->dname : lv->name); return 1; } diff --git a/tools/commands.h b/tools/commands.h index 86d1f4c5c..babeedb05 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -600,13 +600,15 @@ xx(lvremove, "\t[-h|--help]\n" "\t[--nohistory]\n" "\t[--noudevsync]\n" + "\t[-r|--removed]\n" "\t[-S|--select Selection]\n" "\t[-t|--test]\n" "\t[-v|--verbose]\n" "\t[--version]\n" "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n", - autobackup_ARG, force_ARG, nohistory_ARG, noudevsync_ARG, select_ARG, test_ARG) + autobackup_ARG, force_ARG, nohistory_ARG, noudevsync_ARG, removed_ARG, + select_ARG, test_ARG) xx(lvrename, "Rename a logical volume", |