Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
From: Inga Stotland <inga.stotland@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, Inga Stotland <inga.stotland@intel.com>
Subject: [PATCH BlueZ 04/10] mesh: Add finalization of a newly created node
Date: Thu, 21 May 2020 17:34:55 -0700
Message-ID: <20200522003501.106165-5-inga.stotland@intel.com> (raw)
In-Reply-To: <20200522003501.106165-1-inga.stotland@intel.com>

When a new node is created as a result of successful completion
of either Join() or Create() or Import() methods and has been
confirmed via successful token delivery to the application,
clean up node's D-Bus resources (application path, element paths, etc)
that have been gathered during the initial GetMAnagedObjects() call.
Also, remove the agent instance associaed with the new node.

These resources will be re-populated after the Attach() call
verifies the node's integrity.
---
 mesh/mesh.c |  4 ++--
 mesh/node.c | 39 +++++++++++++++++++++++++--------------
 mesh/node.h |  1 +
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/mesh/mesh.c b/mesh/mesh.c
index 14ac543e2..8bd7b3978 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
@@ -449,7 +449,7 @@ static void prov_join_complete_reply_cb(struct l_dbus_message *message,
 		failed = true;
 
 	if (!failed)
-		node_attach_io(join_pending->node, mesh.io);
+		node_finalize_new_node(join_pending->node, mesh.io);
 
 	free_pending_join_call(failed);
 }
@@ -693,7 +693,7 @@ static void create_join_complete_reply_cb(struct l_dbus_message *message,
 		return;
 	}
 
-	node_attach_io(node, mesh.io);
+	node_finalize_new_node(node, mesh.io);
 }
 
 static void create_node_ready_cb(void *user_data, int status,
diff --git a/mesh/node.c b/mesh/node.c
index 8ad77639e..8cfe1ddc8 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -992,12 +992,6 @@ static void attach_io(void *a, void *b)
 		mesh_net_attach(node->net, io);
 }
 
-/* Register callback for the node's io */
-void node_attach_io(struct mesh_node *node, struct mesh_io *io)
-{
-	attach_io(node, io);
-}
-
 /* Register callbacks for all nodes io */
 void node_attach_io_all(struct mesh_io *io)
 {
@@ -1467,7 +1461,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 	const char *path;
 	struct mesh_node *node = req->node;
 	struct node_import *import;
-	void *agent = NULL;
 	bool have_app = false;
 	unsigned int num_ele;
 	struct keyring_net_key net_key;
@@ -1515,13 +1508,11 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 				const char *sender;
 
 				sender = l_dbus_message_get_sender(msg);
-				agent = mesh_agent_create(path, sender,
+				node->agent = mesh_agent_create(path, sender,
 								&properties);
-				if (!agent)
+				if (!node->agent)
 					goto fail;
 
-				node->agent = agent;
-
 			} else if (!strcmp(MESH_PROVISIONER_INTERFACE,
 								interface)) {
 				node->provisioner = true;
@@ -1629,9 +1620,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 	}
 
 fail:
-	if (agent)
-		mesh_agent_remove(agent);
-
 	/* Handle failed requests */
 	if (node)
 		node_remove(node);
@@ -2348,3 +2336,26 @@ bool node_load_from_storage(const char *storage_dir)
 {
 	return mesh_config_load_nodes(storage_dir, init_from_storage, NULL);
 }
+
+/*
+ * This is called for a new node that:
+ *         - has been created as a result of successful completion of Join()
+ *           or Create() or Import() methods
+ *     and
+ *         - has been confirmed via successful token delivery to the application
+ *
+ * After a node has been created, the information gathered during initial
+ * GetManagedObjects() call is cleared. The subsequent call to Attach() would
+ * verify node's integrity and re-initialize node's D-Bus resources.
+ */
+void node_finalize_new_node(struct mesh_node *node, struct mesh_io *io)
+{
+	if (!node)
+		return;
+
+	free_node_dbus_resources(node);
+	mesh_agent_remove(node->agent);
+
+	/* Register callback for the node's io */
+	attach_io(node, io);
+}
diff --git a/mesh/node.h b/mesh/node.h
index 38aea138f..3019d316b 100644
--- a/mesh/node.h
+++ b/mesh/node.h
@@ -100,3 +100,4 @@ struct mesh_config *node_config_get(struct mesh_node *node);
 struct mesh_agent *node_get_agent(struct mesh_node *node);
 const char *node_get_storage_dir(struct mesh_node *node);
 bool node_load_from_storage(const char *storage_dir);
+void node_finalize_new_node(struct mesh_node *node, struct mesh_io *io);
-- 
2.26.2


  parent reply index

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22  0:34 [PATCH BlueZ 00/10] Mesh code clean up Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 01/10] mesh: Remove unused structure member Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 02/10] mesh: Free allocated agent in mesh_remove_agent() Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 03/10] mesh: Remove agent when freeing node's dynamic resources Inga Stotland
2020-05-22  0:34 ` Inga Stotland [this message]
2020-05-22  0:34 ` [PATCH BlueZ 05/10] mesh: Remove unused function prototypes from node.h Inga Stotland
2020-05-22  1:12   ` [BlueZ,05/10] " bluez.test.bot
2020-05-22  0:34 ` [PATCH BlueZ 06/10] mesh: Create a queue of pending requests in mesh_init() Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 07/10] mesh: Clean up Import() method call Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 08/10] mesh: Clean up Attach() " Inga Stotland
2020-05-22  0:35 ` [PATCH BlueZ 09/10] mesh: Fix memory leak in Create, Import & Attach methods Inga Stotland
2020-05-22  0:35 ` [PATCH BlueZ 10/10] mesh: Clean up Join() method Inga Stotland
2020-05-22 20:54 ` [PATCH BlueZ 00/10] Mesh code clean up Gix, Brian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200522003501.106165-5-inga.stotland@intel.com \
    --to=inga.stotland@intel.com \
    --cc=brian.gix@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git