mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 3 years ago
Clone

Blame SOURCES/lvm2-2_03_06-metadata-include-description-with-command-in-metadat.patch

26e710
 lib/format_text/export.c      |  4 ++--
26e710
 lib/format_text/format-text.c | 27 ++++++++++++++++++++++++++-
26e710
 lib/metadata/metadata.h       |  1 -
26e710
 lib/metadata/vg.h             |  1 +
26e710
 test/shell/metadata.sh        |  4 ++++
26e710
 5 files changed, 33 insertions(+), 4 deletions(-)
26e710
26e710
diff --git a/lib/format_text/export.c b/lib/format_text/export.c
26e710
index 841e06d..2a3f844 100644
26e710
--- a/lib/format_text/export.c
26e710
+++ b/lib/format_text/export.c
26e710
@@ -1086,7 +1086,7 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
26e710
 	return r;
26e710
 }
26e710
 
26e710
-size_t export_vg_to_buffer(struct volume_group *vg, char **buf)
26e710
+static size_t _export_vg_to_buffer(struct volume_group *vg, char **buf)
26e710
 {
26e710
 	return text_vg_export_raw(vg, "", buf);
26e710
 }
26e710
@@ -1096,7 +1096,7 @@ struct dm_config_tree *export_vg_to_config_tree(struct volume_group *vg)
26e710
 	char *buf = NULL;
26e710
 	struct dm_config_tree *vg_cft;
26e710
 
26e710
-	if (!export_vg_to_buffer(vg, &buf)) {
26e710
+	if (!_export_vg_to_buffer(vg, &buf)) {
26e710
 		log_error("Could not format metadata for VG %s.", vg->name);
26e710
 		return NULL;
26e710
 	}
26e710
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
26e710
index 13b2c66..6873f19 100644
26e710
--- a/lib/format_text/format-text.c
26e710
+++ b/lib/format_text/format-text.c
26e710
@@ -493,6 +493,29 @@ static struct volume_group *_vg_read_precommit_raw(struct format_instance *fid,
26e710
 	return vg;
26e710
 }
26e710
 
26e710
+#define MAX_DESC_LEN 2048
26e710
+
26e710
+static char *_build_desc_write(struct cmd_context *cmd, struct volume_group *vg)
26e710
+{
26e710
+	size_t len = strlen(cmd->cmd_line) + 32;
26e710
+	char *desc;
26e710
+
26e710
+	if (len > MAX_DESC_LEN)
26e710
+		len = MAX_DESC_LEN;
26e710
+
26e710
+	if (!(desc = zalloc(len)))
26e710
+		return_NULL;
26e710
+
26e710
+	vg->write_count++;
26e710
+
26e710
+	if (vg->write_count == 1)
26e710
+		dm_snprintf(desc, len, "Write from %s.", cmd->cmd_line);
26e710
+	else
26e710
+		dm_snprintf(desc, len, "Write[%u] from %s.", vg->write_count, cmd->cmd_line);
26e710
+
26e710
+	return desc;
26e710
+}
26e710
+
26e710
 /*
26e710
  * VG metadata updates:
26e710
  *
26e710
@@ -576,9 +599,11 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
26e710
 		new_buf = fidtc->raw_metadata_buf;
26e710
 		new_size = fidtc->raw_metadata_buf_size;
26e710
 	} else {
26e710
-		new_size = text_vg_export_raw(vg, "", &new_buf);
26e710
+		char *desc = _build_desc_write(fid->fmt->cmd, vg);
26e710
+		new_size = text_vg_export_raw(vg, desc, &new_buf);
26e710
 		fidtc->raw_metadata_buf = new_buf;
26e710
 		fidtc->raw_metadata_buf_size = new_size;
26e710
+		free(desc);
26e710
 	}
26e710
 
26e710
 	if (!new_size || !new_buf) {
26e710
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
26e710
index 63ee4a6..2fc0015 100644
26e710
--- a/lib/metadata/metadata.h
26e710
+++ b/lib/metadata/metadata.h
26e710
@@ -473,7 +473,6 @@ void lv_calculate_readahead(const struct logical_volume *lv, uint32_t *read_ahea
26e710
 /*
26e710
  * For internal metadata caching.
26e710
  */
26e710
-size_t export_vg_to_buffer(struct volume_group *vg, char **buf);
26e710
 struct dm_config_tree *export_vg_to_config_tree(struct volume_group *vg);
26e710
 struct volume_group *import_vg_from_config_tree(const struct dm_config_tree *cft,
26e710
 						struct format_instance *fid);
26e710
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
26e710
index 6e89b33..2e21461 100644
26e710
--- a/lib/metadata/vg.h
26e710
+++ b/lib/metadata/vg.h
26e710
@@ -42,6 +42,7 @@ struct volume_group {
26e710
 	struct lvmcache_vginfo *vginfo;
26e710
 	uint32_t seqno;		/* Metadata sequence number */
26e710
 	unsigned skip_validate_lock_args : 1;
26e710
+	uint32_t write_count; /* count the number of vg_write calls */
26e710
 
26e710
 	/*
26e710
 	 * The parsed committed (on-disk) copy of this VG; is NULL if this VG is committed
26e710
diff --git a/test/shell/metadata.sh b/test/shell/metadata.sh
26e710
index a86bc0b..f5d6483 100644
26e710
--- a/test/shell/metadata.sh
26e710
+++ b/test/shell/metadata.sh
26e710
@@ -26,6 +26,10 @@ pvcreate --metadatacopies 0 "$dev5"
26e710
 vgcreate $SHARED "$vg" "${DEVICES[@]}"
26e710
 lvcreate -n $lv -l 1 -i5 -I256 $vg
26e710
 
26e710
+pvck --dump metadata "$dev1" > meta1
26e710
+grep "description = " meta1 > desc1
26e710
+grep "Write from lvcreate" desc1
26e710
+
26e710
 pvchange -x n "$dev1"
26e710
 pvchange -x y "$dev1"
26e710
 vgchange -a n $vg