Skip to contentSkip to conversation

tools: ynl-gen: fix subset attributes handling

PATCH Superseded Jiri Pirko 2 participants 11 messages Sep 29, 2023 – Oct 5, 2023

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

v2 cover tools: ynl-gen: fix subset attributes handling

From: Jiri Pirko <[email protected]>

Attributes defined in an attribute subset should just specify a list of attributes of the original attribute set. The original attribute definitions should be used. This patchset ensures that.

Jiri Pirko (3):
tools: ynl-gen: lift type requirement for attribute subsets
netlink: specs: remove redundant type keys from attributes in subsets
tools: ynl-gen: raise exception when subset attribute contains more
than "name" key

 Documentation/netlink/genetlink-c.yaml      |  2 +-
 Documentation/netlink/genetlink-legacy.yaml |  2 +-
 Documentation/netlink/genetlink.yaml        |  2 +-
 Documentation/netlink/netlink-raw.yaml      |  2 +-
 Documentation/netlink/specs/devlink.yaml    | 10 ----------
 Documentation/netlink/specs/dpll.yaml       |  8 --------
 Documentation/netlink/specs/ethtool.yaml    |  3 ---
 tools/net/ynl/lib/nlspec.py                 |  2 ++
 tools/net/ynl/ynl-gen-c.py                  |  2 ++
 9 files changed, 8 insertions(+), 25 deletions(-)
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH v2 1/3 tools: ynl-gen: lift type requirement for attribute subsets

From: Jiri Pirko <[email protected]>

In case an attribute is used in a subset, the type has to be currently specified. As the attribute is already defined in the original set, this is a redundant information in yaml file, moreover, may lead to inconsistencies.

Example:
attribute-sets:

    ...
    name: pin
    enum-name: dpll_a_pin
    attributes:
      ...
      -
        name: parent-id
        type: u32
      ...
  -
    name: pin-parent-device
    subset-of: pin
    attributes:
      -
        name: parent-id
        type: u32             <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Remove the requirement from schema files to specify the "type" and add check and bail out if "type" is not set.

---
 Documentation/netlink/genetlink-c.yaml      | 2 +-
 Documentation/netlink/genetlink-legacy.yaml | 2 +-
 Documentation/netlink/genetlink.yaml        | 2 +-
 Documentation/netlink/netlink-raw.yaml      | 2 +-
 tools/net/ynl/ynl-gen-c.py                  | 2 ++
 5 files changed, 6 insertions(+), 4 deletions(-)
Documentation/netlink/genetlink-c.yaml +1 -1
index 9806c44f604c..80d8aa2708c5 100644
@@ -142,7 +142,7 @@ properties:
           type: array
           items:
             type: object
-            required: [ name, type ]
+            required: [ name ]
             additionalProperties: False
             properties:
               name:
Documentation/netlink/genetlink-legacy.yaml +1 -1
index 12a0a045605d..2a21aae525a4 100644
@@ -180,7 +180,7 @@ properties:
           type: array
           items:
             type: object
-            required: [ name, type ]
+            required: [ name ]
             additionalProperties: False
             properties:
               name:
Documentation/netlink/genetlink.yaml +1 -1
index 3d338c48bf21..9e8354f80466 100644
@@ -115,7 +115,7 @@ properties:
           type: array
           items:
             type: object
-            required: [ name, type ]
+            required: [ name ]
             additionalProperties: False
             properties:
               name:
Documentation/netlink/netlink-raw.yaml +1 -1
index 896797876414..9aeb64b27ada 100644
@@ -187,7 +187,7 @@ properties:
           type: array
           items:
             type: object
-            required: [ name, type ]
+            required: [ name ]
             additionalProperties: False
             properties:
               name:
tools/net/ynl/ynl-gen-c.py +2 -0
index 897af958cee8..b378412a9d7a 100755
@@ -723,6 +723,8 @@ class AttrSet(SpecAttrSet):
             self.c_name = ''
 
     def new_attr(self, elem, value):
+        if 'type' not in elem:
+            raise Exception(f"Type has to be set for attribute {elem['name']}")
         if elem['type'] in scalars:
             t = TypeScalar(self.family, self, elem, value)
         elif elem['type'] == 'unused':
Signature · 1 line
2.41.0
maintainer
#2 lore raw

Re: [patch net-next v2 1/3] tools: ynl-gen: lift type requirement for attribute subsets

tools/net/ynl/ynl-gen-c.py class AttrSet(SpecAttrSet): · line 730

