Skip to contentSkip to conversation

master - pvck: use new dump routines for old output

PATCH David Teigland 1 participant 1 message Jun 6, 2019

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2b241eb1f666e93f47917f2495e900bf80c9d5ff
Commit:        2b241eb1f666e93f47917f2495e900bf80c9d5ff
Parent:        356ea897ccfca5a80b00a0a6b2479042f6efd144
Author:        David Teigland <[email protected]>
AuthorDate:    Wed Jun 5 16:23:23 2019 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Wed Jun 5 16:28:52 2019 -0500

pvck: use new dump routines for old output

Use the recently added dump routines to produce the old/traditional pvck output, and remove the code that had been used for that.

The validation/checking done by the new routines means that new lines prefixed with CHECK are printed for incorrect values.

---
 lib/format_text/format-text.c |  152 -----------------------------------------
 lib/label/label.c             |   60 ----------------
 lib/metadata/metadata.c       |   35 ----------
 tools/pvck.c                  |  151 +++++++++++++++++++++++++----------------
 4 files changed, 92 insertions(+), 306 deletions(-)
lib/format_text/format-text.c +0 -152
index 3828d5f..2831a53 100644
@@ -121,157 +121,6 @@ static struct device *_mda_get_device_raw(struct metadata_area *mda)
 	return mdac->area.dev;
 }
 
