diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2011-03-30 13:14:34 +0000 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2011-03-30 13:14:34 +0000 |
commit | d992bbbaa383882511fd3f5038f619ff8ca589d4 (patch) | |
tree | 2e8d3f8eb64a08731f5344d36fedf92f47d63a79 /lib/cache/lvmcache.c | |
parent | a66bff47f1e5c1bb9fc461917bf1d5abb9c77bc1 (diff) | |
download | lvm2-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.
Diffstat (limited to 'lib/cache/lvmcache.c')
-rw-r--r-- | lib/cache/lvmcache.c | 17 |
1 files changed, 13 insertions, 4 deletions
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))) { |