summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2011-03-30 13:14:34 +0000
committerZdenek Kabelac <zkabelac@redhat.com>2011-03-30 13:14:34 +0000
commitd992bbbaa383882511fd3f5038f619ff8ca589d4 (patch)
tree2e8d3f8eb64a08731f5344d36fedf92f47d63a79
parenta66bff47f1e5c1bb9fc461917bf1d5abb9c77bc1 (diff)
downloadlvm2-d992bbbaa383882511fd3f5038f619ff8ca589d4.tar.gz
lvm2-d992bbbaa383882511fd3f5038f619ff8ca589d4.tar.xz
lvm2-d992bbbaa383882511fd3f5038f619ff8ca589d4.zip
Keep the cache content when the exported vg buffer is matching
Instead of regenerating config tree and parsing same data again, check whether export_vg_to_buffer does not produce same string as the one already cached - in this case keep it, otherwise throw cached content away. For the code simplicity calling _free_cached_vgmetadata() with vgmetadata == NULL as the function handles this itself. Note: sometimes export_vg_to_buffer() generates almost the same data with just different time stamp, but for the patch simplicity, data are reparsed in this case. This patch currently helps for vgrefresh.
-rw-r--r--WHATS_NEW1
-rw-r--r--lib/cache/lvmcache.c17
-rw-r--r--lib/cache/lvmcache.h1
3 files changed, 15 insertions, 4 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index 366fd86f..10b2a647 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.85 -
===================================
+ Keep the cache content when the exported vg buffer is matching.
Extend the set of memory regions, that are not locked to memory.
Enhance usability with the valgrind memcheck tool.
Support regular quit of the lvm_thread_fn function in clvmd.
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index ee7d278f..1d72746d 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -99,6 +99,7 @@ static void _store_metadata(struct volume_group *vg, unsigned precommitted)
{
char uuid[64] __attribute__((aligned(8)));
struct lvmcache_vginfo *vginfo;
+ char *data;
int size;
if (!(vginfo = vginfo_from_vgid((const char *)&vg->id))) {
@@ -106,14 +107,22 @@ static void _store_metadata(struct volume_group *vg, unsigned precommitted)
return;
}
- if (vginfo->vgmetadata)
- _free_cached_vgmetadata(vginfo);
-
- if (!(size = export_vg_to_buffer(vg, &vginfo->vgmetadata))) {
+ if (!(size = export_vg_to_buffer(vg, &data))) {
stack;
+ _free_cached_vgmetadata(vginfo);
return;
}
+ /* Avoid reparsing of the same data string */
+ if (vginfo->vgmetadata && vginfo->vgmetadata_size == size &&
+ strcmp(vginfo->vgmetadata, data) == 0)
+ dm_free(data);
+ else {
+ _free_cached_vgmetadata(vginfo);
+ vginfo->vgmetadata_size = size;
+ vginfo->vgmetadata = data;
+ }
+
vginfo->precommitted = precommitted;
if (!id_write_format((const struct id *)vginfo->vgid, uuid, sizeof(uuid))) {
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index 080f3b5e..f13cad2b 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -46,6 +46,7 @@ struct lvmcache_vginfo {
char _padding[7];
struct lvmcache_vginfo *next; /* Another VG with same name? */
char *creation_host;
+ size_t vgmetadata_size;
char *vgmetadata; /* Copy of VG metadata as format_text string */
struct config_tree *cft; /* Config tree created from vgmetadata */
/* Lifetime is directly tied to vgmetadata */