-/*
- * For circular region between region_start and region_start + region_size,
- * back up one SECTOR_SIZE from 'region_ptr' and return the value.
- * This allows reverse traversal through text metadata area to find old
- * metadata.
- *
- * Parameters:
- *   region_start: start of the region (bytes)
- *   region_size: size of the region (bytes)
- *   region_ptr: pointer within the region (bytes)
- *   NOTE: region_start <= region_ptr <= region_start + region_size
- */
-static uint64_t _get_prev_sector_circular(uint64_t region_start,
-					  uint64_t region_size,
-					  uint64_t region_ptr)
-{
-	if (region_ptr >= region_start + SECTOR_SIZE)
-		return region_ptr - SECTOR_SIZE;
-
-	return (region_start + region_size - SECTOR_SIZE);
-}
-
-/*
- * Analyze a metadata area for old metadata records in the circular buffer.
- * This function just looks through and makes a first pass at the data in
- * the sectors for particular things.
- * FIXME: do something with each metadata area (try to extract vg, write
- * raw data to file, etc)
- */
-static int _pv_analyze_mda_raw (const struct format_type * fmt,
-				struct metadata_area *mda)
-{
-	struct mda_header *mdah;
-	struct raw_locn *rlocn;
-	uint64_t area_start;
-	uint64_t area_size;
-	uint64_t prev_sector, prev_sector2;
-	uint64_t latest_mrec_offset;
-	uint64_t offset;
-	uint64_t offset2;
-	size_t size;
-	size_t size2;
-	char *buf=NULL;
-	struct device_area *area;
-	struct mda_context *mdac;
-	int r=0;
-
-	mdac = (struct mda_context *) mda->metadata_locn;
-
-	log_print("Found text metadata area: offset=" FMTu64 ", size="
-		  FMTu64, mdac->area.start, mdac->area.size);
-	area = &mdac->area;
-
-	if (!(mdah = raw_read_mda_header(fmt, area, mda_is_primary(mda))))
-		goto_out;
-
-	rlocn = mdah->raw_locns;
-
-	/*
-	 * The device area includes the metadata header as well as the
-	 * records, so remove the metadata header from the start and size
-	 */
-	area_start = area->start + MDA_HEADER_SIZE;
-	area_size = area->size - MDA_HEADER_SIZE;
-	latest_mrec_offset = rlocn->offset + area->start;
-
-	/*
-	 * Start searching at rlocn (point of live metadata) and go
-	 * backwards.
-	 */
-	prev_sector = _get_prev_sector_circular(area_start, area_size,
-					       latest_mrec_offset);
-	offset = prev_sector;
-	size = SECTOR_SIZE;
-	offset2 = size2 = 0;
-
-	while (prev_sector != latest_mrec_offset) {
-		prev_sector2 = prev_sector;
-		prev_sector = _get_prev_sector_circular(area_start, area_size,
-							prev_sector);
-		if (prev_sector > prev_sector2)
-			goto_out;
-		/*
-		 * FIXME: for some reason, the whole metadata region from
-		 * area->start to area->start+area->size is not used.
-		 * Only ~32KB seems to contain valid metadata records
-		 * (LVM2 format - format_text).  As a result, I end up with
-		 * "dm_config_maybe_section" returning true when there's no valid
-		 * metadata in a sector (sectors with all nulls).
-		 */
-		if (!(buf = malloc(size + size2)))
-			goto_out;
-
-		if (!dev_read_bytes(area->dev, offset, size, buf)) {
-			log_error("Failed to read dev %s offset %llu size %llu",
-				  dev_name(area->dev),
-				  (unsigned long long)offset,
-				  (unsigned long long)size);
-			goto out;
-		}
-
-		if (size2) {
-			if (!dev_read_bytes(area->dev, offset2, size2, buf + size)) {
-				log_error("Failed to read dev %s offset %llu size %llu",
-				  	  dev_name(area->dev),
-					  (unsigned long long)offset2,
-				          (unsigned long long)size2);
-				goto out;
-			}
-		}
-
-		/*
-		 * FIXME: We could add more sophisticated metadata detection
-		 */
-		if (dm_config_maybe_section(buf, size + size2)) {
-			/* FIXME: Validate region, pull out timestamp?, etc */
-			/* FIXME: Do something with this region */
-			log_verbose ("Found LVM2 metadata record at "
-				     "offset=" FMTu64 ", size=" FMTsize_t ", "
-				     "offset2=" FMTu64 " size2=" FMTsize_t,
-				     offset, size, offset2, size2);
-			offset = prev_sector;
-			size = SECTOR_SIZE;
-			offset2 = size2 = 0;
-		} else {
-			/*
-			 * Not a complete metadata record, assume we have
-			 * metadata and just increase the size and offset.
-			 * Start the second region if the previous sector is
-			 * wrapping around towards the end of the disk.
-			 */
-			if (prev_sector > offset) {
-				offset2 = prev_sector;
-				size2 += SECTOR_SIZE;
-			} else {
-				offset = prev_sector;
-				size += SECTOR_SIZE;
-			}
-		}
-		free(buf);
-		buf = NULL;
-	}
-
-	r = 1;
- out:
-	free(buf);
-	return r;
-}
-
-
-
 static int _text_lv_setup(struct format_instance *fid __attribute__((unused)),
 			  struct logical_volume *lv)
 {
@@ -1962,7 +1811,6 @@ static struct metadata_area_ops _metadata_text_raw_ops = {
 	.mda_free_sectors = _mda_free_sectors_raw,
 	.mda_total_sectors = _mda_total_sectors_raw,
 	.mda_in_vg = _mda_in_vg_raw,
-	.pv_analyze_mda = _pv_analyze_mda_raw,
 	.mda_locns_match = _mda_locns_match_raw,
 	.mda_get_device = _mda_get_device_raw,
 };
lib/label/label.c +0 -60

66 lines not on this page · raw message

lib/metadata/metadata.c +0 -35
index 8f6de26..65da7e1 100644
@@ -4664,41 +4664,6 @@ int is_real_vg(const char *vg_name)
 	return (vg_name && *vg_name != '#');
 }
 
-static int _analyze_mda(struct metadata_area *mda, void *baton)
-{
-	const struct format_type *fmt = baton;
-	mda->ops->pv_analyze_mda(fmt, mda);
-	return 1;
-}
-
-/*
- * Returns:
- *  0 - fail
- *  1 - success
- */
-int pv_analyze(struct cmd_context *cmd, struct device *dev,
-	       uint64_t label_sector)
-{
-	struct label *label;
-	struct lvmcache_info *info;
-
-	if (!(label = lvmcache_get_dev_label(dev))) {
-		log_error("Could not find LVM label on %s", dev_name(dev));
-		return 0;
-	}
-
-	log_print("Found label on %s, sector %"PRIu64", type=%.8s",
-		  dev_name(dev), label->sector, label->type);
-
-	/*
-	 * Next, loop through metadata areas
-	 */
-	info = label->info;
-	lvmcache_foreach_mda(info, _analyze_mda, (void *)lvmcache_fmt(info));
-
-	return 1;
-}
-
 /* FIXME: remove / combine this with locking? */
 int vg_check_write_mode(struct volume_group *vg)
 {
tools/pvck.c +92 -59

286 lines not on this page · raw message