1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

lvmetad: unlock vg on out-of-memory path

If we fail to get memory for mutex, hash the mutex
or fail somewhere along pthread function calls
return allocated resources back and unlock vg_lock_map mutex.
This commit is contained in:
Zdenek Kabelac 2012-12-14 16:35:26 +01:00
parent 788ac7fa54
commit a4269aadf3
2 changed files with 15 additions and 10 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.99 - Version 2.02.99 -
=================================== ===================================
Unlock vg mutex in error path when lvmetad tries to lock_vg.
Add check for key string duplication in config_make_nodes_v. Add check for key string duplication in config_make_nodes_v.
Add check for created fid in _scan_file. Add check for created fid in _scan_file.
Log output also to syslog when abort_on_internal_error is set. Log output also to syslog when abort_on_internal_error is set.

View File

@ -121,19 +121,18 @@ static response reply_unknown(const char *reason)
static struct dm_config_tree *lock_vg(lvmetad_state *s, const char *id) { static struct dm_config_tree *lock_vg(lvmetad_state *s, const char *id) {
pthread_mutex_t *vg; pthread_mutex_t *vg;
struct dm_config_tree *cft; struct dm_config_tree *cft;
pthread_mutexattr_t rec;
pthread_mutex_lock(&s->lock.vg_lock_map); pthread_mutex_lock(&s->lock.vg_lock_map);
vg = dm_hash_lookup(s->lock.vg, id); if (!(vg = dm_hash_lookup(s->lock.vg, id))) {
if (!vg) { if (!(vg = malloc(sizeof(pthread_mutex_t))) ||
pthread_mutexattr_t rec; pthread_mutexattr_init(&rec) ||
pthread_mutexattr_init(&rec); pthread_mutexattr_settype(&rec, PTHREAD_MUTEX_RECURSIVE_NP) ||
pthread_mutexattr_settype(&rec, PTHREAD_MUTEX_RECURSIVE_NP); pthread_mutex_init(vg, &rec))
if (!(vg = malloc(sizeof(pthread_mutex_t)))) goto bad;
return NULL;
pthread_mutex_init(vg, &rec);
if (!dm_hash_insert(s->lock.vg, id, vg)) { if (!dm_hash_insert(s->lock.vg, id, vg)) {
free(vg); pthread_mutex_destroy(vg);
return NULL; goto bad;
} }
} }
/* We never remove items from s->lock.vg => the pointer remains valid. */ /* We never remove items from s->lock.vg => the pointer remains valid. */
@ -147,6 +146,11 @@ static struct dm_config_tree *lock_vg(lvmetad_state *s, const char *id) {
cft = dm_hash_lookup(s->vgid_to_metadata, id); cft = dm_hash_lookup(s->vgid_to_metadata, id);
unlock_vgid_to_metadata(s); unlock_vgid_to_metadata(s);
return cft; return cft;
bad:
pthread_mutex_unlock(&s->lock.vg_lock_map);
free(vg);
ERROR(s, "Out of memory");
return NULL;
} }
static void unlock_vg(lvmetad_state *s, const char *id) { static void unlock_vg(lvmetad_state *s, const char *id) {