diff options
Diffstat (limited to 'lib/metadata/pv_manip.c')
-rw-r--r-- | lib/metadata/pv_manip.c | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c index 6499e361d..ce7f66140 100644 --- a/lib/metadata/pv_manip.c +++ b/lib/metadata/pv_manip.c @@ -24,6 +24,7 @@ #include "display.h" #include "label.h" #include "archiver.h" +#include "lvm-signal.h" static struct pv_segment *_alloc_pv_segment(struct dm_pool *mem, struct physical_volume *pv, @@ -694,12 +695,11 @@ const char _really_wipe[] = * 0 indicates we may not. */ static int pvremove_check(struct cmd_context *cmd, const char *name, - unsigned force_count, unsigned prompt) + unsigned force_count, unsigned prompt, struct dm_list *pvslist) { struct device *dev; struct label *label; struct pv_list *pvl; - struct dm_list *pvslist; struct physical_volume *pv = NULL; int r = 0; @@ -720,10 +720,6 @@ static int pvremove_check(struct cmd_context *cmd, const char *name, return 0; } - lvmcache_seed_infos_from_lvmetad(cmd); - if (!(pvslist = get_pvs(cmd))) - return_0; - dm_list_iterate_items(pvl, pvslist) if (pvl->pv->dev == dev) pv = pvl->pv; @@ -765,26 +761,18 @@ static int pvremove_check(struct cmd_context *cmd, const char *name, r = 1; out: - if (pvslist) - dm_list_iterate_items(pvl, pvslist) - free_pv_fid(pvl->pv); return r; } int pvremove_single(struct cmd_context *cmd, const char *pv_name, void *handle __attribute__((unused)), unsigned force_count, - unsigned prompt) + unsigned prompt, struct dm_list *pvslist) { struct device *dev; struct lvmcache_info *info; int r = 0; - if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) { - log_error("Can't get lock for orphan PVs"); - return 0; - } - - if (!pvremove_check(cmd, pv_name, force_count, prompt)) + if (!pvremove_check(cmd, pv_name, force_count, prompt, pvslist)) goto out; if (!(dev = dev_cache_get(pv_name, cmd->filter))) { @@ -820,9 +808,48 @@ int pvremove_single(struct cmd_context *cmd, const char *pv_name, r = 1; out: + return r; +} + +int pvremove_many(struct cmd_context *cmd, struct dm_list *pv_names, + unsigned force_count, unsigned prompt) +{ + int ret = 1; + struct dm_list *pvslist = NULL; + struct pv_list *pvl; + const struct dm_str_list *pv_name; + + if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) { + log_error("Can't get lock for orphan PVs"); + return 0; + } + + lvmcache_seed_infos_from_lvmetad(cmd); + + if (!(pvslist = get_pvs(cmd))) { + ret = 0; + goto_out; + } + + dm_list_iterate_items(pv_name, pv_names) { + if (!pvremove_single(cmd, pv_name->str, NULL, force_count, prompt, pvslist)) { + stack; + ret = 0; + } + if (sigint_caught()) { + ret = 0; + goto_out; + } + } + +out: unlock_vg(cmd, VG_ORPHANS); - return r; + if (pvslist) + dm_list_iterate_items(pvl, pvslist) + free_pv_fid(pvl->pv); + + return ret; } int pvcreate_single(struct cmd_context *cmd, const char *pv_name, |