mirror of
git://sourceware.org/git/lvm2.git
synced 2025-04-01 18:50:41 +03:00
pvremove: device check doesn't require label_read
It just needs to check if the device was found during the scan, which means checking if it exists in lvmcache.
This commit is contained in:
parent
29c6c17121
commit
f17c2cf7c6
19
lib/cache/lvmcache.c
vendored
19
lib/cache/lvmcache.c
vendored
@ -2562,6 +2562,25 @@ int lvmcache_foreach_ba(struct lvmcache_info *info,
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct label *lvmcache_get_dev_label(struct device *dev)
|
||||
{
|
||||
struct lvmcache_info *info;
|
||||
|
||||
if ((info = lvmcache_info_from_pvid(dev->pvid, NULL, 0))) {
|
||||
/* dev would be different for a duplicate */
|
||||
if (info->dev == dev)
|
||||
return info->label;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int lvmcache_has_dev_info(struct device *dev)
|
||||
{
|
||||
if (lvmcache_info_from_pvid(dev->pvid, NULL, 0))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The lifetime of the label returned is tied to the lifetime of the
|
||||
* lvmcache_info which is the same as lvmcache itself.
|
||||
|
2
lib/cache/lvmcache.h
vendored
2
lib/cache/lvmcache.h
vendored
@ -160,6 +160,8 @@ uint32_t lvmcache_ext_flags(struct lvmcache_info *info);
|
||||
|
||||
const struct format_type *lvmcache_fmt(struct lvmcache_info *info);
|
||||
struct label *lvmcache_get_label(struct lvmcache_info *info);
|
||||
struct label *lvmcache_get_dev_label(struct device *dev);
|
||||
int lvmcache_has_dev_info(struct device *dev);
|
||||
|
||||
void lvmcache_update_pv(struct lvmcache_info *info, struct physical_volume *pv,
|
||||
const struct format_type *fmt);
|
||||
|
@ -5292,14 +5292,12 @@ static int _pvremove_check_single(struct cmd_context *cmd,
|
||||
* Is there a pv here already?
|
||||
* If not, this is an error unless you used -f.
|
||||
*/
|
||||
if (!label_read(pd->dev, &label, 0)) {
|
||||
if (!lvmcache_has_dev_info(pv->dev)) {
|
||||
if (pp->force) {
|
||||
dm_list_move(&pp->arg_process, &pd->list);
|
||||
return 1;
|
||||
} else {
|
||||
log_error("No PV label found on %s.", pd->name);
|
||||
dm_list_move(&pp->arg_fail, &pd->list);
|
||||
return 1;
|
||||
pd->is_not_pv = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5308,7 +5306,11 @@ static int _pvremove_check_single(struct cmd_context *cmd,
|
||||
* device, a PV used in a VG.
|
||||
*/
|
||||
|
||||
if (vg && !is_orphan_vg(vg->name)) {
|
||||
if (pd->is_not_pv) {
|
||||
/* Device is not a PV. */
|
||||
log_debug("Found pvremove arg %s: device is not a PV.", pd->name);
|
||||
|
||||
} else if (vg && !is_orphan_vg(vg->name)) {
|
||||
/* Device is a PV used in a VG. */
|
||||
log_debug("Found pvremove arg %s: pv is used in %s.", pd->name, vg->name);
|
||||
pd->is_vg_pv = 1;
|
||||
@ -5330,6 +5332,7 @@ static int _pvremove_check_single(struct cmd_context *cmd,
|
||||
else
|
||||
pp->orphan_vg_name = FMT_TEXT_ORPHAN_VG_NAME;
|
||||
} else {
|
||||
/* FIXME: is it possible to reach here? */
|
||||
log_debug("Found pvremove arg %s: device is not a PV.", pd->name);
|
||||
/* Device is not a PV. */
|
||||
pd->is_not_pv = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user