From patchwork Mon Nov 9 06:26:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Helin" X-Patchwork-Id: 8786 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 29BF8532D; Mon, 9 Nov 2015 07:26:31 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C4F783979 for ; Mon, 9 Nov 2015 07:26:29 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 08 Nov 2015 22:26:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,265,1444719600"; d="scan'208";a="681183606" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga003.jf.intel.com with ESMTP; 08 Nov 2015 22:26:18 -0800 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id tA96QFWK019648; Mon, 9 Nov 2015 14:26:15 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id tA96QDxe030455; Mon, 9 Nov 2015 14:26:15 +0800 Received: (from hzhan75@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id tA96QDWq030451; Mon, 9 Nov 2015 14:26:13 +0800 From: Helin Zhang To: dev@dpdk.org Date: Mon, 9 Nov 2015 14:26:12 +0800 Message-Id: <1447050372-30419-1-git-send-email-helin.zhang@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [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: , Errors-To: dev-bounces@dpdk.org Sender: "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 Acked-by: Pablo de Lara --- 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 #include #include #include @@ -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"); }