Skip to contentSkip to conversation

master - pvck: new dump option to extract metadata

PATCH David Teigland 1 participant 1 message May 23, 2019

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=52586b1039a0c1d273676416ba074cadde308bc4
Commit:        52586b1039a0c1d273676416ba074cadde308bc4
Parent:        1022b88a66dd02e981e738719e17452cd5c1bd59
Author:        David Teigland <[email protected]>
AuthorDate:    Wed May 22 14:25:08 2019 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Thu May 23 11:49:06 2019 -0500

pvck: new dump option to extract metadata

The new command 'pvck --dump metadata PV' will extract the current version of VG metadata from a PV for testing and debugging. --dump metadata_area extracts the entire text metadata area.

---
 lib/cache/lvmcache.c          |   31 ++++++
 lib/cache/lvmcache.h          |    5 +
 lib/format_text/format-text.c |  218 +++++++++++++++++++++++++++++++++++++++++
 lib/format_text/format-text.h |   14 +++
 man/pvck.8_des                |    9 ++-
 tools/args.h                  |    5 +
 tools/command-lines.in        |    6 +
 tools/commands.h              |    2 +-
 tools/pvck.c                  |   99 ++++++++++++++++++-
 9 files changed, 386 insertions(+), 3 deletions(-)
lib/cache/lvmcache.c +31 -0
index 7d0c60d..a4037a5 100644
@@ -2301,3 +2301,34 @@ int lvmcache_vginfo_has_pvid(struct lvmcache_vginfo *vginfo, char *pvid)
 	}
 	return 0;
 }
+
+struct metadata_area *lvmcache_get_mda(struct cmd_context *cmd,
+				       const char *vgname,
+				       struct device *dev,
+				       int use_mda_num)
+{
+	struct lvmcache_vginfo *vginfo;
+	struct lvmcache_info *info;
+	struct metadata_area *mda;
+
+	if (!use_mda_num)
+		use_mda_num = 1;
+
+	if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, NULL)))
+		return NULL;
+
+	dm_list_iterate_items(info, &vginfo->infos) {
+		if (info->dev != dev)
+			continue;
+
+		dm_list_iterate_items(mda, &info->mdas) {
+			if ((use_mda_num == 1) && (mda->status & MDA_PRIMARY))
+				return mda;
+			if ((use_mda_num == 2) && !(mda->status & MDA_PRIMARY))
+				return mda;
+		}
+		return NULL;
+	}
+	return NULL;
+}
+
lib/cache/lvmcache.h +5 -0
index 26e0953..5e59b94 100644
@@ -168,6 +168,11 @@ unsigned lvmcache_mda_count(struct lvmcache_info *info);
 int lvmcache_vgid_is_cached(const char *vgid);
 uint64_t lvmcache_smallest_mda_size(struct lvmcache_info *info);
 
+struct metadata_area *lvmcache_get_mda(struct cmd_context *cmd,
+                                      const char *vgname,
+                                      struct device *dev,
+                                      int use_mda_num);
+
 int lvmcache_found_duplicate_pvs(void);
 int lvmcache_found_duplicate_vgnames(void);
 
lib/format_text/format-text.c +218 -0

221 lines not on this page · raw message

lib/format_text/format-text.h +14 -0
index 1300e58..6be237b 100644
@@ -76,4 +76,18 @@ struct data_area_list {
 	struct disk_locn disk_locn;
 };
 
+int dump_metadata_text(struct cmd_context *cmd,
+                       const char *vgname,
+                       const char *vgid,
+                       struct device *dev,
+                       struct metadata_area *mda,
+                       const char *tofile);
+
+int dump_metadata_area(struct cmd_context *cmd,
+                       const char *vgname,
+                       const char *vgid,
+                       struct device *dev,
+                       struct metadata_area *mda,
+                       const char *tofile);
+
 #endif
man/pvck.8_des +8 -1
index 0a32657..fb826d3 100644
@@ -1 +1,8 @@
-pvck checks the LVM metadata for consistency on PVs.
+pvck checks LVM metadata on PVs.
+
+Use the --dump option to extract metadata from PVs for debugging.
+With dump, set --pvmetadatacopies 2 to extract metadata from a
+second metadata area at the end of the device. Use the --file
+option to save the raw metadata to a specified file. (The raw
+metadata is not usable with vgcfgbackup and vgcfgrestore.)
+
tools/args.h +5 -0
index 3d72e8a..c1efdd6 100644
@@ -213,6 +213,11 @@ arg(driverloaded_ARG, '\0', "driverloaded", bool_VAL, 0, 0,
     "If set to no, the command will not attempt to use device-mapper.\n"
     "For testing and debugging.\n")
 
+arg(dump_ARG, '\0', "dump", string_VAL, 0, 0,
+    "Dump metadata from a PV. Option values include \\fBmetadata\\fP\n"
+    "to extract the current text metadata, and \\fBmetadata_area\\fP\n"
+    "to extract the entire text metadata area.\n")
+
 arg(errorwhenfull_ARG, '\0', "errorwhenfull", bool_VAL, 0, 0,
     "Specifies thin pool behavior when data space is exhausted.\n"
     "When yes, device-mapper will immediately return an error\n"
tools/command-lines.in +6 -0
index 0de3de7..0d97348 100644
@@ -1427,6 +1427,12 @@ ID: pvresize_general
 pvck PV ...
 OO: --labelsector Number
 ID: pvck_general
+DESC: Check for metadata on a device
+
+pvck --dump String PV
+OO: --file String, --pvmetadatacopies MetadataCopiesPV
+ID: pvck_dumpmetadata
+DESC: Dump raw metadata from a device
 
 ---
 
tools/commands.h +1 -1
index 83e50e7..612182b 100644
@@ -114,7 +114,7 @@ xx(pvresize,
    0)
 
 xx(pvck,
-   "Check the consistency of physical volume(s)",
+   "Check metadata on physical volumes",
    LOCKD_VG_SH)
 
 xx(pvcreate,
tools/pvck.c +98 -1

122 lines not on this page · raw message