public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2 libdm/libdevmapper.h libdm/libdm-config.c ...
@ 2011-12-11 23:18 mornfall
0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2011-12-11 23:18 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall@sourceware.org 2011-12-11 23:18:20
Modified files:
libdm : libdevmapper.h libdm-config.c
lib/config : config.c config.h
tools : dumpconfig.c
Log message:
Move dm_config_write out of libdm, back to lib/config, as config_write.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdevmapper.h.diff?cvsroot=lvm2&r1=1.169&r2=1.170
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdm-config.c.diff?cvsroot=lvm2&r1=1.16&r2=1.17
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/config/config.c.diff?cvsroot=lvm2&r1=1.108&r2=1.109
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/config/config.h.diff?cvsroot=lvm2&r1=1.38&r2=1.39
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/dumpconfig.c.diff?cvsroot=lvm2&r1=1.10&r2=1.11
--- LVM2/libdm/libdevmapper.h 2011/11/12 22:44:10 1.169
+++ LVM2/libdm/libdevmapper.h 2011/12/11 23:18:20 1.170
@@ -1346,9 +1346,6 @@
void dm_config_destroy(struct dm_config_tree *cft);
-int dm_config_write(struct dm_config_tree *cft, const char *file,
- int argc, char **argv);
-
typedef int (*dm_putline_fn)(const char *line, void *baton);
int dm_config_write_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton);
--- LVM2/libdm/libdm-config.c 2011/12/11 15:18:32 1.16
+++ LVM2/libdm/libdm-config.c 2011/12/11 23:18:20 1.17
@@ -62,7 +62,6 @@
};
struct output_line {
- FILE *fp;
struct dm_pool *mem;
dm_putline_fn putline;
void *putline_baton;
@@ -356,14 +355,11 @@
}
line = dm_pool_end_object(outline->mem);
- if (outline->putline)
- outline->putline(line, outline->putline_baton);
- else {
- if (!outline->fp)
- log_print("%s", line);
- else
- fprintf(outline->fp, "%s\n", line);
- }
+
+ if (!outline->putline)
+ return 0;
+
+ outline->putline(line, outline->putline_baton);
return 1;
}
@@ -458,7 +454,6 @@
int dm_config_write_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton)
{
struct output_line outline;
- outline.fp = NULL;
if (!(outline.mem = dm_pool_create("config_line", 1024)))
return_0;
outline.putline = putline;
@@ -471,57 +466,6 @@
return 1;
}
-int dm_config_write(struct dm_config_tree *cft, const char *file,
- int argc, char **argv)
-{
- const struct dm_config_node *cn;
- int r = 1;
- struct output_line outline;
- outline.fp = NULL;
- outline.putline = NULL;
-
-// FIXME AGK remove the fopen from libdm before release
- if (!file)
- file = "stdout";
- else if (!(outline.fp = fopen(file, "w"))) {
- log_sys_error("open", file);
- return 0;
- }
-
- if (!(outline.mem = dm_pool_create("config_line", 1024))) {
- r = 0;
- goto_out;
- }
-
- log_verbose("Dumping configuration to %s", file);
- if (!argc) {
- if (!_write_config(cft->root, 0, &outline, 0)) {
- log_error("Failure while writing to %s", file);
- r = 0;
- }
- } else while (argc--) {
- if ((cn = dm_config_find_node(cft->root, *argv))) {
- if (!_write_config(cn, 1, &outline, 0)) {
- log_error("Failure while writing to %s", file);
- r = 0;
- }
- } else {
- log_error("Configuration node %s not found", *argv);
- r = 0;
- }
- argv++;
- }
-
- dm_pool_destroy(outline.mem);
-
-out:
- if (outline.fp && dm_fclose(outline.fp)) {
- stack;
- r = 0;
- }
-
- return r;
-}
/*
* parser
--- LVM2/lib/config/config.c 2011/10/28 20:06:49 1.108
+++ LVM2/lib/config/config.c 2011/12/11 23:18:20 1.109
@@ -324,3 +324,51 @@
return 1;
}
+static int _putline_fn(const char *line, void *baton) {
+ FILE *fp = baton;
+ fprintf(fp, "%s\n", line);
+ return 1;
+};
+
+int config_write(struct dm_config_tree *cft, const char *file,
+ int argc, char **argv)
+{
+ const struct dm_config_node *cn;
+ int r = 1;
+ FILE *fp = NULL;
+
+ if (!file) {
+ fp = stdout;
+ file = "stdout";
+ } else if (!(fp = fopen(file, "w"))) {
+ log_sys_error("open", file);
+ return 0;
+ }
+
+ log_verbose("Dumping configuration to %s", file);
+ if (!argc) {
+ if (!dm_config_write_node(cft->root, _putline_fn, fp)) {
+ log_error("Failure while writing to %s", file);
+ r = 0;
+ }
+ } else while (argc--) {
+ if ((cn = dm_config_find_node(cft->root, *argv))) {
+ if (!dm_config_write_node(cn, _putline_fn, fp)) {
+ log_error("Failure while writing to %s", file);
+ r = 0;
+ }
+ } else {
+ log_error("Configuration node %s not found", *argv);
+ r = 0;
+ }
+ argv++;
+ }
+
+out:
+ if (fp && dm_fclose(fp)) {
+ stack;
+ r = 0;
+ }
+
+ return r;
+}
--- LVM2/lib/config/config.h 2011/10/28 20:06:49 1.38
+++ LVM2/lib/config/config.h 2011/12/11 23:18:20 1.39
@@ -32,6 +32,9 @@
off_t offset, size_t size, off_t offset2, size_t size2,
checksum_fn_t checksum_fn, uint32_t checksum);
+int config_write(struct dm_config_tree *cft, const char *file,
+ int argc, char **argv);
+
int read_config_file(struct dm_config_tree *cft);
int merge_config_tree(struct cmd_context *cmd, struct dm_config_tree *cft,
--- LVM2/tools/dumpconfig.c 2011/08/30 14:55:19 1.10
+++ LVM2/tools/dumpconfig.c 2011/12/11 23:18:20 1.11
@@ -19,7 +19,7 @@
{
const char *file = arg_str_value(cmd, file_ARG, NULL);
- if (!dm_config_write(cmd->cft, file, argc, argv)) {
+ if (!config_write(cmd->cft, file, argc, argv)) {
stack;
return ECMD_FAILED;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* LVM2 libdm/libdevmapper.h libdm/libdm-config.c ...
@ 2012-03-01 19:54 mornfall
0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2012-03-01 19:54 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall@sourceware.org 2012-03-01 19:54:53
Modified files:
libdm : libdevmapper.h libdm-config.c
libdaemon/client: daemon-client.h
Log message:
Use 64 bit integers whenever extracting numbers from daemon replies.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdevmapper.h.diff?cvsroot=lvm2&r1=1.184&r2=1.185
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdm-config.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdaemon/client/daemon-client.h.diff?cvsroot=lvm2&r1=1.2&r2=1.3
--- LVM2/libdm/libdevmapper.h 2012/02/23 22:45:43 1.184
+++ LVM2/libdm/libdevmapper.h 2012/03/01 19:54:53 1.185
@@ -1453,6 +1453,7 @@
const char *dm_config_find_str(const struct dm_config_node *cn, const char *path, const char *fail);
const char *dm_config_find_str_allow_empty(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);
+int64_t dm_config_find_int64(const struct dm_config_node *cn, const char *path, int64_t fail);
float dm_config_find_float(const struct dm_config_node *cn, const char *path, float fail);
const struct dm_config_node *dm_config_tree_find_node(const struct dm_config_tree *cft, const char *path);
--- LVM2/libdm/libdm-config.c 2012/02/28 17:46:47 1.22
+++ LVM2/libdm/libdm-config.c 2012/03/01 19:54:53 1.23
@@ -877,6 +877,11 @@
return (int) _find_config_int64(cn, _find_config_node, path, (int64_t) fail);
}
+int64_t dm_config_find_int64(const struct dm_config_node *cn, const char *path, int64_t fail)
+{
+ return _find_config_int64(cn, _find_config_node, path, fail);
+}
+
float dm_config_find_float(const struct dm_config_node *cn, const char *path,
float fail)
{
--- LVM2/libdaemon/client/daemon-client.h 2012/02/28 18:35:05 1.2
+++ LVM2/libdaemon/client/daemon-client.h 2012/03/01 19:54:53 1.3
@@ -90,8 +90,8 @@
void daemon_reply_destroy(daemon_reply r);
-static inline int daemon_reply_int(daemon_reply r, const char *path, int def) {
- return dm_config_find_int(r.cft->root, path, def);
+static inline int64_t daemon_reply_int(daemon_reply r, const char *path, int64_t def) {
+ return dm_config_find_int64(r.cft->root, path, def);
}
static inline const char *daemon_reply_str(daemon_reply r, const char *path, const char *def) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* LVM2 libdm/libdevmapper.h libdm/libdm-config.c ...
@ 2011-08-31 12:40 mornfall
0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2011-08-31 12:40 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall@sourceware.org 2011-08-31 12:39:58
Modified files:
libdm : libdevmapper.h libdm-config.c
daemons/common : daemon-server.c daemon-server.h
daemons/lvmetad: lvmetad-core.c
Log message:
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).
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdevmapper.h.diff?cvsroot=lvm2&r1=1.145&r2=1.146
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdm-config.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-server.c.diff?cvsroot=lvm2&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-server.h.diff?cvsroot=lvm2&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/lvmetad/lvmetad-core.c.diff?cvsroot=lvm2&r1=1.23&r2=1.24
--- LVM2/libdm/libdevmapper.h 2011/08/30 14:55:15 1.145
+++ LVM2/libdm/libdevmapper.h 2011/08/31 12:39:58 1.146
@@ -1275,7 +1275,7 @@
time_t dm_config_timestamp(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);
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);
--- LVM2/libdm/libdm-config.c 2011/08/30 14:55:16 1.1
+++ LVM2/libdm/libdm-config.c 2011/08/31 12:39:58 1.2
@@ -809,8 +809,8 @@
/*
* utility functions
*/
-static const struct dm_config_node *_find_config_node(const void *start,
- const char *path)
+static struct dm_config_node *_find_config_node(const void *start,
+ const char *path)
{
const char *e;
const struct dm_config_node *cn = start;
@@ -848,15 +848,15 @@
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_node *cn = NULL;
+ struct dm_config_node *cn = NULL;
while (cft) {
if ((cn = _find_config_node(cft->root, path)))
@@ -973,8 +973,8 @@
* node-based lookup
**/
-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)
{
return _find_config_node(cn, path);
}
--- LVM2/daemons/common/daemon-server.c 2011/08/31 12:18:40 1.12
+++ LVM2/daemons/common/daemon-server.c 2011/08/31 12:39:58 1.13
@@ -201,7 +201,7 @@
setsid();
}
-response daemon_reply_simple(char *id, ...)
+response daemon_reply_simple(const char *id, ...)
{
va_list ap;
va_start(ap, id);
--- LVM2/daemons/common/daemon-server.h 2011/08/30 15:42:57 1.10
+++ LVM2/daemons/common/daemon-server.h 2011/08/31 12:39:58 1.11
@@ -41,7 +41,7 @@
* 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.
*/
-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) {
if (!r.cft)
--- LVM2/daemons/lvmetad/lvmetad-core.c 2011/08/30 15:44:01 1.23
+++ LVM2/daemons/lvmetad/lvmetad-core.c 2011/08/31 12:39:58 1.24
@@ -1,11 +1,11 @@
#include <assert.h>
#include <pthread.h>
-
-#include "libdevmapper.h"
#include <malloc.h>
#include <stdint.h>
+#include <unistd.h>
-#include "../common/daemon-server.h"
+#include "libdevmapper.h"
+#include "daemon-server.h"
typedef struct {
struct dm_hash_table *pvs;
@@ -19,29 +19,29 @@
} lock;
} lvmetad_state;
-void debug(const char *fmt, ...) {
+static void debug(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
- fprintf(stderr, "[D %u] ", pthread_self());
+ fprintf(stderr, "[D %lu] ", pthread_self());
vfprintf(stderr, fmt, ap);
va_end(ap);
};
-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 lock_pvs(lvmetad_state *s) { pthread_mutex_lock(&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); }
-void unlock_vgs(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.vgs); }
+static void lock_vgs(lvmetad_state *s) { pthread_mutex_lock(&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); }
-void unlock_pvid_map(lvmetad_state *s) { pthread_mutex_unlock(&s->lock.pvid_map); }
+static void lock_pvid_map(lvmetad_state *s) { pthread_mutex_lock(&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,
* since if we have many "rogue" requests for nonexistent things, we will keep
* 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);
pthread_mutex_t *vg = dm_hash_lookup(s->lock.vg, id);
if (!vg) {
@@ -58,7 +58,7 @@
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
* now, so avoid stepping on each other's toes */
pthread_mutex_unlock(dm_hash_lookup(s->lock.vg, id));
@@ -78,10 +78,9 @@
* library here or there.
*/
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_node *node = dm_config_find_node(parent->child, field);
- int found = 0;
if (node)
value = node->v;
@@ -184,20 +183,23 @@
static int compare_value(struct dm_config_value *a, struct dm_config_value *b)
{
+ int r = 0;
+
if (a->type > b->type)
return 1;
if (a->type < b->type)
return -1;
switch (a->type) {
- case DM_CFG_STRING: return strcmp(a->v.str, b->v.str);
- case DM_CFG_FLOAT: return a->v.r == b->v.r;
- case DM_CFG_INT: return a->v.i == b->v.i;
+ case DM_CFG_STRING: r = strcmp(a->v.str, b->v.str);
+ case DM_CFG_FLOAT: r = (a->v.r == b->v.r);
+ case DM_CFG_INT: r = (a->v.i == b->v.i);
case DM_CFG_EMPTY_ARRAY: return 0;
}
- if (a->next && b->next)
- return compare_value(a->next, b->next);
+ if (r == 0 && 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)
@@ -226,7 +228,7 @@
}
/* 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);
@@ -234,8 +236,8 @@
return 0;
while (pv) {
- char *pvid = dm_config_find_str(pv->child, "id", NULL);
- dm_hash_insert(s->pvid_map, pvid, vgid);
+ const char *pvid = dm_config_find_str(pv->child, "id", NULL);
+ dm_hash_insert(s->pvid_map, pvid, (void *) vgid);
pv = pv->sib;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-01 19:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-11 23:18 LVM2 libdm/libdevmapper.h libdm/libdm-config.c mornfall
-- strict thread matches above, loose matches on Subject: below --
2012-03-01 19:54 mornfall
2011-08-31 12:40 mornfall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).