Quoted 11 lines · On Fri, 29 Sep 2023 15:47:40 +0200 Jiri Pirko wrote:
tools/net/ynl/ynl-gen-c.py +2 -0
@@ -723,6 +723,8 @@ class AttrSet(SpecAttrSet):
             self.c_name = ''
 
     def new_attr(self, elem, value):
+        if 'type' not in elem:
+            raise Exception(f"Type has to be set for attribute {elem['name']}")
         if elem['type'] in scalars:
             t = TypeScalar(self.family, self, elem, value)
         elif elem['type'] == 'unused':

Can this still be enforced using JSON schema? Using dependencies to make sure that if subset-of is not present type is?

author maintainer
#3 lore raw

Re: [patch net-next v2 1/3] tools: ynl-gen: lift type requirement for attribute subsets

Quoted 6 lines · Thu, Oct 05, 2023 at 02:12:02AM CEST, [email protected] wrote:
Quoted 5 lines · On Fri, 29 Sep 2023 15:47:40 +0200 Jiri Pirko wrote:
tools/net/ynl/ynl-gen-c.py +0 -0
@@ -723,6 +723,8 @@ class AttrSet(SpecAttrSet):
             self.c_name = ''
 
Quoted 9 lines

tools/net/ynl/ynl-gen-c.py class AttrSet(SpecAttrSet): · line 730

Quoted 6 lines
tools/net/ynl/ynl-gen-c.py +2 -0
     def new_attr(self, elem, value):
+        if 'type' not in elem:
+            raise Exception(f"Type has to be set for attribute {elem['name']}")
         if elem['type'] in scalars:
             t = TypeScalar(self.family, self, elem, value)
         elif elem['type'] == 'unused':

Can this still be enforced using JSON schema? Using dependencies to make sure that if subset-of is not present type is?

I have no clue. I know very little about json schema. I can take a look.

author maintainer
#4 lore raw

PATCH v2 2/3 netlink: specs: remove redundant type keys from attributes in subsets

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

No longer needed to define type for subset attributes. Remove those.

---
v1->v2:
- new patch

---
 Documentation/netlink/specs/devlink.yaml | 10 ----------
 Documentation/netlink/specs/dpll.yaml    |  8 --------
 Documentation/netlink/specs/ethtool.yaml |  3 ---
 3 files changed, 21 deletions(-)
Documentation/netlink/specs/devlink.yaml +0 -10
index d1ebcd927149..86a12c5bcff1 100644
@@ -199,54 +199,44 @@ attribute-sets:
     attributes:
       -
         name: reload-stats
-        type: nest
       -
         name: remote-reload-stats
-        type: nest
   -
     name: dl-reload-stats
     subset-of: devlink
     attributes:
       -
         name: reload-action-info
-        type: nest
   -
     name: dl-reload-act-info
     subset-of: devlink
     attributes:
       -
         name: reload-action
-        type: u8
       -
         name: reload-action-stats
-        type: nest
   -
     name: dl-reload-act-stats
     subset-of: devlink
     attributes:
       -
         name: reload-stats-entry
-        type: nest
   -
     name: dl-reload-stats-entry
     subset-of: devlink
     attributes:
       -
         name: reload-stats-limit
-        type: u8
       -
         name: reload-stats-value
-        type: u32
   -
     name: dl-info-version
     subset-of: devlink
     attributes:
       -
         name: info-version-name
-        type: string
       -
         name: info-version-value
-        type: string
 
 operations:
   enum-model: directional
Documentation/netlink/specs/dpll.yaml +0 -8
index 8b86b28b47a6..1c1b53136c7b 100644
@@ -278,36 +278,28 @@ attribute-sets:
     attributes:
       -
         name: parent-id
-        type: u32
       -
         name: direction
-        type: u32
       -
         name: prio
-        type: u32
       -
         name: state
-        type: u32
   -
     name: pin-parent-pin
     subset-of: pin
     attributes:
       -
         name: parent-id
-        type: u32
       -
         name: state
-        type: u32
   -
     name: frequency-range
     subset-of: pin
     attributes:
       -
         name: frequency-min
-        type: u64
       -
         name: frequency-max
-        type: u64
 
 operations:
   enum-name: dpll_cmd
Documentation/netlink/specs/ethtool.yaml +0 -3
index 837b565577ca..5c7a65b009b4 100644
@@ -818,13 +818,10 @@ attribute-sets:
     attributes:
       -
         name: hist-bkt-low
-        type: u32
       -
         name: hist-bkt-hi
-        type: u32
       -
         name: hist-val
