All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Hangbin Liu <liuhangbin@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Donald Hunter <donald.hunter@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Stanislav Fomichev <sdf@google.com>
Subject: Re: [PATCH net-next 1/2] ynl: rename array-nest to indexed-array
Date: Tue, 26 Mar 2024 20:46:10 -0700	[thread overview]
Message-ID: <20240326204610.1cb1715b@kernel.org> (raw)
In-Reply-To: <20240326063728.2369353-2-liuhangbin@gmail.com>

On Tue, 26 Mar 2024 14:37:27 +0800 Hangbin Liu wrote:
> diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
> index 5fa7957f6e0f..7239e673a28a 100644
> --- a/tools/net/ynl/lib/ynl.py
> +++ b/tools/net/ynl/lib/ynl.py
> @@ -686,8 +686,9 @@ class YnlFamily(SpecFamily):
>                  decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order)
>                  if 'enum' in attr_spec:
>                      decoded = self._decode_enum(decoded, attr_spec)
> -            elif attr_spec["type"] == 'array-nest':
> -                decoded = self._decode_array_nest(attr, attr_spec)
> +            elif attr_spec["type"] == 'indexed-array' and 'sub-type' in attr_spec:
> +                if attr_spec["sub-type"] == 'nest':
> +                    decoded = self._decode_array_nest(attr, attr_spec)

We need to make sure somehow cleanly that we treat unknown subtype the
same we would treat unknown type. In this elif ladder we have:

            else:
                if not self.process_unknown:
                    raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')

So we should raise an exception if sub-type != nest.

>              elif attr_spec["type"] == 'bitfield32':
>                  value, selector = struct.unpack("II", attr.raw)
>                  if 'enum' in attr_spec:
> diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
> index 6b7eb2d2aaf1..8d5ec5449648 100755
> --- a/tools/net/ynl/ynl-gen-c.py
> +++ b/tools/net/ynl/ynl-gen-c.py
> @@ -838,8 +838,9 @@ class AttrSet(SpecAttrSet):
>              t = TypeBitfield32(self.family, self, elem, value)
>          elif elem['type'] == 'nest':
>              t = TypeNest(self.family, self, elem, value)
> -        elif elem['type'] == 'array-nest':
> -            t = TypeArrayNest(self.family, self, elem, value)
> +        elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
> +            if elem["sub-type"] == 'nest':
> +                t = TypeArrayNest(self.family, self, elem, value)

same here

>          elif elem['type'] == 'nest-type-value':
>              t = TypeNestTypeValue(self.family, self, elem, value)
>          else:
> @@ -1052,8 +1053,9 @@ class Family(SpecFamily):
>                      if nested in self.root_sets:
>                          raise Exception("Inheriting members to a space used as root not supported")
>                      inherit.update(set(spec['type-value']))
> -                elif spec['type'] == 'array-nest':
> -                    inherit.add('idx')
> +                elif spec['type'] == 'indexed-array' and 'sub-type' in spec:
> +                    if spec["sub-type"] == 'nest':
> +                        inherit.add('idx')

Here you don't have to match on sub-type, all indexed-arrays will have
an idx (index) member.

>                  self.pure_nested_structs[nested].set_inherited(inherit)
>  
>          for root_set, rs_members in self.root_sets.items():
> @@ -1616,9 +1618,10 @@ def _multi_parse(ri, struct, init_lines, local_vars):
>      multi_attrs = set()
>      needs_parg = False
>      for arg, aspec in struct.member_list():
> -        if aspec['type'] == 'array-nest':
> -            local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
> -            array_nests.add(arg)
> +        if aspec['type'] == 'indexed-array' and 'sub-type' in aspec:
> +            if aspec["sub-type"] == 'nest':
> +                local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
> +                array_nests.add(arg)

Please also update the info about nested-array in
Documentation/userspace-api/netlink/genetlink-legacy.rst
-- 
pw-bot: cr

  reply	other threads:[~2024-03-27  3:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26  6:37 [PATCH net-next 0/2] ynl: rename array-nest to indexed-array Hangbin Liu
2024-03-26  6:37 ` [PATCH net-next 1/2] " Hangbin Liu
2024-03-27  3:46   ` Jakub Kicinski [this message]
2024-03-28  7:50     ` Hangbin Liu
2024-03-28 16:02       ` Jakub Kicinski
2024-03-26  6:37 ` [PATCH net-next 2/2] ynl: support un-nest sub-type for indexed-array Hangbin Liu
2024-03-28  7:41   ` Hangbin Liu
2024-03-28 16:04     ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240326204610.1cb1715b@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=jacob.e.keller@intel.com \
    --cc=jiri@resnulli.us \
    --cc=liuhangbin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.