From fe3a28e2cc97a4b3f7347e2a8e63291ddb7a417f Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 5 Mar 2009 16:25:35 +0000 Subject: [PATCH] Fix possible increasing in memory allocation if refreshing_context (for example when CLVMD_CMD_LOCK_VG for is called during vgscan). If clvmd calls LV lock, it calls /* clean the pool for another command */ dm_pool_empty(cmd->mem); to clean up memory pool after command. Unfortunately, do_refresh_cache() do not call this and because during it operation it allocates some memory, the pool increases. Also do_refresh_cache should use lvm_lock (it manipulates with lvm internal data). The same applies for lvm_backup command. Signed-off-by: Milan Broz --- WHATS_NEW | 1 + daemons/clvmd/lvm-functions.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 5c8fd034b..c1a5b89ae 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.46 - ================================ + Flush memory pool and fix locking in clvmd refresh and backup command. Version 2.02.45 - 3rd March 2009 ================================ diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c index d720802a7..4fc86136f 100644 --- a/daemons/clvmd/lvm-functions.c +++ b/daemons/clvmd/lvm-functions.c @@ -406,16 +406,15 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource) DEBUGLOG("do_lock_lv: resource '%s', cmd = %s, flags = %s\n", resource, decode_locking_cmd(command), decode_flags(lock_flags)); - pthread_mutex_lock(&lvm_lock); if (!cmd->config_valid || config_files_changed(cmd)) { /* Reinitialise various settings inc. logging, filters */ if (do_refresh_cache()) { log_error("Updated config file invalid. Aborting."); - pthread_mutex_unlock(&lvm_lock); return EINVAL; } } + pthread_mutex_lock(&lvm_lock); if (lock_flags & LCK_MIRROR_NOSYNC_MODE) init_mirror_in_sync(1); @@ -538,9 +537,14 @@ int do_refresh_cache() DEBUGLOG("Refreshing context\n"); log_notice("Refreshing context"); + pthread_mutex_lock(&lvm_lock); + ret = refresh_toolcontext(cmd); init_full_scan_done(0); lvmcache_label_scan(cmd, 2); + dm_pool_empty(cmd->mem); + + pthread_mutex_unlock(&lvm_lock); return ret==1?0:-1; } @@ -711,14 +715,18 @@ void lvm_do_backup(const char *vgname) DEBUGLOG("Triggering backup of VG metadata for %s. suspended=%d\n", vgname, suspended); + pthread_mutex_lock(&lvm_lock); + vg = vg_read_internal(cmd, vgname, NULL /*vgid*/, &consistent); - if (vg) { - if (consistent) - check_current_backup(vg); - } - else { + + if (vg && consistent) + check_current_backup(vg); + else log_error("Error backing up metadata, can't find VG for group %s", vgname); - } + + dm_pool_empty(cmd->mem); + + pthread_mutex_unlock(&lvm_lock); } /* Called to initialise the LVM context of the daemon */