Skip to contentSkip to conversation

batman-adv: prepare and schedule initial OGM without rtnl_lock()

PATCH In review Linus Lüssing 1 participant 2 messages Jul 15, 2013 – Jul 17, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 batman-adv: prepare and schedule initial OGM without rtnl_lock()

There is no need to hold the rtnl-lock during the preparation of the initial OGM of a hard interface.

Besides, it is a little uggly to have batadv_schedule_bat_ogm() executed with an rtnl-lock on its first run but without an rtnl-lock in its rearmed versions as it makes additions to batadv_schedule_bat_ogm() that require an rtnl-lock difficult.

---

the compat code for the multicast-basic patchset needs an rtnl-lock somewhere within batadv_schedule_bat_ogm()

 hard-interface.c |   21 ++++++++++++++++++++-
 types.h          |    2 ++
 2 files changed, 22 insertions(+), 1 deletion(-)
hard-interface.c +20 -1
index c5f871f..c7ad8ae 100644
@@ -470,7 +470,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
 			   hard_iface->net_dev->name);
 
 	/* begin scheduling originator messages on that interface */
-	batadv_schedule_bat_ogm(hard_iface);
+	queue_work(batadv_event_workqueue, &hard_iface->init_ogm_work);
 
 out:
 	return 0;
@@ -554,6 +554,23 @@ static void batadv_hardif_remove_interface_finish(struct work_struct *work)
 	batadv_hardif_free_ref(hard_iface);
 }
 
+/**
+ * batadv_hardif_init_ogm - initialize the ogm scheduler
+ * @work: work queue item
+ *
+ * Prepare and queue the initial OGM on this hard interface to get its ogm
+ * scheduler into gear.
+ */
+static void batadv_hardif_init_ogm(struct work_struct *work)
+{
+	struct batadv_hard_iface *hard_iface;
+
+	hard_iface = container_of(work, struct batadv_hard_iface,
+				  init_ogm_work);
+
+	batadv_schedule_bat_ogm(hard_iface);
+}
+
 static struct batadv_hard_iface *
 batadv_hardif_add_interface(struct net_device *net_dev)
 {
@@ -583,6 +600,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 	INIT_LIST_HEAD(&hard_iface->list);
 	INIT_WORK(&hard_iface->cleanup_work,
 		  batadv_hardif_remove_interface_finish);
+	INIT_WORK(&hard_iface->init_ogm_work,
+		  batadv_hardif_init_ogm);
 
 	hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
 	if (batadv_is_wifi_netdev(net_dev))
types.h +2 -0
index 0d5b24b..a8b5725 100644
@@ -62,6 +62,7 @@ struct batadv_hard_iface_bat_iv {
  * @rcu: struct used for freeing in an RCU-safe manner
  * @bat_iv: BATMAN IV specific per hard interface data
  * @cleanup_work: work queue callback item for hard interface deinit
+ * @init_ogm_work: work queue callback item for ogm scheduler initialization
  */
 struct batadv_hard_iface {
 	struct list_head list;
@@ -76,6 +77,7 @@ struct batadv_hard_iface {
 	struct rcu_head rcu;
 	struct batadv_hard_iface_bat_iv bat_iv;
 	struct work_struct cleanup_work;
+	struct work_struct init_ogm_work;
 };
 
 /**
Signature · 1 line
1.7.10.4
#1 lore raw

Ok, please ignore this patch for now. I'm going to do it differently with the multicast patches which won't need an rtnl-lock.

Cheers, Linus

Quoted 88 lines · Linus Lüssing

There is no need to hold the rtnl-lock during the preparation of the initial OGM of a hard interface.

Besides, it is a little uggly to have batadv_schedule_bat_ogm() executed with an rtnl-lock on its first run but without an rtnl-lock in its rearmed versions as it makes additions to batadv_schedule_bat_ogm() that require an rtnl-lock difficult.

---

the compat code for the multicast-basic patchset needs an rtnl-lock somewhere within batadv_schedule_bat_ogm()

 hard-interface.c |   21 ++++++++++++++++++++-
 types.h          |    2 ++
 2 files changed, 22 insertions(+), 1 deletion(-)
hard-interface.c +20 -1
index c5f871f..c7ad8ae 100644
@@ -470,7 +470,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
 			   hard_iface->net_dev->name);
 
 	/* begin scheduling originator messages on that interface */
-	batadv_schedule_bat_ogm(hard_iface);
+	queue_work(batadv_event_workqueue, &hard_iface->init_ogm_work);
 
 out:
 	return 0;
@@ -554,6 +554,23 @@ static void batadv_hardif_remove_interface_finish(struct work_struct *work)
 	batadv_hardif_free_ref(hard_iface);
 }
 
+/**
+ * batadv_hardif_init_ogm - initialize the ogm scheduler
+ * @work: work queue item
+ *
+ * Prepare and queue the initial OGM on this hard interface to get its ogm
+ * scheduler into gear.
+ */
+static void batadv_hardif_init_ogm(struct work_struct *work)
+{
+	struct batadv_hard_iface *hard_iface;
+
+	hard_iface = container_of(work, struct batadv_hard_iface,
+				  init_ogm_work);
+
+	batadv_schedule_bat_ogm(hard_iface);
+}
+
 static struct batadv_hard_iface *
 batadv_hardif_add_interface(struct net_device *net_dev)
 {
@@ -583,6 +600,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 	INIT_LIST_HEAD(&hard_iface->list);
 	INIT_WORK(&hard_iface->cleanup_work,
 		  batadv_hardif_remove_interface_finish);
+	INIT_WORK(&hard_iface->init_ogm_work,
+		  batadv_hardif_init_ogm);
 
 	hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
 	if (batadv_is_wifi_netdev(net_dev))
types.h +2 -0
index 0d5b24b..a8b5725 100644
@@ -62,6 +62,7 @@ struct batadv_hard_iface_bat_iv {
  * @rcu: struct used for freeing in an RCU-safe manner
  * @bat_iv: BATMAN IV specific per hard interface data
  * @cleanup_work: work queue callback item for hard interface deinit
+ * @init_ogm_work: work queue callback item for ogm scheduler initialization
  */
 struct batadv_hard_iface {
 	struct list_head list;
@@ -76,6 +77,7 @@ struct batadv_hard_iface {
 	struct rcu_head rcu;
 	struct batadv_hard_iface_bat_iv bat_iv;
 	struct work_struct cleanup_work;
+	struct work_struct init_ogm_work;
 };
 
 /**
Signature · 1 line
1.7.10.4