-        type: u64
   -
     name: stats
     attributes:
Signature · 1 line
2.41.0
author maintainer
#6 lore raw

PATCH v2 3/3 tools: ynl-gen: raise exception when subset attribute contains more than "name" key

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

The only key used in the elem dictionary is "name" to lookup the real attribute of a set. Raise exception in case there are other keys present.

---
v1->v2:
- new patch

---
 tools/net/ynl/lib/nlspec.py | 2 ++
 1 file changed, 2 insertions(+)
tools/net/ynl/lib/nlspec.py +2 -0
index 37bcb4d8b37b..12e15ac70309 100644
@@ -208,6 +208,8 @@ class SpecAttrSet(SpecElement):
                 attr = real_set[elem['name']]
                 self.attrs[attr.name] = attr
                 self.attrs_by_val[attr.value] = attr
+                if (len(elem.keys()) > 1):
+                    raise Exception(f"Subset attribute '{elem['name']}' contains other keys")
 
     def new_attr(self, elem, value):
         return SpecAttr(self.family, self, elem, value)
Signature · 1 line
2.41.0
maintainer
#7 lore raw

Re: [patch net-next v2 3/3] tools: ynl-gen: raise exception when subset attribute contains more than "name" key

Quoted 5 lines · On Fri, 29 Sep 2023 15:47:42 +0200 Jiri Pirko wrote:

From: Jiri Pirko <[email protected]>

The only key used in the elem dictionary is "name" to lookup the real attribute of a set. Raise exception in case there are other keys present.

Mm, there are definitely other things that can be set. I'm not fully sold that type can't change but even if - checks can easily be adjusted or nested-attributes, based on the parsing path.

author maintainer
#8 lore raw

Re: [patch net-next v2 3/3] tools: ynl-gen: raise exception when subset attribute contains more than "name" key

Quoted 8 lines · Thu, Oct 05, 2023 at 02:13:50AM CEST, [email protected] wrote:
Quoted 5 lines · On Fri, 29 Sep 2023 15:47:42 +0200 Jiri Pirko wrote:

From: Jiri Pirko <[email protected]>

The only key used in the elem dictionary is "name" to lookup the real attribute of a set. Raise exception in case there are other keys present.

Mm, there are definitely other things that can be set. I'm not fully

Which ones? The name is used, the rest is ignored in the existing code. I just make this obvious to the user. If future show other keys are needed here, the patch adding that would just adjust the exception condition. Do you see any problem in that?

Quoted 2 lines

sold that type can't change but even if - checks can easily be adjusted or nested-attributes, based on the parsing path.

maintainer
#9 lore raw

Re: [patch net-next v2 3/3] tools: ynl-gen: raise exception when subset attribute contains more than "name" key

Quoted 10 lines · On Thu, 5 Oct 2023 09:25:55 +0200 Jiri Pirko wrote:
Quoted 5 lines
Quoted 3 lines

The only key used in the elem dictionary is "name" to lookup the real attribute of a set. Raise exception in case there are other keys present.

Mm, there are definitely other things that can be set. I'm not fully

Which ones? The name is used, the rest is ignored in the existing code. I just make this obvious to the user. If future show other keys are needed here, the patch adding that would just adjust the exception condition. Do you see any problem in that?

Just don't want to give people the impression that this is what's intended, rather than it was simply not implemented yet. If you want to keep the exception please update the message (and the if, no outer brackets necessary in Python ;)).

author maintainer
#10 lore raw

Re: [patch net-next v2 3/3] tools: ynl-gen: raise exception when subset attribute contains more than "name" key

Quoted 12 lines · Thu, Oct 05, 2023 at 04:21:51PM CEST, [email protected] wrote:
Quoted 10 lines · On Thu, 5 Oct 2023 09:25:55 +0200 Jiri Pirko wrote:
Quoted 5 lines
Quoted 3 lines

The only key used in the elem dictionary is "name" to lookup the real attribute of a set. Raise exception in case there are other keys present.

Mm, there are definitely other things that can be set. I'm not fully

Which ones? The name is used, the rest is ignored in the existing code. I just make this obvious to the user. If future show other keys are needed here, the patch adding that would just adjust the exception condition. Do you see any problem in that?

Quoted 4 lines

Just don't want to give people the impression that this is what's intended, rather than it was simply not implemented yet. If you want to keep the exception please update the message (and the if, no outer brackets necessary in Python ;)).

I don't mind dropping the patch entirely. I just thought it would be nice to do some sanitization so the user is not surprised that other possible keys are ignored. I tried and I was :)