From 7510d78909774e33b64ada4055bea65881350763 Mon Sep 17 00:00:00 2001 Message-Id: <7510d78909774e33b64ada4055bea65881350763.1528136610.git.Jim.Somerville@windriver.com> From: Nick Wang Date: Mon, 13 Mar 2017 15:23:29 +0800 Subject: [PATCH 1/1] compat: Statically initialize families In a07ea4d9, genetlink no longer use static family id. GENL_ID_GENERATE is removed. In 489111e5, statically initialize the families and remove the inline functions. Thanks to Nick Wang for preparing a first draft. Unfortunately this version actually broke netlink on v4.10. Probably only compile-tested, but never "drbdadm up" tested. Signed-off-by: Nick Wang [add missing pieces introduced in 489111e5] Signed-off-by: Roland Kammerer [Simplified :-) and backported to drbd 8.4] Signed-off-by: Lars Ellenberg Signed-off-by: Jim Somerville --- .../tests/have_genl_family_in_genlmsg_multicast.c | 9 ++++++ drbd/compat/tests/have_genl_id_generate.c | 6 ++++ .../tests/have_genl_register_family_with_ops.c | 9 ++++++ .../tests/have_genl_register_family_with_ops3.c | 9 ++++++ ...gic_func-genl_register_family_with_ops_groups.h | 4 +++ drbd/linux/genl_magic_func.h | 34 +++++++++++++++------- 6 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 drbd/compat/tests/have_genl_family_in_genlmsg_multicast.c create mode 100644 drbd/compat/tests/have_genl_id_generate.c create mode 100644 drbd/compat/tests/have_genl_register_family_with_ops.c create mode 100644 drbd/compat/tests/have_genl_register_family_with_ops3.c diff --git a/drbd/compat/tests/have_genl_family_in_genlmsg_multicast.c b/drbd/compat/tests/have_genl_family_in_genlmsg_multicast.c new file mode 100644 index 0000000..6d44faa --- /dev/null +++ b/drbd/compat/tests/have_genl_family_in_genlmsg_multicast.c @@ -0,0 +1,9 @@ +#include + +void test(void) +{ + struct genl_family family = { }; + struct sk_buff *skb = NULL; + + genlmsg_multicast(&family, skb, 0, 0, GFP_KERNEL); +} diff --git a/drbd/compat/tests/have_genl_id_generate.c b/drbd/compat/tests/have_genl_id_generate.c new file mode 100644 index 0000000..4ef0e8e --- /dev/null +++ b/drbd/compat/tests/have_genl_id_generate.c @@ -0,0 +1,6 @@ +#include + +void test(void) +{ + int i = GENL_ID_GENERATE; +} diff --git a/drbd/compat/tests/have_genl_register_family_with_ops.c b/drbd/compat/tests/have_genl_register_family_with_ops.c new file mode 100644 index 0000000..27123db --- /dev/null +++ b/drbd/compat/tests/have_genl_register_family_with_ops.c @@ -0,0 +1,9 @@ +#include + +void test(void) +{ + struct genl_family family = { }; + struct genl_ops ops[23]; + + genl_register_family_with_ops(&family, ops); +} diff --git a/drbd/compat/tests/have_genl_register_family_with_ops3.c b/drbd/compat/tests/have_genl_register_family_with_ops3.c new file mode 100644 index 0000000..11b6d73 --- /dev/null +++ b/drbd/compat/tests/have_genl_register_family_with_ops3.c @@ -0,0 +1,9 @@ +#include + +void test(void) +{ + struct genl_family family = { }; + struct genl_ops ops[23]; + + genl_register_family_with_ops(&family, ops, 23); +} diff --git a/drbd/linux/genl_magic_func-genl_register_family_with_ops_groups.h b/drbd/linux/genl_magic_func-genl_register_family_with_ops_groups.h index 27d8f73..403e8e2 100644 --- a/drbd/linux/genl_magic_func-genl_register_family_with_ops_groups.h +++ b/drbd/linux/genl_magic_func-genl_register_family_with_ops_groups.h @@ -29,9 +29,13 @@ static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)( \ int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void) { +#if defined(COMPAT_HAVE_GENL_REGISTER_FAMILY_WITH_OPS) || defined(COMPAT_HAVE_GENL_REGISTER_FAMILY_WITH_OPS3) return genl_register_family_with_ops_groups(&ZZZ_genl_family, \ ZZZ_genl_ops, \ ZZZ_genl_mcgrps); +#else + return genl_register_family(&ZZZ_genl_family); +#endif } void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void) diff --git a/drbd/linux/genl_magic_func.h b/drbd/linux/genl_magic_func.h index 29f44a8..504719a 100644 --- a/drbd/linux/genl_magic_func.h +++ b/drbd/linux/genl_magic_func.h @@ -261,15 +261,7 @@ static struct genl_ops ZZZ_genl_ops[] __read_mostly = { * {{{2 */ #define ZZZ_genl_family CONCAT_(GENL_MAGIC_FAMILY, _genl_family) -static struct genl_family ZZZ_genl_family __read_mostly = { - .id = GENL_ID_GENERATE, - .name = __stringify(GENL_MAGIC_FAMILY), - .version = GENL_MAGIC_VERSION, -#ifdef GENL_MAGIC_FAMILY_HDRSZ - .hdrsize = NLA_ALIGN(GENL_MAGIC_FAMILY_HDRSZ), -#endif - .maxattr = ARRAY_SIZE(drbd_tla_nl_policy)-1, -}; +static struct genl_family ZZZ_genl_family; /* * Magic: define multicast groups @@ -282,13 +274,35 @@ static struct genl_family ZZZ_genl_family __read_mostly = { * genetlink: pass family to functions using groups * genetlink: only pass array to genl_register_family_with_ops() * which are commits c53ed742..2a94fe48 + * + * v4.10, 489111e5 genetlink: statically initialize families + * and previous commit drop GENL_ID_GENERATE and register helper functions. */ -#ifdef genl_register_family_with_ops_groups +#if defined(genl_register_family_with_ops_groups) || !defined(GENL_ID_GENERATE) #include #else #include #endif +static struct genl_family ZZZ_genl_family __read_mostly = { + /* .id = GENL_ID_GENERATE, which exists no longer, and was 0 anyways */ + .name = __stringify(GENL_MAGIC_FAMILY), + .version = GENL_MAGIC_VERSION, +#ifdef GENL_MAGIC_FAMILY_HDRSZ + .hdrsize = NLA_ALIGN(GENL_MAGIC_FAMILY_HDRSZ), +#endif + .maxattr = ARRAY_SIZE(CONCAT_(GENL_MAGIC_FAMILY, _tla_nl_policy))-1, + +#ifndef GENL_ID_GENERATE + .ops = ZZZ_genl_ops, + .n_ops = ARRAY_SIZE(ZZZ_genl_ops), + .mcgrps = ZZZ_genl_mcgrps, + .n_mcgrps = ARRAY_SIZE(ZZZ_genl_mcgrps), + .module = THIS_MODULE, +#endif +}; + + /* * Magic: provide conversion functions {{{1 * populate skb from struct. -- 1.8.3.1