tools: ynl: fix enum-as-flags in the generic CLI
Subsystems (3)
Jakub Kicinski
maintainerPATCH 2/2 tools: ynl: fix enum-as-flags in the generic CLI
In reply to Jakub KicinskiLorenzo points out that the generic CLI is broken for the netdev family. When I added the support for documentation of enums (and sparse enums) the client script was not updated. It expects the values in enum to be a list of names, now it can also be a dict (YAML object).
--- tools/net/ynl/lib/nlspec.py | 7 +++++-- tools/net/ynl/lib/ynl.py | 9 ++------- 2 files changed, 7 insertions(+), 9 deletions(-)
tools/net/ynl/lib/nlspec.py +5 -2
@@ -104,8 +104,9 @@ jsonschema = None as declared in the "definitions" section of the spec. Attributes: - type enum or flags - entries entries by name + type enum or flags + entries entries by name + entries_by_val entries by value Methods: get_mask for flags compute the mask of all defined values """
@@ -117,9 +118,11 @@ jsonschema = None prev_entry = None value_start = self.yaml.get('value-start', 0) self.entries = dict() + self.entries_by_val = dict() for entry in self.yaml['entries']: e = self.new_entry(entry, prev_entry, value_start) self.entries[e.name] = e + self.entries_by_val[e.raw_value()] = e prev_entry = e def new_entry(self, entry, prev_entry, value_start):
tools/net/ynl/lib/ynl.py +2 -7
@@ -303,11 +303,6 @@ genl_family_name_to_id = None self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1) self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_EXT_ACK, 1) - self._types = dict() - - for elem in self.yaml.get('definitions', []): - self._types[elem['name']] = elem - self.async_msg_ids = set() self.async_msg_queue = []
@@ -353,13 +348,13 @@ genl_family_name_to_id = None def _decode_enum(self, rsp, attr_spec): raw = rsp[attr_spec['name']] - enum = self._types[attr_spec['enum']] + enum = self.consts[attr_spec['enum']] i = attr_spec.get('value-start', 0) if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']: value = set() while raw: if raw & 1: - value.add(enum['entries'][i]) + value.add(enum.entries_by_val[i].name) raw >>= 1 i += 1 else:
Signature · 1 line
2.39.2
Jakub Kicinski
maintainercover tools: ynl: fix enum-as-flags in the generic CLI
The CLI needs to use proper classes when looking at Enum definitions rather than interpreting the YAML spec ad-hoc, because we have more than on format of the definition supported.
Jakub Kicinski (2):
tools: ynl: move the enum classes to shared code
tools: ynl: fix enum-as-flags in the generic CLI
tools/net/ynl/lib/__init__.py | 7 ++- tools/net/ynl/lib/nlspec.py | 99 +++++++++++++++++++++++++++++++ tools/net/ynl/lib/ynl.py | 9 +-- tools/net/ynl/ynl-gen-c.py | 107 +++++++--------------------------- 4 files changed, 126 insertions(+), 96 deletions(-)
Signature · 1 line
2.39.2
Jakub Kicinski
maintainerPATCH 1/2 tools: ynl: move the enum classes to shared code
Move bulk of the EnumSet and EnumEntry code to shared code for reuse by cli.
--- tools/net/ynl/lib/__init__.py | 7 ++- tools/net/ynl/lib/nlspec.py | 96 ++++++++++++++++++++++++++++++ tools/net/ynl/ynl-gen-c.py | 107 +++++++--------------------------- 3 files changed, 121 insertions(+), 89 deletions(-)
tools/net/ynl/lib/__init__.py +4 -3
@@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause -from .nlspec import SpecAttr, SpecAttrSet, SpecFamily, SpecOperation +from .nlspec import SpecAttr, SpecAttrSet, SpecEnumEntry, SpecEnumSet, \ + SpecFamily, SpecOperation from .ynl import YnlFamily -__all__ = ["SpecAttr", "SpecAttrSet", "SpecFamily", "SpecOperation", - "YnlFamily"] +__all__ = ["SpecAttr", "SpecAttrSet", "SpecEnumEntry", "SpecEnumSet", + "SpecFamily", "SpecOperation", "YnlFamily"]
tools/net/ynl/lib/nlspec.py +96 -0
126 lines not on this page · raw message
tools/net/ynl/ynl-gen-c.py +21 -86
165 lines not on this page · raw message
Signature · 1 line
2.39.2
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 7 Mar 2023 16:39:21 -0800 you wrote:
The CLI needs to use proper classes when looking at Enum definitions rather than interpreting the YAML spec ad-hoc, because we have more than on format of the definition supported.
Jakub Kicinski (2):
tools: ynl: move the enum classes to shared code
tools: ynl: fix enum-as-flags in the generic CLI[...]
Here is the summary with links:
- [net,1/2] tools: ynl: move the enum classes to shared code
https://git.kernel.org/netdev/net/c/6517a60b0307 - [net,2/2] tools: ynl: fix enum-as-flags in the generic CLI https://git.kernel.org/netdev/net/c/c311aaa74ca1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html