add YAML spec for team
Subsystems (4)
cover add YAML spec for team
Hi Jakub,
You suggested me to add yaml spec for bridge. Since I'm not familiar with writing the spec file, I choose to convert team as a start.
There are still some questions I got during convertion.
1. Is there a preference to use "-" instead of "_" for the names in spec file? e.g. the attr-cnt-name in team.spec, should I use __team-attr-item-port-max or --team-attr-item-port-max, or __team_attr_item_port_max?
2. I saw ynl-gen-c.py deals with unterminated-ok. But this policy is not shown in the schemas. Is it a new feature that still working on?
3. Do we have to hard code the string max-len? Is there a way to use
the name in definitions? e.g.
name: name
type: string
checks:
max-len: string-max-len
4. The doc will be generate to rst file in future, so there will not have other comments in the _nl.c or _nl.h files, right?
5. the genl_multicast_group is forced to use list. But the team use format like { .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, }. Should we support this legacy format?
6. The _UAPI_LINUX_IF_TEAM_H_ is rename to _UAPI_LINUX_IF_TEAM_H in uapi header. Does that affects?
7. When build, I got error modpost: missing MODULE_LICENSE() in drivers/net/team/team_nl.o. Should we add the MODULE_LICENSE support in ynl-gen-c.py?
8. When build, I also got errors like
ERROR: modpost: "team_nl_policy" [drivers/net/team/team.ko] undefined!
ERROR: modpost: "team_nl_ops" [drivers/net/team/team.ko] undefined!
ERROR: modpost: "team_nl_noop_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_options_set_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_options_get_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_port_list_get_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_attr_option_nl_policy" [drivers/net/team/team.ko] undefined!
Do you know why include "team_nl.h" doesn't help?
Thanks
Hangbin
Hangbin Liu (3):
Documentation: netlink: add a YAML spec for team
net: team: use policy generated by YAML spec
uapi: team: use header file generated from YAML spec
Documentation/netlink/specs/team.yaml | 205 ++++++++++++++++++++++++++ MAINTAINERS | 1 + drivers/net/team/Makefile | 2 +- drivers/net/team/team.c | 59 +------- drivers/net/team/team_nl.c | 59 ++++++++ drivers/net/team/team_nl.h | 29 ++++ include/uapi/linux/if_team.h | 116 ++++++--------- 7 files changed, 345 insertions(+), 126 deletions(-) create mode 100644 Documentation/netlink/specs/team.yaml create mode 100644 drivers/net/team/team_nl.c create mode 100644 drivers/net/team/team_nl.h
Signature · 1 line
2.43.0
PATCH 1/3 Documentation: netlink: add a YAML spec for team
Add a YAML specification for team.
--- Documentation/netlink/specs/team.yaml | 205 ++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 206 insertions(+) create mode 100644 Documentation/netlink/specs/team.yaml
Documentation/netlink/specs/team.yaml new file +205 -0
@@ -0,0 +1,205 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) + +name: team + +protocol: genetlink-legacy + +doc: | + Network team device driver. + +c-family-name: team-genl-name +c-version-name: team-genl-version +kernel-policy: global +uapi-header: linux/if_team.h + +definitions: + - + name: string-max-len + type: const + value: 32 + - + name: genl-change-event-mc-grp-name + type: const + value: change_event + +attribute-sets: + - + name: team + doc: + The team nested layout of get/set msg looks like + [TEAM_ATTR_LIST_OPTION] + [TEAM_ATTR_ITEM_OPTION] + [TEAM_ATTR_OPTION_*], ... + [TEAM_ATTR_ITEM_OPTION] + [TEAM_ATTR_OPTION_*], ... + ... + [TEAM_ATTR_LIST_PORT] + [TEAM_ATTR_ITEM_PORT] + [TEAM_ATTR_PORT_*], ... + [TEAM_ATTR_ITEM_PORT] + [TEAM_ATTR_PORT_*], ... + ... + name-prefix: team-attr- + attributes: + - + name: unspec + type: unused + value: 0 + - + name: team-ifindex + type: u32 + - + name: list-option + type: nest + nested-attributes: item-option + - + name: list-port + type: nest + nested-attributes: item-port + - + name: item-option + name-prefix: team-attr-item- + attr-cnt-name: __team-attr-item-option-max + attr-max-name: team-attr-item-option-max + attributes: + - + name: option-unspec + type: unused + value: 0 + - + name: option + type: nest + nested-attributes: attr-option + - + name: attr-option + name-prefix: team-attr-option- + attributes: + - + name: unspec + type: unused + value: 0 + - + name: name + type: string + checks: + # no unterminated-ok defination? + # do we have to hard code this? + max-len: 32 + - + name: changed + type: flag + - + name: type + type: u8 + - + name: data + type: binary + - + name: removed + type: flag + - + name: port-ifindex + type: u32 + doc: for per-port options + - + name: array-index + type: u32 + doc: for for array options + - + name: item-port + name-prefix: team-attr-item- + attr-cnt-name: __team-attr-item-port-max + attr-max-name: team-attr-item-port-max + attributes: + - + name: port-unspec + type: unused + value: 0 + - + name: port + type: nest + nested-attributes: attr-port + - + name: attr-port + name-prefix: team-attr-port- + attributes: + - + name: unspec + type: unused + value: 0 + - + name: ifindex + type: u32 + - + name: changed + type: flag + - + name: linkup + type: flag + - + name: speed + type: u32 + - + name: duplex + type: u8 + - + name: removed + type: flag + +operations: + list: + - + name: noop + doc: No operation + value: 0 + attribute-set: team + dont-validate: [ strict, dump ] + + do: + # Actually it only reply the team netlink family + reply: + attributes: + - team-ifindex + + - + name: options-set + doc: Set team options + attribute-set: team + dont-validate: [ strict, dump ] + flags: [ admin-perm ] + + do: + request: + attributes: + - team-ifindex + - list-option + + - + name: options-get + doc: Get team options info + attribute-set: team + dont-validate: [ strict, dump ] + flags: [ admin-perm ] + + do: + request: + attributes: + - team-ifindex + reply: + attributes: + - list-option + + - + name: port-list-get + doc: Get team ports info + attribute-set: team + dont-validate: [ strict, dump ] + flags: [ admin-perm ] + + do: + request: + attributes: + - team-ifindex + reply: + attributes: + - list-port
MAINTAINERS +1 -0
@@ -21301,6 +21301,7 @@ F: drivers/net/team/ F: include/linux/if_team.h F: include/uapi/linux/if_team.h F: tools/testing/selftests/drivers/net/team/ +F: Documentation/netlink/specs/team.yaml TECHNICAL ADVISORY BOARD PROCESS DOCS M: "Theodore Ts'o" <[email protected]>
Signature · 1 line
2.43.0
Jiri Pirko
maintainerRe: [Draft PATCH net-next 1/3] Documentation: netlink: add a YAML spec for team
Quoted 161 lines · Wed, Dec 13, 2023 at 09:45:00AM CET, [email protected] wrote:
Add a YAML specification for team.
Signed-off-by Hangbin Liu <[email protected]>---
Documentation/netlink/specs/team.yaml| 205 ++++++++++++++++++++++++++MAINTAINERS| 1 +2 files changed, 206 insertions(+)create mode 100644
Documentation/netlink/specs/team.yamlDocumentation/netlink/specs/team.yaml new file +146
-0@@ -0,0 +1,205 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) + +name: team + +protocol: genetlink-legacy + +doc: | + Network team device driver. + +c-family-name: team-genl-name +c-version-name: team-genl-version +kernel-policy: global +uapi-header: linux/if_team.h + +definitions: + - + name: string-max-len + type: const + value: 32 + - + name: genl-change-event-mc-grp-name + type: const + value: change_event + +attribute-sets: + - + name: team + doc: + The team nested layout of get/set msg looks like + [TEAM_ATTR_LIST_OPTION] + [TEAM_ATTR_ITEM_OPTION] + [TEAM_ATTR_OPTION_*], ... + [TEAM_ATTR_ITEM_OPTION] + [TEAM_ATTR_OPTION_*], ... + ... + [TEAM_ATTR_LIST_PORT] + [TEAM_ATTR_ITEM_PORT] + [TEAM_ATTR_PORT_*], ... + [TEAM_ATTR_ITEM_PORT] + [TEAM_ATTR_PORT_*], ... + ... + name-prefix: team-attr- + attributes: + - + name: unspec + type: unused + value: 0 + - + name: team-ifindex + type: u32 + - + name: list-option + type: nest + nested-attributes: item-option + - + name: list-port + type: nest + nested-attributes: item-port + - + name: item-option + name-prefix: team-attr-item- + attr-cnt-name: __team-attr-item-option-max + attr-max-name: team-attr-item-option-max + attributes: + - + name: option-unspec + type: unused + value: 0 + - + name: option + type: nest + nested-attributes: attr-option + - + name: attr-option + name-prefix: team-attr-option- + attributes: + - + name: unspec + type: unused + value: 0 + - + name: name + type: string + checks: + # no unterminated-ok defination? + # do we have to hard code this? + max-len: 32 + - + name: changed + type: flag + - + name: type + type: u8 + - + name: data + type: binary + - + name: removed + type: flag + - + name: port-ifindex + type: u32 + doc: for per-port options + - + name: array-index + type: u32 + doc: for for array options + - + name: item-port + name-prefix: team-attr-item- + attr-cnt-name: __team-attr-item-port-max + attr-max-name: team-attr-item-port-max + attributes: + - + name: port-unspec + type: unused + value: 0 + - + name: port + type: nest + nested-attributes: attr-port + - + name: attr-port + name-prefix: team-attr-port- + attributes: + - + name: unspec + type: unused + value: 0 + - + name: ifindex + type: u32 + - + name: changed + type: flag + - + name: linkup + type: flag + - + name: speed + type: u32 + - + name: duplex + type: u8 + - + name: removed
Documentation/netlink/specs/team.yaml line 156
Quoted 10 lines
Documentation/netlink/specs/team.yaml new file +10
-0+ type: flag + +operations: + list: + - + name: noop + doc: No operation + value: 0 + attribute-set: team + dont-validate: [ strict, dump ]
What is this good for?
Documentation/netlink/specs/team.yaml line 168
Quoted 12 lines
Documentation/netlink/specs/team.yaml new file +12
-0+ + do: + # Actually it only reply the team netlink family + reply: + attributes: + - team-ifindex + + - + name: options-set + doc: Set team options + attribute-set: team + dont-validate: [ strict, dump ]
There is no dump op. Same below.
Quoted 52 lines
Documentation/netlink/specs/team.yaml new file +37
-0+ flags: [ admin-perm ] + + do: + request: + attributes: + - team-ifindex + - list-option + + - + name: options-get + doc: Get team options info + attribute-set: team + dont-validate: [ strict, dump ] + flags: [ admin-perm ] + + do: + request: + attributes: + - team-ifindex + reply: + attributes: + - list-option + + - + name: port-list-get + doc: Get team ports info + attribute-set: team + dont-validate: [ strict, dump ] + flags: [ admin-perm ] + + do: + request: + attributes: + - team-ifindex + reply: + attributes: + - list-portMAINTAINERS +0
-0@@ -21301,6 +21301,7 @@ F: drivers/net/team/F:
include/linux/if_team.h
F:include/uapi/linux/if_team.h
F:tools/testing/selftests/drivers/net/team/
+F:Documentation/netlink/specs/team.yamlTECHNICAL ADVISORY BOARD PROCESS DOCS
M: "Theodore Ts'o" <[email protected]>Signature · 1 line
2.43.0
Re: [Draft PATCH net-next 1/3] Documentation: netlink: add a YAML spec for team
Quoted 12 lines · Jiri Pirko
Documentation/netlink/specs/team.yaml line 156
Quoted 8 lines
Documentation/netlink/specs/team.yaml new file +8
-0+operations: + list: + - + name: noop + doc: No operation + value: 0 + attribute-set: team + dont-validate: [ strict, dump ]What is this good for?
Quoted 15 lines
Documentation/netlink/specs/team.yaml line 168
Quoted 12 lines
Documentation/netlink/specs/team.yaml new file +12
-0+ + do: + # Actually it only reply the team netlink family + reply: + attributes: + - team-ifindex + + - + name: options-set + doc: Set team options + attribute-set: team + dont-validate: [ strict, dump ]There is no dump op. Same below.
Hi Jiri,
I just copied this from the current team.c code. e.g.
static const struct genl_small_ops team_nl_ops[] = {
{
.cmd = TEAM_CMD_NOOP,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = team_nl_cmd_noop,
},
{
.cmd = TEAM_CMD_OPTIONS_SET,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = team_nl_cmd_options_set,
.flags = GENL_ADMIN_PERM,
},
Do you want to remove all the GENL_DONT_VALIDATE_DUMP flags from team_nl_ops?
Thanks
Hangbin
Jiri Pirko
maintainerRe: [Draft PATCH net-next 1/3] Documentation: netlink: add a YAML spec for team
Quoted 28 lines · Thu, Dec 14, 2023 at 04:44:10AM CET, [email protected] wrote:
Quoted 12 lines · Jiri Pirko
Documentation/netlink/specs/team.yaml line 156
Quoted 8 lines
Documentation/netlink/specs/team.yaml new file +8
-0+operations: + list: + - + name: noop + doc: No operation + value: 0 + attribute-set: team + dont-validate: [ strict, dump ]What is this good for?
Quoted 15 lines
Documentation/netlink/specs/team.yaml line 168
Quoted 12 lines
Documentation/netlink/specs/team.yaml new file +12
-0+ + do: + # Actually it only reply the team netlink family + reply: + attributes: + - team-ifindex + + - + name: options-set + doc: Set team options + attribute-set: team + dont-validate: [ strict, dump ]There is no dump op. Same below.
Quoted 3 lines
Hi Jiri,
I just copied this from the current
team.ccode. e.g.
Right, it is something which is not looked at. Remove it during the conversion.
Quoted 18 lines
static const struct
genl_small_opsteam_nl_ops[] = {
{
.cmd =TEAM_CMD_NOOP,
.validate =GENL_DONT_VALIDATE_STRICT|GENL_DONT_VALIDATE_DUMP, .doit =team_nl_cmd_noop,
},
{
.cmd =TEAM_CMD_OPTIONS_SET,
.validate =GENL_DONT_VALIDATE_STRICT|GENL_DONT_VALIDATE_DUMP, .doit =team_nl_cmd_options_set,
.flags =GENL_ADMIN_PERM,
},Do you want to remove all the
GENL_DONT_VALIDATE_DUMPflags fromteam_nl_ops?Thanks
Hangbin
Jakub Kicinski
maintainerRe: [Draft PATCH net-next 1/3] Documentation: netlink: add a YAML spec for team
In reply to Hangbin LiuDocumentation/netlink/specs/team.yaml line 162
Quoted 12 lines · On Wed, 13 Dec 2023 16:45:00 +0800 Hangbin Liu wrote:
Documentation/netlink/specs/team.yaml new file +12
-0+ - + name: noop + doc: No operation + value: 0 + attribute-set: team + dont-validate: [ strict, dump ] + + do: + # Actually it only reply the team netlink family + reply: + attributes: + - team-ifindex
Oh my. Does it actually take team-ifindex or its an op with no input and no output?
Re: [Draft PATCH net-next 1/3] Documentation: netlink: add a YAML spec for team
Quoted 14 lines · Jakub Kicinski
Documentation/netlink/specs/team.yaml line 162
Quoted 12 lines · On Wed, 13 Dec 2023 16:45:00 +0800 Hangbin Liu wrote:
Documentation/netlink/specs/team.yaml new file +12
-0+ - + name: noop + doc: No operation + value: 0 + attribute-set: team + dont-validate: [ strict, dump ] + + do: + # Actually it only reply the team netlink family + reply: + attributes: + - team-ifindex
Quoted 2 lines
Oh my. Does it actually take team-ifindex or its an op with no input and no output?
No, it doesn't take team-ifindex. It's an option with no input and just reply the team_nl_family.
I added this reply attribute just to make sure the TEAM_CMD_NOOP show in the cmd enum to not break uAPI.
Thanks
Hangbin
Jakub Kicinski
maintainerRe: [Draft PATCH net-next 1/3] Documentation: netlink: add a YAML spec for team
Quoted 8 lines · On Thu, 14 Dec 2023 11:52:50 +0800 Hangbin Liu wrote:
Quoted 2 lines
Oh my. Does it actually take team-ifindex or its an op with no input and no output?
No, it doesn't take team-ifindex. It's an option with no input and just reply the
team_nl_family.I added this reply attribute just to make sure the
TEAM_CMD_NOOPshow in the cmd enum to not break uAPI.
Another todo for the codegen, I guess.
PATCH 2/3 net: team: use policy generated by YAML spec
In reply to Hangbin Liugenerated with:
$ ./tools/net/ynl/ynl-gen-c.py --mode kernel \
Quoted 2 lines
--spec
Documentation/netlink/specs/team.yaml--source \
-odrivers/net/team/team_nl.c
$ ./tools/net/ynl/ynl-gen-c.py --mode kernel \
Quoted 2 lines
--spec
Documentation/netlink/specs/team.yaml--header \
-odrivers/net/team/team_nl.h
The TEAM_ATTR_LIST_PORT in team_nl_policy is removed as it only in the port list reply attributes.
--- drivers/net/team/Makefile | 2 +- drivers/net/team/team.c | 59 +++++--------------------------------- drivers/net/team/team_nl.c | 59 ++++++++++++++++++++++++++++++++++++++ drivers/net/team/team_nl.h | 29 +++++++++++++++++++ 4 files changed, 96 insertions(+), 53 deletions(-) create mode 100644 drivers/net/team/team_nl.c create mode 100644 drivers/net/team/team_nl.h
drivers/net/team/Makefile +1 -1
@@ -3,7 +3,7 @@ # Makefile for the network team driver # -obj-$(CONFIG_NET_TEAM) += team.o +obj-$(CONFIG_NET_TEAM) += team.o team_nl.o obj-$(CONFIG_NET_TEAM_MODE_BROADCAST) += team_mode_broadcast.o obj-$(CONFIG_NET_TEAM_MODE_ROUNDROBIN) += team_mode_roundrobin.o obj-$(CONFIG_NET_TEAM_MODE_RANDOM) += team_mode_random.o
drivers/net/team/team.c +7 -52
101 lines not on this page · raw message
drivers/net/team/team_nl.c new file +59 -0
59 lines not on this page · raw message
drivers/net/team/team_nl.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/team.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_TEAM_GEN_H +#define _LINUX_TEAM_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <uapi/linux/if_team.h> + +/* Common nested types */ +extern const struct nla_policy team_attr_option_nl_policy[TEAM_ATTR_OPTION_ARRAY_INDEX +1 ]; +extern const struct nla_policy team_item_option_nl_policy[TEAM_ATTR_ITEM_OPTION +1 ]; + +/* Global operation policy for team */ +extern const struct nla_policy team_nl_policy[TEAM_ATTR_LIST_OPTION +1 ]; + +/* Ops table for team */ +extern const struct genl_small_ops team_nl_ops[4 ]; + +int team_nl_noop_doit (struct sk_buff *skb,struct genl_info *info); +int team_nl_options_set_doit (struct sk_buff *skb,struct genl_info *info); +int team_nl_options_get_doit (struct sk_buff *skb,struct genl_info *info); +int team_nl_port_list_get_doit (struct sk_buff *skb,struct genl_info *info); + +#endif /* _LINUX_TEAM_GEN_H */
Signature · 1 line
2.43.0
Jiri Pirko
maintainerRe: [Draft PATCH net-next 2/3] net: team: use policy generated by YAML spec
Quoted 10 lines · Wed, Dec 13, 2023 at 09:45:01AM CET, [email protected] wrote:
generated with:
$ ./tools/net/ynl/ynl-gen-c.py --mode kernel \Quoted 2 lines
--spec
Documentation/netlink/specs/team.yaml--source \
-odrivers/net/team/team_nl.c$ ./tools/net/ynl/ynl-gen-c.py --mode kernel \Quoted 2 lines
--spec
Documentation/netlink/specs/team.yaml--header \
-odrivers/net/team/team_nl.hThe
TEAM_ATTR_LIST_PORTinteam_nl_policyis removed as it only in the
"only is in the" ? Looks like you are missing verb somewhere anyway.
Overall looks fine.
Quoted 2 lines
port list reply attributes.
PATCH 3/3 uapi: team: use header file generated from YAML spec
In reply to Hangbin Liugenerated with:
$ ./tools/net/ynl/ynl-gen-c.py --mode uapi \
Quoted 2 lines
--spec
Documentation/netlink/specs/team.yaml\
--header -oinclude/uapi/linux/if_team.h
--- include/uapi/linux/if_team.h | 116 +++++++++++++---------------------- 1 file changed, 43 insertions(+), 73 deletions(-)
include/uapi/linux/if_team.h +43 -73
@@ -1,108 +1,78 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ -/* -* include/linux/if_team.h - Network team device driver header -* Copyright (c) 2011 Jiri Pirko <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -*/ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/team.yaml */ +/* YNL-GEN uapi header */ -#ifndef _UAPI_LINUX_IF_TEAM_H_ -#define _UAPI_LINUX_IF_TEAM_H_ +#ifndef _UAPI_LINUX_IF_TEAM_H +#define _UAPI_LINUX_IF_TEAM_H +#define TEAM_GENL_NAME "team" +#define TEAM_GENL_VERSION 1 -#define TEAM_STRING_MAX_LEN 32 - -/********************************** -* NETLINK_GENERIC netlink family. -**********************************/ - -enum { -TEAM_CMD_NOOP , -TEAM_CMD_OPTIONS_SET , -TEAM_CMD_OPTIONS_GET , -TEAM_CMD_PORT_LIST_GET , - - __TEAM_CMD_MAX, -TEAM_CMD_MAX = (__TEAM_CMD_MAX -1 ), -}; +#define TEAM_STRING_MAX_LEN 32 +#define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"enum {TEAM_ATTR_UNSPEC , -TEAM_ATTR_TEAM_IFINDEX ,/* u32 */ -TEAM_ATTR_LIST_OPTION ,/* nest */ -TEAM_ATTR_LIST_PORT ,/* nest */ +TEAM_ATTR_TEAM_IFINDEX , +TEAM_ATTR_LIST_OPTION , +TEAM_ATTR_LIST_PORT , __TEAM_ATTR_MAX, -TEAM_ATTR_MAX = __TEAM_ATTR_MAX -1 , +TEAM_ATTR_MAX = (__TEAM_ATTR_MAX -1 ) }; -/* Nested layout of get/set msg: -* -* [TEAM_ATTR_LIST_OPTION] -* [TEAM_ATTR_ITEM_OPTION] -* [TEAM_ATTR_OPTION_*], ... -* [TEAM_ATTR_ITEM_OPTION] -* [TEAM_ATTR_OPTION_*], ... -* ... -* [TEAM_ATTR_LIST_PORT] -* [TEAM_ATTR_ITEM_PORT] -* [TEAM_ATTR_PORT_*], ... -* [TEAM_ATTR_ITEM_PORT] -* [TEAM_ATTR_PORT_*], ... -* ... -*/ -enum {TEAM_ATTR_ITEM_OPTION_UNSPEC , -TEAM_ATTR_ITEM_OPTION ,/* nest */ +TEAM_ATTR_ITEM_OPTION , __TEAM_ATTR_ITEM_OPTION_MAX, -TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX -1 , +TEAM_ATTR_ITEM_OPTION_MAX = (__TEAM_ATTR_ITEM_OPTION_MAX -1 ) };enum {TEAM_ATTR_OPTION_UNSPEC , -TEAM_ATTR_OPTION_NAME ,/* string */ -TEAM_ATTR_OPTION_CHANGED ,/* flag */ -TEAM_ATTR_OPTION_TYPE ,/* u8 */ -TEAM_ATTR_OPTION_DATA ,/* dynamic */ -TEAM_ATTR_OPTION_REMOVED ,/* flag */ -TEAM_ATTR_OPTION_PORT_IFINDEX ,/* u32 */ /* for per-port options */ -TEAM_ATTR_OPTION_ARRAY_INDEX ,/* u32 */ /* for array options */ +TEAM_ATTR_OPTION_NAME , +TEAM_ATTR_OPTION_CHANGED , +TEAM_ATTR_OPTION_TYPE , +TEAM_ATTR_OPTION_DATA , +TEAM_ATTR_OPTION_REMOVED , +TEAM_ATTR_OPTION_PORT_IFINDEX , +TEAM_ATTR_OPTION_ARRAY_INDEX , __TEAM_ATTR_OPTION_MAX, -TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX -1 , +TEAM_ATTR_OPTION_MAX = (__TEAM_ATTR_OPTION_MAX -1 ) };enum {TEAM_ATTR_ITEM_PORT_UNSPEC , -TEAM_ATTR_ITEM_PORT ,/* nest */ +TEAM_ATTR_ITEM_PORT , __TEAM_ATTR_ITEM_PORT_MAX, -TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX -1 , +TEAM_ATTR_ITEM_PORT_MAX = (__TEAM_ATTR_ITEM_PORT_MAX -1 ) };enum {TEAM_ATTR_PORT_UNSPEC , -TEAM_ATTR_PORT_IFINDEX ,/* u32 */ -TEAM_ATTR_PORT_CHANGED ,/* flag */ -TEAM_ATTR_PORT_LINKUP ,/* flag */ -TEAM_ATTR_PORT_SPEED ,/* u32 */ -TEAM_ATTR_PORT_DUPLEX ,/* u8 */ -TEAM_ATTR_PORT_REMOVED ,/* flag */ +TEAM_ATTR_PORT_IFINDEX , +TEAM_ATTR_PORT_CHANGED , +TEAM_ATTR_PORT_LINKUP , +TEAM_ATTR_PORT_SPEED , +TEAM_ATTR_PORT_DUPLEX , +TEAM_ATTR_PORT_REMOVED , __TEAM_ATTR_PORT_MAX, -TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX -1 , +TEAM_ATTR_PORT_MAX = (__TEAM_ATTR_PORT_MAX -1 ) }; -/* -* NETLINK_GENERIC related info -*/ -#define TEAM_GENL_NAME "team" -#define TEAM_GENL_VERSION 0x1 -#define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event" +enum { +TEAM_CMD_NOOP , +TEAM_CMD_OPTIONS_SET , +TEAM_CMD_OPTIONS_GET , +TEAM_CMD_PORT_LIST_GET , + + __TEAM_CMD_MAX, +TEAM_CMD_MAX = (__TEAM_CMD_MAX -1 ) +}; -#endif /* _UAPI_LINUX_IF_TEAM_H_ */ +#endif /* _UAPI_LINUX_IF_TEAM_H */
Signature · 1 line
2.43.0
Jiri Pirko
maintainerRe: [Draft PATCH net-next 3/3] uapi: team: use header file generated from YAML spec
Quoted 7 lines · Wed, Dec 13, 2023 at 09:45:02AM CET, [email protected] wrote:
generated with:
$ ./tools/net/ynl/ynl-gen-c.py --mode uapi \Quoted 2 lines
--spec
Documentation/netlink/specs/team.yaml\
--header -oinclude/uapi/linux/if_team.hSigned-off-by Hangbin Liu <[email protected]>
This looks fine to me. I don't see why s/_UAPI_LINUX_IF_TEAM_H_/_UAPI_LINUX_IF_TEAM_H/ would cause issues...
Jakub Kicinski
maintainerQuoted 2 lines · On Wed, 13 Dec 2023 16:44:59 +0800 Hangbin Liu wrote:
You suggested me to add yaml spec for bridge. Since I'm not familiar with writing the spec file, I choose to convert team as a start.
Nice work! If you write a spec you don't necessarily have to use the spec for C code gen, but I will obviously not stop you from going the extra mile :)
Quoted 5 lines
There are still some questions I got during convertion.
1. Is there a preference to use "-" instead of "_" for the names in spec file? e.g. the attr-cnt-name in team.spec, should I use __team-attr-item-port-max or --team-attr-item-port-max, or
__team_attr_item_port_max?
Minor preference for using -, but it mostly matters for things which will be visible outside of C. For instance in attr names when they are used in python:
msg['port-index']
looks nicer to me than
msg['port_index']
and is marginally easier to type. But cnt-name is a C thing, so up to you. If I was writing it myself I'd probably go with --team-attr-item-port-max, that's what MPTCP did.
Quoted 2 lines
2. I saw
ynl-gen-c.pydeals with unterminated-ok. But this policy is not shown in the schemas. Is it a new feature that still working on?
I must have added it to the code gen when experimenting with a family I didn't end up supporting. I'm not actively working on that one, feel free to take a stab at finishing it or LMK if you need help.
Quoted 6 lines
3. Do we have to hard code the string max-len? Is there a way to use the name in definitions? e.g.
name: name
type: string
checks:
max-len: string-max-len
Yes, that's the intention, if codegen doesn't support that today it should be improved.
Quoted 2 lines
4. The doc will be generate to rst file in future, so there will not have other comments in the
_nl.cor_nl.hfiles, right?
It already generates ReST:
https://docs.kernel.org/next/networking/netlink_spec/
We do still generate kdoc in the uAPI header, tho.
Quoted 3 lines
5. the
genl_multicast_groupis forced to use list. But the team use format like { .name =TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, }. Should we support this legacy format?
Do you mean that we generate:
[ID] = { "name", }rather than:
[ID] = { .name = "name", }? I think the struct had only one member at the time, so I didn't bother adding the .name, but you can change the code-gen.
Quoted 2 lines
6. The _UAPI_LINUX_IF_TEAM_H_ is rename to
_UAPI_LINUX_IF_TEAM_Hin uapi header. Does that affects?
Hopefully it's fine. Let's try to make the change and deal with problems if any get reported. Having the standardized guards helps a little bit in our Makefile magic...
Quoted 2 lines
7. When build, I got error modpost: missing
MODULE_LICENSE()indrivers/net/team/team_nl.o. Should we add theMODULE_LICENSEsupport inynl-gen-c.py?
Not sure if we can, the generated code should be linked with the implementation to form a full module. The manually written part of the implementation should define the license. YAML specs have a fairly odd / broadly open license because they are uAPI. We don't want to start getting into licensing business.
Quoted 9 lines
8. When build, I also got errors like
ERROR: modpost: "team_nl_policy" [drivers/net/team/team.ko] undefined!
ERROR: modpost: "team_nl_ops" [drivers/net/team/team.ko] undefined!
ERROR: modpost: "team_nl_noop_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_options_set_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_options_get_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_port_list_get_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_attr_option_nl_policy" [drivers/net/team/team.ko] undefined!
Do you know why include "team_nl.h" doesn't help?
Same reason as the reason you're getting the LICENSE warning. kbuild is probably trying to build team_nl and team as separate modules.
I think you'll have to rename team.c, take a look at what I did around commit 08d323234d10. I don't know a better way...
Hi Jakub,
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines
There are still some questions I got during convertion.
1. Is there a preference to use "-" instead of "_" for the names in spec file? e.g. the attr-cnt-name in team.spec, should I use __team-attr-item-port-max or --team-attr-item-port-max, or
__team_attr_item_port_max?
Quoted 9 lines
Minor preference for using -, but it mostly matters for things which will be visible outside of C. For instance in attr names when they are used in python:
msg['port-index']
looks nicer to me than
msg['port_index']
and is marginally easier to type. But cnt-name is a C thing, so up to you. If I was writing it myself I'd probably go with --team-attr-item-port-max, that's what MPTCP did.
Thanks, I will do as what else do
Quoted 7 lines
Quoted 3 lines
2. I saw
ynl-gen-c.pydeals with unterminated-ok. But this policy is not shown in the schemas. Is it a new feature that still working on?I must have added it to the code gen when experimenting with a family I didn't end up supporting. I'm not actively working on that one, feel free to take a stab at finishing it or LMK if you need help.
OK, I will do it.
Quoted 10 lines
Quoted 7 lines
3. Do we have to hard code the string max-len? Is there a way to use the name in definitions? e.g.
name: name
type: string
checks:
max-len: string-max-lenYes, that's the intention, if codegen doesn't support that today it should be improved.
I can try improve this. But may a little late (should go next year). If you have time you can improve this directly.
Quoted 7 lines
Quoted 3 lines
4. The doc will be generate to rst file in future, so there will not have other comments in the
_nl.cor_nl.hfiles, right?It already generates ReST:
https://docs.kernel.org/next/networking/netlink_spec/
We do still generate kdoc in the uAPI header, tho.
How to generate the doc in uAPI header?
Quoted 7 lines
Quoted 4 lines
5. the
genl_multicast_groupis forced to use list. But the team use format like { .name =TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, }. Should we support this legacy format?Do you mean that we generate:
Quoted 8 lines
[ID] = { "name", }rather than:
[ID] = { .name = "name", }? I think the struct had only one member at the time, so I didn't bother adding the .name, but you can change the code-gen.
No, the current team just do like
static const struct genl_multicast_group team_nl_mcgrps[] = {
{ .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, },
};
So there is new ID was defined. Looks the group id is not a must.
Quoted 19 lines
Quoted 2 lines
7. When build, I got error modpost: missing
MODULE_LICENSE()indrivers/net/team/team_nl.o. Should we add theMODULE_LICENSEsupport inynl-gen-c.py?Not sure if we can, the generated code should be linked with the implementation to form a full module. The manually written part of the implementation should define the license. YAML specs have a fairly odd / broadly open license because they are uAPI. We don't want to start getting into licensing business.
Quoted 9 lines
8. When build, I also got errors like
ERROR: modpost: "team_nl_policy" [drivers/net/team/team.ko] undefined!
ERROR: modpost: "team_nl_ops" [drivers/net/team/team.ko] undefined!
ERROR: modpost: "team_nl_noop_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_options_set_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_options_get_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_nl_port_list_get_doit" [drivers/net/team/team_nl.ko] undefined!
ERROR: modpost: "team_attr_option_nl_policy" [drivers/net/team/team.ko] undefined!
Do you know why include "team_nl.h" doesn't help?
Quoted 5 lines
Same reason as the reason you're getting the LICENSE warning. kbuild is probably trying to build
team_nland team as separate modules.I think you'll have to rename
team.c, take a look at what I did around commit08d323234d10. I don't know a better way...
Thanks, this works for me.
Cheers
Hangbin
Jakub Kicinski
maintainerQuoted 7 lines · On Thu, 14 Dec 2023 12:15:07 +0800 Hangbin Liu wrote:
Quoted 7 lines
Quoted 6 lines
3. Do we have to hard code the string max-len? Is there a way to use the name in definitions? e.g.
name: name
type: string
checks:
max-len: string-max-len
Quoted 5 lines
Quoted 2 lines
Yes, that's the intention, if codegen doesn't support that today it should be improved.
I can try improve this. But may a little late (should go next year). If you have time you can improve this directly.
Noted on my todo list but no ETA, let's see who gets to it first.. :)
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
4. The doc will be generate to rst file in future, so there will not have other comments in the
_nl.cor_nl.hfiles, right?It already generates ReST:
https://docs.kernel.org/next/networking/netlink_spec/
We do still generate kdoc in the uAPI header, tho.How to generate the doc in uAPI header?
The doc strings for enum types should appear in uAPI. Other docs in uAPI usually describe nesting.. which the YAML spec makes a bit obsolete / possible to generate automatically. If there's more that we need we can extend the codegen..