]> sourceware.org Git - lvm2.git/commitdiff
Add find_vgname_from_{pvname|pvid} functions.
authorDave Wysochanski <dwysocha@redhat.com>
Wed, 19 May 2010 11:52:37 +0000 (11:52 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Wed, 19 May 2010 11:52:37 +0000 (11:52 +0000)
Some commands start with a pvname, but we'd like to force users to
start with a vg handle to obtain a pv handle.  Our best option seems
to be providing a way to look up the vgname from the pvname, and then
require them to use vg_read/vg_open.

In addition to the pvname lookup function, this patch also provides a
lookup by pvid.  The lookup by pvid can be used in conjunction with
lvmcache_get_pvids to process all pvs in the system.

The pvid find function first calls lvmcache_vgname_from_pvid, which may
cause the label to be read if it is not in the cache.  If the vgname is
returned is an orphan, we then check to see if there are metadata areas,
and if not, we scan every PV on the system by calling scan_vgs_for_pvs().
In most cases we should not need to do this, and by using the info->mdas
count, we avoid calling pv_read() as prior code did.  So this patch is a
bit cleaner and should allow us to refactor more of the pv code.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
lib/metadata/metadata-exported.h
lib/metadata/metadata.c

index ae23b9bfc4c02f5a0efb3694096f25914ac2ca60..9e1b564aeefe13b3ddea900160b65774364e7744 100644 (file)
@@ -625,6 +625,10 @@ struct logical_volume *find_lv(const struct volume_group *vg,
 struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
                                        const char *pv_name);
 
+const char *find_vgname_from_pvname(struct cmd_context *cmd,
+                                   const char *pvname);
+const char *find_vgname_from_pvid(struct cmd_context *cmd,
+                                 const char *pvid);
 /* Find LV segment containing given LE */
 struct lv_segment *first_seg(const struct logical_volume *lv);
 
index 017e8ce75194f9c26a2c9e877201fb959f5e1c47..36d817c89600ed74161be0d18eb7eba42d593035 100644 (file)
@@ -3110,6 +3110,52 @@ out:
        return NULL;
 }
 
+
+const char *find_vgname_from_pvid(struct cmd_context *cmd,
+                                 const char *pvid)
+{
+       char *vgname;
+       struct lvmcache_info *info;
+
+       vgname = lvmcache_vgname_from_pvid(cmd, pvid);
+
+       if (is_orphan_vg(vgname)) {
+               if (!(info = info_from_pvid(pvid, 0))) {
+                       return_NULL;
+               }
+               /*
+                * If an orphan PV has no MDAs it may appear to be an
+                * orphan until the metadata is read off another PV in
+                * the same VG.  Detecting this means checking every VG
+                * by scanning every PV on the system.
+                */
+               if (!dm_list_size(&info->mdas)) {
+                       if (!scan_vgs_for_pvs(cmd)) {
+                               log_error("Rescan for PVs without "
+                                         "metadata areas failed.");
+                               return NULL;
+                       }
+               }
+               /* Ask lvmcache again - we may have a non-orphan name now */
+               vgname = lvmcache_vgname_from_pvid(cmd, pvid);
+       }
+       return vgname;
+}
+
+
+const char *find_vgname_from_pvname(struct cmd_context *cmd,
+                                   const char *pvname)
+{
+       const char *pvid;
+
+       pvid = pvid_from_devname(cmd, pvname);
+       if (!pvid)
+               /* Not a PV */
+               return NULL;
+
+       return find_vgname_from_pvid(cmd, pvid);
+}
+
 /**
  * pv_read - read and return a handle to a physical volume
  * @cmd: LVM command initiating the pv_read
This page took 0.036408 seconds and 5 git commands to generate.