All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>,
	Jeff Layton <jlayton@kernel.org>,
	linux-nfs@vger.kernel.org, neilb@suse.de, chuck.lever@oracle.com,
	netdev@vger.kernel.org
Subject: Re: [PATCH] NFSD: convert write_threads and write_v4_end_grace to netlink commands
Date: Thu, 5 Oct 2023 06:59:19 -0700	[thread overview]
Message-ID: <20231005065919.6001b7ca@kernel.org> (raw)
In-Reply-To: <ZR55TnN4Sr/O5z4a@lore-desk>

On Thu, 5 Oct 2023 10:52:30 +0200 Lorenzo Bianconi wrote:
> running ynl-regen.sh, I got the following error for the get method:
> 
> $ ./tools/net/ynl/ynl-regen.sh
>         GEN kernel      fs/nfsd/netlink.h
> Traceback (most recent call last):
>   File "/home/lorenzo/workspace/nfsd-next/tools/net/ynl/ynl-gen-c.py", line 2609, in <module>
>     main()
>   File "/home/lorenzo/workspace/nfsd-next/tools/net/ynl/ynl-gen-c.py", line 2445, in main
>     print_req_policy_fwd(cw, ri.struct['request'], ri=ri)
>                              ~~~~~~~~~^^^^^^^^^^^
> KeyError: 'request'
> 
> am I missing something?

Not at all, the codegen was only handling dumps with no ops.
This change seems to make it a little happier, at least it
doesn't throw any exceptions. Will it work for your case?

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 168fe612b029..593be2632f23 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -645,6 +645,33 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
         self.inherited = [c_lower(x) for x in sorted(self._inherited)]
 
 
+class StructNone:
+    def __init__(self, family, space_name):
+        self.family = family
+        self.space_name = space_name
+        self.attr_set = family.attr_sets[space_name]
+
+        if family.name == c_lower(space_name):
+            self.render_name = f"{family.name}"
+        else:
+            self.render_name = f"{family.name}_{c_lower(space_name)}"
+
+        self.request = False
+        self.reply = False
+
+        self.attr_list = []
+        self.attrs = dict()
+
+    def __iter__(self):
+        yield from self.attrs
+
+    def __getitem__(self, key):
+        return self.attrs[key]
+
+    def member_list(self):
+        return self.attr_list
+
+
 class EnumEntry(SpecEnumEntry):
     def __init__(self, enum_set, yaml, prev, value_start):
         super().__init__(enum_set, yaml, prev, value_start)
@@ -1041,9 +1068,12 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
         if op_mode == 'notify':
             op_mode = 'do'
         for op_dir in ['request', 'reply']:
-            if op and op_dir in op[op_mode]:
-                self.struct[op_dir] = Struct(family, self.attr_set,
-                                             type_list=op[op_mode][op_dir]['attributes'])
+            if op:
+                if op_dir in op[op_mode]:
+                    self.struct[op_dir] = Struct(family, self.attr_set,
+                                                 type_list=op[op_mode][op_dir]['attributes'])
+                else:
+                    self.struct[op_dir] = StructNone(family, self.attr_set)
         if op_mode == 'event':
             self.struct['reply'] = Struct(family, self.attr_set, type_list=op['event']['attributes'])
 
@@ -1752,6 +1782,8 @@ _C_KW = {
 
 
 def print_req_type_helpers(ri):
+    if isinstance(ri.struct["request"], StructNone):
+        return
     print_alloc_wrapper(ri, "request")
     print_type_helpers(ri, "request")
 
@@ -1773,6 +1805,8 @@ _C_KW = {
 
 
 def print_req_type(ri):
+    if isinstance(ri.struct["request"], StructNone):
+        return
     print_type(ri, "request")
 
 
@@ -2515,9 +2549,8 @@ _C_KW = {
                 if 'dump' in op:
                     cw.p(f"/* {op.enum_name} - dump */")
                     ri = RenderInfo(cw, parsed, args.mode, op, 'dump')
-                    if 'request' in op['dump']:
-                        print_req_type(ri)
-                        print_req_type_helpers(ri)
+                    print_req_type(ri)
+                    print_req_type_helpers(ri)
                     if not ri.type_consistent:
                         print_rsp_type(ri)
                     print_wrapped_type(ri)
-- 
2.41.0


      reply	other threads:[~2023-10-05 14:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22 12:44 [PATCH] NFSD: convert write_threads and write_v4_end_grace to netlink commands Lorenzo Bianconi
2023-09-22 16:04 ` Jeff Layton
2023-09-22 16:06   ` Chuck Lever III
2023-09-22 16:21     ` Jeff Layton
2023-09-22 16:23       ` Lorenzo Bianconi
2023-09-22 17:23         ` Chuck Lever III
2023-09-22 16:20   ` Lorenzo Bianconi
2023-09-22 16:53     ` Jeff Layton
2023-09-22 17:25     ` Chuck Lever III
2023-09-22 19:25       ` Lorenzo Bianconi
2023-09-22 20:49         ` Chuck Lever III
2023-10-04 17:04     ` Jakub Kicinski
2023-10-05  8:52       ` Lorenzo Bianconi
2023-10-05 13:59         ` Jakub Kicinski [this message]

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=20231005065919.6001b7ca@kernel.org \
    --to=kuba@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=lorenzo@kernel.org \
    --cc=neilb@suse.de \
    --cc=netdev@vger.kernel.org \
    /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.