B.A.T.M.A.N Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 6/6] batman-adv: Avoid sysfs name collision for netns moves
Date: Sun, 29 May 2016 14:50:25 +0200	[thread overview]
Message-ID: <1464526225-10178-1-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1464439110-3113-1-git-send-email-sven@narfation.org>

The kobject_put is only removing the sysfs entry and corresponding entries
when its reference counter becomes zero. This tends to lead to collisions
when a device is moved between two different network namespaces because
some of the sysfs files have to be removed first and then added again to
the already moved sysfs entry.

    WARNING: CPU: 0 PID: 290 at lib/kobject.c:240 kobject_add_internal+0x5ec/0x8a0
    kobject_add_internal failed for batman_adv with -EEXIST, don't try to register things with the same name in the same directory.

But the caller of kobject_put can already remove the sysfs entry before it
does the kobject_put. This removal is done even when the reference counter
is not yet zero and thus avoids the problem.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Minor addition while testing the patchset with namespaces +
CONFIG_DEBUG_KOBJECT_RELEASE=y

Idea was taken from bridge del_nbp(...)

 net/batman-adv/sysfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index 9ca90d1..a146fcf 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -713,6 +713,8 @@ rem_attr:
 	for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
 		sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
 
+	kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE);
+	kobject_del(bat_priv->mesh_obj);
 	kobject_put(bat_priv->mesh_obj);
 	bat_priv->mesh_obj = NULL;
 out:
@@ -727,6 +729,8 @@ void batadv_sysfs_del_meshif(struct net_device *dev)
 	for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
 		sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
 
+	kobject_uevent(bat_priv->mesh_obj, KOBJ_REMOVE);
+	kobject_del(bat_priv->mesh_obj);
 	kobject_put(bat_priv->mesh_obj);
 	bat_priv->mesh_obj = NULL;
 }
@@ -782,6 +786,8 @@ rem_attr:
 	for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
 		sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
 
+	kobject_uevent(vlan->kobj, KOBJ_REMOVE);
+	kobject_del(vlan->kobj);
 	kobject_put(vlan->kobj);
 	vlan->kobj = NULL;
 out:
@@ -801,6 +807,8 @@ void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv,
 	for (bat_attr = batadv_vlan_attrs; *bat_attr; ++bat_attr)
 		sysfs_remove_file(vlan->kobj, &((*bat_attr)->attr));
 
+	kobject_uevent(vlan->kobj, KOBJ_REMOVE);
+	kobject_del(vlan->kobj);
 	kobject_put(vlan->kobj);
 	vlan->kobj = NULL;
 }
@@ -1103,6 +1111,8 @@ out:
 
 void batadv_sysfs_del_hardif(struct kobject **hardif_obj)
 {
+	kobject_uevent(*hardif_obj, KOBJ_REMOVE);
+	kobject_del(*hardif_obj);
 	kobject_put(*hardif_obj);
 	*hardif_obj = NULL;
 }
-- 
2.8.1


  parent reply	other threads:[~2016-05-29 12:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-28 12:38 [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: Clean up untagged vlan when destroying via rtnl-link Sven Eckelmann
2016-05-28 12:38 ` [B.A.T.M.A.N.] [PATCH 2/5] batman-adv: Define module rtnl link name Sven Eckelmann
2016-05-28 12:38 ` [B.A.T.M.A.N.] [PATCH 3/5] batman-adv: Use rtnl link in device creation example Sven Eckelmann
2016-05-28 12:38 ` [B.A.T.M.A.N.] [PATCH 4/5] batman-adv: Modify mesh_iface outside sysfs context Sven Eckelmann
2016-05-28 12:38 ` [B.A.T.M.A.N.] [PATCH 5/5] batman-adv: Revert "postpone sysfs removal when unregistering" Sven Eckelmann
2016-05-29 12:50 ` Sven Eckelmann [this message]
2016-06-06 15:44 ` [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: Clean up untagged vlan when destroying via rtnl-link Antonio Quartulli
2016-06-06 15:46   ` Marek Lindner

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=1464526225-10178-1-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox