]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - include/net/net_namespace.h
[NET]: Fix race when opening a proc file while a network namespace is exiting.
[linux-2.6.git] / include / net / net_namespace.h
index fac42db7f6d0772b8d2fbd3c93bb075a5b7f2577..ac8f8304094ed62e25c4f35eb1a9203fe89f386c 100644 (file)
@@ -28,7 +28,14 @@ struct net {
        struct hlist_head       *dev_index_head;
 };
 
+#ifdef CONFIG_NET
+/* Init's network namespace */
 extern struct net init_net;
+#define INIT_NET_NS(net_ns) .net_ns = &init_net,
+#else
+#define INIT_NET_NS(net_ns)
+#endif
+
 extern struct list_head net_namespace_list;
 
 extern void __put_net(struct net *net);
@@ -39,6 +46,18 @@ static inline struct net *get_net(struct net *net)
        return net;
 }
 
+static inline struct net *maybe_get_net(struct net *net)
+{
+       /* Used when we know struct net exists but we
+        * aren't guaranteed a previous reference count
+        * exists.  If the reference count is zero this
+        * function fails and returns NULL.
+        */
+       if (!atomic_inc_not_zero(&net->count))
+               net = NULL;
+       return net;
+}
+
 static inline void put_net(struct net *net)
 {
        if (atomic_dec_and_test(&net->count))