mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-11 20:58:50 +03:00
pvremove: Avoid using pv_read in favour of scanning.
This commit is contained in:
parent
93108125ac
commit
4e9bbccb33
@ -24,59 +24,60 @@ const char _really_wipe[] =
|
||||
*/
|
||||
static int pvremove_check(struct cmd_context *cmd, const char *name)
|
||||
{
|
||||
struct physical_volume *pv;
|
||||
struct device *dev;
|
||||
struct label *label;
|
||||
struct pv_list *pvl;
|
||||
struct dm_list *pvslist;
|
||||
|
||||
struct physical_volume *pv = NULL;
|
||||
int r = 0;
|
||||
|
||||
/* FIXME Check partition type is LVM unless --force is given */
|
||||
|
||||
/* Is there a pv here already? */
|
||||
/* If not, this is an error unless you used -f. */
|
||||
if (!(pv = pv_read(cmd, name, 1, 0))) {
|
||||
if (arg_count(cmd, force_ARG))
|
||||
return 1;
|
||||
log_error("Physical Volume %s not found", name);
|
||||
if (!(dev = dev_cache_get(name, cmd->filter))) {
|
||||
log_error("Device %s not found", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If a PV has no MDAs it may appear to be an
|
||||
* orphan until the metadata is read off
|
||||
* another PV in the same VG. Detecting this
|
||||
* means checking every VG by scanning every
|
||||
* PV on the system.
|
||||
*/
|
||||
if (is_orphan(pv) && !dm_list_size(&pv->fid->metadata_areas_in_use) &&
|
||||
!dm_list_size(&pv->fid->metadata_areas_ignored)) {
|
||||
if (!scan_vgs_for_pvs(cmd, 0)) {
|
||||
log_error("Rescan for PVs without metadata areas "
|
||||
"failed.");
|
||||
goto bad;
|
||||
}
|
||||
free_pv_fid(pv);
|
||||
if (!(pv = pv_read(cmd, name, 1, 0))) {
|
||||
log_error("Failed to read physical volume %s", name);
|
||||
goto bad;
|
||||
}
|
||||
/* Is there a pv here already? */
|
||||
/* If not, this is an error unless you used -f. */
|
||||
if (!label_read(dev, &label, 0)) {
|
||||
if (arg_count(cmd, force_ARG))
|
||||
return 1;
|
||||
log_error("No PV label found on %s.", 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;
|
||||
|
||||
if (!pv) {
|
||||
log_error("Physical Volume %s not found through scanning.", name);
|
||||
goto out; /* better safe than sorry */
|
||||
}
|
||||
|
||||
/* orphan ? */
|
||||
if (is_orphan(pv)) {
|
||||
free_pv_fid(pv);
|
||||
return 1;
|
||||
r = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Allow partial & exported VGs to be destroyed. */
|
||||
/* we must have -ff to overwrite a non orphan */
|
||||
if (arg_count(cmd, force_ARG) < 2) {
|
||||
log_error("PV %s belongs to Volume Group %s so please use vgreduce first.", name, pv_vg_name(pv));
|
||||
log_error("(If you are certain you need pvremove, then confirm by using --force twice.)");
|
||||
goto bad;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* prompt */
|
||||
if (!arg_count(cmd, yes_ARG) &&
|
||||
yes_no_prompt(_really_wipe, name, pv_vg_name(pv)) == 'n') {
|
||||
log_error("%s: physical volume label not removed", name);
|
||||
goto bad;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (arg_count(cmd, force_ARG)) {
|
||||
@ -87,12 +88,12 @@ static int pvremove_check(struct cmd_context *cmd, const char *name)
|
||||
!is_orphan(pv) ? "\"" : "");
|
||||
}
|
||||
|
||||
free_pv_fid(pv);
|
||||
return 1;
|
||||
|
||||
bad:
|
||||
free_pv_fid(pv);
|
||||
return 0;
|
||||
r = 1;
|
||||
out:
|
||||
if (pvslist)
|
||||
dm_list_iterate_items(pvl, pvslist)
|
||||
free_pv_fid(pvl->pv);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int pvremove_single(struct cmd_context *cmd, const char *pv_name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user