[ovs-dev] [PATCH net-next v4 1/2] datapath: Improve net-namespace compat code.

Pravin B Shelar pshelar at nicira.com
Thu Jul 18 23:55:00 UTC 2013


Following patch improves compat net-namespace code which is mostly
targeted for 2.6.32 kernel. upcoming vxlan restructuring patch
needs this patch.

Signed-off-by: Pravin Shelar <pshelar at nicira.com>
---
v3-v4:
 - Defined DEFINE_COMPAT_PNET_REG_FUNC for older kernel.
 - remove the 'gen' prefix.
 - Added back __net_init and __net_exit annotations.
v2-v3:
 - Removed inline
 - Moved compat function declaration to correct block.
 - simplified DEFINE_COMPAT_PNET_REG_FUNC() def.
v1-v2:
Fixed code for compat net init and exit.
---
 datapath/datapath.c                               |    2 +
 datapath/linux/compat/include/net/net_namespace.h |   46 +++++++++++++++++++--
 datapath/linux/compat/net_namespace.c             |   43 ++-----------------
 3 files changed, 49 insertions(+), 42 deletions(-)

diff --git a/datapath/datapath.c b/datapath/datapath.c
index 1de50c1..9a3a07b 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -2459,6 +2459,8 @@ static struct pernet_operations ovs_net_ops = {
 	.size = sizeof(struct ovs_net),
 };
 
+DEFINE_COMPAT_PNET_REG_FUNC(device);
+
 static int __init dp_init(void)
 {
 	int err;
diff --git a/datapath/linux/compat/include/net/net_namespace.h b/datapath/linux/compat/include/net/net_namespace.h
index 77f0a16..85dee1a 100644
--- a/datapath/linux/compat/include/net/net_namespace.h
+++ b/datapath/linux/compat/include/net/net_namespace.h
@@ -64,20 +64,58 @@ static inline struct net *read_pnet(struct net * const *pnet)
 #endif /* 2.6.29 */
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
-#define pernet_operations rpl_pernet_operations
-struct pernet_operations {
+struct rpl_pernet_operations {
 	int (*init)(struct net *net);
 	void (*exit)(struct net *net);
 	int *id;
 	size_t size;
+	struct pernet_operations ops;
 };
+#define pernet_operations rpl_pernet_operations
+
+#define register_pernet_device rpl_register_pernet_gen_device
+#define unregister_pernet_device rpl_unregister_pernet_gen_device
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
 extern int rpl_register_pernet_gen_device(struct rpl_pernet_operations *ops);
 extern void rpl_unregister_pernet_gen_device(struct rpl_pernet_operations *ops);
 
-#define register_pernet_device rpl_register_pernet_gen_device
-#define unregister_pernet_device rpl_unregister_pernet_gen_device
+#else /* for 2.6.32* */
+
+int __net_init compat_init_net(struct net *net, struct rpl_pernet_operations *pnet);
+void __net_exit compat_exit_net(struct net *net, struct rpl_pernet_operations *pnet);
+
+#define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)					\
+									\
+static struct rpl_pernet_operations *pnet_gen_##TYPE;			\
+static int __net_init compat_init_net_gen_##TYPE(struct net *net)	\
+{									\
+	return compat_init_net(net, pnet_gen_##TYPE);			\
+}									\
+									\
+static void __net_exit compat_exit_net_gen_##TYPE(struct net *net)	\
+{									\
+	compat_exit_net(net, pnet_gen_##TYPE);				\
+}									\
+									\
+static int __net_init rpl_register_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet)	\
+{										\
+	pnet_gen_##TYPE = rpl_pnet;						\
+	rpl_pnet->ops.init = compat_init_net_gen_##TYPE;			\
+	rpl_pnet->ops.exit = compat_exit_net_gen_##TYPE;			\
+	return register_pernet_gen_##TYPE(pnet_gen_##TYPE->id, &rpl_pnet->ops); \
+}											\
+											\
+static void __net_exit rpl_unregister_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_pnet)		\
+{											\
+	unregister_pernet_gen_##TYPE(*pnet_gen_##TYPE->id, &rpl_pnet->ops);		\
+}
+#endif
+#endif /* 2.6.33 */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) || \
+    LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
+#define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)
 #endif /* 2.6.33 */
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
diff --git a/datapath/linux/compat/net_namespace.c b/datapath/linux/compat/net_namespace.c
index 4e8a891..82404af 100644
--- a/datapath/linux/compat/net_namespace.c
+++ b/datapath/linux/compat/net_namespace.c
@@ -3,14 +3,12 @@
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
 
-#undef pernet_operations
-
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,32)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
 static int net_assign_generic(struct net *net, int id, void *data);
 #endif
 
-static int __net_init compat_init_net(struct net *net, struct rpl_pernet_operations *pnet)
+int __net_init compat_init_net(struct net *net, struct rpl_pernet_operations *pnet)
 {
 	int err;
 	void *ovs_net = kzalloc(pnet->size, GFP_KERNEL);
@@ -34,7 +32,7 @@ err:
 	return err;
 }
 
-static void __net_exit compat_exit_net(struct net *net, struct rpl_pernet_operations *pnet)
+void __net_exit compat_exit_net(struct net *net, struct rpl_pernet_operations *pnet)
 {
 	void *ovs_net = net_generic(net, *pnet->id);
 
@@ -44,39 +42,8 @@ static void __net_exit compat_exit_net(struct net *net, struct rpl_pernet_operat
 }
 #endif
 
-#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32)
-#define DEFINE_PNET_REG_FUNC(PNET_TYPE)					\
-	static struct rpl_pernet_operations *pnet_##PNET_TYPE;		\
-static int __net_init compat_init_net_##PNET_TYPE(struct net *net)	\
-{									\
-	return compat_init_net(net, pnet_##PNET_TYPE);			\
-}									\
-									\
-static void __net_exit compat_exit_net_##PNET_TYPE(struct net *net)	\
-{									\
-	compat_exit_net(net, pnet_##PNET_TYPE);				\
-}									\
-									\
-static struct pernet_operations pnet_compat_##PNET_TYPE = {		\
-	.init = compat_init_net_##PNET_TYPE,				\
-	.exit = compat_exit_net_##PNET_TYPE,				\
-};									\
-									\
-int rpl_register_pernet_##PNET_TYPE(struct rpl_pernet_operations *rpl_pnet)	\
-{										\
-	pnet_##PNET_TYPE = rpl_pnet;						\
-	return register_pernet_##PNET_TYPE(pnet_##PNET_TYPE->id, &pnet_compat_##PNET_TYPE); \
-}											\
-											\
-void rpl_unregister_pernet_##PNET_TYPE(struct rpl_pernet_operations *pnet)		\
-{											\
-	unregister_pernet_##PNET_TYPE(*pnet->id, &pnet_compat_##PNET_TYPE);		\
-}
-
-DEFINE_PNET_REG_FUNC(gen_device);
-
-#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
-#define MAX_DATA_COUNT 1
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
+#define MAX_DATA_COUNT 2
 static struct net *net;
 
 static void *__ovs_net_data[MAX_DATA_COUNT];
-- 
1.7.1




More information about the dev mailing list