Message ID | 20230319193803.97453-3-donald.hunter@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | ynl: add support for user headers and struct attrs | expand |
Context | Check | Description |
---|---|---|
netdev/series_format | success | Posting correctly formatted |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/fixes_present | success | Fixes tag not required for -next series |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 18 this patch: 18 |
netdev/cc_maintainers | success | CCed 5 of 5 maintainers |
netdev/build_clang | success | Errors and warnings before: 18 this patch: 18 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/deprecated_api | success | None detected |
netdev/check_selftest | success | No net selftest shell script |
netdev/verify_fixes | success | No Fixes tag |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 18 this patch: 18 |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 60 lines checked |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
On Sun, 19 Mar 2023 19:37:59 +0000 Donald Hunter wrote: > +class SpecStructMember(SpecElement): > + """Struct member attribute > + > + Represents a single struct member attribute. > + > + Attributes: > + type string, kernel type of the member attribute We can have structs inside structs in theory, or "binary blobs" so this is really a subset of what attr can be rather than necessarily a kernel type? > + """ > + def __init__(self, family, yaml): > + super().__init__(family, yaml) > + self.type = yaml['type'] > + nit: double new line > +class SpecStruct(SpecElement): > + """Netlink struct type
Jakub Kicinski <kuba@kernel.org> writes: > On Sun, 19 Mar 2023 19:37:59 +0000 Donald Hunter wrote: >> +class SpecStructMember(SpecElement): >> + """Struct member attribute >> + >> + Represents a single struct member attribute. >> + >> + Attributes: >> + type string, kernel type of the member attribute > > We can have structs inside structs in theory, or "binary blobs" so this > is really a subset of what attr can be rather than necessarily a kernel > type? Okay, so the schema currently defines the member types as u*, s* and string. Does it make sense to add 'binary' and 'struct'? To be clear, do you want me to drop the word 'kernel' from the docstring, or something more? >> + """ >> + def __init__(self, family, yaml): >> + super().__init__(family, yaml) >> + self.type = yaml['type'] >> + > > nit: double new line Ack.
On Wed, 22 Mar 2023 11:38:01 +0000 Donald Hunter wrote: > >> + Attributes: > >> + type string, kernel type of the member attribute > > > > We can have structs inside structs in theory, or "binary blobs" so this > > is really a subset of what attr can be rather than necessarily a kernel > > type? > > Okay, so the schema currently defines the member types as u*, s* and > string. Does it make sense to add 'binary' and 'struct'? We don't have to until it's needed. > To be clear, do you want me to drop the word 'kernel' from the > docstring, or something more? Removing kernel should be good enough
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py index d04450c2a44a..5ac2dfd415c5 100644 --- a/tools/net/ynl/lib/nlspec.py +++ b/tools/net/ynl/lib/nlspec.py @@ -214,6 +214,43 @@ class SpecAttrSet(SpecElement): return self.attrs.items() +class SpecStructMember(SpecElement): + """Struct member attribute + + Represents a single struct member attribute. + + Attributes: + type string, kernel type of the member attribute + """ + def __init__(self, family, yaml): + super().__init__(family, yaml) + self.type = yaml['type'] + +class SpecStruct(SpecElement): + """Netlink struct type + + Represents a C struct definition. + + Attributes: + members ordered list of struct members + """ + def __init__(self, family, yaml): + super().__init__(family, yaml) + + self.members = [] + for member in yaml.get('members', []): + self.members.append(self.new_member(family, member)) + + def new_member(self, family, elem): + return SpecStructMember(family, elem) + + def __iter__(self): + yield from self.members + + def items(self): + return self.members.items() + + class SpecOperation(SpecElement): """Netlink Operation @@ -344,6 +381,9 @@ class SpecFamily(SpecElement): def new_attr_set(self, elem): return SpecAttrSet(self, elem) + def new_struct(self, elem): + return SpecStruct(self, elem) + def new_operation(self, elem, req_val, rsp_val): return SpecOperation(self, elem, req_val, rsp_val) @@ -399,6 +439,8 @@ class SpecFamily(SpecElement): for elem in definitions: if elem['type'] == 'enum' or elem['type'] == 'flags': self.consts[elem['name']] = self.new_enum(elem) + elif elem['type'] == 'struct': + self.consts[elem['name']] = self.new_struct(elem) else: self.consts[elem['name']] = elem
Add python classes for struct definitions to nlspec Signed-off-by: Donald Hunter <donald.hunter@gmail.com> --- tools/net/ynl/lib/nlspec.py | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)