Skip to contentSkip to conversation

master - pvck: dump headers and metadata

PATCH David Teigland 1 participant 1 message Jun 3, 2019

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d18e491f6890e15a677e8189de0699ccc7412f16
Commit:        d18e491f6890e15a677e8189de0699ccc7412f16
Parent:        669a834981c0bc808d42dbe5097d7beeead982ad
Author:        David Teigland <[email protected]>
AuthorDate:    Fri May 31 14:10:44 2019 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Mon Jun 3 15:13:32 2019 -0500

pvck: dump headers and metadata

Add 'pvck --dump headers' to print all the lvm ondisk structs. Also checks the values and prints any problems.

The previous dump metadata is also converted to use these same routines, which do not depend on lvm fully scanning/reading/processing the headers and metadata on disk. This makes it useful to get data in cases where there is corruption that would otherwise prevent the normal functions from working.

---
 lib/format_text/format-text.c |  218 ----------
 lib/format_text/format-text.h |   14 -
 tools/args.h                  |    5 +-
 tools/command-lines.in        |    6 +-
 tools/pvck.c                  |  888 ++++++++++++++++++++++++++++++++++++++---
 5 files changed, 848 insertions(+), 283 deletions(-)
lib/format_text/format-text.c +0 -218
index abf8afc..3828d5f 100644
@@ -2602,221 +2602,3 @@ bad:
 
 	return NULL;
 }
