From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id AB50F5921 for ; Mon, 9 Nov 2015 08:45:06 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 08 Nov 2015 23:45:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,265,1444719600"; d="scan'208";a="845882736" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 08 Nov 2015 23:45:05 -0800 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 8 Nov 2015 23:44:58 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 8 Nov 2015 23:44:57 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.138]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.193]) with mapi id 14.03.0248.002; Mon, 9 Nov 2015 15:44:56 +0800 From: "Cao, Waterman" To: "Zhang, Helin" , "dev@dpdk.org" , "Tang, HaifengX" Thread-Topic: [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions Thread-Index: AQHRGref1OyP8lMgvkGArGUD68nfrp6TT2fg Date: Mon, 9 Nov 2015 07:44:55 +0000 Message-ID: References: <1447050372-30419-1-git-send-email-helin.zhang@intel.com> In-Reply-To: <1447050372-30419-1-git-send-email-helin.zhang@intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] kni: fix compile issue on different kernel versions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Nov 2015 07:45:07 -0000 Hi Haifeng, Can you verify helin's patch and acknowledge it if it works fine? Thanks Waterman=20 -----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 vers= ions 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 specifi= ed in initializer lib/librte_eal/linuxapp/kni/kni_misc.c:121: error: excess elements in struc= t 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 speci= fied in initializer lib/librte_eal/linuxapp/kni/kni_misc.c:122: error: excess elements in struc= t 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 --- 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/linuxa= pp/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 */ =20 +#include #include #include #include @@ -102,9 +103,20 @@ struct kni_net { struct list_head kni_list_head; }; =20 -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 =3D net_generic(net, kni_net_id); +#else + struct kni_net *knet; + int ret; + + knet =3D kmalloc(sizeof(struct kni_net), GFP_KERNEL); + if (!knet) { + ret =3D -ENOMEM; + return ret; + } +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */ =20 /* 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); =20 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) return 0; +#else + ret =3D 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=20 +LINUX_VERSION_CODE <=3D KERNEL_VERSION(2, 6, 32) + struct kni_net *knet =3D net_generic(net, kni_net_id); + + kfree(knet); +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */ } =20 static struct pernet_operations kni_net_ops =3D { .init =3D kni_init_net, - .exit =3D NULL, + .exit =3D kni_exit_net, +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) .id =3D &kni_net_id, .size =3D sizeof(struct kni_net), +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */ }; =20 static int __init @@ -134,7 +165,11 @@ kni_init(void) return -EINVAL; } =20 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) rc =3D register_pernet_subsys(&kni_net_ops); +#else + rc =3D register_pernet_gen_subsys(&kni_net_id, &kni_net_ops); #endif /*=20 +LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */ if (rc) return -EPERM; =20 @@ -152,7 +187,11 @@ kni_init(void) return 0; =20 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 /*=20 +LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */ return rc; } =20 @@ -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 /*=20 +LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) */ KNI_PRINT("####### DPDK kni module unloaded #######\n"); } =20 -- 1.8.1.4