[lvm-devel] [PATCH 2/6] Add lvmcache function to lookup a vgname from a pvid.
Dave Wysochanski
dwysocha at redhat.com
Tue May 11 12:36:06 UTC 2010
Signed-off-by: Dave Wysochanski <dwysocha at redhat.com>
---
lib/cache/lvmcache.c | 25 +++++++++++++++++++++++++
lib/cache/lvmcache.h | 1 +
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 2a5f2d7..bcff43d 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -499,6 +499,31 @@ struct lvmcache_info *info_from_pvid(const char *pvid, int valid_only)
return info;
}
+char *lvmcache_vgname_from_pvid(struct cmd_context *cmd, const char *pvid)
+{
+ struct lvmcache_info *info;
+ char *vgname;
+
+ if (!device_from_pvid(cmd, pvid, NULL)) {
+ char buffer[64] __attribute((aligned(8)));
+
+ if (!id_write_format(pvid, buffer, sizeof(buffer)))
+ buffer[0] = '\0';
+ log_error("Couldn't find device with uuid %s.", buffer);
+ return NULL;
+ }
+
+ info = info_from_pvid(pvid, 0);
+ if (!info)
+ return_NULL;
+
+ if (!(vgname = dm_pool_strdup(cmd->mem, info->vginfo->vgname))) {
+ log_errno(ENOMEM, "vgname allocation failed");
+ return NULL;
+ }
+ return vgname;
+}
+
static void _rescan_entry(struct lvmcache_info *info)
{
struct label *label;
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index 5b0ca73..55c2e7a 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -97,6 +97,7 @@ 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);
+char *lvmcache_vgname_from_pvid(struct cmd_context *cmd, const char *pvid);
int vgs_locked(void);
int vgname_is_locked(const char *vgname);
--
1.6.0.6
More information about the lvm-devel
mailing list