-
-static char *_read_metadata_text(struct cmd_context *cmd, struct device *dev,
-				 uint64_t area_start, uint64_t area_size,
-				 uint32_t *len, uint64_t *disk_offset)
-{
-	struct mda_header *mh;
-	struct raw_locn *rlocn_slot0;
-	uint64_t text_offset, text_size;
-	char *area_buf;
-	char *text_buf;
-
-	/*
-	 * Read the entire metadata area, including mda_header and entire
-	 * circular buffer.
-	 */
-	if (!(area_buf = malloc(area_size)))
-		return_NULL;
-
-	if (!dev_read_bytes(dev, area_start, area_size, area_buf)) {
-		log_error("Failed to read device %s at %llu size %llu",
-			  dev_name(dev),
-			  (unsigned long long)area_start,
-			  (unsigned long long)area_size);
-		return NULL;
-	}
-
-	mh = (struct mda_header *)area_buf;
-	_xlate_mdah(mh);
-
-	rlocn_slot0 = &mh->raw_locns[0];
-	text_offset = rlocn_slot0->offset;
-	text_size = rlocn_slot0->size;
-
-	/*
-	 * Copy and return the current metadata text out of the metadata area.
-	 */
-
-	if (!(text_buf = malloc(text_size)))
-		return_NULL;
-
-	memcpy(text_buf, area_buf + text_offset, text_size);
-
-	if (len)
-		*len = (uint32_t)text_size;
-	if (disk_offset)
-		*disk_offset = area_start + text_offset;
-
-	free(area_buf);
-
-	return text_buf;
-}
-
-int dump_metadata_text(struct cmd_context *cmd,
-		       const char *vgname,
-		       const char *vgid,
-		       struct device *dev,
-		       struct metadata_area *mda,
-		       const char *tofile)
-{
-	char *textbuf;
-	struct format_instance *fid;
-	struct format_instance_ctx fic;
-	struct mda_context *mdac;
-	struct volume_group *vg;
-	unsigned use_previous_vg = 0;
-	uint32_t textlen = 0;
-	uint32_t textcrc;
-	uint64_t text_disk_offset;
-	int ret = 0;
-
-	/*
-	 * Set up overhead/abstractions for reading a given vgname
-	 * (fmt/fid/fic/vgid).
-	 */
-
-	fic.type = FMT_INSTANCE_MDAS | FMT_INSTANCE_AUX_MDAS;
-	fic.context.vg_ref.vg_name = vgname;
-	fic.context.vg_ref.vg_id = vgid;
-
-	if (!(fid = _text_create_text_instance(cmd->fmt, &fic))) {
-		log_error("Failed to create format instance");
-		return 0;
-	}
-
-	mdac = mda->metadata_locn;
-
-	/*
-	 * Read the VG metadata from the device as a raw chunk of original text.
-	 */
-	textbuf = _read_metadata_text(cmd, dev,
-				      mdac->area.start, mdac->area.size,
-				      &textlen, &text_disk_offset);
-	if (!textbuf || !textlen) {
-		log_error("No metadata text found on %s", dev_name(dev));
-		_text_destroy_instance(fid);
-		return 0;
-	}
-
-	textcrc = calc_crc(INITIAL_CRC, (uint8_t *)textbuf, textlen);
-
-	/*
-	 * Read the same VG metadata, but imported/parsed into a vg struct
-	 * format so we know it's valid/parsable, and can look at values in it.
-	 */
-	if (!(vg = _vg_read_raw(fid, vgname, mda, NULL, &use_previous_vg))) {
-		log_warn("WARNING: parse error for metadata on %s.", dev_name(dev));
-		_text_destroy_instance(fid);
-	}
-
-	log_print("Metadata for %s from %s at %llu size %u with seqno %u checksum 0x%x.",
-		  vgname, dev_name(dev),
-		  (unsigned long long)text_disk_offset, textlen,
-		  vg ? vg->seqno : 0, textcrc);
-
-	if (!tofile) {
-		log_print("---");
-		printf("%s\n", textbuf);
-		log_print("---");
-	} else {
-		FILE *fp;
-		if (!(fp = fopen(tofile, "wx"))) {
-			log_error("Failed to create file %s", tofile);
-			goto out;
-		}
-
-		fprintf(fp, "%s", textbuf);
-
-		if (fflush(fp))
-			stack;
-		if (fclose(fp))
-			stack;
-	}
-
-	if (vg)
-		release_vg(vg);
-
-	free(textbuf);
-	ret = 1;
-out:
-	return ret;
-}
-
-static char *_read_metadata_area(struct cmd_context *cmd, struct device *dev,
-				 uint64_t area_start, uint64_t area_size)
-{
-	char *area_buf;
-
-	/*
-	 * Read the entire metadata area, including mda_header and entire
-	 * circular buffer.
-	 */
-	if (!(area_buf = malloc(area_size)))
-		return_NULL;
-
-	if (!dev_read_bytes(dev, area_start, area_size, area_buf)) {
-		log_error("Failed to read device %s at %llu size %llu",
-			  dev_name(dev),
-			  (unsigned long long)area_start,
-			  (unsigned long long)area_size);
-		return NULL;
-	}
-
-	return area_buf;
-}
-
-int dump_metadata_area(struct cmd_context *cmd,
-		       const char *vgname,
-		       const char *vgid,
-		       struct device *dev,
-		       struct metadata_area *mda,
-		       const char *tofile)
-{
-	char *areabuf;
-	char *textbuf;
-	struct mda_context *mdac;
-	int ret = 0;
-
-	mdac = mda->metadata_locn;
-
-	areabuf = _read_metadata_area(cmd, dev,
-				      mdac->area.start, mdac->area.size);
-	if (!areabuf) {
-		log_error("No metadata area found on %s", dev_name(dev));
-		return 0;
-	}
-
-	log_print("Metadata buffer for %s from %s in area at %llu size %llu offset 512.",
-		  vgname, dev_name(dev),
-		  (unsigned long long)mdac->area.start,
-		  (unsigned long long)mdac->area.size);
-
-	/* text starts after mda_header which uses 512 bytes */
-	textbuf = areabuf + 512;
-
-	if (!tofile) {
-		/* N.B. this will often include unprintable data */
-		log_print("---");
-		fwrite(textbuf, mdac->area.size - 512, 1, stdout);
-		log_print("---");
-	} else {
-		FILE *fp;
-		if (!(fp = fopen(tofile, "wx"))) {
-			log_error("Failed to create file %s", tofile);
-			goto out;
-		}
-
-		fwrite(textbuf, mdac->area.size - 512, 1, fp);
-
-		if (fflush(fp))
-			stack;
-		if (fclose(fp))
-			stack;
-	}
-	ret = 1;
-out:
-	free(areabuf);
-	return ret;
-}
lib/format_text/format-text.h +0 -14
index 6be237b..1300e58 100644
@@ -76,18 +76,4 @@ 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
tools/args.h +3 -2
index c1efdd6..83c1cfe 100644
@@ -215,8 +215,9 @@ arg(driverloaded_ARG, '\0', "driverloaded", bool_VAL, 0, 0,
 
 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")
+    "to extract the current text metadata, \\fBmetadata_area\\fP\n"
+    "to extract the entire text metadata area, and \\fBheaders\\fP\n"
+    "to print and check LVM headers.\n")
 
 arg(errorwhenfull_ARG, '\0', "errorwhenfull", bool_VAL, 0, 0,
     "Specifies thin pool behavior when data space is exhausted.\n"
tools/command-lines.in +3 -3
index 0d97348..03dbf57 100644
@@ -1430,9 +1430,9 @@ 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
+OO: --file String, --pvmetadatacopies MetadataCopiesPV, --labelsector Number
+ID: pvck_dump
+DESC: Print metadata from a device
 
 ---
 
tools/pvck.c +844 -48

935 lines not on this page · raw message