Skip to content

Commit

Permalink
datapath: Allow compile against current net-next.
Browse files Browse the repository at this point in the history
This patch allows openvswitch kernel module in the OVS tree to be
compiled against the current net-next Linux kernel.  The changes are
due to these upstream commits:

56989f6d856 ("genetlink: mark families as __ro_after_init")
489111e5c25 ("genetlink: statically initialize families")
a07ea4d9941 ("genetlink: no longer support using static family IDs")

struct genl_family initialization is changed be completely static and
to include the new (in Linux 4.6) __ro_after_init attribute.  Compat
code defines it as an empty macro if not defined already.

GENL_ID_GENERATE is no longer defined, but since it was defined as 0,
it is safe to drop it from all initializers also on older Linux
versions.  A compiletime_assert is added to make sure this is true
whenever GENL_ID_GENERATE is defined.

Tested with current Linux net-next (4.9) and 3.16.

It should be noted that there are still a number of fixes and new
features in upstream net-next that are yet to be backported.

Signed-off-by: Jarno Rajahalme <[email protected]>
Acked-by: Andy Zhou <[email protected]>
  • Loading branch information
Jarno Rajahalme committed Dec 10, 2016
1 parent cbef684 commit ba63fe2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ AC_DEFUN([OVS_CHECK_LINUX], [
AC_MSG_RESULT([$kversion])
if test "$version" -ge 4; then
if test "$version" = 4 && test "$patchlevel" -le 8; then
if test "$version" = 4 && test "$patchlevel" -le 9; then
: # Linux 4.x
else
AC_ERROR([Linux kernel in $KBUILD is version $kversion, but version newer than 4.8.x is not supported (please refer to the FAQ for advice)])
AC_ERROR([Linux kernel in $KBUILD is version $kversion, but version newer than 4.9.x is not supported (please refer to the FAQ for advice)])
fi
elif test "$version" = 3 && test "$patchlevel" -ge 10; then
: # Linux 3.x
Expand Down
18 changes: 9 additions & 9 deletions datapath/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,7 @@ static struct genl_ops dp_packet_genl_ops[] = {
}
};

static struct genl_family dp_packet_genl_family = {
.id = GENL_ID_GENERATE,
static struct genl_family dp_packet_genl_family __ro_after_init = {
.hdrsize = sizeof(struct ovs_header),
.name = OVS_PACKET_FAMILY,
.version = OVS_PACKET_VERSION,
Expand All @@ -692,6 +691,7 @@ static struct genl_family dp_packet_genl_family = {
.parallel_ops = true,
.ops = dp_packet_genl_ops,
.n_ops = ARRAY_SIZE(dp_packet_genl_ops),
.module = THIS_MODULE,
};

static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats,
Expand Down Expand Up @@ -1447,8 +1447,7 @@ static struct genl_ops dp_flow_genl_ops[] = {
},
};

static struct genl_family dp_flow_genl_family = {
.id = GENL_ID_GENERATE,
static struct genl_family dp_flow_genl_family __ro_after_init = {
.hdrsize = sizeof(struct ovs_header),
.name = OVS_FLOW_FAMILY,
.version = OVS_FLOW_VERSION,
Expand All @@ -1459,6 +1458,7 @@ static struct genl_family dp_flow_genl_family = {
.n_ops = ARRAY_SIZE(dp_flow_genl_ops),
.mcgrps = &ovs_dp_flow_multicast_group,
.n_mcgrps = 1,
.module = THIS_MODULE,
};

static size_t ovs_dp_cmd_msg_size(void)
Expand Down Expand Up @@ -1832,8 +1832,7 @@ static struct genl_ops dp_datapath_genl_ops[] = {
},
};

static struct genl_family dp_datapath_genl_family = {
.id = GENL_ID_GENERATE,
static struct genl_family dp_datapath_genl_family __ro_after_init = {
.hdrsize = sizeof(struct ovs_header),
.name = OVS_DATAPATH_FAMILY,
.version = OVS_DATAPATH_VERSION,
Expand All @@ -1844,6 +1843,7 @@ static struct genl_family dp_datapath_genl_family = {
.n_ops = ARRAY_SIZE(dp_datapath_genl_ops),
.mcgrps = &ovs_dp_datapath_multicast_group,
.n_mcgrps = 1,
.module = THIS_MODULE,
};

/* Called with ovs_mutex or RCU read lock. */
Expand Down Expand Up @@ -2254,8 +2254,7 @@ static struct genl_ops dp_vport_genl_ops[] = {
},
};

struct genl_family dp_vport_genl_family = {
.id = GENL_ID_GENERATE,
struct genl_family dp_vport_genl_family __ro_after_init = {
.hdrsize = sizeof(struct ovs_header),
.name = OVS_VPORT_FAMILY,
.version = OVS_VPORT_VERSION,
Expand All @@ -2266,6 +2265,7 @@ struct genl_family dp_vport_genl_family = {
.n_ops = ARRAY_SIZE(dp_vport_genl_ops),
.mcgrps = &ovs_dp_vport_multicast_group,
.n_mcgrps = 1,
.module = THIS_MODULE,
};

static struct genl_family *dp_genl_families[] = {
Expand All @@ -2283,7 +2283,7 @@ static void dp_unregister_genl(int n_families)
genl_unregister_family(dp_genl_families[i]);
}

static int dp_register_genl(void)
static int __init dp_register_genl(void)
{
int err;
int i;
Expand Down
1 change: 1 addition & 0 deletions datapath/linux/Modules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ openvswitch_headers += \
linux/compat/gso.h \
linux/compat/include/linux/percpu.h \
linux/compat/include/linux/bug.h \
linux/compat/include/linux/cache.h \
linux/compat/include/linux/compiler.h \
linux/compat/include/linux/compiler-gcc.h \
linux/compat/include/linux/cpumask.h \
Expand Down
10 changes: 10 additions & 0 deletions datapath/linux/compat/include/linux/cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __LINUX_CACHE_WRAPPER_H
#define __LINUX_CACHE_WRAPPER_H 1

#include_next <linux/cache.h>

#ifndef __ro_after_init
#define __ro_after_init
#endif

#endif
4 changes: 4 additions & 0 deletions datapath/linux/compat/include/linux/genetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
#define GENL_UNS_ADMIN_PERM GENL_ADMIN_PERM
#endif

#ifdef GENL_ID_GENERATE
compiletime_assert(GENL_ID_GENERATE == 0, "GENL_ID_GENERATE is assumed to be zero")
#endif

#endif

0 comments on commit ba63fe2

Please sign in to comment.