From de2c5ab2ac0100c1d2f0648b9fec5304371a1ae5 Mon Sep 17 00:00:00 2001
From: Petr Rockai <prockai@redhat.com>
Date: Thu, 20 Nov 2014 12:05:09 +0100
Subject: [PATCH] libdm-config: Implement dm_config_remove_node.

---
 libdm/libdevmapper.h |  1 +
 libdm/libdm-config.c | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 3400c2825..895ad48b7 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -1879,6 +1879,7 @@ int dm_config_write_one_node_out(const struct dm_config_node *cn, const struct d
 
 struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn, const char *path);
 int dm_config_has_node(const struct dm_config_node *cn, const char *path);
+int dm_config_remove_node(struct dm_config_node *parent, struct dm_config_node *remove);
 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);
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index 1bc88e15c..e99ae267e 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -1380,3 +1380,20 @@ struct dm_config_tree *dm_config_flatten(struct dm_config_tree *cft)
 
 	return res;
 }
+
+int dm_config_remove_node(struct dm_config_node *parent, struct dm_config_node *remove)
+{
+	struct dm_config_node *cn = parent->child, *last = NULL;
+	while (cn) {
+		if (cn == remove) {
+			if (last)
+				last->sib = cn->sib;
+			else
+				parent->child = cn->sib;
+			return 1;
+		}
+		last = cn;
+		cn = cn->sib;
+	}
+	return 0;
+}