Skip to contentSkip to conversation

master - libdaemon: Extend and refactor APIs.

PATCH Petr Rockai 1 participant 1 message Sep 26, 2012

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ea14d5159cd3a196c0754f4e37539dee1eb2d169
Commit:        ea14d5159cd3a196c0754f4e37539dee1eb2d169
Parent:        72d82e21d44c48a3823156afa900eb071b3eb144
Author:        Petr Rockai <[email protected]>
AuthorDate:    Sat Aug 11 10:33:53 2012 +0200
Committer:     Petr Rockai <[email protected]>
CommitterDate: Wed Sep 26 14:49:09 2012 +0200

libdaemon: Extend and refactor APIs.

- move common dm_config_tree manipulation functions from lvmetad-core to daemon-shared
- add config-tree-based request manipulation APIs to daemon-client
- factor out _v (va_list) variants of most variadic functions in libdaemon

---
 daemons/lvmetad/lvmetad-core.c   |  123 --------------------
 lib/config/config.c              |    1 +
 libdaemon/client/daemon-client.c |   74 +++++++++++--
 libdaemon/client/daemon-client.h |    6 +
 libdaemon/client/daemon-shared.c |  232 +++++++++++++++++++++++++++++++++++++-
 libdaemon/client/daemon-shared.h |   38 ++++++-
 libdaemon/server/daemon-server.c |   45 +++-----
 7 files changed, 354 insertions(+), 165 deletions(-)
daemons/lvmetad/lvmetad-core.c +0 -123
index 146ee69..c96e285 100644
@@ -107,129 +107,6 @@ static struct dm_config_node *pvs(struct dm_config_node *vg)
 	return pv;
 }
 
-/*
- * TODO: This set_flag function is pretty generic and might make sense in a
- * library here or there.
- */
-static int set_flag(struct dm_config_tree *cft, struct dm_config_node *parent,
-		     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);
-	struct dm_config_value *new;
-
-	if (node)
-		value = node->v;
-
-	while (value && value->type != DM_CFG_EMPTY_ARRAY && strcmp(value->v.str, flag)) {
-		pred = value;
-		value = value->next;
-	}
-
-	if (value && want)
-		return 1;
-
-	if (!value && !want)
-		return 1;
-
-	if (value && !want) {
-		if (pred) {
-			pred->next = value->next;
-		} else if (value == node->v && value->next) {
-			node->v = value->next;
-		} else {
-			node->v->type = DM_CFG_EMPTY_ARRAY;
-		}
-	}
-
-	if (!value && want) {
-		if (!node) {
-			if (!(node = dm_config_create_node(cft, field)))
-				return 0;
-			node->sib = parent->child;
-			if (!(node->v = dm_config_create_value(cft)))
-				return 0;
-			node->v->type = DM_CFG_EMPTY_ARRAY;
-			node->parent = parent;
-			parent->child = node;
-		}
-		if (!(new = dm_config_create_value(cft))) {
-			/* FIXME error reporting */
-			return 0;
-		}
-		new->type = DM_CFG_STRING;
-		new->v.str = flag;
-		new->next = node->v;
-		node->v = new;
-	}
-
-	return 1;
-}
-
-static struct dm_config_node *make_config_node(struct dm_config_tree *cft,
-					       const char *key,
-					       struct dm_config_node *parent,
-					       struct dm_config_node *pre_sib)
-{
-	struct dm_config_node *cn;
-
-	if (!(cn = dm_config_create_node(cft, key)))
-		return NULL;
-
-	cn->parent = parent;
-	cn->sib = NULL;
-	cn->v = NULL;
-	cn->child = NULL;
-
-	if (parent && parent->child && !pre_sib) { /* find the last one */
-		pre_sib = parent->child;
-		while (pre_sib && pre_sib->sib)
-			pre_sib = pre_sib->sib;
-	}
-
-	if (parent && !parent->child)
-		parent->child = cn;
-	if (pre_sib)
-		pre_sib->sib = cn;
-
-	return cn;
-}
-
-static struct dm_config_node *make_text_node(struct dm_config_tree *cft,
-					     const char *key,
-					     const char *value,
-					     struct dm_config_node *parent,
-					     struct dm_config_node *pre_sib)
-{
-	struct dm_config_node *cn;
-
-	if (!(cn = make_config_node(cft, key, parent, pre_sib)) ||
-	    !(cn->v = dm_config_create_value(cft)))
-		return NULL;
-
-	cn->v->type = DM_CFG_STRING;
-	cn->v->v.str = value;
-	return cn;
-}
-
-#if 0
-static struct dm_config_node *make_int_node(struct dm_config_tree *cft,
-					    const char *key,
-					    int64_t value,
-					    struct dm_config_node *parent,
-					    struct dm_config_node *pre_sib)
-{
-	struct dm_config_node *cn;
-
-	if (!(cn = make_config_node(cft, key, parent, pre_sib)) ||
-	    !(cn->v = dm_config_create_value(cft)))
-		return NULL;
-
-	cn->v->type = DM_CFG_INT;
-	cn->v->v.i = value;
-	return cn;
-}
-#endif
-
 static void filter_metadata(struct dm_config_node *vg) {
 	struct dm_config_node *pv = pvs(vg);
 	while (pv) {
lib/config/config.c +1 -0
index a7bda97..00bfcab 100644
@@ -489,3 +489,4 @@ int config_write(struct dm_config_tree *cft, const char *file,
 
 	return r;
 }
+
libdaemon/client/daemon-client.c +66 -8

98 lines not on this page · raw message

libdaemon/client/daemon-client.h +6 -0
index 15fef70..2863d03 100644
@@ -87,6 +87,12 @@ daemon_reply daemon_send(daemon_handle h, daemon_request r);
  * for ? in %?: d for integer, s for string.
  */
 daemon_reply daemon_send_simple(daemon_handle h, const char *id, ...);
+daemon_reply daemon_send_simple_v(daemon_handle h, const char *id, va_list ap);
+
+daemon_request daemon_request_make(const char *id);
+int daemon_request_extend(daemon_request r, ...);
+int daemon_request_extend_v(daemon_request r, va_list ap);
+void daemon_request_destroy(daemon_request r);
 
 void daemon_reply_destroy(daemon_reply r);
 
libdaemon/client/daemon-shared.c +228 -4

257 lines not on this page · raw message

libdaemon/client/daemon-shared.h +37 -1
index 3e5fa9c..acb71c6 100644
@@ -16,15 +16,51 @@
 #define _LVM_DAEMON_SHARED_H
 
 #include "configure.h"
+#include "libdevmapper.h"
 
 #define _REENTRANT
 #define _GNU_SOURCE
 #define _FILE_OFFSET_BITS 64
 
+/* TODO function names */
+
 #include <stdarg.h>
 
 int read_buffer(int fd, char **buffer);
 int write_buffer(int fd, const char *buffer, int length);
-char *format_buffer(const char *what, const char *id, va_list ap);
+char *format_buffer_v(const char *head, va_list ap);
+char *format_buffer(const char *head, ...);
+
+int buffer_line(const char *line, void *baton);
+int buffer_rewrite(char **buf, const char *format, const char *string);
+
+int set_flag(struct dm_config_tree *cft, struct dm_config_node *parent,
+	     const char *field, const char *flag, int want);
+
+struct dm_config_node *make_config_node(struct dm_config_tree *cft,
+					const char *key,
+					struct dm_config_node *parent,
+					struct dm_config_node *pre_sib);
+
+struct dm_config_node *make_text_node(struct dm_config_tree *cft,
+				      const char *key,
+				      const char *value,
+				      struct dm_config_node *parent,
+				      struct dm_config_node *pre_sib);
+
+struct dm_config_node *make_int_node(struct dm_config_tree *cft,
+				     const char *key,
+				     int64_t value,
+				     struct dm_config_node *parent,
+				     struct dm_config_node *pre_sib);
+
+struct dm_config_node *config_make_nodes_v(struct dm_config_tree *cft,
+					   struct dm_config_node *parent,
+					   struct dm_config_node *pre_sib,
+					   va_list ap);
+struct dm_config_node *config_make_nodes(struct dm_config_tree *cft,
+					 struct dm_config_node *parent,
+					 struct dm_config_node *pre_sib,
+					 ...);
 
 #endif /* _LVM_DAEMON_SHARED_H */
libdaemon/server/daemon-server.c +16 -29

82 lines not on this page · raw message