Skip to contentSkip to conversation

master - metadata: extend writes to zero space

PATCH David Teigland 1 participant 1 message Jul 12, 2019

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c22ad12bab1cff6fa4c23cb0242650751716803e
Commit:        c22ad12bab1cff6fa4c23cb0242650751716803e
Parent:        76573137404dafa58795995f5c10dfb5dbc714de
Author:        David Teigland <[email protected]>
AuthorDate:    Mon Jul 1 15:00:34 2019 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Fri Jul 12 15:00:12 2019 -0500

metadata: extend writes to zero space

Previously, consecutive copies of metadata would have garbage data in the space between them. After metadata wrapping, the garbage would be portions of old metadata. This made analysis of the metadata area more difficult.

This would happen because the start of new copy of metadata is advanced from the end of the last copy to start at the next 512 byte boundary.

Zero the space between consecutive copies of metadata by extending each metadata write to end at the next 512 byte boundary. The size of the metadata itself is not extended, only the write. The buffer being written contains the metadata text followed by the necessary number of zeros.

---
 lib/format_text/export.c        |   10 +-
 lib/format_text/format-text.c   |  303 ++++++++++++++++++++++++++++++---------
 lib/format_text/import-export.h |    2 +-
 3 files changed, 244 insertions(+), 71 deletions(-)
lib/format_text/export.c +7 -3
index 2a3f844..b5e987e 100644
@@ -129,6 +129,7 @@ static int _extend_buffer(struct formatter *f)
 		log_error("Buffer reallocation failed.");
 		return 0;
 	}
+	memset(newbuf + f->data.buf.size, 0, f->data.buf.size);
 	f->data.buf.start = newbuf;
 	f->data.buf.size *= 2;
 
@@ -1052,7 +1053,7 @@ int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp)
 }
 
 /* Returns amount of buffer used incl. terminating NUL */
-size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
+size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf, uint32_t *buf_size)
 {
 	struct formatter *f;
 	size_t r = 0;
@@ -1063,7 +1064,7 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
 		return_0;
 
 	f->data.buf.size = 65536;	/* Initial metadata limit */
-	if (!(f->data.buf.start = malloc(f->data.buf.size))) {
+	if (!(f->data.buf.start = zalloc(f->data.buf.size))) {
 		log_error("text_export buffer allocation failed");
 		goto out;
 	}
@@ -1081,6 +1082,9 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
 	r = f->data.buf.used + 1;
 	*buf = f->data.buf.start;
 
+	if (buf_size)
+		*buf_size = f->data.buf.size;
+
       out:
 	free(f);
 	return r;
@@ -1088,7 +1092,7 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
 
 static size_t _export_vg_to_buffer(struct volume_group *vg, char **buf)
 {
-	return text_vg_export_raw(vg, "", buf);
+	return text_vg_export_raw(vg, "", buf, NULL);
 }
 
 struct dm_config_tree *export_vg_to_config_tree(struct volume_group *vg)
lib/format_text/format-text.c +236 -67

493 lines not on this page · raw message

lib/format_text/import-export.h +1 -1
index b7a8fa6..0bfc60b 100644
@@ -66,7 +66,7 @@ int print_segtype_lvflags(char *buffer, size_t size, uint64_t status);
 int read_segtype_lvflags(uint64_t *status, char *segtype_str);
 
 int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp);
-size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf);
+size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf, uint32_t *alloc_size);
 struct volume_group *text_read_metadata_file(struct format_instance *fid,
 					 const char *file,
 					 time_t *when, char **desc);