1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

Fix warnings and constness handling in lvmetad-core (adjusting the

dm_config_find_node to give non-const node pointer, since that better reflects
the contract of that function).
This commit is contained in:
Petr Rockai 2011-08-31 12:39:58 +00:00
parent 178675bec5
commit dbe351860e
5 changed files with 36 additions and 34 deletions

View File

@ -201,7 +201,7 @@ static void _daemonise(void)
setsid(); setsid();
} }
response daemon_reply_simple(char *id, ...) response daemon_reply_simple(const char *id, ...)
{ {
va_list ap; va_list ap;
va_start(ap, id); va_start(ap, id);

View File

@ -41,7 +41,7 @@ struct daemon_state;
* Craft a simple reply, without the need to construct a config_tree. See * Craft a simple reply, without the need to construct a config_tree. See
* daemon_send_simple in daemon-client.h for the description of the parameters. * daemon_send_simple in daemon-client.h for the description of the parameters.
*/ */
response daemon_reply_simple(char *id, ...); response daemon_reply_simple(const char *id, ...);
static inline int daemon_request_int(request r, const char *path, int def) { static inline int daemon_request_int(request r, const char *path, int def) {
if (!r.cft) if (!r.cft)

View File

@ -1,11 +1,11 @@
#include <assert.h> #include <assert.h>
#include <pthread.h> #include <pthread.h>
#include "libdevmapper.h"
#include <malloc.h> #include <malloc.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h>
#include "../common/daemon-server.h" #include "libdevmapper.h"
#include "daemon-server.h"
typedef struct { typedef struct {
struct dm_hash_table *pvs; struct dm_hash_table *pvs;
@ -19,29 +19,29 @@ typedef struct {
} lock; } lock;
} lvmetad_state; } lvmetad_state;
void debug(const char *fmt, ...) { static void debug(const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
fprintf(stderr, "[D %u] ", pthread_self()); fprintf(stderr, "[D %lu] ", pthread_self());
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
va_end(ap); va_end(ap);
}; };
void lock_pvs(lvmetad_state *s) { pthread_mutex_lock(&s->lock.pvs); } static void lock_pvs(lvmetad_state *s) { pthread_mutex_lock(&s->lock.pvs); }
void unlock_pvs(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.pvs); } static void unlock_pvs(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.pvs); }
void lock_vgs(lvmetad_state *s) { pthread_mutex_lock(&s->lock.vgs); } static void lock_vgs(lvmetad_state *s) { pthread_mutex_lock(&s->lock.vgs); }
void unlock_vgs(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.vgs); } static 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); } static 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); } static 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, * 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 * since if we have many "rogue" requests for nonexistent things, we will keep
* allocating memory that we never release. Not good. * allocating memory that we never release. Not good.
*/ */
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) {
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);
if (!vg) { if (!vg) {
@ -58,7 +58,7 @@ struct dm_config_tree *lock_vg(lvmetad_state *s, const char *id) {
return cft; return cft;
} }
void unlock_vg(lvmetad_state *s, const char *id) { static void unlock_vg(lvmetad_state *s, const char *id) {
lock_vgs(s); /* someone might be changing the s->lock.vg structure right lock_vgs(s); /* someone might be changing the s->lock.vg structure right
* now, so avoid stepping on each other's toes */ * now, so avoid stepping on each other's toes */
pthread_mutex_unlock(dm_hash_lookup(s->lock.vg, id)); pthread_mutex_unlock(dm_hash_lookup(s->lock.vg, id));
@ -78,10 +78,9 @@ static struct dm_config_node *pvs(struct dm_config_node *vg)
* library here or there. * library here or there.
*/ */
static void set_flag(struct dm_config_tree *cft, struct dm_config_node *parent, static void set_flag(struct dm_config_tree *cft, struct dm_config_node *parent,
char *field, const char *flag, int want) { const char *field, const char *flag, int want) {
struct dm_config_value *value = NULL, *pred = NULL; struct dm_config_value *value = NULL, *pred = NULL;
struct dm_config_node *node = dm_config_find_node(parent->child, field); struct dm_config_node *node = dm_config_find_node(parent->child, field);
int found = 0;
if (node) if (node)
value = node->v; value = node->v;
@ -184,20 +183,23 @@ static response vg_by_uuid(lvmetad_state *s, request r)
static int compare_value(struct dm_config_value *a, struct dm_config_value *b) static int compare_value(struct dm_config_value *a, struct dm_config_value *b)
{ {
int r = 0;
if (a->type > b->type) if (a->type > b->type)
return 1; return 1;
if (a->type < b->type) if (a->type < b->type)
return -1; return -1;
switch (a->type) { switch (a->type) {
case DM_CFG_STRING: return strcmp(a->v.str, b->v.str); case DM_CFG_STRING: r = strcmp(a->v.str, b->v.str);
case DM_CFG_FLOAT: return a->v.r == b->v.r; case DM_CFG_FLOAT: r = (a->v.r == b->v.r);
case DM_CFG_INT: return a->v.i == b->v.i; case DM_CFG_INT: r = (a->v.i == b->v.i);
case DM_CFG_EMPTY_ARRAY: return 0; case DM_CFG_EMPTY_ARRAY: return 0;
} }
if (a->next && b->next) if (r == 0 && a->next && b->next)
return compare_value(a->next, b->next); r = compare_value(a->next, b->next);
return r;
} }
static int compare_config(struct dm_config_node *a, struct dm_config_node *b) static int compare_config(struct dm_config_node *a, struct dm_config_node *b)
@ -226,7 +228,7 @@ static int compare_config(struct dm_config_node *a, struct dm_config_node *b)
} }
/* You need to be holding the pvid_map lock already to call this. */ /* You need to be holding the pvid_map lock already to call this. */
int update_pvid_map(lvmetad_state *s, struct dm_config_tree *vg, const char *vgid) static int update_pvid_map(lvmetad_state *s, struct dm_config_tree *vg, const char *vgid)
{ {
struct dm_config_node *pv = pvs(vg->root); struct dm_config_node *pv = pvs(vg->root);
@ -234,8 +236,8 @@ int update_pvid_map(lvmetad_state *s, struct dm_config_tree *vg, const char *vgi
return 0; return 0;
while (pv) { while (pv) {
char *pvid = dm_config_find_str(pv->child, "id", NULL); const char *pvid = dm_config_find_str(pv->child, "id", NULL);
dm_hash_insert(s->pvid_map, pvid, vgid); dm_hash_insert(s->pvid_map, pvid, (void *) vgid);
pv = pv->sib; pv = pv->sib;
} }

View File

@ -1275,7 +1275,7 @@ int dm_config_write_node(const struct dm_config_node *cn, dm_putline_fn putline,
time_t dm_config_timestamp(struct dm_config_tree *cft); time_t dm_config_timestamp(struct dm_config_tree *cft);
int dm_config_changed(struct dm_config_tree *cft); int dm_config_changed(struct dm_config_tree *cft);
const struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn, const char *path); struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn, const char *path);
const char *dm_config_find_str(const struct dm_config_node *cn, const char *path, const char *fail); const char *dm_config_find_str(const struct dm_config_node *cn, const char *path, const char *fail);
int dm_config_find_int(const struct dm_config_node *cn, const char *path, int fail); int dm_config_find_int(const struct dm_config_node *cn, const char *path, int fail);
float dm_config_find_float(const struct dm_config_node *cn, const char *path, float fail); float dm_config_find_float(const struct dm_config_node *cn, const char *path, float fail);

View File

@ -809,8 +809,8 @@ static char *_dup_tok(struct parser *p)
/* /*
* utility functions * utility functions
*/ */
static const struct dm_config_node *_find_config_node(const void *start, static struct dm_config_node *_find_config_node(const void *start,
const char *path) const char *path)
{ {
const char *e; const char *e;
const struct dm_config_node *cn = start; const struct dm_config_node *cn = start;
@ -848,15 +848,15 @@ static const struct dm_config_node *_find_config_node(const void *start,
path = e; path = e;
} }
return cn_found; return (struct dm_config_node *) cn_found;
} }
typedef const struct dm_config_node *_node_lookup_fn(const void *start, const char *path); typedef struct dm_config_node *_node_lookup_fn(const void *start, const char *path);
static const struct dm_config_node *_find_first_config_node(const void *start, const char *path) static struct dm_config_node *_find_first_config_node(const void *start, const char *path)
{ {
const struct dm_config_tree *cft = start; const struct dm_config_tree *cft = start;
const struct dm_config_node *cn = NULL; struct dm_config_node *cn = NULL;
while (cft) { while (cft) {
if ((cn = _find_config_node(cft->root, path))) if ((cn = _find_config_node(cft->root, path)))
@ -973,8 +973,8 @@ static int _find_config_bool(const void *start, _node_lookup_fn find,
* node-based lookup * node-based lookup
**/ **/
const struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn, struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn,
const char *path) const char *path)
{ {
return _find_config_node(cn, path); return _find_config_node(cn, path);
} }