diff mbox series

[net-next,1/3] tools: ynl: correctly handle overrides of fields in subset

Message ID 20250105012523.1722231-2-kuba@kernel.org (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series tools: ynl: decode link types present in tests | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl fail Tree is dirty after regen; no warnings/errors; no diff in generated;
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: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 0 (+23) this patch: 0 (+23)
netdev/cc_maintainers warning 2 maintainers not CCed: alessandromarcolini99@gmail.com horms@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
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: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-01-05--09-00 (tests: 887)

Commit Message

Jakub Kicinski Jan. 5, 2025, 1:25 a.m. UTC
We stated in documentation [1] and previous discussions [2]
that the need for overriding fields in members of subsets
is anticipated. Implement it.

[1] https://docs.kernel.org/next/userspace-api/netlink/specs.html#subset-of
[2] https://lore.kernel.org/netdev/20231004171350.1f59cd1d@kernel.org/

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/lib/nlspec.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Donald Hunter Jan. 6, 2025, 1:27 p.m. UTC | #1
Jakub Kicinski <kuba@kernel.org> writes:

> We stated in documentation [1] and previous discussions [2]
> that the need for overriding fields in members of subsets
> is anticipated. Implement it.
>
> [1] https://docs.kernel.org/next/userspace-api/netlink/specs.html#subset-of
> [2] https://lore.kernel.org/netdev/20231004171350.1f59cd1d@kernel.org/
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

I guess we're okay with requiring Python >= 3.9 for combining
dicts with |

Reviewed-by: Donald Hunter <donald.hunter@gmail.com>

> ---
>  tools/net/ynl/lib/nlspec.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
> index a745739655ad..314ec8007496 100644
> --- a/tools/net/ynl/lib/nlspec.py
> +++ b/tools/net/ynl/lib/nlspec.py
> @@ -219,7 +219,10 @@ jsonschema = None
>          else:
>              real_set = family.attr_sets[self.subset_of]
>              for elem in self.yaml['attributes']:
> -                attr = real_set[elem['name']]
> +                real_attr = real_set[elem['name']]
> +                combined_elem = real_attr.yaml | elem
> +                attr = self.new_attr(combined_elem, real_attr.value)
> +
>                  self.attrs[attr.name] = attr
>                  self.attrs_by_val[attr.value] = attr
Jakub Kicinski Jan. 6, 2025, 3:36 p.m. UTC | #2
On Mon, 06 Jan 2025 13:27:49 +0000 Donald Hunter wrote:
> > We stated in documentation [1] and previous discussions [2]
> > that the need for overriding fields in members of subsets
> > is anticipated. Implement it.
> >
> > [1] https://docs.kernel.org/next/userspace-api/netlink/specs.html#subset-of
> > [2] https://lore.kernel.org/netdev/20231004171350.1f59cd1d@kernel.org/
> >
> > Signed-off-by: Jakub Kicinski <kuba@kernel.org>  
> 
> I guess we're okay with requiring Python >= 3.9 for combining
> dicts with |

Ah, I didn't realize. Does YNL work on older versions today?
I thought we already narrowed down to 3.9+. That may have
been tests not YNL itself.

The "oldest" OS I have is CentOS 9(-derived) and has 3.9,
so from my selfish perspective 3.9+ is perfectly fine :)
Donald Hunter Jan. 6, 2025, 5:33 p.m. UTC | #3
On Mon, 6 Jan 2025 at 15:36, Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon, 06 Jan 2025 13:27:49 +0000 Donald Hunter wrote:
> > > We stated in documentation [1] and previous discussions [2]
> > > that the need for overriding fields in members of subsets
> > > is anticipated. Implement it.
> > >
> > > [1] https://docs.kernel.org/next/userspace-api/netlink/specs.html#subset-of
> > > [2] https://lore.kernel.org/netdev/20231004171350.1f59cd1d@kernel.org/
> > >
> > > Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> >
> > I guess we're okay with requiring Python >= 3.9 for combining
> > dicts with |
>
> Ah, I didn't realize. Does YNL work on older versions today?
> I thought we already narrowed down to 3.9+. That may have
> been tests not YNL itself.

You're right, we may already be committed to 3.9+

> The "oldest" OS I have is CentOS 9(-derived) and has 3.9,
> so from my selfish perspective 3.9+ is perfectly fine :)

To be fair, on a previous commit you mentioned that it affected CentOS
8 which EOLed back in May 2024 so we shouldn't feel compelled to
support it any more.

https://lore.kernel.org/all/20230524170712.2036128-1-kuba@kernel.org/
diff mbox series

Patch

diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index a745739655ad..314ec8007496 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -219,7 +219,10 @@  jsonschema = None
         else:
             real_set = family.attr_sets[self.subset_of]
             for elem in self.yaml['attributes']:
-                attr = real_set[elem['name']]
+                real_attr = real_set[elem['name']]
+                combined_elem = real_attr.yaml | elem
+                attr = self.new_attr(combined_elem, real_attr.value)
+
                 self.attrs[attr.name] = attr
                 self.attrs_by_val[attr.value] = attr