1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 11:55:55 +03:00

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.
This commit is contained in:
Zdenek Kabelac 2011-03-30 13:14:34 +00:00
parent a66bff47f1
commit d992bbbaa3
3 changed files with 15 additions and 4 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.85 - 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. Extend the set of memory regions, that are not locked to memory.
Enhance usability with the valgrind memcheck tool. Enhance usability with the valgrind memcheck tool.
Support regular quit of the lvm_thread_fn function in clvmd. Support regular quit of the lvm_thread_fn function in clvmd.

17
lib/cache/lvmcache.c vendored
View File

@ -99,6 +99,7 @@ static void _store_metadata(struct volume_group *vg, unsigned precommitted)
{ {
char uuid[64] __attribute__((aligned(8))); char uuid[64] __attribute__((aligned(8)));
struct lvmcache_vginfo *vginfo; struct lvmcache_vginfo *vginfo;
char *data;
int size; int size;
if (!(vginfo = vginfo_from_vgid((const char *)&vg->id))) { if (!(vginfo = vginfo_from_vgid((const char *)&vg->id))) {
@ -106,14 +107,22 @@ static void _store_metadata(struct volume_group *vg, unsigned precommitted)
return; return;
} }
if (vginfo->vgmetadata) if (!(size = export_vg_to_buffer(vg, &data))) {
_free_cached_vgmetadata(vginfo);
if (!(size = export_vg_to_buffer(vg, &vginfo->vgmetadata))) {
stack; stack;
_free_cached_vgmetadata(vginfo);
return; 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; vginfo->precommitted = precommitted;
if (!id_write_format((const struct id *)vginfo->vgid, uuid, sizeof(uuid))) { if (!id_write_format((const struct id *)vginfo->vgid, uuid, sizeof(uuid))) {

View File

@ -46,6 +46,7 @@ struct lvmcache_vginfo {
char _padding[7]; char _padding[7];
struct lvmcache_vginfo *next; /* Another VG with same name? */ struct lvmcache_vginfo *next; /* Another VG with same name? */
char *creation_host; char *creation_host;
size_t vgmetadata_size;
char *vgmetadata; /* Copy of VG metadata as format_text string */ char *vgmetadata; /* Copy of VG metadata as format_text string */
struct config_tree *cft; /* Config tree created from vgmetadata */ struct config_tree *cft; /* Config tree created from vgmetadata */
/* Lifetime is directly tied to vgmetadata */ /* Lifetime is directly tied to vgmetadata */