summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2021-09-27 15:55:53 +0200
committerZdenek Kabelac <zkabelac@redhat.com>2021-09-27 18:49:41 +0200
commit24e90f9594a79a8be851cffe1a5e47741dbff663 (patch)
tree675c57dd629ad7b09516f281627ce5fe1e8811a7
parenta42ea349f6733fda6eef7741c49208274b0a5388 (diff)
downloadlvm2-24e90f9594a79a8be851cffe1a5e47741dbff663.tar.gz
metadata: remember parsing size of VG metadata
When creating lvm2 metadata for VG, lvm2 allocate some buffer, and if buffer is not big enough, the buffer is 'reallocated' bigger, and whole metadata creation is repeated until metadata fits. We can try to use 'previous' metadata size as hint to reduce looping here.
-rw-r--r--lib/format_text/export.c2
-rw-r--r--lib/format_text/import.c1
-rw-r--r--lib/metadata/vg.h1
3 files changed, 3 insertions, 1 deletions
diff --git a/lib/format_text/export.c b/lib/format_text/export.c
index 6ece94042..fbb8fb1ee 100644
--- a/lib/format_text/export.c
+++ b/lib/format_text/export.c
@@ -1071,7 +1071,7 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf,
.header = 0,
.out_with_comment = &_out_with_comment_raw,
.nl = &_nl_raw,
- .data.buf.size = 65536, /* Initial metadata limit */
+ .data.buf.size = vg->buffer_size_hint + 16384, /* Initial metadata limit */
};
_init();
diff --git a/lib/format_text/import.c b/lib/format_text/import.c
index 2687d172e..e4e526354 100644
--- a/lib/format_text/import.c
+++ b/lib/format_text/import.c
@@ -187,6 +187,7 @@ struct volume_group *text_read_metadata(struct format_instance *fid,
(*vsn)->read_desc(vg->vgmem, cft, when, desc);
vg->committed_cft = cft; /* Reuse CFT for recreation of committed VG */
+ vg->buffer_size_hint = size + size2;
cft = NULL;
break;
}
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index 8ce57acdc..96ab6a0b2 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -45,6 +45,7 @@ struct volume_group {
unsigned needs_backup : 1;
unsigned needs_write_and_commit : 1;
uint32_t write_count; /* count the number of vg_write calls */
+ uint32_t buffer_size_hint; /* hint with buffer size of parsed VG */
/*
* The parsed committed (on-disk) copy of this VG; is NULL if this VG is committed