Commit 8f632a0a authored by David S. Miller's avatar David S. Miller

Merge branch 'net-tools-ynl-fixes'

Jakub Kicinski says:

====================
tools: ynl: fix subset use and change default value for attrs/ops

Fix a problem in subsetting, which will become apparent when
the devlink family comes after the merge window. Even tho none
of the existing families need this, we don't want someone to
get "inspired" by the current, incorrect code when using specs
in other languages.

Change the default value for the first attr/op. This is a slight
behavior change so needs to go in now. The diffstat of the last
patch should serve as the clearest justification there..
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents ad93bab6 bcec7171
...@@ -11,7 +11,6 @@ attribute-sets: ...@@ -11,7 +11,6 @@ attribute-sets:
- -
name: dev-index name: dev-index
type: u32 type: u32
value: 1
- -
name: dev-name name: dev-name
type: string type: string
...@@ -25,7 +24,6 @@ attribute-sets: ...@@ -25,7 +24,6 @@ attribute-sets:
- -
name: index name: index
type: u32 type: u32
value: 1
- -
name: name name: name
type: string type: string
...@@ -39,14 +37,12 @@ attribute-sets: ...@@ -39,14 +37,12 @@ attribute-sets:
name: bit name: bit
type: nest type: nest
nested-attributes: bitset-bit nested-attributes: bitset-bit
value: 1
- -
name: bitset name: bitset
attributes: attributes:
- -
name: nomask name: nomask
type: flag type: flag
value: 1
- -
name: size name: size
type: u32 type: u32
...@@ -61,7 +57,6 @@ attribute-sets: ...@@ -61,7 +57,6 @@ attribute-sets:
- -
name: index name: index
type: u32 type: u32
value: 1
- -
name: value name: value
type: string type: string
...@@ -71,7 +66,6 @@ attribute-sets: ...@@ -71,7 +66,6 @@ attribute-sets:
- -
name: string name: string
type: nest type: nest
value: 1
multi-attr: true multi-attr: true
nested-attributes: string nested-attributes: string
- -
...@@ -80,7 +74,6 @@ attribute-sets: ...@@ -80,7 +74,6 @@ attribute-sets:
- -
name: id name: id
type: u32 type: u32
value: 1
- -
name: count name: count
type: u32 type: u32
...@@ -96,14 +89,12 @@ attribute-sets: ...@@ -96,14 +89,12 @@ attribute-sets:
name: stringset name: stringset
type: nest type: nest
multi-attr: true multi-attr: true
value: 1
nested-attributes: stringset nested-attributes: stringset
- -
name: strset name: strset
attributes: attributes:
- -
name: header name: header
value: 1
type: nest type: nest
nested-attributes: header nested-attributes: header
- -
...@@ -119,7 +110,6 @@ attribute-sets: ...@@ -119,7 +110,6 @@ attribute-sets:
attributes: attributes:
- -
name: header name: header
value: 1
type: nest type: nest
nested-attributes: header nested-attributes: header
- -
...@@ -132,7 +122,6 @@ attribute-sets: ...@@ -132,7 +122,6 @@ attribute-sets:
attributes: attributes:
- -
name: header name: header
value: 1
type: nest type: nest
nested-attributes: header nested-attributes: header
- -
...@@ -180,7 +169,6 @@ attribute-sets: ...@@ -180,7 +169,6 @@ attribute-sets:
attributes: attributes:
- -
name: pad name: pad
value: 1
type: pad type: pad
- -
name: reassembly-errors name: reassembly-errors
...@@ -205,7 +193,6 @@ attribute-sets: ...@@ -205,7 +193,6 @@ attribute-sets:
attributes: attributes:
- -
name: header name: header
value: 1
type: nest type: nest
nested-attributes: header nested-attributes: header
- -
...@@ -251,13 +238,11 @@ operations: ...@@ -251,13 +238,11 @@ operations:
do: &strset-get-op do: &strset-get-op
request: request:
value: 1
attributes: attributes:
- header - header
- stringsets - stringsets
- counts-only - counts-only
reply: reply:
value: 1
attributes: attributes:
- header - header
- stringsets - stringsets
......
...@@ -26,6 +26,7 @@ attribute-sets: ...@@ -26,6 +26,7 @@ attribute-sets:
- -
name: unspec name: unspec
type: unused type: unused
value: 0
- -
name: port name: port
type: u16 type: u16
...@@ -71,6 +72,7 @@ operations: ...@@ -71,6 +72,7 @@ operations:
- -
name: unspec name: unspec
doc: unused doc: unused
value: 0
- -
name: add name: add
......
...@@ -48,7 +48,6 @@ attribute-sets: ...@@ -48,7 +48,6 @@ attribute-sets:
name: ifindex name: ifindex
doc: netdev ifindex doc: netdev ifindex
type: u32 type: u32
value: 1
checks: checks:
min: 1 min: 1
- -
...@@ -66,7 +65,6 @@ operations: ...@@ -66,7 +65,6 @@ operations:
- -
name: dev-get name: dev-get
doc: Get / dump information about a netdev. doc: Get / dump information about a netdev.
value: 1
attribute-set: dev attribute-set: dev
do: do:
request: request:
......
...@@ -197,9 +197,15 @@ value ...@@ -197,9 +197,15 @@ value
Numerical attribute ID, used in serialized Netlink messages. Numerical attribute ID, used in serialized Netlink messages.
The ``value`` property can be skipped, in which case the attribute ID The ``value`` property can be skipped, in which case the attribute ID
will be the value of the previous attribute plus one (recursively) will be the value of the previous attribute plus one (recursively)
and ``0`` for the first attribute in the attribute set. and ``1`` for the first attribute in the attribute set.
Note that the ``value`` of an attribute is defined only in its main set. Attributes (and operations) use ``1`` as the default value for the first
entry (unlike enums in definitions which start from ``0``) because
entry ``0`` is almost always reserved as undefined. Spec can explicitly
set value to ``0`` if needed.
Note that the ``value`` of an attribute is defined only in its main set
(not in subsets).
enum enum
~~~~ ~~~~
......
...@@ -95,15 +95,22 @@ class SpecAttrSet(SpecElement): ...@@ -95,15 +95,22 @@ class SpecAttrSet(SpecElement):
self.attrs = collections.OrderedDict() self.attrs = collections.OrderedDict()
self.attrs_by_val = collections.OrderedDict() self.attrs_by_val = collections.OrderedDict()
val = 0 if self.subset_of is None:
for elem in self.yaml['attributes']: val = 1
if 'value' in elem: for elem in self.yaml['attributes']:
val = elem['value'] if 'value' in elem:
val = elem['value']
attr = self.new_attr(elem, val) attr = self.new_attr(elem, val)
self.attrs[attr.name] = attr self.attrs[attr.name] = attr
self.attrs_by_val[attr.value] = attr self.attrs_by_val[attr.value] = attr
val += 1 val += 1
else:
real_set = family.attr_sets[self.subset_of]
for elem in self.yaml['attributes']:
attr = real_set[elem['name']]
self.attrs[attr.name] = attr
self.attrs_by_val[attr.value] = attr
def new_attr(self, elem, value): def new_attr(self, elem, value):
return SpecAttr(self.family, self, elem, value) return SpecAttr(self.family, self, elem, value)
...@@ -245,7 +252,7 @@ class SpecFamily(SpecElement): ...@@ -245,7 +252,7 @@ class SpecFamily(SpecElement):
self._resolution_list.append(elem) self._resolution_list.append(elem)
def _dictify_ops_unified(self): def _dictify_ops_unified(self):
val = 0 val = 1
for elem in self.yaml['operations']['list']: for elem in self.yaml['operations']['list']:
if 'value' in elem: if 'value' in elem:
val = elem['value'] val = elem['value']
...@@ -256,7 +263,7 @@ class SpecFamily(SpecElement): ...@@ -256,7 +263,7 @@ class SpecFamily(SpecElement):
self.msgs[op.name] = op self.msgs[op.name] = op
def _dictify_ops_directional(self): def _dictify_ops_directional(self):
req_val = rsp_val = 0 req_val = rsp_val = 1
for elem in self.yaml['operations']['list']: for elem in self.yaml['operations']['list']:
if 'notify' in elem: if 'notify' in elem:
if 'value' in elem: if 'value' in elem:
......
...@@ -2044,14 +2044,17 @@ def render_uapi(family, cw): ...@@ -2044,14 +2044,17 @@ def render_uapi(family, cw):
max_value = f"({cnt_name} - 1)" max_value = f"({cnt_name} - 1)"
uapi_enum_start(family, cw, family['operations'], 'enum-name') uapi_enum_start(family, cw, family['operations'], 'enum-name')
val = 0
for op in family.msgs.values(): for op in family.msgs.values():
if separate_ntf and ('notify' in op or 'event' in op): if separate_ntf and ('notify' in op or 'event' in op):
continue continue
suffix = ',' suffix = ','
if 'value' in op: if op.value != val:
suffix = f" = {op['value']}," suffix = f" = {op.value},"
val = op.value
cw.p(op.enum_name + suffix) cw.p(op.enum_name + suffix)
val += 1
cw.nl() cw.nl()
cw.p(cnt_name + ('' if max_by_define else ',')) cw.p(cnt_name + ('' if max_by_define else ','))
if not max_by_define: if not max_by_define:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment