public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/daemons/lvmetad lvmetad-client.h lvmetad- ...
@ 2011-08-30 15:44 mornfall
  0 siblings, 0 replies; 2+ messages in thread
From: mornfall @ 2011-08-30 15:44 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2011-08-30 15:44:02

Modified files:
	daemons/lvmetad: lvmetad-client.h lvmetad-core.c 

Log message:
	Adapt LVMetaD to use the new dm_config interfaces.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/lvmetad/lvmetad-client.h.diff?cvsroot=lvm2&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/lvmetad/lvmetad-core.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23

--- LVM2/daemons/lvmetad/lvmetad-client.h	2011/06/14 02:36:38	1.3
+++ LVM2/daemons/lvmetad/lvmetad-client.h	2011/08/30 15:44:01	1.4
@@ -27,7 +27,7 @@
 
 typedef struct {
 	daemon_reply r;
-	struct config_tree *cft;
+	struct dm_config_tree *cft;
 } lvmetad_vg;
 
 static inline daemon_handle lvmetad_open();
--- LVM2/daemons/lvmetad/lvmetad-core.c	2011/07/25 17:59:50	1.22
+++ LVM2/daemons/lvmetad/lvmetad-core.c	2011/08/30 15:44:01	1.23
@@ -41,7 +41,7 @@
  * 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 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) {
@@ -53,7 +53,7 @@
 		dm_hash_insert(s->lock.vg, id, vg);
 	}
 	pthread_mutex_lock(vg);
-	struct config_tree *cft = dm_hash_lookup(s->vgs, id);
+	struct dm_config_tree *cft = dm_hash_lookup(s->vgs, id);
 	unlock_vgs(s);
 	return cft;
 }
@@ -65,9 +65,9 @@
 	unlock_vgs(s);
 }
 
-static struct config_node *pvs(struct config_node *vg)
+static struct dm_config_node *pvs(struct dm_config_node *vg)
 {
-	struct config_node *pv = find_config_node(vg, "metadata/physical_volumes");
+	struct dm_config_node *pv = dm_config_find_node(vg, "metadata/physical_volumes");
 	if (pv)
 		pv = pv->child;
 	return pv;
@@ -77,16 +77,16 @@
  * 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 dm_config_tree *cft, struct dm_config_node *parent,
 		     char *field, const char *flag, int want) {
-	struct config_value *value = NULL, *pred = NULL;
-	struct config_node *node = find_config_node(parent->child, field);
+	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;
 
-	while (value && value->type != CFG_EMPTY_ARRAY && strcmp(value->v.str, flag)) {
+	while (value && value->type != DM_CFG_EMPTY_ARRAY && strcmp(value->v.str, flag)) {
 		pred = value;
 		value = value->next;
 	}
@@ -106,15 +106,15 @@
 
 	if (!value && want) {
 		if (!node) {
-			node = create_config_node(cft, field);
+			node = dm_config_create_node(cft, field);
 			node->sib = parent->child;
-			node->v = create_config_value(cft);
-			node->v->type = CFG_EMPTY_ARRAY;
+			node->v = dm_config_create_value(cft);
+			node->v->type = DM_CFG_EMPTY_ARRAY;
 			node->parent = parent;
 			parent->child = node;
 		}
-		struct config_value *new = create_config_value(cft);
-		new->type = CFG_STRING;
+		struct dm_config_value *new = dm_config_create_value(cft);
+		new->type = DM_CFG_STRING;
 		new->v.str = flag;
 		new->next = node->v;
 		node->v = new;
@@ -123,14 +123,16 @@
 
 /* Either the "big" vgs lock, or a per-vg lock needs to be held before entering
  * this function. */
-static int update_pv_status(lvmetad_state *s, struct config_tree *cft, struct config_node *vg, int act)
+static int update_pv_status(lvmetad_state *s,
+			    struct dm_config_tree *cft,
+			    struct dm_config_node *vg, int act)
 {
 	int complete = 1;
 
 	lock_pvs(s);
-	struct config_node *pv = pvs(vg);
+	struct dm_config_node *pv = pvs(vg);
 	while (pv) {
-		const char *uuid = find_config_str(pv->child, "id", NULL);
+		const char *uuid = dm_config_find_str(pv->child, "id", NULL);
 		int found = uuid ? (dm_hash_lookup(s->pvs, uuid) ? 1 : 0) : 0;
 		if (act)
 			set_flag(cft, pv, "status", "MISSING", !found);
@@ -152,25 +154,25 @@
 {
 	const char *uuid = daemon_request_str(r, "uuid", "NONE");
 	debug("vg_by_uuid: %s (vgs = %p)\n", uuid, s->vgs);
-	struct config_tree *cft = lock_vg(s, uuid);
+	struct dm_config_tree *cft = lock_vg(s, uuid);
 	if (!cft || !cft->root) {
 		unlock_vg(s, uuid);
 		return daemon_reply_simple("failed", "reason = %s", "uuid not found", NULL);
 	}
 
-	struct config_node *metadata = cft->root;
+	struct dm_config_node *metadata = cft->root;
 
 	response res = { .buffer = NULL };
-	struct config_node *n;
-	res.cft = create_config_tree(NULL, 0);
+	struct dm_config_node *n;
+	res.cft = dm_config_create(NULL, 0);
 
 	/* The response field */
-	res.cft->root = n = create_config_node(res.cft, "response");
-	n->v->type = CFG_STRING;
+	res.cft->root = n = dm_config_create_node(res.cft, "response");
+	n->v->type = DM_CFG_STRING;
 	n->v->v.str = "OK";
 
 	/* The metadata section */
-	n = n->sib = clone_config_node(res.cft, metadata, 1);
+	n = n->sib = dm_config_clone_node(res.cft, metadata, 1);
 	n->parent = res.cft->root;
 	res.error = 0;
 	unlock_vg(s, uuid);
@@ -180,7 +182,7 @@
 	return res;
 }
 
-static int compare_value(struct config_value *a, struct config_value *b)
+static int compare_value(struct dm_config_value *a, struct dm_config_value *b)
 {
 	if (a->type > b->type)
 		return 1;
@@ -188,17 +190,17 @@
 		return -1;
 
 	switch (a->type) {
-	case CFG_STRING: return strcmp(a->v.str, b->v.str);
-	case CFG_FLOAT: return a->v.r == b->v.r;
-	case CFG_INT: return a->v.i == b->v.i;
-	case CFG_EMPTY_ARRAY: return 0;
+	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_EMPTY_ARRAY: return 0;
 	}
 
 	if (a->next && b->next)
 		return compare_value(a->next, b->next);
 }
 
-static int compare_config(struct config_node *a, struct config_node *b)
+static int compare_config(struct dm_config_node *a, struct dm_config_node *b)
 {
 	int result = 0;
 	if (a->v && b->v)
@@ -224,15 +226,15 @@
 }
 
 /* You need to be holding the pvid_map lock already to call this. */
-int update_pvid_map(lvmetad_state *s, struct config_tree *vg, const char *vgid)
+int update_pvid_map(lvmetad_state *s, struct dm_config_tree *vg, const char *vgid)
 {
-	struct config_node *pv = pvs(vg);
+	struct dm_config_node *pv = pvs(vg->root);
 
 	if (!vgid)
 		return 0;
 
 	while (pv) {
-		char *pvid = find_config_str(pv->child, "id", NULL);
+		char *pvid = dm_config_find_str(pv->child, "id", NULL);
 		dm_hash_insert(s->pvid_map, pvid, vgid);
 		pv = pv->sib;
 	}
@@ -243,19 +245,19 @@
 /* No locks need to be held. The pointers are never used outside of the scope of
  * this function, so they can be safely destroyed after update_metadata returns
  * (anything that might have been retained is copied). */
-static int update_metadata(lvmetad_state *s, const char *_vgid, struct config_node *metadata)
+static int update_metadata(lvmetad_state *s, const char *_vgid, struct dm_config_node *metadata)
 {
 	int retval = 0;
 	lock_vgs(s);
-	struct config_tree *old = dm_hash_lookup(s->vgs, _vgid);
+	struct dm_config_tree *old = dm_hash_lookup(s->vgs, _vgid);
 	lock_vg(s, _vgid);
 	unlock_vgs(s);
 
-	int seq = find_config_int(metadata, "metadata/seqno", -1);
+	int seq = dm_config_find_int(metadata, "metadata/seqno", -1);
 	int haveseq = -1;
 
 	if (old)
-		haveseq = find_config_int(old->root, "metadata/seqno", -1);
+		haveseq = dm_config_find_int(old->root, "metadata/seqno", -1);
 
 	if (seq < 0)
 		goto out;
@@ -274,9 +276,9 @@
 		goto out;
 	}
 
-	struct config_tree *cft = create_config_tree(NULL, 0);
-	cft->root = clone_config_node(cft, metadata, 0);
-	const char *vgid = find_config_str(cft->root, "metadata/id", NULL);
+	struct dm_config_tree *cft = dm_config_create(NULL, 0);
+	cft->root = dm_config_clone_node(cft, metadata, 0);
+	const char *vgid = dm_config_find_str(cft->root, "metadata/id", NULL);
 
 	if (!vgid)
 		goto out;
@@ -287,7 +289,7 @@
 		/* temporarily orphan all of our PVs */
 		update_pvid_map(s, old, "#orphan");
 		/* need to update what we have since we found a newer version */
-		destroy_config_tree(old);
+		dm_config_destroy(old);
 		dm_hash_remove(s->vgs, vgid);
 	}
 
@@ -306,7 +308,7 @@
 
 static response pv_add(lvmetad_state *s, request r)
 {
-	struct config_node *metadata = find_config_node(r.cft->root, "metadata");
+	struct dm_config_node *metadata = dm_config_find_node(r.cft->root, "metadata");
 	const char *pvid = daemon_request_str(r, "uuid", NULL);
 	const char *vgid = daemon_request_str(r, "metadata/id", NULL);
 
@@ -336,7 +338,7 @@
 
 	int complete = 0;
 	if (vgid) {
-		struct config_tree *cft = lock_vg(s, vgid);
+		struct dm_config_tree *cft = lock_vg(s, vgid);
 		complete = update_pv_status(s, cft, cft->root, 0);
 		unlock_vg(s, vgid);
 	}
@@ -400,7 +402,7 @@
 	lvmetad_state *ls = s->private;
 	struct dm_hash_node *n = dm_hash_get_first(ls->vgs);
 	while (n) {
-		destroy_config_tree(dm_hash_get_data(ls->vgs, n));
+		dm_config_destroy(dm_hash_get_data(ls->vgs, n));
 		n = dm_hash_get_next(ls->vgs, n);
 	}
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* LVM2/daemons/lvmetad lvmetad-client.h lvmetad- ...
@ 2012-01-16  8:25 mornfall
  0 siblings, 0 replies; 2+ messages in thread
From: mornfall @ 2012-01-16  8:25 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2012-01-16 08:25:33

Modified files:
	daemons/lvmetad: lvmetad-client.h lvmetad-core.c 

Log message:
	Beef up the lvmetad code with more functionality and a bunch of bugfixes. There
	used to be a few mis-ordered memory accesses (release and access in the next
	block). Fix that set_flag could have sometimes corrupted the flags being
	modified.
	
	A few issues with metadata tracking are sorted out as well now, and there are
	only a few problems remaining before we can integrate lvmetad, mostly on the
	client side:
	
	- metadata areas need to be tracked in lvmetad (most likely to be addressed
	through an extension of metadata, meaning no special support in lvmetad would
	be needed)
	- non-udev scanning code needs to be taught about telling lvmetad about device
	disappearance (pvscan most importantly)
	- this last item also needs to mesh with metadata inconsistencies and
	suddenly-incomplete volume groups (aux disable_dev in tests); udev-based
	scanning should address this separately and more elegantly

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/lvmetad/lvmetad-client.h.diff?cvsroot=lvm2&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/lvmetad/lvmetad-core.c.diff?cvsroot=lvm2&r1=1.28&r2=1.29

--- LVM2/daemons/lvmetad/lvmetad-client.h	2011/08/30 15:44:01	1.4
+++ LVM2/daemons/lvmetad/lvmetad-client.h	2012/01/16 08:25:32	1.5
@@ -62,12 +62,12 @@
 
 /* Implementation of inline functions */
 
-static inline daemon_handle lvmetad_open()
+static inline daemon_handle lvmetad_open(const char *socket)
 {
 	/* TODO configurable */
 	daemon_info lvmetad_info = {
 		.path = "lvmetad",
-		.socket = "/var/run/lvm/lvmetad.socket",
+		.socket = socket ?: "/var/run/lvm/lvmetad.socket",
 		.autostart = 1
 	};
 
--- LVM2/daemons/lvmetad/lvmetad-core.c	2011/12/18 22:31:10	1.28
+++ LVM2/daemons/lvmetad/lvmetad-core.c	2012/01/16 08:25:32	1.29
@@ -13,6 +13,8 @@
 typedef struct {
 	struct dm_hash_table *pvs;
 	struct dm_hash_table *vgs;
+	struct dm_hash_table *vg_names;
+	struct dm_hash_table *vgname_map;
 	struct dm_hash_table *pvid_map;
 	struct {
 		struct dm_hash_table *vg;
@@ -59,6 +61,7 @@
 		pthread_mutex_init(vg, &rec);
 		dm_hash_insert(s->lock.vg, id, vg);
 	}
+	debug("lock VG %s\n", id);
 	pthread_mutex_lock(vg);
 	cft = dm_hash_lookup(s->vgs, id);
 	unlock_vgs(s);
@@ -66,6 +69,7 @@
 }
 
 static void unlock_vg(lvmetad_state *s, const char *id) {
+	debug("unlock VG %s\n", 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));
@@ -105,10 +109,13 @@
 		return;
 
 	if (value && !want) {
-		if (pred)
+		if (pred) {
 			pred->next = value->next;
-		if (value == node->v)
+		} else if (value == node->v && value->next) {
 			node->v = value->next;
+		} else {
+			node->v->type = DM_CFG_EMPTY_ARRAY;
+		}
 	}
 
 	if (!value && want) {
@@ -158,30 +165,48 @@
 	return complete;
 }
 
-static response vg_by_uuid(lvmetad_state *s, request r)
+static response vg_lookup(lvmetad_state *s, request r)
 {
-	struct dm_config_tree *cft;
-	struct dm_config_node *metadata;
-	struct dm_config_node *n;
-	response res = { .buffer = NULL };
-	const char *uuid = daemon_request_str(r, "uuid", "NONE");
+	const char *uuid = daemon_request_str(r, "uuid", NULL),
+		   *name = daemon_request_str(r, "name", NULL);
+	debug("vg_lookup: uuid = %s, name = %s\n", uuid, name);
 
-	debug("vg_by_uuid: %s (vgs = %p)\n", uuid, s->vgs);
-	cft = lock_vg(s, uuid);
+	if (!uuid || !name) {
+		lock_vgs(s);
+		if (name && !uuid)
+			uuid = dm_hash_lookup(s->vgname_map, (void *)name);
+		if (uuid && !name)
+			name = dm_hash_lookup(s->vg_names, (void *)uuid);
+		unlock_vgs(s);
+	}
+
+	debug("vg_lookup: updated uuid = %s, name = %s\n", uuid, name);
+
+	if (!uuid)
+		return daemon_reply_simple("failed", "reason = %s", "VG not found", NULL);
+
+	struct dm_config_tree *cft = lock_vg(s, uuid);
 	if (!cft || !cft->root) {
 		unlock_vg(s, uuid);
-		return daemon_reply_simple("failed", "reason = %s", "uuid not found", NULL);
+		return daemon_reply_simple("failed", "reason = %s", "UUID not found", NULL);
 	}
 
-	metadata = cft->root;
+	struct dm_config_node *metadata = cft->root, *n;
+	response res = { .buffer = NULL };
 
 	res.cft = dm_config_create();
 
 	/* The response field */
 	res.cft->root = n = dm_config_create_node(res.cft, "response");
+	n->parent = res.cft->root;
 	n->v->type = DM_CFG_STRING;
 	n->v->v.str = "OK";
 
+	n = n->sib = dm_config_create_node(res.cft, "name");
+	n->parent = res.cft->root;
+	n->v->type = DM_CFG_STRING;
+	n->v->v.str = name;
+
 	/* The metadata section */
 	n = n->sib = dm_config_clone_node(res.cft, metadata, 1);
 	n->parent = res.cft->root;
@@ -256,27 +281,50 @@
 	return 1;
 }
 
+/* A pvid map lock needs to be held. */
+static int remove_metadata(lvmetad_state *s, const char *vgid)
+{
+	lock_vgs(s);
+	struct dm_config_tree *old = dm_hash_lookup(s->vgs, vgid);
+	const char *oldname = dm_hash_lookup(s->vg_names, vgid);
+	unlock_vgs(s);
+
+	if (!old)
+		return 0;
+
+	update_pvid_map(s, old, "#orphan");
+	/* need to update what we have since we found a newer version */
+	dm_hash_remove(s->vgs, vgid);
+	dm_hash_remove(s->vg_names, vgid);
+	dm_hash_remove(s->vgname_map, oldname);
+	dm_config_destroy(old);
+	return 1;
+}
+
 /* No locks need to be held. The pointers are never used outside of the scope of
  * this function, so they can be safely destroyed after update_metadata returns
  * (anything that might have been retained is copied). */
-static int update_metadata(lvmetad_state *s, const char *_vgid, struct dm_config_node *metadata)
+static int update_metadata(lvmetad_state *s, const char *name, const char *_vgid,
+			   struct dm_config_node *metadata)
 {
 	struct dm_config_tree *cft;
 	struct dm_config_tree *old;
-	const char *vgid;
 	int retval = 0;
-	int haveseq = -1;
-	int seq;
 
 	lock_vgs(s);
 	old = dm_hash_lookup(s->vgs, _vgid);
 	lock_vg(s, _vgid);
 	unlock_vgs(s);
 
-	seq = dm_config_find_int(metadata, "metadata/seqno", -1);
+	int seq = dm_config_find_int(metadata, "metadata/seqno", -1);
+	int haveseq = -1;
+	const char *oldname = NULL;
 
-	if (old)
+	if (old) {
 		haveseq = dm_config_find_int(old->root, "metadata/seqno", -1);
+		oldname = dm_hash_lookup(s->vg_names, _vgid);
+		assert(oldname);
+	}
 
 	if (seq < 0)
 		goto out;
@@ -285,10 +333,12 @@
 		retval = 1;
 		if (compare_config(metadata, old->root))
 			retval = 0;
+		debug("Not updating metadata for %s at %d (equal = %d)\n", _vgid, haveseq, retval);
 		goto out;
 	}
 
 	if (seq < haveseq) {
+		debug("Refusing to update metadata for %s at %d to %d\n", _vgid, haveseq, seq);
 		// TODO: we may want to notify the client that their metadata is
 		// out of date?
 		retval = 1;
@@ -297,23 +347,27 @@
 
 	cft = dm_config_create();
 	cft->root = dm_config_clone_node(cft, metadata, 0);
-	vgid = dm_config_find_str(cft->root, "metadata/id", NULL);
 
-	if (!vgid)
+	const char *vgid = dm_config_find_str(cft->root, "metadata/id", NULL);
+
+	if (!vgid || !name) {
+		debug("Name '%s' or uuid '%s' missing!\n", name, vgid);
 		goto out;
+	}
 
 	lock_pvid_map(s);
 
 	if (haveseq >= 0 && haveseq < seq) {
+		debug("Updating metadata for %s at %d to %d\n", _vgid, haveseq, seq);
 		/* temporarily orphan all of our PVs */
-		update_pvid_map(s, old, "#orphan");
-		/* need to update what we have since we found a newer version */
-		dm_config_destroy(old);
-		dm_hash_remove(s->vgs, vgid);
+		remove_metadata(s, vgid);
 	}
 
 	lock_vgs(s);
 	dm_hash_insert(s->vgs, vgid, cft);
+	debug("Mapping %s to %s\n", vgid, name);
+	dm_hash_insert(s->vg_names, vgid, dm_pool_strdup(dm_config_memory(cft), name));
+	dm_hash_insert(s->vgname_map, name, (void *)vgid);
 	unlock_vgs(s);
 
 	update_pvid_map(s, cft, vgid);
@@ -325,17 +379,35 @@
 	return retval;
 }
 
-static response pv_add(lvmetad_state *s, request r)
+static response pv_gone(lvmetad_state *s, request r)
+{
+	int found = 0;
+	const char *pvid = daemon_request_str(r, "uuid", NULL);
+	debug("pv_gone: %s\n", pvid);
+
+	lock_pvs(s);
+	found = dm_hash_lookup(s->pvs, pvid) ? 1 : 0;
+	dm_hash_remove(s->pvs, pvid);
+	unlock_pvs(s);
+
+	if (found)
+		return daemon_reply_simple("OK", NULL);
+	else
+		return daemon_reply_simple("failed", "reason = %s", "PVID does not exist", NULL);
+}
+
+static response pv_found(lvmetad_state *s, request r)
 {
 	struct dm_config_node *metadata = dm_config_find_node(r.cft->root, "metadata");
 	const char *pvid = daemon_request_str(r, "uuid", NULL);
+	const char *vgname = daemon_request_str(r, "vgname", NULL);
 	const char *vgid = daemon_request_str(r, "metadata/id", NULL);
 	int complete = 0;
 
 	if (!pvid)
 		return daemon_reply_simple("failed", "reason = %s", "need PV UUID", NULL);
 
-	debug("pv_add %s, vgid = %s\n", pvid, vgid);
+	debug("pv_found %s, vgid = %s\n", pvid, vgid);
 
 	lock_pvs(s);
 	dm_hash_insert(s->pvs, pvid, (void*)1);
@@ -344,10 +416,12 @@
 	if (metadata) {
 		if (!vgid)
 			return daemon_reply_simple("failed", "reason = %s", "need VG UUID", NULL);
+		if (!vgname)
+			return daemon_reply_simple("failed", "reason = %s", "need VG name", NULL);
 		if (daemon_request_int(r, "metadata/seqno", -1) < 0)
 			return daemon_reply_simple("failed", "reason = %s", "need VG seqno", NULL);
 
-		if (!update_metadata(s, vgid, metadata))
+		if (!update_metadata(s, vgname, vgid, metadata))
 			return daemon_reply_simple("failed", "reason = %s",
 						   "metadata update failed", NULL);
 	} else {
@@ -358,6 +432,10 @@
 
 	if (vgid) {
 		struct dm_config_tree *cft = lock_vg(s, vgid);
+		if (!cft) {
+			unlock_vg(s, vgid);
+			return daemon_reply_simple("failed", "reason = %s", "vg unknown and no PV metadata", NULL);
+		}
 		complete = update_pv_status(s, cft, cft->root, 0);
 		unlock_vg(s, vgid);
 	}
@@ -368,8 +446,40 @@
 				   NULL);
 }
 
-static void pv_del(lvmetad_state *s, request r)
+static response vg_update(lvmetad_state *s, request r)
 {
+	struct dm_config_node *metadata = dm_config_find_node(r.cft->root, "metadata");
+	const char *vgid = daemon_request_str(r, "metadata/id", NULL);
+	const char *vgname = daemon_request_str(r, "vgname", NULL);
+	if (metadata) {
+		if (!vgid)
+			return daemon_reply_simple("failed", "reason = %s", "need VG UUID", NULL);
+		if (!vgname)
+			return daemon_reply_simple("failed", "reason = %s", "need VG name", NULL);
+		if (daemon_request_int(r, "metadata/seqno", -1) < 0)
+			return daemon_reply_simple("failed", "reason = %s", "need VG seqno", NULL);
+
+		if (!update_metadata(s, vgname, vgid, metadata))
+			return daemon_reply_simple("failed", "reason = %s",
+						   "metadata update failed", NULL);
+	}
+	return daemon_reply_simple("OK", NULL);
+}
+
+static response vg_remove(lvmetad_state *s, request r)
+{
+	const char *vgid = daemon_request_str(r, "uuid", NULL);
+
+	if (!vgid)
+		return daemon_reply_simple("failed", "reason = %s", "need VG UUID", NULL);
+
+	fprintf(stderr, "vg_remove: %s\n", vgid);
+
+	lock_pvid_map(s);
+	remove_metadata(s, vgid);
+	unlock_pvid_map(s);
+
+	return daemon_reply_simple("OK", NULL);
 }
 
 static response handler(daemon_state s, client_handle h, request r)
@@ -379,14 +489,22 @@
 
 	debug("REQUEST: %s\n", rq);
 
-	if (!strcmp(rq, "pv_add"))
-		return pv_add(state, r);
-	else if (!strcmp(rq, "pv_del"))
-		pv_del(state, r);
-	else if (!strcmp(rq, "vg_by_uuid"))
-		return vg_by_uuid(state, r);
+	if (!strcmp(rq, "pv_found"))
+		return pv_found(state, r);
 
-	return daemon_reply_simple("OK", NULL);
+	if (!strcmp(rq, "pv_gone"))
+		pv_gone(state, r);
+
+	if (!strcmp(rq, "vg_update"))
+		return vg_update(state, r);
+
+	if (!strcmp(rq, "vg_remove"))
+		return vg_remove(state, r);
+
+	if (!strcmp(rq, "vg_lookup"))
+		return vg_lookup(state, r);
+
+	return daemon_reply_simple("failed", "reason = %s", "no such request", NULL);
 }
 
 static int init(daemon_state *s)
@@ -396,7 +514,9 @@
 
 	ls->pvs = dm_hash_create(32);
 	ls->vgs = dm_hash_create(32);
+	ls->vg_names = dm_hash_create(32);
 	ls->pvid_map = dm_hash_create(32);
+	ls->vgname_map = dm_hash_create(32);
 	ls->lock.vg = dm_hash_create(32);
 	pthread_mutexattr_init(&rec);
 	pthread_mutexattr_settype(&rec, PTHREAD_MUTEX_RECURSIVE_NP);
@@ -466,7 +586,7 @@
 	s.pidfile = "/var/run/lvm/lvmetad.pid";
         s.log_level = 0;
 
-	while ((opt = getopt(argc, argv, "?fhVdR")) != EOF) {
+	while ((opt = getopt(argc, argv, "?fhVdRs:")) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage(argv[0], stdout);
@@ -483,6 +603,9 @@
 		case 'd':
 			s.log_level++;
 			break;
+		case 's':
+			s.socket_path = optarg;
+			break;
 		case 'V':
 			printf("lvmetad version 0\n");
 			exit(1);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-16  8:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-30 15:44 LVM2/daemons/lvmetad lvmetad-client.h lvmetad- mornfall
2012-01-16  8:25 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).