linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/9] mesh: Configuration storage re-org
@ 2019-07-10  5:09 Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 1/9] mesh: Move network config setup from storage.c to node.c Inga Stotland
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This set of patches introduces the notion of generic mesh-config API
that allows the daemon to be agnostic of the underlying node configuration
directory layout and the format of the file(s) in which node configuration
is saved. The only assumption is that the configuration is stored in
<mesh_storage_directory>/<node_uuid> directory.

Currently, the daemon supports only JSON-based configuration format.
It is expected that other configuration formats may be added in future.


Inga Stotland (9):
  mesh: Move network config setup from storage.c to node.c
  mesh: Rename mesh-db.c to mesh-config-json.c
  mesh: Change mesh_db prefix to mesh_config
  mesh: Generalize mesh-config APIs
  mesh: Change variable prefix "jconfig" to "config"
  mesh: Define storage format specific read/write routines
  mesh: Implement config read/write for mesh json format
  mesh: Switch to using mesh-config routines for storage
  mesh: Make storage.c json-c agnostic

 Makefile.mesh                          |   2 +-
 mesh/cfgmod-server.c                   |  27 +-
 mesh/{mesh-db.c => mesh-config-json.c} | 515 ++++++++++++++++++-------
 mesh/mesh-config.h                     | 161 ++++++++
 mesh/mesh-db.h                         | 157 --------
 mesh/mesh.c                            |  11 +-
 mesh/model.c                           |   7 +-
 mesh/node.c                            |  83 ++--
 mesh/node.h                            |   4 +-
 mesh/storage.c                         | 385 +++++++-----------
 10 files changed, 745 insertions(+), 607 deletions(-)
 rename mesh/{mesh-db.c => mesh-config-json.c} (73%)
 create mode 100644 mesh/mesh-config.h
 delete mode 100644 mesh/mesh-db.h

-- 
2.21.0


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

* [PATCH BlueZ 1/9] mesh: Move network config setup from storage.c to node.c
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 2/9] mesh: Rename mesh-db.c to mesh-config-json.c Inga Stotland
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This commit moves initialization of configuration parameters
for node->net when the local node state is restored from stored
configuration. Old location: storage.c, new locaiton node.c.
---
 mesh/node.c    | 28 ++++++++++++++++++++++++++++
 mesh/storage.c | 39 ---------------------------------------
 2 files changed, 28 insertions(+), 39 deletions(-)

diff --git a/mesh/node.c b/mesh/node.c
index 1f781cfe9..a2d95dacf 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -375,6 +375,7 @@ bool node_init_from_storage(struct mesh_node *node, void *data)
 {
 	struct mesh_db_node *db_node = data;
 	unsigned int num_ele;
+	uint8_t mode;
 
 	node->comp = l_new(struct node_composition, 1);
 	node->comp->cid = db_node->cid;
@@ -407,6 +408,33 @@ bool node_init_from_storage(struct mesh_node *node, void *data)
 
 	node->primary = db_node->unicast;
 
+	mesh_net_set_seq_num(node->net, node->seq_number);
+	mesh_net_set_default_ttl(node->net, node->ttl);
+
+	mode = node->proxy;
+	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+		mesh_net_set_proxy_mode(node->net, mode == MESH_MODE_ENABLED);
+
+	mode = node->lpn;
+	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+		mesh_net_set_friend_mode(node->net, mode == MESH_MODE_ENABLED);
+
+	mode = node->relay.mode;
+	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+		mesh_net_set_relay_mode(node->net, mode == MESH_MODE_ENABLED,
+					node->relay.cnt, node->relay.interval);
+
+	mode = node->beacon;
+	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
+		mesh_net_set_beacon_mode(node->net, mode == MESH_MODE_ENABLED);
+
+	if (!IS_UNASSIGNED(node->primary) &&
+		!mesh_net_register_unicast(node->net, node->primary, num_ele))
+		return false;
+
+	if (node->uuid)
+		mesh_net_id_uuid_set(node->net, node->uuid);
+
 	/* Initialize configuration server model */
 	mesh_config_srv_init(node, PRIMARY_ELE_IDX);
 
diff --git a/mesh/storage.c b/mesh/storage.c
index 0f2b77fde..2b7804242 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -56,51 +56,12 @@ static const char *storage_dir;
 static bool read_node_cb(struct mesh_db_node *db_node, void *user_data)
 {
 	struct mesh_node *node = user_data;
-	struct mesh_net *net;
-	uint32_t seq_number;
-	uint8_t ttl, mode, cnt, num_ele;
-	uint16_t unicast, interval;
-	uint8_t *uuid;
 
 	if (!node_init_from_storage(node, db_node)) {
 		node_remove(node);
 		return false;
 	}
 
-	net = node_get_net(node);
-	seq_number = node_get_sequence_number(node);
-	mesh_net_set_seq_num(net, seq_number);
-	ttl = node_default_ttl_get(node);
-	mesh_net_set_default_ttl(net, ttl);
-
-	mode = node_proxy_mode_get(node);
-	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-		mesh_net_set_proxy_mode(net, mode == MESH_MODE_ENABLED);
-
-	mode = node_friend_mode_get(node);
-	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-		mesh_net_set_friend_mode(net, mode == MESH_MODE_ENABLED);
-
-	mode = node_relay_mode_get(node, &cnt, &interval);
-	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-		mesh_net_set_relay_mode(net, mode == MESH_MODE_ENABLED, cnt,
-								interval);
-
-	mode = node_beacon_mode_get(node);
-	if (mode == MESH_MODE_ENABLED || mode == MESH_MODE_DISABLED)
-		mesh_net_set_beacon_mode(net, mode == MESH_MODE_ENABLED);
-
-	unicast = db_node->unicast;
-	num_ele = node_get_num_elements(node);
-
-	if (!IS_UNASSIGNED(unicast) &&
-		!mesh_net_register_unicast(net, unicast, num_ele))
-		return false;
-
-	uuid = node_uuid_get(node);
-	if (uuid)
-		mesh_net_id_uuid_set(net, uuid);
-
 	return true;
 }
 
-- 
2.21.0


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

* [PATCH BlueZ 2/9] mesh: Rename mesh-db.c to mesh-config-json.c
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 1/9] mesh: Move network config setup from storage.c to node.c Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 3/9] mesh: Change mesh_db prefix to mesh_config Inga Stotland
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This moves mesh-db.h to mesh-config.h and mesh-db.c to mesh-config-json.c.
mesh-config.h declares common APIs for storing mesh node configuration.
mesh-config-json.c defines the APIs for JSOn specific storage.
This allows for future parallel implementation a different (not JSON-based)
mechanism of storing node configuration.
---
 Makefile.mesh                          | 2 +-
 mesh/cfgmod-server.c                   | 3 +--
 mesh/{mesh-db.c => mesh-config-json.c} | 3 +--
 mesh/{mesh-db.h => mesh-config.h}      | 0
 mesh/model.c                           | 2 +-
 mesh/node.c                            | 2 +-
 mesh/storage.c                         | 3 +--
 7 files changed, 6 insertions(+), 9 deletions(-)
 rename mesh/{mesh-db.c => mesh-config-json.c} (99%)
 rename mesh/{mesh-db.h => mesh-config.h} (100%)

diff --git a/Makefile.mesh b/Makefile.mesh
index 1ace507af..502ba2a47 100644
--- a/Makefile.mesh
+++ b/Makefile.mesh
@@ -25,7 +25,7 @@ mesh_sources = mesh/mesh.h mesh/mesh.c \
 				mesh/provision.h mesh/prov.h \
 				mesh/model.h mesh/model.c \
 				mesh/cfgmod.h mesh/cfgmod-server.c \
-				mesh/mesh-db.h mesh/mesh-db.c \
+				mesh/mesh-config.h mesh/mesh-config-json.c \
 				mesh/util.h mesh/util.c \
 				mesh/dbus.h mesh/dbus.c \
 				mesh/agent.h mesh/agent.c \
diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index a19ddc72e..486c87307 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -32,8 +32,7 @@
 #include "mesh/appkey.h"
 #include "mesh/model.h"
 #include "mesh/storage.h"
-#include "mesh/mesh-db.h"
-
+#include "mesh/mesh-config.h"
 #include "mesh/cfgmod.h"
 
 #define CFG_MAX_MSG_LEN 380
diff --git a/mesh/mesh-db.c b/mesh/mesh-config-json.c
similarity index 99%
rename from mesh/mesh-db.c
rename to mesh/mesh-config-json.c
index e0a000261..35d0bd27e 100644
--- a/mesh/mesh-db.c
+++ b/mesh/mesh-config-json.c
@@ -31,8 +31,7 @@
 
 #include "mesh/mesh-defs.h"
 #include "mesh/util.h"
-
-#include "mesh/mesh-db.h"
+#include "mesh/mesh-config.h"
 
 #define CHECK_KEY_IDX_RANGE(x) (((x) >= 0) && ((x) <= 4095))
 
diff --git a/mesh/mesh-db.h b/mesh/mesh-config.h
similarity index 100%
rename from mesh/mesh-db.h
rename to mesh/mesh-config.h
diff --git a/mesh/model.c b/mesh/model.c
index e08f95b71..0474762e0 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -30,7 +30,7 @@
 #include "mesh/mesh.h"
 #include "mesh/crypto.h"
 #include "mesh/node.h"
-#include "mesh/mesh-db.h"
+#include "mesh/mesh-config.h"
 #include "mesh/net.h"
 #include "mesh/appkey.h"
 #include "mesh/cfgmod.h"
diff --git a/mesh/node.c b/mesh/node.c
index a2d95dacf..06e809706 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -31,7 +31,7 @@
 #include "mesh/mesh-defs.h"
 #include "mesh/mesh.h"
 #include "mesh/net.h"
-#include "mesh/mesh-db.h"
+#include "mesh/mesh-config.h"
 #include "mesh/provision.h"
 #include "mesh/storage.h"
 #include "mesh/keyring.h"
diff --git a/mesh/storage.c b/mesh/storage.c
index 2b7804242..bba2ef348 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -22,7 +22,6 @@
 #endif
 
 #define _GNU_SOURCE
-//#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -37,7 +36,7 @@
 #include "mesh/node.h"
 #include "mesh/net.h"
 #include "mesh/appkey.h"
-#include "mesh/mesh-db.h"
+#include "mesh/mesh-config.h"
 #include "mesh/util.h"
 #include "mesh/storage.h"
 
-- 
2.21.0


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

* [PATCH BlueZ 3/9] mesh: Change mesh_db prefix to mesh_config
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 1/9] mesh: Move network config setup from storage.c to node.c Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 2/9] mesh: Rename mesh-db.c to mesh-config-json.c Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs Inga Stotland
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This changes the naming the API declarations in mesh-config.h:
mesh_db_... ->mesh_config_...
---
 mesh/cfgmod-server.c    |  20 ++--
 mesh/mesh-config-json.c | 213 +++++++++++++++++++++-------------------
 mesh/mesh-config.h      | 122 ++++++++++++-----------
 mesh/model.c            |   4 +-
 mesh/node.c             |  36 +++----
 mesh/storage.c          |  54 +++++-----
 6 files changed, 234 insertions(+), 215 deletions(-)

diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 486c87307..0479a9185 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -197,14 +197,14 @@ static bool config_pub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 
 		/* Remove model publication from config file */
 		if (status == MESH_STATUS_SUCCESS)
