diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 4060ca223..020e89710 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -1251,11 +1251,14 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name, struct device *dev; uint64_t md_superblock, swap_signature; int wipe_md, wipe_swap; + struct dm_list mdas; + + dm_list_init(&mdas); /* FIXME Check partition type is LVM unless --force is given */ /* Is there a pv here already? */ - pv = pv_read(cmd, name, NULL, NULL, 0, 0); + pv = pv_read(cmd, name, &mdas, NULL, 0, 0); /* * If a PV has no MDAs it may appear to be an orphan until the @@ -1263,7 +1266,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name, * this means checking every VG by scanning every PV on the * system. */ - if (pv && is_orphan(pv)) { + if (pv && is_orphan(pv) && !dm_list_size(&mdas)) { if (!scan_vgs_for_pvs(cmd)) return_0; pv = pv_read(cmd, name, NULL, NULL, 0, 0); @@ -1747,14 +1750,16 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd, static struct physical_volume *_find_pv_by_name(struct cmd_context *cmd, const char *pv_name) { + struct dm_list mdas; struct physical_volume *pv; - if (!(pv = _pv_read(cmd, cmd->mem, pv_name, NULL, NULL, 1, 0))) { + dm_list_init(&mdas); + if (!(pv = _pv_read(cmd, cmd->mem, pv_name, &mdas, NULL, 1, 0))) { log_error("Physical volume %s not found", pv_name); return NULL; } - if (is_orphan_vg(pv->vg_name)) { + if (is_orphan_vg(pv->vg_name) && !dm_list_size(&mdas)) { /* If a PV has no MDAs - need to search all VGs for it */ if (!scan_vgs_for_pvs(cmd)) return_NULL; diff --git a/tools/toollib.c b/tools/toollib.c index 0d3fe0aef..efe870c45 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -642,6 +642,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, struct str_list *sll; char *tagname; int scanned = 0; + struct dm_list mdas; dm_list_init(&tags); @@ -682,7 +683,9 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, } pv = pvl->pv; } else { - if (!(pv = pv_read(cmd, argv[opt], NULL, + + dm_list_init(&mdas); + if (!(pv = pv_read(cmd, argv[opt], &mdas, NULL, 1, scan_label_only))) { log_error("Failed to read physical " "volume \"%s\"", argv[opt]); @@ -697,7 +700,8 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, * means checking every VG by scanning every * PV on the system. */ - if (!scanned && is_orphan(pv)) { + if (!scanned && is_orphan(pv) && + !dm_list_size(&mdas)) { if (!scan_label_only && !scan_vgs_for_pvs(cmd)) { stack;