From dd4097a6a49d250dbbe592b312db94504b17e5fa Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Wed, 19 May 2010 11:52:07 +0000 Subject: Add pvid_from_devname() lvmcache function. Add supporting function for mappings from devname -> pvid -> vgname. --- lib/cache/lvmcache.c | 19 +++++++++++++++++++ lib/cache/lvmcache.h | 2 ++ 2 files changed, 21 insertions(+) (limited to 'lib/cache') diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 1f1e1e6a..6e46e31c 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -757,6 +757,25 @@ struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid, return NULL; } +const char *pvid_from_devname(struct cmd_context *cmd, + const char *devname) +{ + struct device *dev; + struct label *label; + + if (!(dev = dev_cache_get(devname, cmd->filter))) { + log_error("%s: Couldn't find device. Check your filters?", + devname); + return NULL; + } + + if (!(label_read(dev, &label, UINT64_C(0)))) + return NULL; + + return dev->pvid; +} + + static int _free_vginfo(struct lvmcache_vginfo *vginfo) { struct lvmcache_vginfo *primary_vginfo, *vginfo2; diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h index 5706dcff..faf00cf4 100644 --- a/lib/cache/lvmcache.h +++ b/lib/cache/lvmcache.h @@ -96,6 +96,8 @@ struct lvmcache_info *info_from_pvid(const char *pvid, int valid_only); const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid); struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid, unsigned *scan_done_once); +const char *pvid_from_devname(struct cmd_context *cmd, + const char *dev_name); int vgs_locked(void); int vgname_is_locked(const char *vgname); -- cgit