-			mesh_db_model_pub_del(node_jconfig_get(node), ele_addr,
-					vendor ? mod_id : mod_id & 0x0000ffff,
-					vendor);
+			mesh_config_model_pub_del(node_jconfig_get(node),
+				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
+									vendor);
 		goto done;
 	}
 
 	if (status == MESH_STATUS_SUCCESS) {
-		struct mesh_db_pub db_pub = {
+		struct mesh_config_pub db_pub = {
 			.virt = b_virt,
 			.addr = ota,
 			.idx = idx,
@@ -219,7 +219,7 @@ static bool config_pub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 			memcpy(db_pub.virt_addr, pub_addr, 16);
 
 		/* Save model publication to config file */
-		if (!mesh_db_model_pub_add(node_jconfig_get(node), ele_addr,
+		if (!mesh_config_model_pub_add(node_jconfig_get(node), ele_addr,
 					vendor ? mod_id : mod_id & 0x0000ffff,
 					vendor, &db_pub))
 			status = MESH_STATUS_STORAGE_FAIL;
@@ -321,7 +321,7 @@ static bool save_config_sub(struct mesh_node *node, uint16_t ele_addr,
 					const uint8_t *addr, bool virt,
 					uint16_t grp, uint32_t opcode)
 {
-	struct mesh_db_sub db_sub = {
+	struct mesh_config_sub db_sub = {
 				.virt = virt,
 				.src.addr = grp
 				};
@@ -331,18 +331,18 @@ static bool save_config_sub(struct mesh_node *node, uint16_t ele_addr,
 
 	if (opcode == OP_CONFIG_MODEL_SUB_VIRT_OVERWRITE ||
 					opcode == OP_CONFIG_MODEL_SUB_OVERWRITE)
-		mesh_db_model_sub_del_all(node_jconfig_get(node),
+		mesh_config_model_sub_del_all(node_jconfig_get(node),
 				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
 									vendor);
 
 	if (opcode != OP_CONFIG_MODEL_SUB_VIRT_DELETE &&
 			opcode != OP_CONFIG_MODEL_SUB_DELETE)
-		return mesh_db_model_sub_add(node_jconfig_get(node),
+		return mesh_config_model_sub_add(node_jconfig_get(node),
 					ele_addr,
 					vendor ? mod_id : mod_id & 0x0000ffff,
 					vendor, &db_sub);
 	else
-		return mesh_db_model_sub_del(node_jconfig_get(node),
+		return mesh_config_model_sub_del(node_jconfig_get(node),
 					ele_addr,
 					vendor ? mod_id : mod_id & 0x0000ffff,
 					vendor, &db_sub);
@@ -419,7 +419,7 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 		status = mesh_model_sub_del_all(node, ele_addr, mod_id);
 
 		if (status == MESH_STATUS_SUCCESS)
-			mesh_db_model_sub_del_all(node_jconfig_get(node),
+			mesh_config_model_sub_del_all(node_jconfig_get(node),
 				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
 									vendor);
 		break;
diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 35d0bd27e..8fcb8afe3 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -252,7 +252,7 @@ static json_object *jarray_key_del(json_object *jarray, int16_t idx)
 	return jarray_new;
 }
 
-bool mesh_db_read_iv_index(json_object *jobj, uint32_t *idx, bool *update)
+bool mesh_config_read_iv_index(json_object *jobj, uint32_t *idx, bool *update)
 {
 	int tmp;
 
@@ -270,7 +270,7 @@ bool mesh_db_read_iv_index(json_object *jobj, uint32_t *idx, bool *update)
 	return true;
 }
 
-bool mesh_db_read_token(json_object *jobj, uint8_t token[8])
+bool mesh_config_read_token(json_object *jobj, uint8_t token[8])
 {
 	json_object *jvalue;
 	char *str;
@@ -288,7 +288,7 @@ bool mesh_db_read_token(json_object *jobj, uint8_t token[8])
 	return true;
 }
 
-bool mesh_db_read_device_key(json_object *jobj, uint8_t key_buf[16])
+bool mesh_config_read_device_key(json_object *jobj, uint8_t key_buf[16])
 {
 	json_object *jvalue;
 	char *str;
@@ -306,7 +306,7 @@ bool mesh_db_read_device_key(json_object *jobj, uint8_t key_buf[16])
 	return true;
 }
 
-bool mesh_db_read_app_keys(json_object *jobj, mesh_db_app_key_cb cb,
+bool mesh_config_read_app_keys(json_object *jobj, mesh_config_app_key_cb cb,
 							void *user_data)
 {
 	json_object *jarray;
@@ -368,7 +368,7 @@ bool mesh_db_read_app_keys(json_object *jobj, mesh_db_app_key_cb cb,
 	return true;
 }
 
-bool mesh_db_read_net_keys(json_object *jobj, mesh_db_net_key_cb cb,
+bool mesh_config_read_net_keys(json_object *jobj, mesh_config_net_key_cb cb,
 								void *user_data)
 {
 	json_object *jarray;
@@ -431,7 +431,7 @@ bool mesh_db_read_net_keys(json_object *jobj, mesh_db_net_key_cb cb,
 	return true;
 }
 
-bool mesh_db_net_key_add(json_object *jobj, uint16_t idx,
+bool mesh_config_net_key_add(json_object *jobj, uint16_t idx,
 							const uint8_t key[16])
 {
 	json_object *jarray = NULL, *jentry = NULL, *jstring;
@@ -479,7 +479,7 @@ fail:
 	return false;
 }
 
-bool mesh_db_net_key_update(json_object *jobj, uint16_t idx,
+bool mesh_config_net_key_update(json_object *jobj, uint16_t idx,
 							const uint8_t key[16])
 {
 	json_object *jarray, *jentry, *jstring;
@@ -510,7 +510,7 @@ bool mesh_db_net_key_update(json_object *jobj, uint16_t idx,
 	return true;
 }
 
-bool mesh_db_net_key_del(json_object *jobj, uint16_t idx)
+bool mesh_config_net_key_del(json_object *jobj, uint16_t idx)
 {
 	json_object *jarray, *jarray_new;
 
@@ -541,18 +541,18 @@ bool mesh_db_net_key_del(json_object *jobj, uint16_t idx)
 	return true;
 }
 
-bool mesh_db_write_device_key(json_object *jnode, uint8_t *key)
+bool mesh_config_write_device_key(json_object *jnode, uint8_t *key)
 {
 	return add_key_value(jnode, "deviceKey", key);
 }
 
-bool mesh_db_write_token(json_object *jnode, uint8_t *token)
+bool mesh_config_write_token(json_object *jnode, uint8_t *token)
 {
 	return add_u64_value(jnode, "token", token);
 }
 
-bool mesh_db_app_key_add(json_object *jobj, uint16_t net_idx, uint16_t app_idx,
-							const uint8_t key[16])
+bool mesh_config_app_key_add(json_object *jobj, uint16_t net_idx,
+					uint16_t app_idx, const uint8_t key[16])
 {
 	json_object *jarray = NULL, *jentry = NULL, *jstring = NULL;
 	char buf[5];
@@ -604,7 +604,7 @@ fail:
 	return false;
 }
 
-bool mesh_db_app_key_update(json_object *jobj, uint16_t app_idx,
+bool mesh_config_app_key_update(json_object *jobj, uint16_t app_idx,
 							const uint8_t key[16])
 {
 	json_object *jarray, *jentry = NULL, *jstring = NULL;
@@ -629,7 +629,7 @@ bool mesh_db_app_key_update(json_object *jobj, uint16_t app_idx,
 	return add_key_value(jentry, "key", key);
 }
 
-bool mesh_db_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx)
+bool mesh_config_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx)
 {
 	json_object *jarray, *jarray_new;
 
@@ -660,8 +660,9 @@ bool mesh_db_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx)
 	return true;
 }
 
-bool mesh_db_model_binding_add(json_object *jnode, uint8_t ele_idx, bool vendor,
-				uint32_t mod_id, uint16_t app_idx)
+bool mesh_config_model_binding_add(json_object *jnode, uint8_t ele_idx,
+					bool vendor, uint32_t mod_id,
+							uint16_t app_idx)
 {
 	json_object *jmodel, *jstring, *jarray = NULL;
 	char buf[5];
@@ -694,8 +695,9 @@ bool mesh_db_model_binding_add(json_object *jnode, uint8_t ele_idx, bool vendor,
 	return true;
 }
 
-bool mesh_db_model_binding_del(json_object *jnode, uint8_t ele_idx, bool vendor,
-				uint32_t mod_id, uint16_t app_idx)
+bool mesh_config_model_binding_del(json_object *jnode, uint8_t ele_idx,
+					bool vendor, uint32_t mod_id,
+							uint16_t app_idx)
 {
 	json_object *jmodel, *jarray, *jarray_new;
 	char buf[5];
@@ -734,7 +736,7 @@ bool mesh_db_model_binding_del(json_object *jnode, uint8_t ele_idx, bool vendor,
 
 static void free_model(void *data)
 {
-	struct mesh_db_model *mod = data;
+	struct mesh_config_model *mod = data;
 
 	l_free(mod->bindings);
 	l_free(mod->subs);
@@ -744,18 +746,18 @@ static void free_model(void *data)
 
 static void free_element(void *data)
 {
-	struct mesh_db_element *ele = data;
+	struct mesh_config_element *ele = data;
 
 	l_queue_destroy(ele->models, free_model);
 	l_free(ele);
 }
 
-static bool parse_bindings(json_object *jbindings, struct mesh_db_model *mod)
+static bool parse_bindings(json_object *jarray, struct mesh_config_model *mod)
 {
 	int cnt;
 	int i;
 
-	cnt = json_object_array_length(jbindings);
+	cnt = json_object_array_length(jarray);
 	if (cnt > 0xffff)
 		return false;
 
@@ -771,7 +773,7 @@ static bool parse_bindings(json_object *jbindings, struct mesh_db_model *mod)
 		int idx;
 		json_object *jvalue;
 
-		jvalue = json_object_array_get_idx(jbindings, i);
+		jvalue = json_object_array_get_idx(jarray, i);
 		if (!jvalue)
 			return false;
 
@@ -800,10 +802,10 @@ static bool get_key_index(json_object *jobj, const char *keyword,
 	return true;
 }
 
-static struct mesh_db_pub *parse_model_publication(json_object *jpub)
+static struct mesh_config_pub *parse_model_publication(json_object *jpub)
 {
 	json_object *jvalue;
-	struct mesh_db_pub *pub;
+	struct mesh_config_pub *pub;
 	int len, value;
 	char *str;
 
@@ -812,7 +814,7 @@ static struct mesh_db_pub *parse_model_publication(json_object *jpub)
 
 	str = (char *)json_object_get_string(jvalue);
 	len = strlen(str);
-	pub = l_new(struct mesh_db_pub, 1);
+	pub = l_new(struct mesh_config_pub, 1);
 
 	switch (len) {
 	case 4:
@@ -862,9 +864,9 @@ fail:
 }
 
 static bool parse_model_subscriptions(json_object *jsubs,
-						struct mesh_db_model *mod)
+						struct mesh_config_model *mod)
 {
-	struct mesh_db_sub *subs;
+	struct mesh_config_sub *subs;
 	int i, cnt;
 
 	if (json_object_get_type(jsubs) != json_type_array)
@@ -875,7 +877,7 @@ static bool parse_model_subscriptions(json_object *jsubs,
 	if (!cnt)
 		return true;
 
-	subs = l_new(struct mesh_db_sub, cnt);
+	subs = l_new(struct mesh_config_sub, cnt);
 
 	for (i = 0; i < cnt; ++i) {
 		char *str;
@@ -913,7 +915,7 @@ fail:
 	return false;
 }
 
-static bool parse_models(json_object *jmodels, struct mesh_db_element *ele)
+static bool parse_models(json_object *jmodels, struct mesh_config_element *ele)
 {
 	int i, num_models;
 
@@ -923,7 +925,7 @@ static bool parse_models(json_object *jmodels, struct mesh_db_element *ele)
 
 	for (i = 0; i < num_models; ++i) {
 		json_object *jmodel, *jarray, *jvalue;
-		struct mesh_db_model *mod;
+		struct mesh_config_model *mod;
 		uint32_t id;
 		int len;
 		char *str;
@@ -932,7 +934,7 @@ static bool parse_models(json_object *jmodels, struct mesh_db_element *ele)
 		if (!jmodel)
 			goto fail;
 
-		mod = l_new(struct mesh_db_model, 1);
+		mod = l_new(struct mesh_config_model, 1);
 
 		if (!json_object_object_get_ex(jmodel, "modelId", &jvalue))
 			goto fail;
@@ -987,14 +989,14 @@ fail:
 	return false;
 }
 
-static bool parse_elements(json_object *jelements, struct mesh_db_node *node)
+static bool parse_elements(json_object *jelems, struct mesh_config_node *node)
 {
 	int i, num_ele;
 
-	if (json_object_get_type(jelements) != json_type_array)
+	if (json_object_get_type(jelems) != json_type_array)
 		return false;
 
-	num_ele = json_object_array_length(jelements);
+	num_ele = json_object_array_length(jelems);
 	if (!num_ele)
 		/* Allow "empty" nodes */
 		return true;
@@ -1005,11 +1007,11 @@ static bool parse_elements(json_object *jelements, struct mesh_db_node *node)
 		json_object *jelement;
 		json_object *jmodels;
 		json_object *jvalue;
-		struct mesh_db_element *ele;
+		struct mesh_config_element *ele;
 		int index;
 		char *str;
 
-		jelement = json_object_array_get_idx(jelements, i);
+		jelement = json_object_array_get_idx(jelems, i);
 		if (!jelement)
 			goto fail;
 
@@ -1017,7 +1019,7 @@ static bool parse_elements(json_object *jelements, struct mesh_db_node *node)
 								index > num_ele)
 			goto fail;
 
-		ele = l_new(struct mesh_db_element, 1);
+		ele = l_new(struct mesh_config_element, 1);
 		ele->index = index;
 		ele->models = l_queue_new();
 
@@ -1066,7 +1068,7 @@ static int get_mode(json_object *jvalue)
 	return 0xffffffff;
 }
 
-static void parse_features(json_object *jconfig, struct mesh_db_node *node)
+static void parse_features(json_object *jconfig, struct mesh_config_node *node)
 {
 	json_object *jvalue, *jrelay;
 	int mode, count;
@@ -1123,7 +1125,7 @@ static void parse_features(json_object *jconfig, struct mesh_db_node *node)
 	node->modes.relay.interval = interval;
 }
 
-static bool parse_composition(json_object *jcomp, struct mesh_db_node *node)
+static bool parse_composition(json_object *jcomp, struct mesh_config_node *node)
 {
 	json_object *jvalue;
 	char *str;
@@ -1160,9 +1162,10 @@ static bool parse_composition(json_object *jcomp, struct mesh_db_node *node)
 	return true;
 }
 
-bool mesh_db_read_node(json_object *jnode, mesh_db_node_cb cb, void *user_data)
+bool mesh_config_read_node(json_object *jnode, mesh_config_node_cb cb,
+							void *user_data)
 {
-	struct mesh_db_node node;
+	struct mesh_config_node node;
 	json_object *jvalue;
 	char *str;
 
@@ -1213,7 +1216,7 @@ bool mesh_db_read_node(json_object *jnode, mesh_db_node_cb cb, void *user_data)
 	return cb(&node, user_data);
 }
 
-bool mesh_db_write_uint16_hex(json_object *jobj, const char *desc,
+bool mesh_config_write_uint16_hex(json_object *jobj, const char *desc,
 								uint16_t value)
 {
 	json_object *jstring;
@@ -1231,7 +1234,7 @@ bool mesh_db_write_uint16_hex(json_object *jobj, const char *desc,
 	return true;
 }
 
-bool mesh_db_write_uint32_hex(json_object *jobj, const char *desc,
+bool mesh_config_write_uint32_hex(json_object *jobj, const char *desc,
 								uint32_t value)
 {
 	json_object *jstring;
@@ -1249,7 +1252,7 @@ bool mesh_db_write_uint32_hex(json_object *jobj, const char *desc,
 	return true;
 }
 
-bool mesh_db_write_int(json_object *jobj, const char *keyword, int value)
+bool mesh_config_write_int(json_object *jobj, const char *keyword, int value)
 {
 	json_object *jvalue;
 
@@ -1266,7 +1269,7 @@ bool mesh_db_write_int(json_object *jobj, const char *keyword, int value)
 	return true;
 }
 
-bool mesh_db_write_bool(json_object *jobj, const char *keyword, bool value)
+bool mesh_config_write_bool(json_object *jobj, const char *keyword, bool value)
 {
 	json_object *jvalue;
 
@@ -1295,7 +1298,7 @@ static const char *mode_to_string(int mode)
 	}
 }
 
-bool mesh_db_write_mode(json_object *jobj, const char *keyword, int value)
+bool mesh_config_write_mode(json_object *jobj, const char *keyword, int value)
 {
 	json_object *jstring;
 
@@ -1312,8 +1315,8 @@ bool mesh_db_write_mode(json_object *jobj, const char *keyword, int value)
 	return true;
 }
 
-bool mesh_db_write_relay_mode(json_object *jnode, uint8_t mode, uint8_t count,
-							uint16_t interval)
+bool mesh_config_write_relay_mode(json_object *jnode, uint8_t mode,
+					uint8_t count, uint16_t interval)
 {
 	json_object *jrelay;
 
@@ -1326,13 +1329,13 @@ bool mesh_db_write_relay_mode(json_object *jnode, uint8_t mode, uint8_t count,
 	if (!jrelay)
 		return false;
 
-	if (!mesh_db_write_mode(jrelay, "mode", mode))
+	if (!mesh_config_write_mode(jrelay, "mode", mode))
 		goto fail;
 
-	if (!mesh_db_write_int(jrelay, "count", count))
+	if (!mesh_config_write_int(jrelay, "count", count))
 		goto fail;
 
-	if (!mesh_db_write_int(jrelay, "interval", interval))
+	if (!mesh_config_write_int(jrelay, "interval", interval))
 		goto fail;
 
 	json_object_object_add(jnode, "relay", jrelay);
@@ -1343,7 +1346,7 @@ fail:
 	return false;
 }
 
-bool mesh_db_read_net_transmit(json_object *jobj, uint8_t *cnt,
+bool mesh_config_read_net_transmit(json_object *jobj, uint8_t *cnt,
 							uint16_t *interval)
 {
 	json_object *jretransmit, *jvalue;
@@ -1367,7 +1370,7 @@ bool mesh_db_read_net_transmit(json_object *jobj, uint8_t *cnt,
 	return true;
 }
 
-bool mesh_db_write_net_transmit(json_object *jobj, uint8_t cnt,
+bool mesh_config_write_net_transmit(json_object *jobj, uint8_t cnt,
 							uint16_t interval)
 {
 	json_object *jretransmit;
@@ -1381,10 +1384,10 @@ bool mesh_db_write_net_transmit(json_object *jobj, uint8_t cnt,
 	if (jretransmit)
 		return false;
 
-	if (!mesh_db_write_int(jretransmit, "count", cnt))
+	if (!mesh_config_write_int(jretransmit, "count", cnt))
 		goto fail;
 
-	if (!mesh_db_write_int(jretransmit, "interval", interval))
+	if (!mesh_config_write_int(jretransmit, "interval", interval))
 		goto fail;
 
 	json_object_object_add(jobj, "retransmit", jretransmit);
@@ -1396,23 +1399,23 @@ fail:
 
 }
 
-bool mesh_db_write_iv_index(json_object *jobj, uint32_t idx, bool update)
+bool mesh_config_write_iv_index(json_object *jobj, uint32_t idx, bool update)
 {
 	int tmp = update ? 1 : 0;
 
 	if (!jobj)
 		return false;
 
-	if (!mesh_db_write_int(jobj, "IVindex", idx))
+	if (!mesh_config_write_int(jobj, "IVindex", idx))
 		return false;
 
-	if (!mesh_db_write_int(jobj, "IVupdate", tmp))
+	if (!mesh_config_write_int(jobj, "IVupdate", tmp))
 		return false;
 
 	return true;
 }
 
-void mesh_db_remove_property(json_object *jobj, const char *desc)
+void mesh_config_remove_property(json_object *jobj, const char *desc)
 {
 	if (jobj)
 		json_object_object_del(jobj, desc);
@@ -1420,7 +1423,7 @@ void mesh_db_remove_property(json_object *jobj, const char *desc)
 
 static void add_model(void *a, void *b)
 {
-	struct mesh_db_model *mod = a;
+	struct mesh_config_model *mod = a;
 	json_object *jmodels = b, *jmodel;
 
 	jmodel = json_object_new_object();
@@ -1428,54 +1431,54 @@ static void add_model(void *a, void *b)
 		return;
 
 	if (!mod->vendor)
-		mesh_db_write_uint16_hex(jmodel, "modelId",
+		mesh_config_write_uint16_hex(jmodel, "modelId",
 						(uint16_t) mod->id);
 	else
-		mesh_db_write_uint32_hex(jmodel, "modelId", mod->id);
+		mesh_config_write_uint32_hex(jmodel, "modelId", mod->id);
 
 	json_object_array_add(jmodels, jmodel);
 }
 
 /* Add unprovisioned node (local) */
-bool mesh_db_add_node(json_object *jnode, struct mesh_db_node *node) {
-
-	struct mesh_db_modes *modes = &node->modes;
+bool mesh_config_add_node(json_object *jnode, struct mesh_config_node *node)
+{
+	struct mesh_config_modes *modes = &node->modes;
 	const struct l_queue_entry *entry;
-	json_object *jelements;
+	json_object *jelems;
 
 	if (!jnode)
 		return false;
 
 	/* CID, PID, VID, crpl */
-	if (!mesh_db_write_uint16_hex(jnode, "cid", node->cid))
+	if (!mesh_config_write_uint16_hex(jnode, "cid", node->cid))
 		return false;
 
-	if (!mesh_db_write_uint16_hex(jnode, "pid", node->pid))
+	if (!mesh_config_write_uint16_hex(jnode, "pid", node->pid))
 		return false;
 
-	if (!mesh_db_write_uint16_hex(jnode, "vid", node->vid))
+	if (!mesh_config_write_uint16_hex(jnode, "vid", node->vid))
 		return false;
 
-	if (!mesh_db_write_uint16_hex(jnode, "crpl", node->crpl))
+	if (!mesh_config_write_uint16_hex(jnode, "crpl", node->crpl))
 		return false;
 
 	/* Features: relay, LPN, friend, proxy*/
-	if (!mesh_db_write_relay_mode(jnode, modes->relay.state,
+	if (!mesh_config_write_relay_mode(jnode, modes->relay.state,
 						modes->relay.cnt,
 						modes->relay.interval))
 		return false;
 
-	if (!mesh_db_write_mode(jnode, "lowPower", modes->lpn))
+	if (!mesh_config_write_mode(jnode, "lowPower", modes->lpn))
 		return false;
 
-	if (!mesh_db_write_mode(jnode, "friend", modes->friend))
+	if (!mesh_config_write_mode(jnode, "friend", modes->friend))
 		return false;
 
-	if (!mesh_db_write_mode(jnode, "proxy", modes->proxy))
+	if (!mesh_config_write_mode(jnode, "proxy", modes->proxy))
 		return false;
 
 	/* Beaconing state */
-	if (!mesh_db_write_mode(jnode, "beacon", modes->beacon))
+	if (!mesh_config_write_mode(jnode, "beacon", modes->beacon))
 		return false;
 
 	/* Sequence number */
@@ -1487,26 +1490,27 @@ bool mesh_db_add_node(json_object *jnode, struct mesh_db_node *node) {
 						json_object_new_int(node->ttl));
 
 	/* Elements */
-	jelements = json_object_new_array();
-	if (!jelements)
+	jelems = json_object_new_array();
+	if (!jelems)
 		return false;
 
 	entry = l_queue_get_entries(node->elements);
 
 	for (; entry; entry = entry->next) {
-		struct mesh_db_element *ele = entry->data;
+		struct mesh_config_element *ele = entry->data;
 		json_object *jelement, *jmodels;
 
 		jelement = json_object_new_object();
 
 		if (!jelement) {
-			json_object_put(jelements);
+			json_object_put(jelems);
 			return false;
 		}
 
-		mesh_db_write_int(jelement, "elementIndex", ele->index);
-		mesh_db_write_uint16_hex(jelement, "location", ele->location);
-		json_object_array_add(jelements, jelement);
+		mesh_config_write_int(jelement, "elementIndex", ele->index);
+		mesh_config_write_uint16_hex(jelement, "location",
+								ele->location);
+		json_object_array_add(jelems, jelement);
 
 		/* Models */
 		if (l_queue_isempty(ele->models))
@@ -1514,7 +1518,7 @@ bool mesh_db_add_node(json_object *jnode, struct mesh_db_node *node) {
 
 		jmodels = json_object_new_array();
 		if (!jmodels) {
-			json_object_put(jelements);
+			json_object_put(jelems);
 			return false;
 		}
 
@@ -1522,7 +1526,7 @@ bool mesh_db_add_node(json_object *jnode, struct mesh_db_node *node) {
 		l_queue_foreach(ele->models, add_model, jmodels);
 	}
 
-	json_object_object_add(jnode, "elements", jelements);
+	json_object_object_add(jnode, "elements", jelems);
 
 	return true;
 }
@@ -1558,7 +1562,8 @@ static void finish_key_refresh(json_object *jobj, uint16_t net_idx)
 
 }
 
-bool mesh_db_net_key_set_phase(json_object *jobj, uint16_t idx, uint8_t phase)
+bool mesh_config_net_key_set_phase(json_object *jobj, uint16_t idx,
+								uint8_t phase)
 {
 	json_object *jarray, *jentry = NULL;
 
@@ -1583,8 +1588,9 @@ bool mesh_db_net_key_set_phase(json_object *jobj, uint16_t idx, uint8_t phase)
 	return true;
 }
 
-bool mesh_db_model_pub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
-					bool vendor, struct mesh_db_pub *pub)
+bool mesh_config_model_pub_add(json_object *jnode, uint16_t addr,
+					uint32_t mod_id, bool vendor,
+					struct mesh_config_pub *pub)
 {
 	json_object *jmodel, *jpub, *jretransmit;
 	bool res;
@@ -1610,31 +1616,32 @@ bool mesh_db_model_pub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
 	if (pub->virt)
 		res = add_key_value(jpub, "address", pub->virt_addr);
 	else
-		res = mesh_db_write_uint16_hex(jpub, "address", pub->addr);
+		res = mesh_config_write_uint16_hex(jpub, "address", pub->addr);
 
 	if (!res)
 		goto fail;
 
-	if (!mesh_db_write_uint16_hex(jpub, "index", pub->idx))
+	if (!mesh_config_write_uint16_hex(jpub, "index", pub->idx))
 		goto fail;
 
-	if (!mesh_db_write_int(jpub, "ttl", pub->ttl))
+	if (!mesh_config_write_int(jpub, "ttl", pub->ttl))
 		goto fail;
 
-	if (!mesh_db_write_int(jpub, "period", pub->period))
+	if (!mesh_config_write_int(jpub, "period", pub->period))
 		goto fail;
 
-	if (!mesh_db_write_int(jpub, "credentials", pub->credential ? 1 : 0))
+	if (!mesh_config_write_int(jpub, "credentials",
+						pub->credential ? 1 : 0))
 		goto fail;
 
 	jretransmit = json_object_new_object();
 	if (!jretransmit)
 		goto fail;
 
-	if (!mesh_db_write_int(jretransmit, "count", pub->count))
+	if (!mesh_config_write_int(jretransmit, "count", pub->count))
 		goto fail;
 
-	if (!mesh_db_write_int(jretransmit, "interval", pub->interval))
+	if (!mesh_config_write_int(jretransmit, "interval", pub->interval))
 		goto fail;
 
 	json_object_object_add(jpub, "retransmit", jretransmit);
@@ -1665,8 +1672,8 @@ static bool delete_model_property(json_object *jnode, uint16_t addr,
 	return true;
 }
 
-bool mesh_db_model_pub_del(json_object *jnode, uint16_t addr, uint32_t mod_id,
-								bool vendor)
+bool mesh_config_model_pub_del(json_object *jnode, uint16_t addr,
+						uint32_t mod_id, bool vendor)
 {
 	if (!jnode)
 		return false;
@@ -1674,8 +1681,9 @@ bool mesh_db_model_pub_del(json_object *jnode, uint16_t addr, uint32_t mod_id,
 	return delete_model_property(jnode, addr, mod_id, vendor, "publish");
 }
 
-bool mesh_db_model_sub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
-					bool vendor, struct mesh_db_sub *sub)
+bool mesh_config_model_sub_add(json_object *jnode, uint16_t addr,
+						uint32_t mod_id, bool vendor,
+						struct mesh_config_sub *sub)
 {
 	json_object *jmodel, *jstring, *jarray = NULL;
 	int ele_idx, len;
@@ -1722,8 +1730,9 @@ bool mesh_db_model_sub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
 	return true;
 }
 
-bool mesh_db_model_sub_del(json_object *jnode, uint16_t addr,
-			uint32_t mod_id, bool vendor, struct mesh_db_sub *sub)
+bool mesh_config_model_sub_del(json_object *jnode, uint16_t addr,
+						uint32_t mod_id, bool vendor,
+						struct mesh_config_sub *sub)
 {
 	json_object *jmodel, *jarray, *jarray_new;
 	char buf[33];
@@ -1774,7 +1783,7 @@ bool mesh_db_model_sub_del(json_object *jnode, uint16_t addr,
 	return true;
 }
 
-bool mesh_db_model_sub_del_all(json_object *jnode, uint16_t addr,
+bool mesh_config_model_sub_del_all(json_object *jnode, uint16_t addr,
 						uint32_t mod_id, bool vendor)
 {
 	if (!jnode)
diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h
index da5efa12a..f60ae18cd 100644
--- a/mesh/mesh-config.h
+++ b/mesh/mesh-config.h
@@ -17,7 +17,7 @@
  *
  */
 
-struct mesh_db_sub {
+struct mesh_config_sub {
 	bool virt;
 	union {
 		uint16_t addr;
@@ -25,7 +25,7 @@ struct mesh_db_sub {
 	} src;
 };
 
-struct mesh_db_pub {
+struct mesh_config_pub {
 	bool virt;
 	uint32_t period;
 	uint16_t addr;
@@ -37,9 +37,9 @@ struct mesh_db_pub {
 	uint8_t virt_addr[16];
 };
 
-struct mesh_db_model {
-	struct mesh_db_sub *subs;
-	struct mesh_db_pub *pub;
+struct mesh_config_model {
+	struct mesh_config_sub *subs;
+	struct mesh_config_pub *pub;
 	uint16_t *bindings;
 	uint32_t id;
 	bool vendor;
@@ -47,13 +47,13 @@ struct mesh_db_model {
 	uint32_t num_subs;
 };
 
-struct mesh_db_element {
+struct mesh_config_element {
 	struct l_queue *models;
 	uint16_t location;
 	uint8_t index;
 };
 
-struct mesh_db_modes {
+struct mesh_config_modes {
 	struct {
 		uint16_t interval;
 		uint8_t cnt;
@@ -65,10 +65,10 @@ struct mesh_db_modes {
 	uint8_t beacon;
 };
 
-struct mesh_db_node {
+struct mesh_config_node {
 	bool provisioner;
 	uint32_t seq_number;
-	struct mesh_db_modes modes;
+	struct mesh_config_modes modes;
 	uint16_t cid;
 	uint16_t pid;
 	uint16_t vid;
@@ -78,7 +78,7 @@ struct mesh_db_node {
 	struct l_queue *elements;
 };
 
-struct mesh_db_prov {
+struct mesh_config_prov {
 	uint16_t algorithm;
 	struct {
 		uint16_t actions;
@@ -93,65 +93,73 @@ struct mesh_db_prov {
 	uint8_t priv_key[32];
 };
 
-typedef bool (*mesh_db_net_key_cb)(uint16_t idx, uint8_t key[16],
+typedef bool (*mesh_config_net_key_cb)(uint16_t idx, uint8_t key[16],
 			uint8_t new_key[16], int phase, void *user_data);
-typedef bool (*mesh_db_app_key_cb)(uint16_t idx, uint16_t net_idx,
+typedef bool (*mesh_config_app_key_cb)(uint16_t idx, uint16_t net_idx,
 			uint8_t key[16], uint8_t new_key[16], void *user_data);
-typedef bool (*mesh_db_node_cb)(struct mesh_db_node *node, void *user_data);
+typedef bool (*mesh_config_node_cb)(struct mesh_config_node *node,
+							void *user_data);
 
-bool mesh_db_read_node(json_object *jobj, mesh_db_node_cb cb, void *user_data);
-bool mesh_db_add_node(json_object *jnode, struct mesh_db_node *node);
-bool mesh_db_read_iv_index(json_object *jobj, uint32_t *idx, bool *update);
-bool mesh_db_read_device_key(json_object *jobj, uint8_t key_buf[16]);
-bool mesh_db_read_token(json_object *jobj, uint8_t token[8]);
-bool mesh_db_read_net_transmit(json_object *jobj, uint8_t *cnt,
+bool mesh_config_read_node(json_object *jobj, mesh_config_node_cb cb,
+							void *user_data);
+bool mesh_config_add_node(json_object *jnode, struct mesh_config_node *node);
+bool mesh_config_read_iv_index(json_object *jobj, uint32_t *idx, bool *update);
+bool mesh_config_read_device_key(json_object *jobj, uint8_t key_buf[16]);
+bool mesh_config_read_token(json_object *jobj, uint8_t token[8]);
+bool mesh_config_read_net_transmit(json_object *jobj, uint8_t *cnt,
 							uint16_t *interval);
-bool mesh_db_write_net_transmit(json_object *jobj, uint8_t cnt,
+bool mesh_config_write_net_transmit(json_object *jobj, uint8_t cnt,
 							uint16_t interval);
-bool mesh_db_read_net_keys(json_object *jobj, mesh_db_net_key_cb cb,
+bool mesh_config_read_net_keys(json_object *jobj, mesh_config_net_key_cb cb,
 							void *user_data);
-bool mesh_db_read_app_keys(json_object *jobj, mesh_db_app_key_cb cb,
+bool mesh_config_read_app_keys(json_object *jobj, mesh_config_app_key_cb cb,
 							void *user_data);
-bool mesh_db_write_device_key(json_object *jobj, uint8_t *key);
-bool mesh_db_write_token(json_object *jobj, uint8_t *token);
-bool mesh_db_write_network_key(json_object *jobj, uint16_t idx, uint8_t *key,
-						uint8_t *new_key, int phase);
-bool mesh_db_write_app_key(json_object *jobj, uint16_t net_idx,
+bool mesh_config_write_device_key(json_object *jobj, uint8_t *key);
+bool mesh_config_write_token(json_object *jobj, uint8_t *token);
+bool mesh_config_write_network_key(json_object *jobj, uint16_t idx,
+				uint8_t *key, uint8_t *new_key, int phase);
+bool mesh_config_write_app_key(json_object *jobj, uint16_t net_idx,
 			uint16_t app_idx, uint8_t *key, uint8_t *new_key);
-bool mesh_db_write_int(json_object *jobj, const char *keyword, int value);
-bool mesh_db_write_uint16_hex(json_object *jobj, const char *desc,
+bool mesh_config_write_int(json_object *jobj, const char *keyword, int value);
+bool mesh_config_write_uint16_hex(json_object *jobj, const char *desc,
 								uint16_t value);
-bool mesh_db_write_uint32_hex(json_object *jobj, const char *desc,
+bool mesh_config_write_uint32_hex(json_object *jobj, const char *desc,
 								uint32_t value);
-bool mesh_db_write_bool(json_object *jobj, const char *keyword, bool value);
-bool mesh_db_write_relay_mode(json_object *jnode, uint8_t mode, uint8_t count,
-							uint16_t interval);
-bool mesh_db_write_mode(json_object *jobj, const char *keyword, int value);
-bool mesh_db_model_binding_add(json_object *jnode, uint8_t ele_idx, bool vendor,
-					uint32_t mod_id, uint16_t app_idx);
-bool mesh_db_model_binding_del(json_object *jnode, uint8_t ele_idx, bool vendor,
-					uint32_t mod_id, uint16_t app_idx);
-bool mesh_db_model_pub_add(json_object *jnode, uint16_t ele_addr,
-			uint32_t mod_id, bool vendor, struct mesh_db_pub *pub);
-bool mesh_db_model_pub_del(json_object *jnode, uint16_t ele_addr,
+bool mesh_config_write_bool(json_object *jobj, const char *keyword, bool value);
+bool mesh_config_write_relay_mode(json_object *jnode, uint8_t mode,
+					uint8_t count, uint16_t interval);
+bool mesh_config_write_mode(json_object *jobj, const char *keyword, int value);
+bool mesh_config_model_binding_add(json_object *jnode, uint8_t ele_idx,
+						bool vendor, uint32_t mod_id,
+							uint16_t app_idx);
+bool mesh_config_model_binding_del(json_object *jnode, uint8_t ele_idx,
+						bool vendor, uint32_t mod_id,
+							uint16_t app_idx);
+bool mesh_config_model_pub_add(json_object *jnode, uint16_t ele_addr,
+						uint32_t mod_id, bool vendor,
+						struct mesh_config_pub *pub);
+bool mesh_config_model_pub_del(json_object *jnode, uint16_t ele_addr,
 						uint32_t mod_id, bool vendor);
-bool mesh_db_model_sub_add(json_object *jnode, uint16_t addr, uint32_t mod_id,
-					bool vendor, struct mesh_db_sub *sub);
-bool mesh_db_model_sub_del(json_object *jnode, uint16_t addr, uint32_t mod_id,
-					bool vendor, struct mesh_db_sub *sub);
-bool mesh_db_model_sub_del_all(json_object *jnode, uint16_t addr,
+bool mesh_config_model_sub_add(json_object *jnode, uint16_t addr,
+						uint32_t mod_id, bool vendor,
+						struct mesh_config_sub *sub);
+bool mesh_config_model_sub_del(json_object *jnode, uint16_t addr,
+						uint32_t mod_id, bool vendor,
+						struct mesh_config_sub *sub);
+bool mesh_config_model_sub_del_all(json_object *jnode, uint16_t addr,
 						uint32_t mod_id, bool vendor);
-bool mesh_db_app_key_add(json_object *jnode, uint16_t net_idx, uint16_t app_idx,
-							const uint8_t key[16]);
-bool mesh_db_app_key_update(json_object *jobj, uint16_t app_idx,
+bool mesh_config_app_key_add(json_object *jnode, uint16_t net_idx,
+				uint16_t app_idx, const uint8_t key[16]);
+bool mesh_config_app_key_update(json_object *jobj, uint16_t app_idx,
 							const uint8_t key[16]);
-bool mesh_db_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx);
-bool mesh_db_net_key_add(json_object *jobj, uint16_t net_idx,
+bool mesh_config_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx);
+bool mesh_config_net_key_add(json_object *jobj, uint16_t net_idx,
 							const uint8_t key[16]);
-bool mesh_db_net_key_update(json_object *jobj, uint16_t idx,
+bool mesh_config_net_key_update(json_object *jobj, uint16_t idx,
 							const uint8_t key[16]);
-bool mesh_db_net_key_del(json_object *jobj, uint16_t net_idx);
-bool mesh_db_net_key_set_phase(json_object *jobj, uint16_t idx, uint8_t phase);
-bool mesh_db_write_address(json_object *jobj, uint16_t address);
-bool mesh_db_write_iv_index(json_object *jobj, uint32_t idx, bool update);
-void mesh_db_remove_property(json_object *jobj, const char *desc);
+bool mesh_config_net_key_del(json_object *jobj, uint16_t net_idx);
+bool mesh_config_net_key_set_phase(json_object *jobj, uint16_t idx,
+								uint8_t phase);
+bool mesh_config_write_address(json_object *jobj, uint16_t address);
+bool mesh_config_write_iv_index(json_object *jobj, uint32_t idx, bool update);
+void mesh_config_remove_property(json_object *jobj, const char *desc);
diff --git a/mesh/model.c b/mesh/model.c
index 0474762e0..9331e1044 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -1406,10 +1406,10 @@ int mesh_model_sub_del_all(struct mesh_node *node, uint16_t addr, uint32_t id)
 struct mesh_model *mesh_model_setup(struct mesh_node *node, uint8_t ele_idx,
 								void *data)
 {
-	struct mesh_db_model *db_mod = data;
+	struct mesh_config_model *db_mod = data;
 	struct mesh_model *mod;
 	struct mesh_net *net;
-	struct mesh_db_pub *pub = db_mod->pub;
+	struct mesh_config_pub *pub = db_mod->pub;
 	uint32_t i;
 
 	if (db_mod->num_bindings > MAX_BINDINGS) {
diff --git a/mesh/node.c b/mesh/node.c
index 06e809706..6ebdcf588 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -289,7 +289,7 @@ void node_remove(struct mesh_node *node)
 }
 
 static bool add_models(struct mesh_node *node, struct node_element *ele,
-						struct mesh_db_element *db_ele)
+					struct mesh_config_element *db_ele)
 {
 	const struct l_queue_entry *entry;
 
@@ -299,7 +299,7 @@ static bool add_models(struct mesh_node *node, struct node_element *ele,
 	entry = l_queue_get_entries(db_ele->models);
 	for (; entry; entry = entry->next) {
 		struct mesh_model *mod;
-		struct mesh_db_model *db_mod;
+		struct mesh_config_model *db_mod;
 
 		db_mod = entry->data;
 		mod = mesh_model_setup(node, ele->idx, db_mod);
@@ -317,7 +317,7 @@ static void add_internal_model(struct mesh_node *node, uint32_t mod_id,
 {
 	struct node_element *ele;
 	struct mesh_model *mod;
-	struct mesh_db_model db_mod;
+	struct mesh_config_model db_mod;
 
 	ele = l_queue_find(node->elements, match_element_idx,
 							L_UINT_TO_PTR(ele_idx));
@@ -338,7 +338,8 @@ static void add_internal_model(struct mesh_node *node, uint32_t mod_id,
 	l_queue_push_tail(ele->models, mod);
 }
 
-static bool add_element(struct mesh_node *node, struct mesh_db_element *db_ele)
+static bool add_element(struct mesh_node *node,
+					struct mesh_config_element *db_ele)
 {
 	struct node_element *ele;
 
@@ -356,7 +357,8 @@ static bool add_element(struct mesh_node *node, struct mesh_db_element *db_ele)
 	return true;
 }
 
-static bool add_elements(struct mesh_node *node, struct mesh_db_node *db_node)
+static bool add_elements(struct mesh_node *node,
+					struct mesh_config_node *db_node)
 {
 	const struct l_queue_entry *entry;
 
@@ -373,7 +375,7 @@ static bool add_elements(struct mesh_node *node, struct mesh_db_node *db_node)
 
 bool node_init_from_storage(struct mesh_node *node, void *data)
 {
-	struct mesh_db_node *db_node = data;
+	struct mesh_config_node *db_node = data;
 	unsigned int num_ele;
 	uint8_t mode;
 
@@ -1260,7 +1262,7 @@ static bool get_element_properties(struct mesh_node *node, const char *path,
 }
 
 static void convert_node_to_storage(struct mesh_node *node,
-						struct mesh_db_node *db_node)
+					struct mesh_config_node *db_node)
 {
 	const struct l_queue_entry *entry;
 
@@ -1286,10 +1288,10 @@ static void convert_node_to_storage(struct mesh_node *node,
 
 	for (; entry; entry = entry->next) {
 		struct node_element *ele = entry->data;
-		struct mesh_db_element *db_ele;
+		struct mesh_config_element *db_ele;
 		const struct l_queue_entry *mod_entry;
 
-		db_ele = l_new(struct mesh_db_element, 1);
+		db_ele = l_new(struct mesh_config_element, 1);
 
 		db_ele->index = ele->idx;
 		db_ele->location = ele->location;
@@ -1299,10 +1301,10 @@ static void convert_node_to_storage(struct mesh_node *node,
 
 		for (; mod_entry; mod_entry = mod_entry->next) {
 			struct mesh_model *mod = mod_entry->data;
-			struct mesh_db_model *db_mod;
+			struct mesh_config_model *db_mod;
 			uint32_t mod_id = mesh_model_get_model_id(mod);
 
-			db_mod = l_new(struct mesh_db_model, 1);
+			db_mod = l_new(struct mesh_config_model, 1);
 			db_mod->id = mod_id;
 			db_mod->vendor = ((mod_id & VENDOR_ID_MASK)
 							!= VENDOR_ID_MASK);
@@ -1316,7 +1318,7 @@ static void convert_node_to_storage(struct mesh_node *node,
 
 static bool create_node_config(struct mesh_node *node)
 {
-	struct mesh_db_node db_node;
+	struct mesh_config_node db_node;
 	const struct l_queue_entry *entry;
 	bool res;
 
@@ -1326,7 +1328,7 @@ static bool create_node_config(struct mesh_node *node)
 	/* Free temporarily allocated resources */
 	entry = l_queue_get_entries(db_node.elements);
 	for (; entry; entry = entry->next) {
-		struct mesh_db_element *db_ele = entry->data;
+		struct mesh_config_element *db_ele = entry->data;
 
 		l_queue_destroy(db_ele->models, l_free);
 	}
@@ -1429,16 +1431,16 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
 
 	mesh_net_set_iv_index(node->net, iv_idx, ivu);
 
-	if (!mesh_db_write_uint16_hex(node->jconfig, "unicastAddress",
+	if (!mesh_config_write_uint16_hex(node->jconfig, "unicastAddress",
 								unicast))
 		return false;
 
 	l_getrandom(node->token, sizeof(node->token));
-	if (!mesh_db_write_token(node->jconfig, node->token))
+	if (!mesh_config_write_token(node->jconfig, node->token))
 		return false;
 
 	memcpy(node->dev_key, dev_key, 16);
-	if (!mesh_db_write_device_key(node->jconfig, dev_key))
+	if (!mesh_config_write_device_key(node->jconfig, dev_key))
 		return false;
 
 	node->primary = unicast;
@@ -1454,7 +1456,7 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
 							MESH_STATUS_SUCCESS)
 			return false;
 
-		if (!mesh_db_net_key_set_phase(node->jconfig, net_key_idx,
+		if (!mesh_config_net_key_set_phase(node->jconfig, net_key_idx,
 							KEY_REFRESH_PHASE_TWO))
 			return false;
 	}
diff --git a/mesh/storage.c b/mesh/storage.c
index bba2ef348..601669791 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -52,7 +52,7 @@ static const char *bak_ext = ".bak";
 static const char *tmp_ext = ".tmp";
 static const char *storage_dir;
 
-static bool read_node_cb(struct mesh_db_node *db_node, void *user_data)
+static bool read_node_cb(struct mesh_config_node *db_node, void *user_data)
 {
 	struct mesh_node *node = user_data;
 
@@ -95,30 +95,30 @@ static bool parse_node(struct mesh_node *node, json_object *jnode)
 	uint16_t interval;
 	struct mesh_net *net = node_get_net(node);
 
-	if (mesh_db_read_iv_index(jnode, &iv_index, &bvalue))
+	if (mesh_config_read_iv_index(jnode, &iv_index, &bvalue))
 		mesh_net_set_iv_index(net, iv_index, bvalue);
 
-	if (mesh_db_read_net_transmit(jnode, &cnt, &interval))
+	if (mesh_config_read_net_transmit(jnode, &cnt, &interval))
 		mesh_net_transmit_params_set(net, cnt, interval);
 
 	/* Node composition/configuration info */
-	if (!mesh_db_read_node(jnode, read_node_cb, node))
+	if (!mesh_config_read_node(jnode, read_node_cb, node))
 		return false;
 
-	if (!mesh_db_read_net_keys(jnode, read_net_keys_cb, net))
+	if (!mesh_config_read_net_keys(jnode, read_net_keys_cb, net))
 		return false;
 
-	if (!mesh_db_read_token(jnode, key_buf))
+	if (!mesh_config_read_token(jnode, key_buf))
 		return false;
 
 	node_set_token(node, key_buf);
 
-	if (!mesh_db_read_device_key(jnode, key_buf))
+	if (!mesh_config_read_device_key(jnode, key_buf))
 		return false;
 
 	node_set_device_key(node, key_buf);
 
-	mesh_db_read_app_keys(jnode, read_app_keys_cb, net);
+	mesh_config_read_app_keys(jnode, read_app_keys_cb, net);
 
 	return true;
 }
@@ -184,7 +184,7 @@ bool storage_set_ttl(struct mesh_node *node, uint8_t ttl)
 {
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_write_int(jnode, "defaultTTL", ttl))
+	if (!mesh_config_write_int(jnode, "defaultTTL", ttl))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -196,7 +196,7 @@ bool storage_set_relay(struct mesh_node *node, bool enable,
 {
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_write_relay_mode(jnode, enable, count, interval))
+	if (!mesh_config_write_relay_mode(jnode, enable, count, interval))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -208,7 +208,7 @@ bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
 {
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_write_net_transmit(jnode, count, interval))
+	if (!mesh_config_write_net_transmit(jnode, count, interval))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -220,7 +220,7 @@ bool storage_set_mode(struct mesh_node *node, uint8_t mode,
 {
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_write_mode(jnode, mode_name, mode))
+	if (!mesh_config_write_mode(jnode, mode_name, mode))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -241,11 +241,11 @@ bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
 	jnode = node_jconfig_get(node);
 
 	if (unbind)
-		stored = mesh_db_model_binding_del(jnode, ele_idx, is_vendor,
-							mod_id, app_idx);
+		stored = mesh_config_model_binding_del(jnode, ele_idx,
+						is_vendor, mod_id, app_idx);
 	else
-		stored = mesh_db_model_binding_add(jnode, ele_idx, is_vendor,
-							mod_id, app_idx);
+		stored = mesh_config_model_binding_add(jnode, ele_idx,
+						is_vendor, mod_id, app_idx);
 
 	if (stored)
 		storage_save_config(node, true, NULL, NULL);
@@ -265,9 +265,9 @@ bool storage_app_key_add(struct mesh_net *net, uint16_t net_idx,
 		return false;
 
 	if (update)
-		stored = mesh_db_app_key_update(jnode, app_idx, key);
+		stored = mesh_config_app_key_update(jnode, app_idx, key);
 	else
-		stored = mesh_db_app_key_add(jnode, net_idx, app_idx, key);
+		stored = mesh_config_app_key_add(jnode, net_idx, app_idx, key);
 
 	if (stored)
 		storage_save_config(node, true, NULL, NULL);
@@ -285,7 +285,7 @@ bool storage_app_key_del(struct mesh_net *net, uint16_t net_idx,
 	if (!jnode)
 		return false;
 
-	if (!mesh_db_app_key_del(jnode, net_idx, app_idx))
+	if (!mesh_config_app_key_del(jnode, net_idx, app_idx))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -300,9 +300,9 @@ bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
 	bool stored;
 
 	if (!update)
-		stored = mesh_db_net_key_add(jnode, net_idx, key);
+		stored = mesh_config_net_key_add(jnode, net_idx, key);
 	else
-		stored = mesh_db_net_key_update(jnode, net_idx, key);
+		stored = mesh_config_net_key_update(jnode, net_idx, key);
 
 	if (stored)
 		storage_save_config(node, true, NULL, NULL);
@@ -315,7 +315,7 @@ bool storage_net_key_del(struct mesh_net *net, uint16_t net_idx)
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_net_key_del(jnode, net_idx))
+	if (!mesh_config_net_key_del(jnode, net_idx))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -328,7 +328,7 @@ bool storage_set_iv_index(struct mesh_net *net, uint32_t iv_index,
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_write_iv_index(jnode, iv_index, update))
+	if (!mesh_config_write_iv_index(jnode, iv_index, update))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -341,7 +341,7 @@ bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_net_key_set_phase(jnode, net_idx, phase))
+	if (!mesh_config_net_key_set_phase(jnode, net_idx, phase))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -353,7 +353,7 @@ bool storage_write_sequence_number(struct mesh_net *net, uint32_t seq)
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
 
-	if (!mesh_db_write_int(jnode, "sequenceNumber", seq))
+	if (!mesh_config_write_int(jnode, "sequenceNumber", seq))
 		return false;
 
 	storage_save_config(node, false, NULL, NULL);
@@ -523,7 +523,7 @@ bool storage_load_nodes(const char *dir_name)
 
 bool storage_create_node_config(struct mesh_node *node, void *data)
 {
-	struct mesh_db_node *db_node = data;
+	struct mesh_config_node *db_node = data;
 	char uuid[33];
 	char name_buf[PATH_MAX];
 	json_object *jnode;
@@ -534,7 +534,7 @@ bool storage_create_node_config(struct mesh_node *node, void *data)
 
 	jnode = json_object_new_object();
 
-	if (!mesh_db_add_node(jnode, db_node))
+	if (!mesh_config_add_node(jnode, db_node))
 		return false;
 
 	if (!hex2str(node_uuid_get(node), 16, uuid, sizeof(uuid)))
-- 
2.21.0


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

* [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
                   ` (2 preceding siblings ...)
  2019-07-10  5:09 ` [PATCH BlueZ 3/9] mesh: Change mesh_db prefix to mesh_config Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  7:38   ` Michał Lowas-Rzechonek
  2019-07-10  5:09 ` [PATCH BlueZ 5/9] mesh: Change variable prefix "jconfig" to "config" Inga Stotland
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This changes argument for each mesh-config API to use void* as
a pointer to a node configuration object. This makes usage of JSON
opaque for the rest of the code and allows to plug in a non-JSON
configuration storage implementation.
---
 mesh/mesh-config-json.c | 228 +++++++++++++++++++++++-----------------
 mesh/mesh-config.h      | 107 +++++++++----------
 2 files changed, 180 insertions(+), 155 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 8fcb8afe3..5ca086ad0 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -252,10 +252,14 @@ static json_object *jarray_key_del(json_object *jarray, int16_t idx)
 	return jarray_new;
 }
 
-bool mesh_config_read_iv_index(json_object *jobj, uint32_t *idx, bool *update)
+bool mesh_config_read_iv_index(void *cfg, uint32_t *idx, bool *update)
 {
+	json_object *jobj = cfg;
 	int tmp;
 
+	if (!jobj)
+		return false;
+
 	/* IV index */
 	if (!get_int(jobj, "IVindex", &tmp))
 		return false;
@@ -270,12 +274,12 @@ bool mesh_config_read_iv_index(json_object *jobj, uint32_t *idx, bool *update)
 	return true;
 }
 
-bool mesh_config_read_token(json_object *jobj, uint8_t token[8])
+bool mesh_config_read_token(void *cfg, uint8_t token[8])
 {
-	json_object *jvalue;
+	json_object *jobj = cfg, *jvalue;
 	char *str;
 
-	if (!token)
+	if (!token || !jobj)
 		return false;
 
 	if (!json_object_object_get_ex(jobj, "token", &jvalue))
@@ -288,12 +292,12 @@ bool mesh_config_read_token(json_object *jobj, uint8_t token[8])
 	return true;
 }
 
-bool mesh_config_read_device_key(json_object *jobj, uint8_t key_buf[16])
+bool mesh_config_read_device_key(void *cfg, uint8_t key_buf[16])
 {
-	json_object *jvalue;
+	json_object *jvalue, *jobj = cfg;
 	char *str;
 
-	if (!key_buf)
+	if (!key_buf || !jobj)
 		return false;
 
 	if (!json_object_object_get_ex(jobj, "deviceKey", &jvalue))
@@ -306,15 +310,15 @@ bool mesh_config_read_device_key(json_object *jobj, uint8_t key_buf[16])
 	return true;
 }
 
-bool mesh_config_read_app_keys(json_object *jobj, mesh_config_app_key_cb cb,
+bool mesh_config_read_app_keys(void *cfg, mesh_config_app_key_cb cb,
 							void *user_data)
 {
-	json_object *jarray;
+	json_object *jarray, *jobj = cfg;
 	int len;
 	int i;
 
-	if (!cb)
-		return true;
+	if (!jobj || !cb)
+		return false;
 
 	if (!json_object_object_get_ex(jobj, "appKeys", &jarray))
 		return false;
@@ -368,15 +372,15 @@ bool mesh_config_read_app_keys(json_object *jobj, mesh_config_app_key_cb cb,
 	return true;
 }
 
-bool mesh_config_read_net_keys(json_object *jobj, mesh_config_net_key_cb cb,
+bool mesh_config_read_net_keys(void *cfg, mesh_config_net_key_cb cb,
 								void *user_data)
 {
-	json_object *jarray;
+	json_object *jarray, *jobj = cfg;
 	int len;
 	int i;
 
-	if (!cb)
-		return true;
+	if (!cb || !jobj)
+		return false;
 
 	if (!json_object_object_get_ex(jobj, "netKeys", &jarray))
 		return false;
@@ -431,12 +435,14 @@ bool mesh_config_read_net_keys(json_object *jobj, mesh_config_net_key_cb cb,
 	return true;
 }
 
-bool mesh_config_net_key_add(json_object *jobj, uint16_t idx,
-							const uint8_t key[16])
+bool mesh_config_net_key_add(void *cfg, uint16_t idx, const uint8_t key[16])
 {
-	json_object *jarray = NULL, *jentry = NULL, *jstring;
+	json_object *jarray = NULL, *jentry = NULL, *jstring, *jobj = cfg;
 	char buf[5];
 
+	if (!jobj)
+		return false;
+
 	json_object_object_get_ex(jobj, "netKeys", &jarray);
 	if (jarray)
 		jentry = get_key_object(jarray, idx);
@@ -479,12 +485,14 @@ fail:
 	return false;
 }
 
-bool mesh_config_net_key_update(json_object *jobj, uint16_t idx,
-							const uint8_t key[16])
+bool mesh_config_net_key_update(void *cfg, uint16_t idx, const uint8_t key[16])
 {
-	json_object *jarray, *jentry, *jstring;
+	json_object *jarray, *jentry, *jstring, *jobj = cfg;
 	const char *str;
 
+	if (!jobj)
+		return false;
+
 	if (!json_object_object_get_ex(jobj, "netKeys", &jarray))
 		return false;
 
@@ -510,9 +518,12 @@ bool mesh_config_net_key_update(json_object *jobj, uint16_t idx,
 	return true;
 }
 
-bool mesh_config_net_key_del(json_object *jobj, uint16_t idx)
+bool mesh_config_net_key_del(void *cfg, uint16_t idx)
 {
-	json_object *jarray, *jarray_new;
+	json_object *jarray, *jarray_new, *jobj = cfg;
+
+	if (!jobj)
+		return false;
 
 	if (!json_object_object_get_ex(jobj, "netKeys", &jarray))
 		return true;
@@ -541,21 +552,35 @@ bool mesh_config_net_key_del(json_object *jobj, uint16_t idx)
 	return true;
 }
 
-bool mesh_config_write_device_key(json_object *jnode, uint8_t *key)
+bool mesh_config_write_device_key(void *cfg, uint8_t *key)
 {
-	return add_key_value(jnode, "deviceKey", key);
+	json_object *jobj = cfg;
+
+	if (!jobj)
+		return false;
+
+	return add_key_value(jobj, "deviceKey", key);
 }
 
-bool mesh_config_write_token(json_object *jnode, uint8_t *token)
+bool mesh_config_write_token(void *cfg, uint8_t *token)
 {
-	return add_u64_value(jnode, "token", token);
+	json_object *jobj = cfg;
+
+	if (!jobj)
+		return false;
+
+	return add_u64_value(jobj, "token", token);
 }
 
-bool mesh_config_app_key_add(json_object *jobj, uint16_t net_idx,
+bool mesh_config_app_key_add(void *cfg, uint16_t net_idx,
 					uint16_t app_idx, const uint8_t key[16])
 {
 	json_object *jarray = NULL, *jentry = NULL, *jstring = NULL;
 	char buf[5];
+	json_object *jobj = cfg;
+
+	if (!jobj)
+		return false;
 
 	json_object_object_get_ex(jobj, "appKeys", &jarray);
 	if (jarray)
@@ -604,11 +629,15 @@ fail:
 	return false;
 }
 
-bool mesh_config_app_key_update(json_object *jobj, uint16_t app_idx,
+bool mesh_config_app_key_update(void *cfg, uint16_t app_idx,
 							const uint8_t key[16])
 {
 	json_object *jarray, *jentry = NULL, *jstring = NULL;
 	const char *str;
+	json_object *jobj = cfg;
+
+	if (!jobj)
+		return false;
 
 	if (!json_object_object_get_ex(jobj, "appKeys", &jarray))
 		return false;
@@ -629,9 +658,13 @@ bool mesh_config_app_key_update(json_object *jobj, uint16_t app_idx,
 	return add_key_value(jentry, "key", key);
 }
 
-bool mesh_config_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx)
+bool mesh_config_app_key_del(void *cfg, uint16_t net_idx, uint16_t idx)
 {
 	json_object *jarray, *jarray_new;
+	json_object *jobj = cfg;
+
+	if (!jobj)
+		return false;
 
 	if (!json_object_object_get_ex(jobj, "appKeys", &jarray))
 		return true;
@@ -660,14 +693,17 @@ bool mesh_config_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx)
 	return true;
 }
 
-bool mesh_config_model_binding_add(json_object *jnode, uint8_t ele_idx,
-					bool vendor, uint32_t mod_id,
-							uint16_t app_idx)
+bool mesh_config_model_binding_add(void *cfg, uint8_t ele_idx, bool vendor,
+					uint32_t mod_id, uint16_t app_idx)
 {
 	json_object *jmodel, *jstring, *jarray = NULL;
 	char buf[5];
+	json_object *jobj = cfg;
 
-	jmodel = get_element_model(jnode, ele_idx, mod_id, vendor);
+	if (!jobj)
+		return false;
+
+	jmodel = get_element_model(jobj, ele_idx, mod_id, vendor);
 	if (!jmodel)
 		return false;
 
@@ -695,14 +731,16 @@ bool mesh_config_model_binding_add(json_object *jnode, uint8_t ele_idx,
 	return true;
 }
 
-bool mesh_config_model_binding_del(json_object *jnode, uint8_t ele_idx,
-					bool vendor, uint32_t mod_id,
-							uint16_t app_idx)
+bool mesh_config_model_binding_del(void *cfg, uint8_t ele_idx, bool vendor,
+					uint32_t mod_id, uint16_t app_idx)
 {
-	json_object *jmodel, *jarray, *jarray_new;
+	json_object *jmodel, *jarray, *jarray_new, *jobj = cfg;
 	char buf[5];
 
-	jmodel = get_element_model(jnode, ele_idx, mod_id, vendor);
+	if (!jobj)
+		return false;
+
+	jmodel = get_element_model(jobj, ele_idx, mod_id, vendor);
 	if (!jmodel)
 		return false;
 
@@ -1162,14 +1200,13 @@ static bool parse_composition(json_object *jcomp, struct mesh_config_node *node)
 	return true;
 }
 
-bool mesh_config_read_node(json_object *jnode, mesh_config_node_cb cb,
-							void *user_data)
+bool mesh_config_read_node(void *cfg, mesh_config_node_cb cb, void *user_data)
 {
 	struct mesh_config_node node;
-	json_object *jvalue;
+	json_object *jvalue, *jobj = cfg;
 	char *str;
 
-	if (!jnode)
+	if (!jobj)
 		return false;
 
 	if (!cb) {
@@ -1179,14 +1216,14 @@ bool mesh_config_read_node(json_object *jnode, mesh_config_node_cb cb,
 
 	memset(&node, 0, sizeof(node));
 
-	if (!parse_composition(jnode, &node)) {
+	if (!parse_composition(jobj, &node)) {
 		l_info("Failed to parse local node composition");
 		return false;
 	}
 
-	parse_features(jnode, &node);
+	parse_features(jobj, &node);
 
-	if (!json_object_object_get_ex(jnode, "unicastAddress", &jvalue)) {
+	if (!json_object_object_get_ex(jobj, "unicastAddress", &jvalue)) {
 		l_info("Bad config: Unicast address must be present");
 		return false;
 	}
@@ -1195,7 +1232,7 @@ bool mesh_config_read_node(json_object *jnode, mesh_config_node_cb cb,
 	if (sscanf(str, "%04hx", &node.unicast) != 1)
 		return false;
 
-	if (json_object_object_get_ex(jnode, "defaultTTL", &jvalue)) {
+	if (json_object_object_get_ex(jobj, "defaultTTL", &jvalue)) {
 		int ttl = json_object_get_int(jvalue);
 
 		if (ttl < 0 || ttl == 1 || ttl > DEFAULT_TTL)
@@ -1203,11 +1240,11 @@ bool mesh_config_read_node(json_object *jnode, mesh_config_node_cb cb,
 		node.ttl = (uint8_t) ttl;
 	}
 
-	if (json_object_object_get_ex(jnode, "sequenceNumber", &jvalue))
+	if (json_object_object_get_ex(jobj, "sequenceNumber", &jvalue))
 		node.seq_number = json_object_get_int(jvalue);
 
 	/* Check for required "elements" property */
-	if (!json_object_object_get_ex(jnode, "elements", &jvalue))
+	if (!json_object_object_get_ex(jobj, "elements", &jvalue))
 		return false;
 
 	if (!parse_elements(jvalue, &node))
@@ -1216,10 +1253,9 @@ bool mesh_config_read_node(json_object *jnode, mesh_config_node_cb cb,
 	return cb(&node, user_data);
 }
 
-bool mesh_config_write_uint16_hex(json_object *jobj, const char *desc,
-								uint16_t value)
+bool mesh_config_write_uint16_hex(void *cfg, const char *desc, uint16_t value)
 {
-	json_object *jstring;
+	json_object *jstring, *jobj = cfg;
 	char buf[5];
 
 	if (!jobj)
@@ -1234,10 +1270,9 @@ bool mesh_config_write_uint16_hex(json_object *jobj, const char *desc,
 	return true;
 }
 
-bool mesh_config_write_uint32_hex(json_object *jobj, const char *desc,
-								uint32_t value)
+bool mesh_config_write_uint32_hex(void *cfg, const char *desc, uint32_t value)
 {
-	json_object *jstring;
+	json_object *jstring, *jobj = cfg;
 	char buf[9];
 
 	if (!jobj)
@@ -1252,9 +1287,9 @@ bool mesh_config_write_uint32_hex(json_object *jobj, const char *desc,
 	return true;
 }
 
-bool mesh_config_write_int(json_object *jobj, const char *keyword, int value)
+bool mesh_config_write_int(void *cfg, const char *keyword, int value)
 {
-	json_object *jvalue;
+	json_object *jvalue, *jobj = cfg;
 
 	if (!jobj)
 		return false;
@@ -1269,9 +1304,9 @@ bool mesh_config_write_int(json_object *jobj, const char *keyword, int value)
 	return true;
 }
 
-bool mesh_config_write_bool(json_object *jobj, const char *keyword, bool value)
+bool mesh_config_write_bool(void *cfg, const char *keyword, bool value)
 {
-	json_object *jvalue;
+	json_object *jvalue, *jobj = cfg;
 
 	if (!jobj)
 		return false;
@@ -1298,9 +1333,9 @@ static const char *mode_to_string(int mode)
 	}
 }
 
-bool mesh_config_write_mode(json_object *jobj, const char *keyword, int value)
+bool mesh_config_write_mode(void *cfg, const char *keyword, int value)
 {
-	json_object *jstring;
+	json_object *jstring, *jobj = cfg;
 
 	if (!jobj)
 		return false;
@@ -1315,15 +1350,15 @@ bool mesh_config_write_mode(json_object *jobj, const char *keyword, int value)
 	return true;
 }
 
-bool mesh_config_write_relay_mode(json_object *jnode, uint8_t mode,
-					uint8_t count, uint16_t interval)
+bool mesh_config_write_relay_mode(void *cfg, uint8_t mode, uint8_t count,
+							uint16_t interval)
 {
-	json_object *jrelay;
+	json_object *jrelay, *jobj = cfg;
 
-	if (!jnode)
+	if (!jobj)
 		return false;
 
-	json_object_object_del(jnode, "relay");
+	json_object_object_del(jobj, "relay");
 
 	jrelay = json_object_new_object();
 	if (!jrelay)
@@ -1338,7 +1373,7 @@ bool mesh_config_write_relay_mode(json_object *jnode, uint8_t mode,
 	if (!mesh_config_write_int(jrelay, "interval", interval))
 		goto fail;
 
-	json_object_object_add(jnode, "relay", jrelay);
+	json_object_object_add(jobj, "relay", jrelay);
 
 	return true;
 fail:
@@ -1346,10 +1381,9 @@ fail:
 	return false;
 }
 
-bool mesh_config_read_net_transmit(json_object *jobj, uint8_t *cnt,
-							uint16_t *interval)
+bool mesh_config_read_net_transmit(void *cfg, uint8_t *cnt, uint16_t *interval)
 {
-	json_object *jretransmit, *jvalue;
+	json_object *jretransmit, *jvalue, *jobj = cfg;
 
 	if (!jobj)
 		return false;
@@ -1370,10 +1404,9 @@ bool mesh_config_read_net_transmit(json_object *jobj, uint8_t *cnt,
 	return true;
 }
 
-bool mesh_config_write_net_transmit(json_object *jobj, uint8_t cnt,
-							uint16_t interval)
+bool mesh_config_write_net_transmit(void *cfg, uint8_t cnt, uint16_t interval)
 {
-	json_object *jretransmit;
+	json_object *jretransmit, *jobj = cfg;
 
 	if (!jobj)
 		return false;
@@ -1399,8 +1432,9 @@ fail:
 
 }
 
-bool mesh_config_write_iv_index(json_object *jobj, uint32_t idx, bool update)
+bool mesh_config_write_iv_index(void *cfg, uint32_t idx, bool update)
 {
+	json_object *jobj = cfg;
 	int tmp = update ? 1 : 0;
 
 	if (!jobj)
@@ -1415,8 +1449,10 @@ bool mesh_config_write_iv_index(json_object *jobj, uint32_t idx, bool update)
 	return true;
 }
 
-void mesh_config_remove_property(json_object *jobj, const char *desc)
+void mesh_config_remove_property(void *cfg, const char *desc)
 {
+	json_object *jobj = cfg;
+
 	if (jobj)
 		json_object_object_del(jobj, desc);
 }
@@ -1440,11 +1476,11 @@ static void add_model(void *a, void *b)
 }
 
 /* Add unprovisioned node (local) */
-bool mesh_config_add_node(json_object *jnode, struct mesh_config_node *node)
+bool mesh_config_add_node(void *cfg, struct mesh_config_node *node)
 {
 	struct mesh_config_modes *modes = &node->modes;
 	const struct l_queue_entry *entry;
-	json_object *jelems;
+	json_object *jelems, *jnode = cfg;
 
 	if (!jnode)
 		return false;
@@ -1562,10 +1598,9 @@ static void finish_key_refresh(json_object *jobj, uint16_t net_idx)
 
 }
 
-bool mesh_config_net_key_set_phase(json_object *jobj, uint16_t idx,
-								uint8_t phase)
+bool mesh_config_net_key_set_phase(void *cfg, uint16_t idx, uint8_t phase)
 {
-	json_object *jarray, *jentry = NULL;
+	json_object *jobj = cfg, *jarray, *jentry = NULL;
 
 	if (!jobj)
 		return false;
@@ -1588,11 +1623,10 @@ bool mesh_config_net_key_set_phase(json_object *jobj, uint16_t idx,
 	return true;
 }
 
-bool mesh_config_model_pub_add(json_object *jnode, uint16_t addr,
-					uint32_t mod_id, bool vendor,
-					struct mesh_config_pub *pub)
+bool mesh_config_model_pub_add(void *cfg, uint16_t addr, uint32_t mod_id,
+				bool vendor, struct mesh_config_pub *pub)
 {
-	json_object *jmodel, *jpub, *jretransmit;
+	json_object *jnode = cfg, *jmodel, *jpub, *jretransmit;
 	bool res;
 	int ele_idx;
 
@@ -1672,20 +1706,21 @@ static bool delete_model_property(json_object *jnode, uint16_t addr,
 	return true;
 }
 
-bool mesh_config_model_pub_del(json_object *jnode, uint16_t addr,
-						uint32_t mod_id, bool vendor)
+bool mesh_config_model_pub_del(void *cfg, uint16_t addr, uint32_t mod_id,
+								bool vendor)
 {
+	json_object *jnode = cfg;
+
 	if (!jnode)
 		return false;
 
 	return delete_model_property(jnode, addr, mod_id, vendor, "publish");
 }
 
-bool mesh_config_model_sub_add(json_object *jnode, uint16_t addr,
-						uint32_t mod_id, bool vendor,
-						struct mesh_config_sub *sub)
+bool mesh_config_model_sub_add(void *cfg, uint16_t addr, uint32_t mod_id,
+				bool vendor, struct mesh_config_sub *sub)
 {
-	json_object *jmodel, *jstring, *jarray = NULL;
+	json_object *jnode = cfg, *jmodel, *jstring, *jarray = NULL;
 	int ele_idx, len;
 	char buf[33];
 
@@ -1730,11 +1765,10 @@ bool mesh_config_model_sub_add(json_object *jnode, uint16_t addr,
 	return true;
 }
 
-bool mesh_config_model_sub_del(json_object *jnode, uint16_t addr,
-						uint32_t mod_id, bool vendor,
-						struct mesh_config_sub *sub)
+bool mesh_config_model_sub_del(void *cfg, uint16_t addr, uint32_t mod_id,
+				bool vendor, struct mesh_config_sub *sub)
 {
-	json_object *jmodel, *jarray, *jarray_new;
+	json_object *jnode = cfg, *jmodel, *jarray, *jarray_new;
 	char buf[33];
 	int len, ele_idx;
 
@@ -1783,9 +1817,11 @@ bool mesh_config_model_sub_del(json_object *jnode, uint16_t addr,
 	return true;
 }
 
-bool mesh_config_model_sub_del_all(json_object *jnode, uint16_t addr,
-						uint32_t mod_id, bool vendor)
+bool mesh_config_model_sub_del_all(void *cfg, uint16_t addr, uint32_t mod_id,
+								bool vendor)
 {
+	json_object *jnode = cfg;
+
 	if (!jnode)
 		return false;
 
diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h
index f60ae18cd..ab101a331 100644
--- a/mesh/mesh-config.h
+++ b/mesh/mesh-config.h
@@ -21,7 +21,7 @@ struct mesh_config_sub {
 	bool virt;
 	union {
 		uint16_t addr;
-		uint8_t	virt_addr[16];
+		uint8_t virt_addr[16];
 	} src;
 };
 
@@ -100,66 +100,55 @@ typedef bool (*mesh_config_app_key_cb)(uint16_t idx, uint16_t net_idx,
 typedef bool (*mesh_config_node_cb)(struct mesh_config_node *node,
 							void *user_data);
 
-bool mesh_config_read_node(json_object *jobj, mesh_config_node_cb cb,
+bool mesh_config_read_node(void *cfg, mesh_config_node_cb cb, void *user_data);
+bool mesh_config_add_node(void *cfg, struct mesh_config_node *node);
+bool mesh_config_read_iv_index(void *cfg, uint32_t *idx, bool *update);
+bool mesh_config_read_device_key(void *cfg, uint8_t key_buf[16]);
+bool mesh_config_read_token(void *cfg, uint8_t token[8]);
+bool mesh_config_read_net_transmit(void *cfg, uint8_t *cnt, uint16_t *interval);
+bool mesh_config_write_net_transmit(void *cfg, uint8_t cnt, uint16_t interval);
+bool mesh_config_read_net_keys(void *cfg, mesh_config_net_key_cb cb,
 							void *user_data);
-bool mesh_config_add_node(json_object *jnode, struct mesh_config_node *node);
-bool mesh_config_read_iv_index(json_object *jobj, uint32_t *idx, bool *update);
-bool mesh_config_read_device_key(json_object *jobj, uint8_t key_buf[16]);
-bool mesh_config_read_token(json_object *jobj, uint8_t token[8]);
-bool mesh_config_read_net_transmit(json_object *jobj, uint8_t *cnt,
-							uint16_t *interval);
-bool mesh_config_write_net_transmit(json_object *jobj, uint8_t cnt,
-							uint16_t interval);
-bool mesh_config_read_net_keys(json_object *jobj, mesh_config_net_key_cb cb,
-							void *user_data);
-bool mesh_config_read_app_keys(json_object *jobj, mesh_config_app_key_cb cb,
+bool mesh_config_read_app_keys(void *cfg, mesh_config_app_key_cb cb,
 							void *user_data);
-bool mesh_config_write_device_key(json_object *jobj, uint8_t *key);
-bool mesh_config_write_token(json_object *jobj, uint8_t *token);
-bool mesh_config_write_network_key(json_object *jobj, uint16_t idx,
-				uint8_t *key, uint8_t *new_key, int phase);
-bool mesh_config_write_app_key(json_object *jobj, uint16_t net_idx,
-			uint16_t app_idx, uint8_t *key, uint8_t *new_key);
-bool mesh_config_write_int(json_object *jobj, const char *keyword, int value);
-bool mesh_config_write_uint16_hex(json_object *jobj, const char *desc,
-								uint16_t value);
-bool mesh_config_write_uint32_hex(json_object *jobj, const char *desc,
-								uint32_t value);
-bool mesh_config_write_bool(json_object *jobj, const char *keyword, bool value);
-bool mesh_config_write_relay_mode(json_object *jnode, uint8_t mode,
-					uint8_t count, uint16_t interval);
-bool mesh_config_write_mode(json_object *jobj, const char *keyword, int value);
-bool mesh_config_model_binding_add(json_object *jnode, uint8_t ele_idx,
-						bool vendor, uint32_t mod_id,
-							uint16_t app_idx);
-bool mesh_config_model_binding_del(json_object *jnode, uint8_t ele_idx,
-						bool vendor, uint32_t mod_id,
-							uint16_t app_idx);
-bool mesh_config_model_pub_add(json_object *jnode, uint16_t ele_addr,
-						uint32_t mod_id, bool vendor,
-						struct mesh_config_pub *pub);
-bool mesh_config_model_pub_del(json_object *jnode, uint16_t ele_addr,
-						uint32_t mod_id, bool vendor);
-bool mesh_config_model_sub_add(json_object *jnode, uint16_t addr,
-						uint32_t mod_id, bool vendor,
-						struct mesh_config_sub *sub);
-bool mesh_config_model_sub_del(json_object *jnode, uint16_t addr,
-						uint32_t mod_id, bool vendor,
-						struct mesh_config_sub *sub);
-bool mesh_config_model_sub_del_all(json_object *jnode, uint16_t addr,
-						uint32_t mod_id, bool vendor);
-bool mesh_config_app_key_add(json_object *jnode, uint16_t net_idx,
-				uint16_t app_idx, const uint8_t key[16]);
-bool mesh_config_app_key_update(json_object *jobj, uint16_t app_idx,
+bool mesh_config_write_device_key(void *cfg, uint8_t *key);
+bool mesh_config_write_token(void *cfg, uint8_t *token);
+bool mesh_config_write_network_key(void *cfg, uint16_t net_idx, uint8_t *key,
+						uint8_t *new_key, int phase);
+bool mesh_config_write_app_key(void *cfg, uint16_t net_idx, uint16_t app_idx,
+						uint8_t *key, uint8_t *new_key);
+bool mesh_config_write_int(void *cfg, const char *keyword, int value);
+bool mesh_config_write_uint16_hex(void *cfg, const char *desc, uint16_t value);
+bool mesh_config_write_uint32_hex(void *cfg, const char *desc, uint32_t value);
+bool mesh_config_write_bool(void *cfg, const char *keyword, bool value);
+bool mesh_config_write_relay_mode(void *cfg, uint8_t mode, uint8_t count,
+							uint16_t interval);
+bool mesh_config_write_mode(void *cfg, const char *keyword, int value);
+bool mesh_config_model_binding_add(void *cfg, uint8_t ele_idx, bool vendor,
+					uint32_t mod_id, uint16_t app_idx);
+bool mesh_config_model_binding_del(void *cfg, uint8_t ele_idx, bool vendor,
+					uint32_t mod_id, uint16_t app_idx);
+bool mesh_config_model_pub_add(void *cfg, uint16_t ele_addr, uint32_t mod_id,
+				bool vendor, struct mesh_config_pub *pub);
+bool mesh_config_model_pub_del(void *cfg, uint16_t ele_addr, uint32_t mod_id,
+								bool vendor);
+bool mesh_config_model_sub_add(void *cfg, uint16_t addr, uint32_t mod_id,
+				bool vendor, struct mesh_config_sub *sub);
+bool mesh_config_model_sub_del(void *cfg, uint16_t addr, uint32_t mod_id,
+				bool vendor, struct mesh_config_sub *sub);
+bool mesh_config_model_sub_del_all(void *cfg, uint16_t addr, uint32_t mod_id,
+								bool vendor);
+bool mesh_config_app_key_add(void *cfg, uint16_t net_idx, uint16_t app_idx,
+							const uint8_t key[16]);
+bool mesh_config_app_key_update(void *cfg, uint16_t app_idx,
 							const uint8_t key[16]);
-bool mesh_config_app_key_del(json_object *jobj, uint16_t net_idx, uint16_t idx);
-bool mesh_config_net_key_add(json_object *jobj, uint16_t net_idx,
+bool mesh_config_app_key_del(void *cfg, uint16_t net_idx, uint16_t idx);
+bool mesh_config_net_key_add(void *cfg, uint16_t net_idx,
 							const uint8_t key[16]);
-bool mesh_config_net_key_update(json_object *jobj, uint16_t idx,
+bool mesh_config_net_key_update(void *cfg, uint16_t net_idx,
 							const uint8_t key[16]);
-bool mesh_config_net_key_del(json_object *jobj, uint16_t net_idx);
-bool mesh_config_net_key_set_phase(json_object *jobj, uint16_t idx,
-								uint8_t phase);
-bool mesh_config_write_address(json_object *jobj, uint16_t address);
-bool mesh_config_write_iv_index(json_object *jobj, uint32_t idx, bool update);
-void mesh_config_remove_property(json_object *jobj, const char *desc);
+bool mesh_config_net_key_del(void *cfg, uint16_t net_idx);
+bool mesh_config_net_key_set_phase(void *cfg, uint16_t net_idx, uint8_t phase);
+bool mesh_config_write_address(void *cfg, uint16_t address);
+bool mesh_config_write_iv_index(void *cfg, uint32_t net_idx, bool update);
+void mesh_config_remove_property(void *cfg, const char *desc);
-- 
2.21.0


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

* [PATCH BlueZ 5/9] mesh: Change variable prefix "jconfig" to "config"
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
                   ` (3 preceding siblings ...)
  2019-07-10  5:09 ` [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  8:29   ` Michał Lowas-Rzechonek
  2019-07-10  5:09 ` [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines Inga Stotland
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This adjust variable naming by changing "jconfig" prefix to more generic
"config. This also removes #include json-c/json.h for model.c,
cfg-server.c and node.c as they no longer rely on the specifics of node
configuration storage implementation.
---
 mesh/cfgmod-server.c | 16 +++++++---------
 mesh/model.c         |  1 -
 mesh/node.c          | 25 ++++++++++++-------------
 mesh/node.h          |  4 ++--
 mesh/storage.c       | 34 +++++++++++++++++-----------------
 5 files changed, 38 insertions(+), 42 deletions(-)

diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 0479a9185..1aa7c85da 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -24,8 +24,6 @@
 #include <sys/time.h>
 #include <ell/ell.h>
 
-#include "json-c/json.h"
-
 #include "mesh/mesh-defs.h"
 #include "mesh/node.h"
 #include "mesh/net.h"
@@ -197,7 +195,7 @@ static bool config_pub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 
 		/* Remove model publication from config file */
 		if (status == MESH_STATUS_SUCCESS)
-			mesh_config_model_pub_del(node_jconfig_get(node),
+			mesh_config_model_pub_del(node_config_get(node),
 				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
 									vendor);
 		goto done;
@@ -219,7 +217,7 @@ static bool config_pub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 			memcpy(db_pub.virt_addr, pub_addr, 16);
 
 		/* Save model publication to config file */
-		if (!mesh_config_model_pub_add(node_jconfig_get(node), ele_addr,
+		if (!mesh_config_model_pub_add(node_config_get(node), ele_addr,
 					vendor ? mod_id : mod_id & 0x0000ffff,
 					vendor, &db_pub))
 			status = MESH_STATUS_STORAGE_FAIL;
@@ -331,18 +329,18 @@ static bool save_config_sub(struct mesh_node *node, uint16_t ele_addr,
 
 	if (opcode == OP_CONFIG_MODEL_SUB_VIRT_OVERWRITE ||
 					opcode == OP_CONFIG_MODEL_SUB_OVERWRITE)
-		mesh_config_model_sub_del_all(node_jconfig_get(node),
+		mesh_config_model_sub_del_all(node_config_get(node),
 				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
 									vendor);
 
 	if (opcode != OP_CONFIG_MODEL_SUB_VIRT_DELETE &&
 			opcode != OP_CONFIG_MODEL_SUB_DELETE)
-		return mesh_config_model_sub_add(node_jconfig_get(node),
+		return mesh_config_model_sub_add(node_config_get(node),
 					ele_addr,
 					vendor ? mod_id : mod_id & 0x0000ffff,
 					vendor, &db_sub);
 	else
-		return mesh_config_model_sub_del(node_jconfig_get(node),
+		return mesh_config_model_sub_del(node_config_get(node),
 					ele_addr,
 					vendor ? mod_id : mod_id & 0x0000ffff,
 					vendor, &db_sub);
@@ -419,7 +417,7 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 		status = mesh_model_sub_del_all(node, ele_addr, mod_id);
 
 		if (status == MESH_STATUS_SUCCESS)
-			mesh_config_model_sub_del_all(node_jconfig_get(node),
+			mesh_config_model_sub_del_all(node_config_get(node),
 				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
 									vendor);
 		break;
@@ -878,7 +876,7 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst,
 
 		count = (pkt[0] >> 5) + 1;
 		interval = ((pkt[0] & 0x1f) + 1) * 10;
-		if (storage_set_transmit_params(node_jconfig_get(node), count,
+		if (storage_set_transmit_params(node_config_get(node), count,
 								interval))
 			mesh_net_transmit_params_set(net, count, interval);
 		/* Fall Through */
diff --git a/mesh/model.c b/mesh/model.c
index 9331e1044..0f10727b4 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -23,7 +23,6 @@
 
 #include <sys/time.h>
 #include <ell/ell.h>
-#include <json-c/json.h>
 
 #include "mesh/mesh-defs.h"
 
diff --git a/mesh/node.c b/mesh/node.c
index 6ebdcf588..82d917337 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -26,7 +26,6 @@
 #include <sys/time.h>
 
 #include <ell/ell.h>
-#include <json-c/json.h>
 
 #include "mesh/mesh-defs.h"
 #include "mesh/mesh.h"
@@ -81,7 +80,7 @@ struct mesh_node {
 	char *app_path;
 	char *owner;
 	char *path;
-	void *jconfig;
+	void *config;
 	char *node_path;
 	uint32_t disc_watch;
 	time_t upd_sec;
@@ -719,7 +718,7 @@ bool node_proxy_mode_set(struct mesh_node *node, bool enable)
 		return false;
 
 	proxy = enable ? MESH_MODE_ENABLED : MESH_MODE_DISABLED;
-	res = storage_set_mode(node->jconfig, proxy, "proxy");
+	res = storage_set_mode(node->config, proxy, "proxy");
 
 	if (res) {
 		node->proxy = proxy;
@@ -746,7 +745,7 @@ bool node_beacon_mode_set(struct mesh_node *node, bool enable)
 		return false;
 
 	beacon = enable ? MESH_MODE_ENABLED : MESH_MODE_DISABLED;
-	res = storage_set_mode(node->jconfig, beacon, "beacon");
+	res = storage_set_mode(node->config, beacon, "beacon");
 
 	if (res) {
 		node->beacon = beacon;
@@ -773,7 +772,7 @@ bool node_friend_mode_set(struct mesh_node *node, bool enable)
 		return false;
 
 	friend = enable ? MESH_MODE_ENABLED : MESH_MODE_DISABLED;
-	res = storage_set_mode(node->jconfig, friend, "friend");
+	res = storage_set_mode(node->config, friend, "friend");
 
 	if (res) {
 		node->friend = friend;
@@ -1431,16 +1430,16 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
 
 	mesh_net_set_iv_index(node->net, iv_idx, ivu);
 
-	if (!mesh_config_write_uint16_hex(node->jconfig, "unicastAddress",
+	if (!mesh_config_write_uint16_hex(node->config, "unicastAddress",
 								unicast))
 		return false;
 
 	l_getrandom(node->token, sizeof(node->token));
-	if (!mesh_config_write_token(node->jconfig, node->token))
+	if (!mesh_config_write_token(node->config, node->token))
 		return false;
 
 	memcpy(node->dev_key, dev_key, 16);
-	if (!mesh_config_write_device_key(node->jconfig, dev_key))
+	if (!mesh_config_write_device_key(node->config, dev_key))
 		return false;
 
 	node->primary = unicast;
@@ -1456,7 +1455,7 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
 							MESH_STATUS_SUCCESS)
 			return false;
 
-		if (!mesh_config_net_key_set_phase(node->jconfig, net_key_idx,
+		if (!mesh_config_net_key_set_phase(node->config, net_key_idx,
 							KEY_REFRESH_PHASE_TWO))
 			return false;
 	}
@@ -2016,14 +2015,14 @@ bool node_add_pending_local(struct mesh_node *node, void *prov_node_info)
 			info->device_key, info->net_index, info->net_key);
 }
 
-void node_jconfig_set(struct mesh_node *node, void *jconfig)
+void node_config_set(struct mesh_node *node, void *config)
 {
-	node->jconfig = jconfig;
+	node->config = config;
 }
 
-void *node_jconfig_get(struct mesh_node *node)
+void *node_config_get(struct mesh_node *node)
 {
-	return node->jconfig;
+	return node->config;
 }
 
 void node_path_set(struct mesh_node *node, char *path)
diff --git a/mesh/node.h b/mesh/node.h
index 142527b30..055862a7f 100644
--- a/mesh/node.h
+++ b/mesh/node.h
@@ -95,7 +95,7 @@ void node_id_set(struct mesh_node *node, uint16_t node_id);
 uint16_t node_id_get(struct mesh_node *node);
 bool node_dbus_init(struct l_dbus *bus);
 void node_cleanup_all(void);
-void node_jconfig_set(struct mesh_node *node, void *jconfig);
-void *node_jconfig_get(struct mesh_node *node);
+void node_config_set(struct mesh_node *node, void *config);
+void *node_config_get(struct mesh_node *node);
 void node_path_set(struct mesh_node *node, char *path);
 char *node_path_get(struct mesh_node *node);
diff --git a/mesh/storage.c b/mesh/storage.c
index 601669791..e87b58c59 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -169,7 +169,7 @@ static bool parse_config(char *in_file, char *out_dir, const uint8_t uuid[16])
 		node_remove(node);
 	}
 
-	node_jconfig_set(node, jnode);
+	node_config_set(node, jnode);
 	node_path_set(node, out_dir);
 
 done:
@@ -182,7 +182,7 @@ done:
 
 bool storage_set_ttl(struct mesh_node *node, uint8_t ttl)
 {
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_write_int(jnode, "defaultTTL", ttl))
 		return false;
@@ -194,7 +194,7 @@ bool storage_set_ttl(struct mesh_node *node, uint8_t ttl)
 bool storage_set_relay(struct mesh_node *node, bool enable,
 				uint8_t count, uint8_t interval)
 {
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_write_relay_mode(jnode, enable, count, interval))
 		return false;
@@ -206,7 +206,7 @@ bool storage_set_relay(struct mesh_node *node, bool enable,
 bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
 							uint8_t interval)
 {
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_write_net_transmit(jnode, count, interval))
 		return false;
@@ -218,7 +218,7 @@ bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
 bool storage_set_mode(struct mesh_node *node, uint8_t mode,
 						const char *mode_name)
 {
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_write_mode(jnode, mode_name, mode))
 		return false;
@@ -238,7 +238,7 @@ bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
 	if (ele_idx < 0)
 		return false;
 
-	jnode = node_jconfig_get(node);
+	jnode = node_config_get(node);
 
 	if (unbind)
 		stored = mesh_config_model_binding_del(jnode, ele_idx,
@@ -260,7 +260,7 @@ bool storage_app_key_add(struct mesh_net *net, uint16_t net_idx,
 	struct mesh_node *node = mesh_net_node_get(net);
 	bool stored;
 
-	jnode = node_jconfig_get(node);
+	jnode = node_config_get(node);
 	if (!jnode)
 		return false;
 
@@ -281,7 +281,7 @@ bool storage_app_key_del(struct mesh_net *net, uint16_t net_idx,
 	json_object *jnode;
 	struct mesh_node *node = mesh_net_node_get(net);
 
-	jnode = node_jconfig_get(node);
+	jnode = node_config_get(node);
 	if (!jnode)
 		return false;
 
@@ -296,7 +296,7 @@ bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
 					const uint8_t key[16], bool update)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 	bool stored;
 
 	if (!update)
@@ -313,7 +313,7 @@ bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
 bool storage_net_key_del(struct mesh_net *net, uint16_t net_idx)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_net_key_del(jnode, net_idx))
 		return false;
@@ -326,7 +326,7 @@ bool storage_set_iv_index(struct mesh_net *net, uint32_t iv_index,
 								bool update)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_write_iv_index(jnode, iv_index, update))
 		return false;
@@ -339,7 +339,7 @@ bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
 								uint8_t phase)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_net_key_set_phase(jnode, net_idx, phase))
 		return false;
@@ -351,7 +351,7 @@ bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
 bool storage_write_sequence_number(struct mesh_net *net, uint32_t seq)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_jconfig_get(node);
+	json_object *jnode = node_config_get(node);
 
 	if (!mesh_config_write_int(jnode, "sequenceNumber", seq))
 		return false;
@@ -421,7 +421,7 @@ void storage_save_config(struct mesh_node *node, bool no_wait,
 	struct write_info *info;
 
 	info = l_new(struct write_info, 1);
-	info->jnode = node_jconfig_get(node);
+	info->jnode = node_config_get(node);
 	info->node_path = node_path_get(node);
 	info->cb = cb;
 	info->user_data = user_data;
@@ -557,7 +557,7 @@ bool storage_create_node_config(struct mesh_node *node, void *data)
 	if (!save_config(jnode, name_buf))
 		goto fail;
 
-	node_jconfig_set(node, jnode);
+	node_config_set(node, jnode);
 
 	return true;
 fail:
@@ -594,11 +594,11 @@ void storage_remove_node_config(struct mesh_node *node)
 		return;
 
 	/* Free the node config json object */
-	jnode = node_jconfig_get(node);
+	jnode = node_config_get(node);
 	if (jnode)
 		json_object_put(jnode);
 
-	node_jconfig_set(node, NULL);
+	node_config_set(node, NULL);
 
 	node_path = node_path_get(node);
 	l_debug("Delete node config %s", node_path);
-- 
2.21.0


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

* [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
                   ` (4 preceding siblings ...)
  2019-07-10  5:09 ` [PATCH BlueZ 5/9] mesh: Change variable prefix "jconfig" to "config" Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  7:52   ` Michał Lowas-Rzechonek
  2019-07-10  5:09 ` [PATCH BlueZ 7/9] mesh: Implement config read/write for mesh json format Inga Stotland
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This adds the following generic APIs to mesh-config.h
    void *mesh_config_create_config(void);
    void mesh_config_release_config(void *config);
    void *mesh_config_get_config(const char *dir);
    void *mesh_config_get_config_backup(const char *dir);
    bool mesh_config_restore_backup(const char *dir);
    bool mesh_config_save_config(const char *dir, void *cfg);

The implementation of these API routines depends on the
underlying storage directory structure and can be specific to
a chosen configuration file format.
---
 mesh/mesh-config.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h
index ab101a331..077c59bbb 100644
--- a/mesh/mesh-config.h
+++ b/mesh/mesh-config.h
@@ -100,6 +100,13 @@ typedef bool (*mesh_config_app_key_cb)(uint16_t idx, uint16_t net_idx,
 typedef bool (*mesh_config_node_cb)(struct mesh_config_node *node,
 							void *user_data);
 
+void *mesh_config_create_config(void);
+void mesh_config_release_config(void *config);
+void *mesh_config_get_config(const char *dir);
+void *mesh_config_get_config_backup(const char *dir);
+bool mesh_config_restore_backup(const char *dir);
+bool mesh_config_save_config(const char *dir, void *cfg);
+
 bool mesh_config_read_node(void *cfg, mesh_config_node_cb cb, void *user_data);
 bool mesh_config_add_node(void *cfg, struct mesh_config_node *node);
 bool mesh_config_read_iv_index(void *cfg, uint32_t *idx, bool *update);
-- 
2.21.0


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

* [PATCH BlueZ 7/9] mesh: Implement config read/write for mesh json format
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
                   ` (5 preceding siblings ...)
  2019-07-10  5:09 ` [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 8/9] mesh: Switch to using mesh-config routines for storage Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 9/9] mesh: Make storage.c json-c agnostic Inga Stotland
  8 siblings, 0 replies; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This adds implementation of
mesh_config_create_config(), mesh_config_release_config(),
mesh_config_get_config(), mesh_config_get_config_backup(),
mesh_config_restore_backup() and mesh_config_save_config()
for the JSON based node configuration storage.
---
 mesh/mesh-config-json.c | 171 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 171 insertions(+)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 5ca086ad0..3c65b3846 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -22,9 +22,14 @@
 #endif
 
 #define _GNU_SOURCE
+
+#include <dirent.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <ftw.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <ell/ell.h>
 #include <json-c/json.h>
@@ -35,6 +40,10 @@
 
 #define CHECK_KEY_IDX_RANGE(x) (((x) >= 0) && ((x) <= 4095))
 
+static const char *cfg_name = "/node.json";
+static const char *bak_name = "/node.json.bak";
+static const char *tmp_name = "/node.json.tmp";
+
 static bool get_int(json_object *jobj, const char *keyword, int *value)
 {
 	json_object *jvalue;
@@ -1827,3 +1836,165 @@ bool mesh_config_model_sub_del_all(void *cfg, uint16_t addr, uint32_t mod_id,
 
 	return delete_model_property(jnode, addr, mod_id, vendor, "subscribe");
 }
+
+static char *create_filename(const char *dir, const char *fname)
+{
+	size_t path_len = strlen(dir) + strlen(fname);
+
+	if (path_len + 1 >= PATH_MAX)
+		return NULL;
+
+	return l_strdup_printf("%s%s", dir, fname);
+}
+
+static void *get_node_config(const char *dir, const char *fname)
+{
+	int fd;
+	char *str = NULL, *fname_full;
+	struct stat st;
+	ssize_t sz;
+	json_object *jconfig = NULL;
+
+	fname_full = create_filename(dir, fname);
+	if (!fname)
+		return NULL;
+
+	l_info("Loading configuration from %s", fname_full);
+
+	fd = open(fname_full, O_RDONLY);
+	if (fd < 0)
+		goto done;
+
+	if (fstat(fd, &st) == -1)
+		goto done;
+
+	str = (char *) l_new(char, st.st_size + 1);
+	if (!str)
+		goto done;
+
+	sz = read(fd, str, st.st_size);
+	if (sz != st.st_size) {
+		l_error("Failed to read configuration file %s", fname_full);
+		goto done;
+	}
+
+	jconfig = json_tokener_parse(str);
+
+done:
+	if (fd >= 0)
+		close(fd);
+
+	l_free(str);
+	l_free(fname_full);
+
+	return jconfig;
+}
+
+void *mesh_config_get_config(const char *dir)
+{
+	if (!dir)
+		return NULL;
+
+	return get_node_config(dir, cfg_name);
+}
+
+void *mesh_config_get_config_backup(const char *dir)
+{
+	if (!dir)
+		return NULL;
+
+	return get_node_config(cfg_name, bak_name);
+}
+
+bool mesh_config_restore_backup(const char *dir)
+{
+	char *fname_cfg = NULL, *fname_bak = NULL;
+	bool res = false;
+
+	fname_cfg = create_filename(dir, cfg_name);
+	fname_bak = create_filename(dir, bak_name);
+
+	if (fname_cfg && fname_bak) {
+		remove(fname_cfg);
+		rename(fname_bak, fname_cfg);
+		res = true;
+	}
+
+	l_free(fname_bak);
+	l_free(fname_cfg);
+
+	return res;
+}
+
+static bool save_config(void *cfg, const char *fname)
+{
+	FILE *outfile;
+	const char *str;
+	bool result = false;
+	json_object *jnode = cfg;
+
+	outfile = fopen(fname, "w");
+
+	if (!outfile)
+		return false;
+
+	str = json_object_to_json_string_ext(jnode, JSON_C_TO_STRING_PRETTY);
+
+	if (fwrite(str, sizeof(char), strlen(str), outfile) < strlen(str))
+		l_warn("Incomplete write of mesh configuration");
+	else
+		result = true;
+
+	fclose(outfile);
+
+	return result;
+}
+
+void *mesh_config_create_config(void)
+{
+	return json_object_new_object();
+}
+
+void mesh_config_release_config(void *cfg)
+{
+	json_object *jnode = cfg;
+
+	if (!cfg)
+		return;
+
+	json_object_put(jnode);
+}
+
+bool mesh_config_save_config(const char *dir, void *cfg)
+{
+	char *fname_cfg;
+	char *fname_bak;
+	char *fname_tmp;
+	bool result = false;
+
+	fname_cfg = create_filename(dir, cfg_name);
+	fname_bak = create_filename(dir, bak_name);
+	fname_tmp = create_filename(dir, tmp_name);
+
+	if (!fname_cfg || !fname_bak || !fname_tmp)
+		goto done;
+
+	result = save_config(cfg, fname_tmp);
+
+	if (result) {
+		remove(fname_bak);
+		rename(fname_cfg, fname_bak);
+		rename(fname_tmp, fname_cfg);
+	} else {
+		l_error("Failed to save configuration to %s", fname_tmp);
+	}
+
+	remove(fname_tmp);
+
+done:
+	l_free(fname_cfg);
+	l_free(fname_bak);
+	l_free(fname_tmp);
+
+	return result;
+}
-- 
2.21.0


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

* [PATCH BlueZ 8/9] mesh: Switch to using mesh-config routines for storage
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
                   ` (6 preceding siblings ...)
  2019-07-10  5:09 ` [PATCH BlueZ 7/9] mesh: Implement config read/write for mesh json format Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  2019-07-10  5:09 ` [PATCH BlueZ 9/9] mesh: Make storage.c json-c agnostic Inga Stotland
  8 siblings, 0 replies; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This removes the assumptions of the layout of the node configuration
directory from storage.c to allow read/write of persistent node
configuration to be format agnostic.
---
 mesh/mesh.c    |  11 ++-
 mesh/storage.c | 229 +++++++++++++++++--------------------------------
 2 files changed, 87 insertions(+), 153 deletions(-)

diff --git a/mesh/mesh.c b/mesh/mesh.c
index 26acfd4dc..bdd79e6bb 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
@@ -22,6 +22,8 @@
 #endif
 
 #define _GNU_SOURCE
+#include <dirent.h>
+
 #include <ell/ell.h>
 
 #include "mesh/mesh-io.h"
@@ -143,6 +145,12 @@ bool mesh_init(const char *config_dir, enum mesh_io_type type, void *opts)
 	if (mesh.io)
 		return true;
 
+	if (!config_dir)
+		config_dir = MESH_STORAGEDIR;
+
+	if (strlen(config_dir) >= PATH_MAX)
+		return false;
+
 	mesh_model_init();
 	mesh_agent_init();
 
@@ -150,9 +158,6 @@ bool mesh_init(const char *config_dir, enum mesh_io_type type, void *opts)
 	mesh.prov_timeout = DEFAULT_PROV_TIMEOUT;
 	mesh.algorithms = DEFAULT_ALGORITHMS;
 
-	if (!config_dir)
-		config_dir = MESH_STORAGEDIR;
-
 	l_info("Loading node configuration from %s", config_dir);
 
 	if (!storage_load_nodes(config_dir))
diff --git a/mesh/storage.c b/mesh/storage.c
index e87b58c59..721b65904 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -47,9 +47,6 @@ struct write_info {
 	mesh_status_func_t cb;
 };
 
-static const char *cfg_name = "/node.json";
-static const char *bak_ext = ".bak";
-static const char *tmp_ext = ".tmp";
 static const char *storage_dir;
 
 static bool read_node_cb(struct mesh_config_node *db_node, void *user_data)
@@ -123,61 +120,21 @@ static bool parse_node(struct mesh_node *node, json_object *jnode)
 	return true;
 }
 
-static bool parse_config(char *in_file, char *out_dir, const uint8_t uuid[16])
+static struct mesh_node *parse_config(void *node_cfg,  const uint8_t uuid[16])
 {
-	int fd;
-	char *str;
-	struct stat st;
-	ssize_t sz;
-	json_object *jnode = NULL;
 	bool result = false;
 	struct mesh_node *node;
 
-	l_info("Loading configuration from %s", in_file);
-
-	fd = open(in_file, O_RDONLY);
-	if (fd < 0)
-		return false;
-
-	if (fstat(fd, &st) == -1) {
-		close(fd);
-		return false;
-	}
-
-	str = (char *) l_new(char, st.st_size + 1);
-	if (!str) {
-		close(fd);
-		return false;
-	}
-
-	sz = read(fd, str, st.st_size);
-	if (sz != st.st_size) {
-		l_error("Failed to read configuration file %s", in_file);
-		goto done;
-	}
-
-	jnode = json_tokener_parse(str);
-	if (!jnode)
-		goto done;
-
 	node = node_new(uuid);
 
-	result = parse_node(node, jnode);
+	result = parse_node(node, node_cfg);
 
 	if (!result) {
-		json_object_put(jnode);
 		node_remove(node);
+		return NULL;
 	}
 
-	node_config_set(node, jnode);
-	node_path_set(node, out_dir);
-
-done:
-	close(fd);
-	if (str)
-		l_free(str);
-
-	return result;
+	return node;
 }
 
 bool storage_set_ttl(struct mesh_node *node, uint8_t ttl)
@@ -360,54 +317,13 @@ bool storage_write_sequence_number(struct mesh_net *net, uint32_t seq)
 	return true;
 }
 
-static bool save_config(json_object *jnode, const char *config_name)
-{
-	FILE *outfile;
-	const char *str;
-	bool result = false;
-
-	outfile = fopen(config_name, "w");
-	if (!outfile) {
-		l_error("Failed to save configuration to %s", config_name);
-		return false;
-	}
-
-	str = json_object_to_json_string_ext(jnode, JSON_C_TO_STRING_PRETTY);
-
-	if (fwrite(str, sizeof(char), strlen(str), outfile) < strlen(str))
-		l_warn("Incomplete write of mesh configuration");
-	else
-		result = true;
-
-	fclose(outfile);
-
-	return result;
-}
-
 static void idle_save_config(void *user_data)
 {
 	struct write_info *info = user_data;
-	char *tmp, *bak, *cfg;
-	bool result = false;
-
-	cfg = l_strdup_printf("%s%s", info->node_path, cfg_name);
-	tmp = l_strdup_printf("%s%s", cfg, tmp_ext);
-	bak = l_strdup_printf("%s%s", cfg, bak_ext);
-	remove(tmp);
+	bool result;
 
 	l_debug("Storage-Wrote");
-	result = save_config(info->jnode, tmp);
-
-	if (result) {
-		remove(bak);
-		rename(cfg, bak);
-		rename(tmp, cfg);
-	}
-
-	remove(tmp);
-	l_free(tmp);
-	l_free(bak);
-	l_free(cfg);
+	result = mesh_config_save_config(info->node_path, info->jnode);
 
 	if (info->cb)
 		info->cb(info->user_data, result);
@@ -472,7 +388,7 @@ bool storage_load_nodes(const char *dir_name)
 {
 	DIR *dir;
 	struct dirent *entry;
-	size_t path_len = strlen(dir_name) + strlen(cfg_name) + strlen(bak_ext);
+	size_t path_len = strlen(dir_name);
 
 	create_dir(dir_name);
 	dir = opendir(dir_name);
@@ -485,84 +401,53 @@ bool storage_load_nodes(const char *dir_name)
 	storage_dir = dir_name;
 
 	while ((entry = readdir(dir)) != NULL) {
-		char *dir, *cfg, *bak;
+		char *dir;
+		void *config;
 		uint8_t uuid[16];
-		size_t node_len;
+		size_t subdir_len;
+		struct mesh_node *node;
 
 		if (entry->d_type != DT_DIR)
 			continue;
 
 		/* Check path length */
-		node_len = strlen(entry->d_name);
-		if (path_len + node_len + 1 >= PATH_MAX)
+		subdir_len = strlen(entry->d_name);
+		if (path_len + subdir_len + 1 >= PATH_MAX)
 			continue;
 
-		if (!str2hex(entry->d_name, node_len, uuid, sizeof(uuid)))
+		if (!str2hex(entry->d_name, subdir_len, uuid, sizeof(uuid)))
 			continue;
 
 		dir = l_strdup_printf("%s/%s", dir_name, entry->d_name);
-		cfg = l_strdup_printf("%s%s", dir, cfg_name);
-
-		if (!parse_config(cfg, dir, uuid)) {
-
-			/* Fall-back to Backup version */
-			bak = l_strdup_printf("%s%s", cfg, bak_ext);
-
-			if (parse_config(bak, dir, uuid)) {
-				remove(cfg);
-				rename(bak, cfg);
-			}
-			l_free(bak);
-		}
-		l_free(cfg);
-		l_free(dir);
-	}
-
-	return true;
-}
-
-bool storage_create_node_config(struct mesh_node *node, void *data)
-{
-	struct mesh_config_node *db_node = data;
-	char uuid[33];
-	char name_buf[PATH_MAX];
-	json_object *jnode;
-	size_t max_len = strlen(cfg_name) + strlen(bak_ext);
-
-	if (!storage_dir)
-		return false;
-
-	jnode = json_object_new_object();
-
-	if (!mesh_config_add_node(jnode, db_node))
-		return false;
-
-	if (!hex2str(node_uuid_get(node), 16, uuid, sizeof(uuid)))
-		goto fail;
+		config = mesh_config_get_config(dir);
+		if (!config)
+			continue;
 
-	snprintf(name_buf, PATH_MAX, "%s/%s", storage_dir, uuid);
+		node = parse_config(config, uuid);
 
-	if (strlen(name_buf) + max_len >= PATH_MAX)
-		goto fail;
+		if (!node) {
+			mesh_config_release_config(config);
 
-	/* Create a new directory and node.json file */
-	if (mkdir(name_buf, 0755) != 0)
-		goto fail;
+			/* Fall-back to Backup version */
+			config = mesh_config_get_config_backup(dir);
 
-	node_path_set(node, name_buf);
+			node = parse_config(config, uuid);
 
-	snprintf(name_buf, PATH_MAX, "%s/%s%s", storage_dir, uuid, cfg_name);
-	l_debug("New node config %s", name_buf);
+			if (node)
+				mesh_config_restore_backup(dir);
+			else
+				mesh_config_release_config(config);
+		}
 
-	if (!save_config(jnode, name_buf))
-		goto fail;
+		if (node) {
+			node_path_set(node, dir);
+			node_config_set(node, config);
+		}
 
-	node_config_set(node, jnode);
+		l_free(dir);
+	}
 
 	return true;
-fail:
-	json_object_put(jnode);
-	return false;
 }
 
 static int del_fobject(const char *fpath, const struct stat *sb, int typeflag,
@@ -596,7 +481,7 @@ void storage_remove_node_config(struct mesh_node *node)
 	/* Free the node config json object */
 	jnode = node_config_get(node);
 	if (jnode)
-		json_object_put(jnode);
+		mesh_config_release_config(jnode);
 
 	node_config_set(node, NULL);
 
@@ -614,3 +499,47 @@ void storage_remove_node_config(struct mesh_node *node)
 
 	nftw(node_path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
 }
+
+bool storage_create_node_config(struct mesh_node *node, void *data)
+{
+	struct mesh_config_node *db_node = data;
+	char uuid[33];
+	char node_dir[PATH_MAX];
+	json_object *jnode;
+
+	if (!storage_dir)
+		return false;
+
+	jnode = mesh_config_create_config();
+
+	if (!jnode || !mesh_config_add_node(jnode, db_node))
+		return false;
+
+	if (!hex2str(node_uuid_get(node), 16, uuid, sizeof(uuid)))
+		goto fail;
+
+	snprintf(node_dir, PATH_MAX, "%s/%s", storage_dir, uuid);
+
+	if (strlen(node_dir) >= PATH_MAX)
+		goto fail;
+
+	/* Create a new node config directory */
+	if (mkdir(node_dir, 0755) != 0)
+		goto fail;
+
+	if (!mesh_config_save_config(node_dir, jnode)) {
+		nftw(node_dir, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
+		goto fail;
+	}
+
+	l_debug("New node config %s", node_dir);
+	node_path_set(node, node_dir);
+	node_config_set(node, jnode);
+
+	return true;
+fail:
+	mesh_config_release_config(jnode);
+	node_config_set(node, NULL);
+
+	return false;
+}
-- 
2.21.0


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

* [PATCH BlueZ 9/9] mesh: Make storage.c json-c agnostic
  2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
                   ` (7 preceding siblings ...)
  2019-07-10  5:09 ` [PATCH BlueZ 8/9] mesh: Switch to using mesh-config routines for storage Inga Stotland
@ 2019-07-10  5:09 ` Inga Stotland
  8 siblings, 0 replies; 19+ messages in thread
From: Inga Stotland @ 2019-07-10  5:09 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: brian.gix, michal.lowas-rzechonek, jakub.witowski, Inga Stotland

This removes all the references to json-c constructs from storage.c
All the storage operations are now interfacing through mesh-config APIs.
---
 mesh/storage.c | 122 ++++++++++++++++++++++++-------------------------
 1 file changed, 61 insertions(+), 61 deletions(-)

diff --git a/mesh/storage.c b/mesh/storage.c
index 721b65904..a4131404e 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -29,7 +29,6 @@
 #include <libgen.h>
 #include <ftw.h>
 
-#include <json-c/json.h>
 #include <ell/ell.h>
 
 #include "mesh/mesh-defs.h"
@@ -41,8 +40,8 @@
 #include "mesh/storage.h"
 
 struct write_info {
-	json_object *jnode;
-	const char *node_path;
+	void *node_cfg;
+	const char *node_dir;
 	void *user_data;
 	mesh_status_func_t cb;
 };
@@ -83,7 +82,7 @@ static bool read_app_keys_cb(uint16_t net_idx, uint16_t app_idx, uint8_t *key,
 	return appkey_key_init(net, net_idx, app_idx, key, new_key);
 }
 
-static bool parse_node(struct mesh_node *node, json_object *jnode)
+static bool parse_node(struct mesh_node *node, void *node_cfg)
 {
 	bool bvalue;
 	uint32_t iv_index;
@@ -92,30 +91,30 @@ static bool parse_node(struct mesh_node *node, json_object *jnode)
 	uint16_t interval;
 	struct mesh_net *net = node_get_net(node);
 
-	if (mesh_config_read_iv_index(jnode, &iv_index, &bvalue))
+	if (mesh_config_read_iv_index(node_cfg, &iv_index, &bvalue))
 		mesh_net_set_iv_index(net, iv_index, bvalue);
 
-	if (mesh_config_read_net_transmit(jnode, &cnt, &interval))
+	if (mesh_config_read_net_transmit(node_cfg, &cnt, &interval))
 		mesh_net_transmit_params_set(net, cnt, interval);
 
 	/* Node composition/configuration info */
-	if (!mesh_config_read_node(jnode, read_node_cb, node))
+	if (!mesh_config_read_node(node_cfg, read_node_cb, node))
 		return false;
 
-	if (!mesh_config_read_net_keys(jnode, read_net_keys_cb, net))
+	if (!mesh_config_read_net_keys(node_cfg, read_net_keys_cb, net))
 		return false;
 
-	if (!mesh_config_read_token(jnode, key_buf))
+	if (!mesh_config_read_token(node_cfg, key_buf))
 		return false;
 
 	node_set_token(node, key_buf);
 
-	if (!mesh_config_read_device_key(jnode, key_buf))
+	if (!mesh_config_read_device_key(node_cfg, key_buf))
 		return false;
 
 	node_set_device_key(node, key_buf);
 
-	mesh_config_read_app_keys(jnode, read_app_keys_cb, net);
+	mesh_config_read_app_keys(node_cfg, read_app_keys_cb, net);
 
 	return true;
 }
@@ -139,9 +138,9 @@ static struct mesh_node *parse_config(void *node_cfg,  const uint8_t uuid[16])
 
 bool storage_set_ttl(struct mesh_node *node, uint8_t ttl)
 {
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_write_int(jnode, "defaultTTL", ttl))
+	if (!mesh_config_write_int(node_cfg, "defaultTTL", ttl))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -151,9 +150,9 @@ bool storage_set_ttl(struct mesh_node *node, uint8_t ttl)
 bool storage_set_relay(struct mesh_node *node, bool enable,
 				uint8_t count, uint8_t interval)
 {
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_write_relay_mode(jnode, enable, count, interval))
+	if (!mesh_config_write_relay_mode(node_cfg, enable, count, interval))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -163,9 +162,9 @@ bool storage_set_relay(struct mesh_node *node, bool enable,
 bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
 							uint8_t interval)
 {
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_write_net_transmit(jnode, count, interval))
+	if (!mesh_config_write_net_transmit(node_cfg, count, interval))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -175,9 +174,9 @@ bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
 bool storage_set_mode(struct mesh_node *node, uint8_t mode,
 						const char *mode_name)
 {
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_write_mode(jnode, mode_name, mode))
+	if (!mesh_config_write_mode(node_cfg, mode_name, mode))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -187,7 +186,7 @@ bool storage_set_mode(struct mesh_node *node, uint8_t mode,
 bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
 				uint16_t app_idx, bool unbind)
 {
-	json_object *jnode;
+	void *node_cfg;
 	int ele_idx;
 	bool stored, is_vendor = (mod_id > 0xffff);
 
@@ -195,13 +194,13 @@ bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
 	if (ele_idx < 0)
 		return false;
 
-	jnode = node_config_get(node);
+	node_cfg = node_config_get(node);
 
 	if (unbind)
-		stored = mesh_config_model_binding_del(jnode, ele_idx,
+		stored = mesh_config_model_binding_del(node_cfg, ele_idx,
 						is_vendor, mod_id, app_idx);
 	else
-		stored = mesh_config_model_binding_add(jnode, ele_idx,
+		stored = mesh_config_model_binding_add(node_cfg, ele_idx,
 						is_vendor, mod_id, app_idx);
 
 	if (stored)
@@ -213,18 +212,19 @@ bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
 bool storage_app_key_add(struct mesh_net *net, uint16_t net_idx,
 			uint16_t app_idx, const uint8_t key[16], bool update)
 {
-	json_object *jnode;
+	void *node_cfg;
 	struct mesh_node *node = mesh_net_node_get(net);
 	bool stored;
 
-	jnode = node_config_get(node);
-	if (!jnode)
+	node_cfg = node_config_get(node);
+	if (!node_cfg)
 		return false;
 
 	if (update)
-		stored = mesh_config_app_key_update(jnode, app_idx, key);
+		stored = mesh_config_app_key_update(node_cfg, app_idx, key);
 	else
-		stored = mesh_config_app_key_add(jnode, net_idx, app_idx, key);
+		stored = mesh_config_app_key_add(node_cfg, net_idx, app_idx,
+									key);
 
 	if (stored)
 		storage_save_config(node, true, NULL, NULL);
@@ -235,14 +235,14 @@ bool storage_app_key_add(struct mesh_net *net, uint16_t net_idx,
 bool storage_app_key_del(struct mesh_net *net, uint16_t net_idx,
 					uint16_t app_idx)
 {
-	json_object *jnode;
+	void *node_cfg;
 	struct mesh_node *node = mesh_net_node_get(net);
 
-	jnode = node_config_get(node);
-	if (!jnode)
+	node_cfg = node_config_get(node);
+	if (!node_cfg)
 		return false;
 
-	if (!mesh_config_app_key_del(jnode, net_idx, app_idx))
+	if (!mesh_config_app_key_del(node_cfg, net_idx, app_idx))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -253,13 +253,13 @@ bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
 					const uint8_t key[16], bool update)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 	bool stored;
 
 	if (!update)
-		stored = mesh_config_net_key_add(jnode, net_idx, key);
+		stored = mesh_config_net_key_add(node_cfg, net_idx, key);
 	else
-		stored = mesh_config_net_key_update(jnode, net_idx, key);
+		stored = mesh_config_net_key_update(node_cfg, net_idx, key);
 
 	if (stored)
 		storage_save_config(node, true, NULL, NULL);
@@ -270,9 +270,9 @@ bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
 bool storage_net_key_del(struct mesh_net *net, uint16_t net_idx)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_net_key_del(jnode, net_idx))
+	if (!mesh_config_net_key_del(node_cfg, net_idx))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -283,9 +283,9 @@ bool storage_set_iv_index(struct mesh_net *net, uint32_t iv_index,
 								bool update)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_write_iv_index(jnode, iv_index, update))
+	if (!mesh_config_write_iv_index(node_cfg, iv_index, update))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -296,9 +296,9 @@ bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
 								uint8_t phase)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_net_key_set_phase(jnode, net_idx, phase))
+	if (!mesh_config_net_key_set_phase(node_cfg, net_idx, phase))
 		return false;
 
 	storage_save_config(node, true, NULL, NULL);
@@ -308,9 +308,9 @@ bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
 bool storage_write_sequence_number(struct mesh_net *net, uint32_t seq)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
-	json_object *jnode = node_config_get(node);
+	void *node_cfg = node_config_get(node);
 
-	if (!mesh_config_write_int(jnode, "sequenceNumber", seq))
+	if (!mesh_config_write_int(node_cfg, "sequenceNumber", seq))
 		return false;
 
 	storage_save_config(node, false, NULL, NULL);
@@ -323,7 +323,7 @@ static void idle_save_config(void *user_data)
 	bool result;
 
 	l_debug("Storage-Wrote");
-	result = mesh_config_save_config(info->node_path, info->jnode);
+	result = mesh_config_save_config(info->node_dir, info->node_cfg);
 
 	if (info->cb)
 		info->cb(info->user_data, result);
@@ -337,8 +337,8 @@ void storage_save_config(struct mesh_node *node, bool no_wait,
 	struct write_info *info;
 
 	info = l_new(struct write_info, 1);
-	info->jnode = node_config_get(node);
-	info->node_path = node_path_get(node);
+	info->node_cfg = node_config_get(node);
+	info->node_dir = node_path_get(node);
 	info->cb = cb;
 	info->user_data = user_data;
 
@@ -471,33 +471,33 @@ static int del_fobject(const char *fpath, const struct stat *sb, int typeflag,
 /* Permanently remove node configuration */
 void storage_remove_node_config(struct mesh_node *node)
 {
-	char *node_path, *node_name;
+	char *node_dir, *node_name;
 	char uuid[33];
-	struct json_object *jnode;
+	void *node_cfg;
 
 	if (!node)
 		return;
 
 	/* Free the node config json object */
-	jnode = node_config_get(node);
-	if (jnode)
-		mesh_config_release_config(jnode);
+	node_cfg = node_config_get(node);
+	if (node_cfg)
+		mesh_config_release_config(node_cfg);
 
 	node_config_set(node, NULL);
 
-	node_path = node_path_get(node);
-	l_debug("Delete node config %s", node_path);
+	node_dir = node_path_get(node);
+	l_debug("Delete node config %s", node_dir);
 
 	/* Make sure path name of node follows expected guidelines */
 	if (!hex2str(node_uuid_get(node), 16, uuid, sizeof(uuid)))
 		return;
 
-	node_name = basename(node_path);
+	node_name = basename(node_dir);
 
 	if (strcmp(node_name, uuid))
 		return;
 
-	nftw(node_path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
+	nftw(node_dir, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
 }
 
 bool storage_create_node_config(struct mesh_node *node, void *data)
@@ -505,14 +505,14 @@ bool storage_create_node_config(struct mesh_node *node, void *data)
 	struct mesh_config_node *db_node = data;
 	char uuid[33];
 	char node_dir[PATH_MAX];
-	json_object *jnode;
+	void *node_cfg;
 
 	if (!storage_dir)
 		return false;
 
-	jnode = mesh_config_create_config();
+	node_cfg = mesh_config_create_config();
 
-	if (!jnode || !mesh_config_add_node(jnode, db_node))
+	if (!node_cfg || !mesh_config_add_node(node_cfg, db_node))
 		return false;
 
 	if (!hex2str(node_uuid_get(node), 16, uuid, sizeof(uuid)))
@@ -527,18 +527,18 @@ bool storage_create_node_config(struct mesh_node *node, void *data)
 	if (mkdir(node_dir, 0755) != 0)
 		goto fail;
 
-	if (!mesh_config_save_config(node_dir, jnode)) {
+	if (!mesh_config_save_config(node_dir, node_cfg)) {
 		nftw(node_dir, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
 		goto fail;
 	}
 
 	l_debug("New node config %s", node_dir);
 	node_path_set(node, node_dir);
-	node_config_set(node, jnode);
+	node_config_set(node, node_cfg);
 
 	return true;
 fail:
-	mesh_config_release_config(jnode);
+	mesh_config_release_config(node_cfg);
 	node_config_set(node, NULL);
 
 	return false;
-- 
2.21.0


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

* Re: [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs
  2019-07-10  5:09 ` [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs Inga Stotland
@ 2019-07-10  7:38   ` Michał Lowas-Rzechonek
  2019-07-10 15:01     ` Michał Lowas-Rzechonek
  0 siblings, 1 reply; 19+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-07-10  7:38 UTC (permalink / raw)
  To: Inga Stotland; +Cc: linux-bluetooth, brian.gix, jakub.witowski

Hi Inga,

On 07/09, Inga Stotland wrote:
> This changes argument for each mesh-config API to use void* as
> a pointer to a node configuration object. This makes usage of JSON
> opaque for the rest of the code and allows to plug in a non-JSON
> configuration storage implementation.
> ---
>  mesh/mesh-config-json.c | 228 +++++++++++++++++++++++-----------------
>  mesh/mesh-config.h      | 107 +++++++++----------
>  2 files changed, 180 insertions(+), 155 deletions(-)
> 
> diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
> index 8fcb8afe3..5ca086ad0 100644
> --- a/mesh/mesh-config-json.c
> +++ b/mesh/mesh-config-json.c
> @@ -252,10 +252,14 @@ static json_object *jarray_key_del(json_object *jarray, int16_t idx)
>  	return jarray_new;
>  }
>  
> -bool mesh_config_read_iv_index(json_object *jobj, uint32_t *idx, bool *update)
> +bool mesh_config_read_iv_index(void *cfg, uint32_t *idx, bool *update)

I'm not a fan of using void* for polymorphism. While there are places
this makes sense (e.g. user_data pointers in callbacks), I think we
should try to avoid this in our APIs.

Since the proposed patch assumes that we would switch backends during
the build, and you can't have two different config formats compiled in
at the same time, how about this:

mesh-config.h:
    union mesh_config;

    union mesh_config *mesh_config_create_config(void);
    void mesh_config_release_config(union mesh_config *config);

mesh-config-json.c:
    union mesh_config {
        json_object *json
    };

    union mesh_config *mesh_config_create_config(void)
    {
        return (union mesh_config*)json_object_new_object();
    }

    void mesh_config_release_config(union mesh_config *cfg)
    {
        json_object *jnode = (json_object *)cfg;

        if (!cfg)
            return;

        json_object_put(jnode);
    }

etc.

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

* Re: [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines
  2019-07-10  5:09 ` [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines Inga Stotland
@ 2019-07-10  7:52   ` Michał Lowas-Rzechonek
  2019-07-10 16:53     ` Stotland, Inga
  2019-07-10 17:20     ` Gix, Brian
  0 siblings, 2 replies; 19+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-07-10  7:52 UTC (permalink / raw)
  To: Inga Stotland; +Cc: linux-bluetooth, brian.gix, jakub.witowski

On 07/09, Inga Stotland wrote:
> This adds the following generic APIs to mesh-config.h
>     void *mesh_config_create_config(void);
>     void mesh_config_release_config(void *config);
>     void *mesh_config_get_config(const char *dir);
>     void *mesh_config_get_config_backup(const char *dir);
>     bool mesh_config_restore_backup(const char *dir);
>     bool mesh_config_save_config(const char *dir, void *cfg);
>
> The implementation of these API routines depends on the
> underlying storage directory structure and can be specific to
> a chosen configuration file format.

I don't like the assumption that each node is stored in a separate file,
and there needs to be a backup file.

One of the storage formats I had in mind is a single transactional
database (some flavor of berkeley db, or maybe even sqlite) that would
hold all the nodes.

With this in mind, how about:

    union mesh_config *mesh_config_create_config(const uint8_t uuid[16]);
    bool mesh_config_save(union mesh_config *cfg);

and to iterate over saved nodes:
    typedef struct mesh_node *(*mesh_node_load_cb)(union mesh_config *cfg,
                                                    const uint8_t uuid[16],
                                                    void *user_data);

    void mesh_config_load_nodes(mesh_node_load_cb cb, void *user_data);

and move file/directory handling from storage.c to mesh-config-json.c?


regards
-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

* Re: [PATCH BlueZ 5/9] mesh: Change variable prefix "jconfig" to "config"
  2019-07-10  5:09 ` [PATCH BlueZ 5/9] mesh: Change variable prefix "jconfig" to "config" Inga Stotland
@ 2019-07-10  8:29   ` Michał Lowas-Rzechonek
  0 siblings, 0 replies; 19+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-07-10  8:29 UTC (permalink / raw)
  To: Inga Stotland; +Cc: linux-bluetooth, brian.gix, jakub.witowski

Inga,

On 07/09, Inga Stotland wrote:
> This adjust variable naming by changing "jconfig" prefix to more generic
> "config. This also removes #include json-c/json.h for model.c,
> cfg-server.c and node.c as they no longer rely on the specifics of node
> configuration storage implementation.
> ---
>  mesh/cfgmod-server.c | 16 +++++++---------
>  mesh/model.c         |  1 -
>  mesh/node.c          | 25 ++++++++++++-------------
>  mesh/node.h          |  4 ++--
>  mesh/storage.c       | 34 +++++++++++++++++-----------------
>  5 files changed, 38 insertions(+), 42 deletions(-)
> 
> diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
> index 0479a9185..1aa7c85da 100644
> --- a/mesh/cfgmod-server.c
> +++ b/mesh/cfgmod-server.c
> @@ -24,8 +24,6 @@
>  #include <sys/time.h>
>  #include <ell/ell.h>
>  
> -#include "json-c/json.h"
> -
>  #include "mesh/mesh-defs.h"
>  #include "mesh/node.h"
>  #include "mesh/net.h"
> @@ -197,7 +195,7 @@ static bool config_pub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
>  
>  		/* Remove model publication from config file */
>  		if (status == MESH_STATUS_SUCCESS)
> -			mesh_config_model_pub_del(node_jconfig_get(node),
> +			mesh_config_model_pub_del(node_config_get(node),
>  				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
>  									vendor);
>  		goto done;
> @@ -219,7 +217,7 @@ static bool config_pub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
>  			memcpy(db_pub.virt_addr, pub_addr, 16);
>  
>  		/* Save model publication to config file */
> -		if (!mesh_config_model_pub_add(node_jconfig_get(node), ele_addr,
> +		if (!mesh_config_model_pub_add(node_config_get(node), ele_addr,
>  					vendor ? mod_id : mod_id & 0x0000ffff,
>  					vendor, &db_pub))
>  			status = MESH_STATUS_STORAGE_FAIL;
> @@ -331,18 +329,18 @@ static bool save_config_sub(struct mesh_node *node, uint16_t ele_addr,
>  
>  	if (opcode == OP_CONFIG_MODEL_SUB_VIRT_OVERWRITE ||
>  					opcode == OP_CONFIG_MODEL_SUB_OVERWRITE)
> -		mesh_config_model_sub_del_all(node_jconfig_get(node),
> +		mesh_config_model_sub_del_all(node_config_get(node),
>  				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
>  									vendor);
>  
>  	if (opcode != OP_CONFIG_MODEL_SUB_VIRT_DELETE &&
>  			opcode != OP_CONFIG_MODEL_SUB_DELETE)
> -		return mesh_config_model_sub_add(node_jconfig_get(node),
> +		return mesh_config_model_sub_add(node_config_get(node),
>  					ele_addr,
>  					vendor ? mod_id : mod_id & 0x0000ffff,
>  					vendor, &db_sub);
>  	else
> -		return mesh_config_model_sub_del(node_jconfig_get(node),
> +		return mesh_config_model_sub_del(node_config_get(node),
>  					ele_addr,
>  					vendor ? mod_id : mod_id & 0x0000ffff,
>  					vendor, &db_sub);
> @@ -419,7 +417,7 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
>  		status = mesh_model_sub_del_all(node, ele_addr, mod_id);
>  
>  		if (status == MESH_STATUS_SUCCESS)
> -			mesh_config_model_sub_del_all(node_jconfig_get(node),
> +			mesh_config_model_sub_del_all(node_config_get(node),
>  				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
>  									vendor);
>  		break;
> @@ -878,7 +876,7 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst,
>  
>  		count = (pkt[0] >> 5) + 1;
>  		interval = ((pkt[0] & 0x1f) + 1) * 10;
> -		if (storage_set_transmit_params(node_jconfig_get(node), count,
> +		if (storage_set_transmit_params(node_config_get(node), count,
>  								interval))

Given the signature:

bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
                                                            uint8_t interval)

shouldn't that be:

    if (storage_set_transmit_params(node, count, interval))

and in other places as well?

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

* Re: [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs
  2019-07-10  7:38   ` Michał Lowas-Rzechonek
@ 2019-07-10 15:01     ` Michał Lowas-Rzechonek
  2019-07-10 15:58       ` Stotland, Inga
  0 siblings, 1 reply; 19+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-07-10 15:01 UTC (permalink / raw)
  To: Inga Stotland, linux-bluetooth, brian.gix, jakub.witowski

On 07/10, Michał Lowas-Rzechonek wrote:
> mesh-config.h:
>     union mesh_config;
> 
>     union mesh_config *mesh_config_create_config(void);
>     void mesh_config_release_config(union mesh_config *config);
> 
> mesh-config-json.c:
>     union mesh_config {
>         json_object *json
>     };
> 
>     union mesh_config *mesh_config_create_config(void)
>     {
>         return (union mesh_config*)json_object_new_object();
>     }
> 
>     void mesh_config_release_config(union mesh_config *cfg)
>     {
>         json_object *jnode = (json_object *)cfg;
> 
>         if (!cfg)
>             return;
> 
>         json_object_put(jnode);
>     }

Or even simpler, since we don't even need to define the mesh_config:

mesh-config.h
    struct mesh_config;

    struct mesh_config *mesh_config_create_config(void);
    void mesh_config_release_config(struct mesh_config *config);

    struct mesh_config *mesh_config_create_config(void)
    {
        return (struct mesh_config*)json_object_new_object();
    }

    void mesh_config_release_config(struct mesh_config *cfg)
    {
        json_object *jnode = (json_object *)cfg;
    }

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

* Re: [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs
  2019-07-10 15:01     ` Michał Lowas-Rzechonek
@ 2019-07-10 15:58       ` Stotland, Inga
  0 siblings, 0 replies; 19+ messages in thread
From: Stotland, Inga @ 2019-07-10 15:58 UTC (permalink / raw)
  To: michal.lowas-rzechonek, jakub.witowski, linux-bluetooth, Gix, Brian

[-- Attachment #1: Type: text/plain, Size: 1410 bytes --]

Hi Michal,

On Wed, 2019-07-10 at 17:01 +0200, Michał Lowas-Rzechonek wrote:
> On 07/10, Michał Lowas-Rzechonek wrote:
> > mesh-config.h:
> >     union mesh_config;
> > 
> >     union mesh_config *mesh_config_create_config(void);
> >     void mesh_config_release_config(union mesh_config *config);
> > 
> > mesh-config-json.c:
> >     union mesh_config {
> >         json_object *json
> >     };
> > 
> >     union mesh_config *mesh_config_create_config(void)
> >     {
> >         return (union mesh_config*)json_object_new_object();
> >     }
> > 
> >     void mesh_config_release_config(union mesh_config *cfg)
> >     {
> >         json_object *jnode = (json_object *)cfg;
> > 
> >         if (!cfg)
> >             return;
> > 
> >         json_object_put(jnode);
> >     }
> 
> Or even simpler, since we don't even need to define the mesh_config:
> 
> mesh-config.h
>     struct mesh_config;
> 
>     struct mesh_config *mesh_config_create_config(void);
>     void mesh_config_release_config(struct mesh_config *config);
> 
>     struct mesh_config *mesh_config_create_config(void)
>     {
>         return (struct mesh_config*)json_object_new_object();
>     }
> 
>     void mesh_config_release_config(struct mesh_config *cfg)
>     {
>         json_object *jnode = (json_object *)cfg;
>     }
> 

I agree. Defining structure forward is better.
Inga

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3265 bytes --]

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

* Re: [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines
  2019-07-10  7:52   ` Michał Lowas-Rzechonek
@ 2019-07-10 16:53     ` Stotland, Inga
  2019-07-10 17:00       ` michal.lowas-rzechonek
  2019-07-10 17:20     ` Gix, Brian
  1 sibling, 1 reply; 19+ messages in thread
From: Stotland, Inga @ 2019-07-10 16:53 UTC (permalink / raw)
  To: michal.lowas-rzechonek; +Cc: jakub.witowski, linux-bluetooth, Gix, Brian

[-- Attachment #1: Type: text/plain, Size: 1868 bytes --]

Hi Michal,

On Wed, 2019-07-10 at 09:52 +0200, Michał Lowas-Rzechonek wrote:
> On 07/09, Inga Stotland wrote:
> > This adds the following generic APIs to mesh-config.h
> >     void *mesh_config_create_config(void);
> >     void mesh_config_release_config(void *config);
> >     void *mesh_config_get_config(const char *dir);
> >     void *mesh_config_get_config_backup(const char *dir);
> >     bool mesh_config_restore_backup(const char *dir);
> >     bool mesh_config_save_config(const char *dir, void *cfg);
> > 
> > The implementation of these API routines depends on the
> > underlying storage directory structure and can be specific to
> > a chosen configuration file format.
> 
> I don't like the assumption that each node is stored in a separate
> file,
> and there needs to be a backup file.
> 
> One of the storage formats I had in mind is a single transactional
> database (some flavor of berkeley db, or maybe even sqlite) that
> would
> hold all the nodes.
> 
> With this in mind, how about:
> 
>     union mesh_config *mesh_config_create_config(const uint8_t
> uuid[16]);
>     bool mesh_config_save(union mesh_config *cfg);
> 
> and to iterate over saved nodes:
>     typedef struct mesh_node *(*mesh_node_load_cb)(union mesh_config
> *cfg,
>                                                     const uint8_t
> uuid[16],
>                                                     void *user_data);
> 
>     void mesh_config_load_nodes(mesh_node_load_cb cb, void
> *user_data);
> 
> and move file/directory handling from storage.c to mesh-config-
> json.c?
> 
> 
> regards


If we do away with the notion that each node has its own directory,
this means that entire node parsing procedure needs to be pushed into
the corresponding mesh-config-<specific> implementation and storage.c
becomes obsolete.

 

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3265 bytes --]

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

* Re: [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines
  2019-07-10 16:53     ` Stotland, Inga
@ 2019-07-10 17:00       ` michal.lowas-rzechonek
  0 siblings, 0 replies; 19+ messages in thread
From: michal.lowas-rzechonek @ 2019-07-10 17:00 UTC (permalink / raw)
  To: Stotland, Inga; +Cc: jakub.witowski, linux-bluetooth, Gix, Brian

Hi Inga,

On 07/10, Stotland, Inga wrote:
> If we do away with the notion that each node has its own directory,
> this means that entire node parsing procedure needs to be pushed into
> the corresponding mesh-config-<specific> implementation and storage.c
> becomes obsolete.

I know. Isn't that neat? ;)

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

* RE: [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines
  2019-07-10  7:52   ` Michał Lowas-Rzechonek
  2019-07-10 16:53     ` Stotland, Inga
@ 2019-07-10 17:20     ` Gix, Brian
  2019-07-10 19:32       ` Michal Lowas-Rzechonek
  1 sibling, 1 reply; 19+ messages in thread
From: Gix, Brian @ 2019-07-10 17:20 UTC (permalink / raw)
  To: Michal Lowas-Rzechonek, Stotland, Inga; +Cc: linux-bluetooth, jakub.witowski

Hi Michał,

> -----Original Message-----
> From: Michał Lowas-Rzechonek [mailto:michal.lowas-rzechonek@silvair.com]
> Sent: Wednesday, July 10, 2019 12:53 AM
> To: Stotland, Inga <inga.stotland@intel.com>
> Cc: linux-bluetooth@vger.kernel.org; Gix, Brian <brian.gix@intel.com>;
> jakub.witowski@silvair.com
> Subject: Re: [PATCH BlueZ 6/9] mesh: Define storage format specific
> read/write routines
> 
> On 07/09, Inga Stotland wrote:
> > This adds the following generic APIs to mesh-config.h
> >     void *mesh_config_create_config(void);
> >     void mesh_config_release_config(void *config);
> >     void *mesh_config_get_config(const char *dir);
> >     void *mesh_config_get_config_backup(const char *dir);
> >     bool mesh_config_restore_backup(const char *dir);
> >     bool mesh_config_save_config(const char *dir, void *cfg);
> >
> > The implementation of these API routines depends on the underlying
> > storage directory structure and can be specific to a chosen
> > configuration file format.
> 
> I don't like the assumption that each node is stored in a separate file, and there
> needs to be a backup file.

I think I understand what you are saying about *How* the node data is persevered, and that the underlying storage might not be a typical file system.

We *do* need a mechanism to get to an earlier version of a Node if there is corruption detected in the most resent version (perhaps an unexpected loss of power during a write operation).  That is the purpose of the current backup system.  Whether this is accomplished by reading a backup file or "Rolling Back" the history on a journal (or git repo, or whatever) we do need that backup.

But we could certainly hide the mechanism of backing up (and of reverting to a backed up version).

> One of the storage formats I had in mind is a single transactional database
> (some flavor of berkeley db, or maybe even sqlite) that would hold all the
> nodes.
> 


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

* Re: [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines
  2019-07-10 17:20     ` Gix, Brian
@ 2019-07-10 19:32       ` Michal Lowas-Rzechonek
  0 siblings, 0 replies; 19+ messages in thread
From: Michal Lowas-Rzechonek @ 2019-07-10 19:32 UTC (permalink / raw)
  To: Gix, Brian; +Cc: Stotland, Inga, linux-bluetooth, jakub.witowski

Hi Brian,

On 07/10, Gix, Brian wrote:
> > I don't like the assumption that each node is stored in a separate file, and there
> > needs to be a backup file.
> 
> I think I understand what you are saying about *How* the node data is
> persevered, and that the underlying storage might not be a typical
> file system.

Precisely.

> We *do* need a mechanism to get to an earlier version of a Node if
> there is corruption detected in the most resent version (perhaps an
> unexpected loss of power during a write operation).  That is the
> purpose of the current backup system.  Whether this is accomplished by
> reading a backup file or "Rolling Back" the history on a journal (or
> git repo, or whatever) we do need that backup.

Yes, I understand that. But, as you noticed, the rollback mechanism
doesn't need to be a backup *file*. This is an implementation detail of
a filesystem-backed JSON storage.

I would even go as far as saying that we don't need a backup - we need
atomicity and durability from ACID. Achieving that is non-trivial, but
is still an implementation detail.

> But we could certainly hide the mechanism of backing up (and of
> reverting to a backed up version).

Yes, this.

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

end of thread, other threads:[~2019-07-10 19:32 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10  5:09 [PATCH BlueZ 0/9] mesh: Configuration storage re-org Inga Stotland
2019-07-10  5:09 ` [PATCH BlueZ 1/9] mesh: Move network config setup from storage.c to node.c Inga Stotland
2019-07-10  5:09 ` [PATCH BlueZ 2/9] mesh: Rename mesh-db.c to mesh-config-json.c Inga Stotland
2019-07-10  5:09 ` [PATCH BlueZ 3/9] mesh: Change mesh_db prefix to mesh_config Inga Stotland
2019-07-10  5:09 ` [PATCH BlueZ 4/9] mesh: Generalize mesh-config APIs Inga Stotland
2019-07-10  7:38   ` Michał Lowas-Rzechonek
2019-07-10 15:01     ` Michał Lowas-Rzechonek
2019-07-10 15:58       ` Stotland, Inga
2019-07-10  5:09 ` [PATCH BlueZ 5/9] mesh: Change variable prefix "jconfig" to "config" Inga Stotland
2019-07-10  8:29   ` Michał Lowas-Rzechonek
2019-07-10  5:09 ` [PATCH BlueZ 6/9] mesh: Define storage format specific read/write routines Inga Stotland
2019-07-10  7:52   ` Michał Lowas-Rzechonek
2019-07-10 16:53     ` Stotland, Inga
2019-07-10 17:00       ` michal.lowas-rzechonek
2019-07-10 17:20     ` Gix, Brian
2019-07-10 19:32       ` Michal Lowas-Rzechonek
2019-07-10  5:09 ` [PATCH BlueZ 7/9] mesh: Implement config read/write for mesh json format Inga Stotland
2019-07-10  5:09 ` [PATCH BlueZ 8/9] mesh: Switch to using mesh-config routines for storage Inga Stotland
2019-07-10  5:09 ` [PATCH BlueZ 9/9] mesh: Make storage.c json-c agnostic Inga Stotland

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 NNTP newsgroup(s).