[PATCH 1/5][NETNS] Make the init/exit hooks checks outside the loop

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: David Miller <davem@...>
Cc: Linux Netdev List <netdev@...>, Eric W. Biederman <ebiederm@...>, <devel@...>
Date: Wednesday, October 31, 2007 - 3:23 pm

When the new pernet something (subsys, device or operations) is
being registered, the init callback is to be called for each
namespace, that currently exitst in the system. During the
unregister, the same is to be done with the exit callback.

However, not every pernet something has both calls, but the
check for the appropriate pointer to be not NULL is performed
inside the for_each_net() loop.

This is (at least) strange, so tune this.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

---

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 662e6ea..4e52921 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -187,29 +187,28 @@ static int register_pernet_operations(struct list_head *list,
 	struct net *net, *undo_net;
 	int error;
 
-	error = 0;
 	list_add_tail(&ops->list, list);
-	for_each_net(net) {
-		if (ops->init) {
+	if (ops->init) {
+		for_each_net(net) {
 			error = ops->init(net);
 			if (error)
 				goto out_undo;
 		}
 	}
-out:
-	return error;
+	return 0;
 
 out_undo:
 	/* If I have an error cleanup all namespaces I initialized */
 	list_del(&ops->list);
-	for_each_net(undo_net) {
-		if (undo_net == net)
-			goto undone;
-		if (ops->exit)
+	if (ops->exit) {
+		for_each_net(undo_net) {
+			if (undo_net == net)
+				goto undone;
 			ops->exit(undo_net);
+		}
 	}
 undone:
-	goto out;
+	return error;
 }
 
 static void unregister_pernet_operations(struct pernet_operations *ops)
@@ -217,8 +216,8 @@ static void unregister_pernet_operations(struct pernet_operations *ops)
 	struct net *net;
 
 	list_del(&ops->list);
-	for_each_net(net)
-		if (ops->exit)
+	if (ops->exit)
+		for_each_net(net)
 			ops->exit(net);
 }
 
-- 
1.5.3.4

-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Pavel Emelyanov, (Wed Oct 31, 3:19 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Daniel Lezcano, (Wed Oct 31, 5:37 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Eric Dumazet, (Wed Oct 31, 2:49 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Eric W. Biederman, (Wed Oct 31, 6:05 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Eric Dumazet, (Wed Oct 31, 6:40 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Eric W. Biederman, (Wed Oct 31, 8:51 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Eric Dumazet, (Thu Nov 1, 2:58 am)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, David Miller, (Thu Nov 1, 3:02 am)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, David Miller, (Wed Oct 31, 7:31 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Eric W. Biederman, (Wed Oct 31, 8:58 pm)
Re: [PATCH 0/5] Make nicer CONFIG_NET_NS=n case code, Daniel Lezcano, (Wed Oct 31, 5:35 pm)
[PATCH 5/5] Hide the net_ns kmem cache, Pavel Emelyanov, (Wed Oct 31, 3:32 pm)
Re: [PATCH 5/5] Hide the net_ns kmem cache, David Miller, (Thu Nov 1, 3:47 am)
[PATCH 4/5] Mark the setup_net as __net_init, Pavel Emelyanov, (Wed Oct 31, 3:31 pm)
Re: [PATCH 4/5] Mark the setup_net as __net_init, David Miller, (Thu Nov 1, 3:46 am)
[PATCH 3/5] Hide the dead code in the net_namespace.c, Pavel Emelyanov, (Wed Oct 31, 3:28 pm)
[PATCH 2/5] Relax the reference counting of init_net_ns, Pavel Emelyanov, (Wed Oct 31, 3:25 pm)
[PATCH 1/5][NETNS] Make the init/exit hooks checks outside t..., Pavel Emelyanov, (Wed Oct 31, 3:23 pm)