mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
vg_read: look up vgid from name
After recent changes to process_each, vg_read() is usually given both the vgname and vgid for the intended VG. However, in some cases vg_read() is given a vgid with no vgname, or is given a vgname with no vgid. When given a vgid with no vgname, vg_read() uses lvmcache to look up the vgname using the vgid. If the vgname is not found, vg_read() fails. When given a vgname with no vgid, vg_read() should also use lvmcache to look up the vgid using the vgname. If the vgid is not found, vg_read() fails. If the lvmcache lookup finds multiple vgids for the vgname, then the lookup fails, causing vg_read() to fail because the intended VG is uncertain. Usually, both vgname and vgid for the intended VG are passed to vg_read(), which means the lvmcache translations between vgname and vgid are not done.
This commit is contained in:
parent
1e43ec15ce
commit
88cef47b18
17
lib/cache/lvmcache.c
vendored
17
lib/cache/lvmcache.c
vendored
@ -614,6 +614,23 @@ const char *lvmcache_vgname_from_vgid(struct dm_pool *mem, const char *vgid)
|
||||
return vgname;
|
||||
}
|
||||
|
||||
const char *lvmcache_vgid_from_vgname(struct cmd_context *cmd, const char *vgname)
|
||||
{
|
||||
struct lvmcache_vginfo *vginfo;
|
||||
|
||||
if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname)))
|
||||
return_NULL;
|
||||
|
||||
if (!vginfo->next)
|
||||
return dm_pool_strdup(cmd->mem, vginfo->vgid);
|
||||
|
||||
/*
|
||||
* There are multiple VGs with this name to choose from.
|
||||
* Return an error because we don't know which VG is intended.
|
||||
*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _info_is_valid(struct lvmcache_info *info)
|
||||
{
|
||||
if (info->status & CACHE_INVALID)
|
||||
|
1
lib/cache/lvmcache.h
vendored
1
lib/cache/lvmcache.h
vendored
@ -99,6 +99,7 @@ struct lvmcache_vginfo *lvmcache_vginfo_from_vgname(const char *vgname,
|
||||
struct lvmcache_vginfo *lvmcache_vginfo_from_vgid(const char *vgid);
|
||||
struct lvmcache_info *lvmcache_info_from_pvid(const char *pvid, int valid_only);
|
||||
const char *lvmcache_vgname_from_vgid(struct dm_pool *mem, const char *vgid);
|
||||
const char *lvmcache_vgid_from_vgname(struct cmd_context *cmd, const char *vgname);
|
||||
struct device *lvmcache_device_from_pvid(struct cmd_context *cmd, const struct id *pvid,
|
||||
unsigned *scan_done_once, uint64_t *label_sector);
|
||||
const char *lvmcache_pvid_from_devname(struct cmd_context *cmd,
|
||||
|
@ -3617,8 +3617,16 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
|
||||
}
|
||||
|
||||
/* Now determine the correct vgname if none was supplied */
|
||||
if (!vgname && !(vgname = lvmcache_vgname_from_vgid(cmd->mem, vgid)))
|
||||
if (!vgname && !(vgname = lvmcache_vgname_from_vgid(cmd->mem, vgid))) {
|
||||
log_debug_metadata("Cache did not find VG name from vgid %.32s", vgid);
|
||||
return_NULL;
|
||||
}
|
||||
|
||||
/* Determine the correct vgid if none was supplied */
|
||||
if (!vgid && !(vgid = lvmcache_vgid_from_vgname(cmd, vgname))) {
|
||||
log_debug_metadata("Cache did not find VG vgid from name %s", vgname);
|
||||
return_NULL;
|
||||
}
|
||||
|
||||
if (use_precommitted && !(fmt->features & FMT_PRECOMMIT))
|
||||
use_precommitted = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user