1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 10:25:13 +03:00

lvmetad: A couple of TODOs, and fix a few trivial memory leaks.

This commit is contained in:
Petr Rockai 2011-07-25 15:33:04 +00:00
parent 600dbd3b27
commit 9474992482

View File

@ -36,6 +36,11 @@ void unlock_vgs(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.vgs); }
void lock_pvid_map(lvmetad_state *s) { pthread_mutex_lock(&s->lock.pvid_map); } void lock_pvid_map(lvmetad_state *s) { pthread_mutex_lock(&s->lock.pvid_map); }
void unlock_pvid_map(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.pvid_map); } void unlock_pvid_map(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.pvid_map); }
/*
* TODO: It may be beneficial to clean up the vg lock hash from time to time,
* since if we have many "rogue" requests for nonexistent things, we will keep
* allocating memory that we never release. Not good.
*/
struct config_tree *lock_vg(lvmetad_state *s, const char *id) { struct config_tree *lock_vg(lvmetad_state *s, const char *id) {
lock_vgs(s); lock_vgs(s);
pthread_mutex_t *vg = dm_hash_lookup(s->lock.vg, id); pthread_mutex_t *vg = dm_hash_lookup(s->lock.vg, id);
@ -90,6 +95,10 @@ static response vg_by_uuid(lvmetad_state *s, request r)
return res; return res;
} }
/*
* TODO: This set_flag function is pretty generic and might make sense in a
* library here or there.
*/
static void set_flag(struct config_tree *cft, struct config_node *parent, static void set_flag(struct config_tree *cft, struct config_node *parent,
char *field, const char *flag, int want) { char *field, const char *flag, int want) {
struct config_value *value = NULL, *pred = NULL; struct config_value *value = NULL, *pred = NULL;
@ -337,14 +346,25 @@ static int init(daemon_state *s)
static int fini(daemon_state *s) static int fini(daemon_state *s)
{ {
debug("fini\n");
lvmetad_state *ls = s->private; lvmetad_state *ls = s->private;
struct dm_hash_node *n = dm_hash_get_first(ls->vgs); struct dm_hash_node *n = dm_hash_get_first(ls->vgs);
while (n) { while (n) {
destroy_config_tree(dm_hash_get_data(ls->vgs, n)); destroy_config_tree(dm_hash_get_data(ls->vgs, n));
n = dm_hash_get_next(ls->vgs, n); n = dm_hash_get_next(ls->vgs, n);
} }
n = dm_hash_get_first(ls->lock.vg);
while (n) {
pthread_mutex_destroy(dm_hash_get_data(ls->lock.vg, n));
free(dm_hash_get_data(ls->lock.vg, n));
n = dm_hash_get_next(ls->lock.vg, n);
}
dm_hash_destroy(ls->lock.vg);
dm_hash_destroy(ls->pvs); dm_hash_destroy(ls->pvs);
dm_hash_destroy(ls->vgs); dm_hash_destroy(ls->vgs);
dm_hash_destroy(ls->pvid_map);
return 1; return 1;
} }