* [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions
@ 2015-11-09 6:26 Helin Zhang
2015-11-09 7:44 ` Cao, Waterman
2015-11-16 11:50 ` De Lara Guarch, Pablo
0 siblings, 2 replies; 4+ messages in thread
From: Helin Zhang @ 2015-11-09 6:26 UTC (permalink / raw)
To: dev
It fixes the compile issue on kernel version 2.6.32 or old ones.
Error logs:
lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: unknown field id specified in initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: excess elements in struct initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: (near initialization for kni_net_ops)
lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: unknown field size specified in initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: excess elements in struct initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: (near initialization for kni_net_ops)
Fixes: 72a7a2b2469e ("kni: allow per-net instances")
Signed-off-by: Helin Zhang <helin.zhang@intel.com>
---
lib/librte_eal/linuxapp/kni/kni_misc.c | 47 ++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index 635e18f..f5f18f0 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -22,6 +22,7 @@
* Intel Corporation
*/
+#include <linux/version.h>
#include <linux/module.h>
#include <linux/miscdevice.h>
#include <linux/netdevice.h>
@@ -102,9 +103,20 @@ struct kni_net {
struct list_head kni_list_head;
};
-static __net_init int kni_init_net(struct net *net)
+static int __net_init kni_init_net(struct net *net)
{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
struct kni_net *knet = net_generic(net, kni_net_id);
+#else
+ struct kni_net *knet;
+ int ret;
+
+ knet = kmalloc(sizeof(struct kni_net), GFP_KERNEL);
+ if (!knet) {
+ ret = -ENOMEM;
+ return ret;
+ }
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
/* Clear the bit of device in use */
clear_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use);
@@ -112,14 +124,33 @@ static __net_init int kni_init_net(struct net *net)
init_rwsem(&knet->kni_list_lock);
INIT_LIST_HEAD(&knet->kni_list_head);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
return 0;
+#else
+ ret = net_assign_generic(net, kni_net_id, knet);
+ if (ret < 0)
+ kfree(knet);
+
+ return ret;
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
+}
+
+static void __net_exit kni_exit_net(struct net *net)
+{
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 32)
+ struct kni_net *knet = net_generic(net, kni_net_id);
+
+ kfree(knet);
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
}
static struct pernet_operations kni_net_ops = {
.init = kni_init_net,
- .exit = NULL,
+ .exit = kni_exit_net,
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
.id = &kni_net_id,
.size = sizeof(struct kni_net),
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
};
static int __init
@@ -134,7 +165,11 @@ kni_init(void)
return -EINVAL;
}
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
rc = register_pernet_subsys(&kni_net_ops);
+#else
+ rc = register_pernet_gen_subsys(&kni_net_id, &kni_net_ops);
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
if (rc)
return -EPERM;
@@ -152,7 +187,11 @@ kni_init(void)
return 0;
out:
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
unregister_pernet_subsys(&kni_net_ops);
+#else
+ register_pernet_gen_subsys(&kni_net_id, &kni_net_ops);
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
return rc;
}
@@ -160,7 +199,11 @@ static void __exit
kni_exit(void)
{
misc_deregister(&kni_misc);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
unregister_pernet_subsys(&kni_net_ops);
+#else
+ register_pernet_gen_subsys(&kni_net_id, &kni_net_ops);
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
KNI_PRINT("####### DPDK kni module unloaded #######\n");
}
--
1.8.1.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions
2015-11-09 6:26 [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions Helin Zhang
@ 2015-11-09 7:44 ` Cao, Waterman
2015-11-16 11:50 ` De Lara Guarch, Pablo
1 sibling, 0 replies; 4+ messages in thread
From: Cao, Waterman @ 2015-11-09 7:44 UTC (permalink / raw)
To: Zhang, Helin, dev, Tang, HaifengX
Hi Haifeng,
Can you verify helin's patch and acknowledge it if it works fine?
Thanks
Waterman
-----Original Message-----
From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Helin Zhang
Sent: Monday, November 9, 2015 2:26 PM
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions
It fixes the compile issue on kernel version 2.6.32 or old ones.
Error logs:
lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: unknown field id specified in initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: excess elements in struct initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: (near initialization for kni_net_ops)
lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: unknown field size specified in initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: excess elements in struct initializer
lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: (near initialization for kni_net_ops)
Fixes: 72a7a2b2469e ("kni: allow per-net instances")
Signed-off-by: Helin Zhang <helin.zhang@intel.com>
---
lib/librte_eal/linuxapp/kni/kni_misc.c | 47 ++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index 635e18f..f5f18f0 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -22,6 +22,7 @@
* Intel Corporation
*/
+#include <linux/version.h>
#include <linux/module.h>
#include <linux/miscdevice.h>
#include <linux/netdevice.h>
@@ -102,9 +103,20 @@ struct kni_net {
struct list_head kni_list_head;
};
-static __net_init int kni_init_net(struct net *net)
+static int __net_init kni_init_net(struct net *net)
{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
struct kni_net *knet = net_generic(net, kni_net_id);
+#else
+ struct kni_net *knet;
+ int ret;
+
+ knet = kmalloc(sizeof(struct kni_net), GFP_KERNEL);
+ if (!knet) {
+ ret = -ENOMEM;
+ return ret;
+ }
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
/* Clear the bit of device in use */
clear_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use); @@ -112,14 +124,33 @@ static __net_init int kni_init_net(struct net *net)
init_rwsem(&knet->kni_list_lock);
INIT_LIST_HEAD(&knet->kni_list_head);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
return 0;
+#else
+ ret = net_assign_generic(net, kni_net_id, knet);
+ if (ret < 0)
+ kfree(knet);
+
+ return ret;
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */ }
+
+static void __net_exit kni_exit_net(struct net *net) { #if
+LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 32)
+ struct kni_net *knet = net_generic(net, kni_net_id);
+
+ kfree(knet);
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
}
static struct pernet_operations kni_net_ops = {
.init = kni_init_net,
- .exit = NULL,
+ .exit = kni_exit_net,
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
.id = &kni_net_id,
.size = sizeof(struct kni_net),
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
};
static int __init
@@ -134,7 +165,11 @@ kni_init(void)
return -EINVAL;
}
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
rc = register_pernet_subsys(&kni_net_ops);
+#else
+ rc = register_pernet_gen_subsys(&kni_net_id, &kni_net_ops); #endif /*
+LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
if (rc)
return -EPERM;
@@ -152,7 +187,11 @@ kni_init(void)
return 0;
out:
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
unregister_pernet_subsys(&kni_net_ops);
+#else
+ register_pernet_gen_subsys(&kni_net_id, &kni_net_ops); #endif /*
+LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
return rc;
}
@@ -160,7 +199,11 @@ static void __exit
kni_exit(void)
{
misc_deregister(&kni_misc);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32)
unregister_pernet_subsys(&kni_net_ops);
+#else
+ register_pernet_gen_subsys(&kni_net_id, &kni_net_ops); #endif /*
+LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */
KNI_PRINT("####### DPDK kni module unloaded #######\n"); }
--
1.8.1.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions
2015-11-09 6:26 [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions Helin Zhang
2015-11-09 7:44 ` Cao, Waterman
@ 2015-11-16 11:50 ` De Lara Guarch, Pablo
2015-11-19 9:20 ` Thomas Monjalon
1 sibling, 1 reply; 4+ messages in thread
From: De Lara Guarch, Pablo @ 2015-11-16 11:50 UTC (permalink / raw)
To: Zhang, Helin, dev
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Helin Zhang
> Sent: Monday, November 09, 2015 6:26 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] kni: fix compile issue on different kernel
> versions
>
> It fixes the compile issue on kernel version 2.6.32 or old ones.
>
> Error logs:
> lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: unknown field id
> specified in initializer
> lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: excess elements in struct
> initializer
> lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: (near initialization for
> kni_net_ops)
> lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: unknown field size
> specified in initializer
> lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: excess elements in struct
> initializer
> lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: (near initialization for
> kni_net_ops)
>
> Fixes: 72a7a2b2469e ("kni: allow per-net instances")
>
> Signed-off-by: Helin Zhang <helin.zhang@intel.com>
Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions
2015-11-16 11:50 ` De Lara Guarch, Pablo
@ 2015-11-19 9:20 ` Thomas Monjalon
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2015-11-19 9:20 UTC (permalink / raw)
To: Zhang, Helin; +Cc: dev
> > It fixes the compile issue on kernel version 2.6.32 or old ones.
> >
> > Error logs:
> > lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: unknown field id
> > specified in initializer
> > lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: excess elements in struct
> > initializer
> > lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: (near initialization for
> > kni_net_ops)
> > lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: unknown field size
> > specified in initializer
> > lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: excess elements in struct
> > initializer
> > lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: (near initialization for
> > kni_net_ops)
> >
> > Fixes: 72a7a2b2469e ("kni: allow per-net instances")
> >
> > Signed-off-by: Helin Zhang <helin.zhang@intel.com>
>
> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Applied, thanks
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-19 9:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 6:26 [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions Helin Zhang
2015-11-09 7:44 ` Cao, Waterman
2015-11-16 11:50 ` De Lara Guarch, Pablo
2015-11-19 9:20 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).