/* FIXME Check partition type is LVM unless --force is given */
/* Is there a pv here already? */
- if (!(pv = pv_read(cmd, name, 0, 0)))
+ if (!(pv = find_pv_by_name(cmd, name, 1)))
stack;
/*
const char *pv_name,
int allow_orphan)
{
- struct physical_volume *pv;
+ struct device *dev;
+ struct pv_list *pvl;
+ struct dm_list *pvslist;
+ struct physical_volume *pv = NULL;
+
+ lvmcache_seed_infos_from_lvmetad(cmd);
- if (!(pv = _pv_read(cmd, cmd->mem, pv_name, NULL, 1, 0))) {
+ if (!(dev = dev_cache_get(pv_name, cmd->filter))) {
log_error("Physical volume %s not found", pv_name);
- goto bad;
+ return_NULL;
}
- if (is_orphan_vg(pv->vg_name) && dm_list_empty(&pv->fid->metadata_areas_in_use)) {
- /* If a PV has no MDAs - need to search all VGs for it */
- if (!scan_vgs_for_pvs(cmd, 1))
- goto_bad;
- free_pv_fid(pv);
- if (!(pv = _pv_read(cmd, cmd->mem, pv_name, NULL, 1, 0))) {
- log_error("Physical volume %s not found", pv_name);
- goto bad;
- }
- }
+ if (!(pvslist = get_pvs(cmd)))
+ return_NULL;
+
+ dm_list_iterate_items(pvl, pvslist)
+ if (pvl->pv->dev == dev)
+ pv = pvl->pv;
+ else
+ free_pv_fid(pvl->pv);
+
+ if (!pv)
+ log_error("Physical volume %s not found", pv_name);
if (pv && !allow_orphan && is_orphan_vg(pv->vg_name)) {
log_error("Physical volume %s not in a volume group", pv_name);