linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: Khushal Chitturi <kc9282016@gmail.com>, linux-nfs@vger.kernel.org
Cc: Jeff Layton <jlayton@kernel.org>, Neil Brown <neil@brown.name>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Khushal Chitturi <kc928206@gmail.com>
Subject: Re: [PATCH] xdrgen: handle _XdrString in union encoder/decoder
Date: Mon, 27 Oct 2025 09:53:57 -0400	[thread overview]
Message-ID: <fc196a91-4cc3-4fc3-a728-567399cc8185@oracle.com> (raw)
In-Reply-To: <20251026180018.9248-1-kc9282016@gmail.com>

On 10/26/25 2:00 PM, Khushal Chitturi wrote:
> Running xdrgen on xdrgen/tests/test.x fails when
> generating encoder or decoder functions for union members
> of type _XdrString. It was because _XdrString
> does not have a spec attribute like _XdrBasic,
> leading to AttributeError.
> 
> This patch updates emit_union_case_spec_definition
> and emit_union_case_spec_decoder/encoder
> to handle _XdrString by assigning
> type_name = "char *" and  avoiding referencing to spec.
> 
> Testing: Fixed xdrgen tool was ran on originally failing
> test file (tools/net/sunrpc/xdrgen/tests/test.x) and now completes without AttributeError.
> Modified xdrgen tool was also run against nfs4_1.x (Documentation/sunrpc/xdr/nfs4_1.x).
> The output header file matches with nfs4_1.h (include/linux/sunrpc/xdrgen/nfs4_1.h).
> This validates the patch for all XDR input files currently within the kernel.
> 
> Signed-off-by: Khushal Chitturi <kc928206@gmail.com>

Hello Kushal -

Fix looks OK, but there are a couple of nits: The email address in your
Signed-off-by does not match your From: address, and I prefer if you
would keep the lines in the patch description shorter than 72
characters. Can you send a v2?


> ---
>  tools/net/sunrpc/xdrgen/generators/union.py   | 35 ++++++++++++++-----
>  .../templates/C/union/encoder/string.j2       |  6 ++++
>  2 files changed, 32 insertions(+), 9 deletions(-)
>  create mode 100644 tools/net/sunrpc/xdrgen/templates/C/union/encoder/string.j2
> 
> diff --git a/tools/net/sunrpc/xdrgen/generators/union.py b/tools/net/sunrpc/xdrgen/generators/union.py
> index 2cca00e279cd..3118dfdddcc4 100644
> --- a/tools/net/sunrpc/xdrgen/generators/union.py
> +++ b/tools/net/sunrpc/xdrgen/generators/union.py
> @@ -1,3 +1,4 @@
> +# SPDX-License-Identifier: GPL-2.0
>  #!/usr/bin/env python3
>  # ex: set filetype=python:
>  
> @@ -8,7 +9,7 @@ from jinja2 import Environment
>  from generators import SourceGenerator
>  from generators import create_jinja2_environment, get_jinja2_template
>  
> -from xdr_ast import _XdrBasic, _XdrUnion, _XdrVoid, get_header_name
> +from xdr_ast import _XdrBasic, _XdrUnion, _XdrVoid, _XdrString, get_header_name
>  from xdr_ast import _XdrDeclaration, _XdrCaseSpec, public_apis, big_endian
>  
>  
> @@ -40,13 +41,20 @@ def emit_union_case_spec_definition(
>      """Emit a definition for an XDR union's case arm"""
>      if isinstance(node.arm, _XdrVoid):
>          return
> -    assert isinstance(node.arm, _XdrBasic)
> +    if isinstance(node.arm, _XdrString):
> +        type_name = "char *"
> +        classifier = ""
> +    else:
> +        type_name = node.arm.spec.type_name
> +        classifier = node.arm.spec.c_classifier
> +
> +    assert isinstance(node.arm, (_XdrBasic, _XdrString))
>      template = get_jinja2_template(environment, "definition", "case_spec")
>      print(
>          template.render(
>              name=node.arm.name,
> -            type=node.arm.spec.type_name,
> -            classifier=node.arm.spec.c_classifier,
> +            type=type_name,
> +            classifier=classifier,
>          )
>      )
>  
> @@ -84,6 +92,12 @@ def emit_union_case_spec_decoder(
>  
>      if isinstance(node.arm, _XdrVoid):
>          return
> +    if isinstance(node.arm, _XdrString):
> +        type_name = "char *"
> +        classifier = ""
> +    else:
> +        type_name = node.arm.spec.type_name
> +        classifier = node.arm.spec.c_classifier
>  
>      if big_endian_discriminant:
>          template = get_jinja2_template(environment, "decoder", "case_spec_be")
> @@ -92,13 +106,13 @@ def emit_union_case_spec_decoder(
>      for case in node.values:
>          print(template.render(case=case))
>  
> -    assert isinstance(node.arm, _XdrBasic)
> +    assert isinstance(node.arm, (_XdrBasic, _XdrString))
>      template = get_jinja2_template(environment, "decoder", node.arm.template)
>      print(
>          template.render(
>              name=node.arm.name,
> -            type=node.arm.spec.type_name,
> -            classifier=node.arm.spec.c_classifier,
> +            type=type_name,
> +            classifier=classifier,
>          )
>      )
>  
> @@ -169,7 +183,10 @@ def emit_union_case_spec_encoder(
>  
>      if isinstance(node.arm, _XdrVoid):
>          return
> -
> +    if isinstance(node.arm, _XdrString):
> +        type_name = "char *"
> +    else:
> +        type_name = node.arm.spec.type_name
>      if big_endian_discriminant:
>          template = get_jinja2_template(environment, "encoder", "case_spec_be")
>      else:
> @@ -181,7 +198,7 @@ def emit_union_case_spec_encoder(
>      print(
>          template.render(
>              name=node.arm.name,
> -            type=node.arm.spec.type_name,
> +            type=type_name,
>          )
>      )
>  
> diff --git a/tools/net/sunrpc/xdrgen/templates/C/union/encoder/string.j2 b/tools/net/sunrpc/xdrgen/templates/C/union/encoder/string.j2
> new file mode 100644
> index 000000000000..2f035a64f1f4
> --- /dev/null
> +++ b/tools/net/sunrpc/xdrgen/templates/C/union/encoder/string.j2
> @@ -0,0 +1,6 @@
> +{# SPDX-License-Identifier: GPL-2.0 #}
> +{% if annotate %}
> +		/* member {{ name }} (variable-length string) */
> +{% endif %}
> +		if (!xdrgen_encode_string(xdr, ptr->u.{{ name }}, {{ maxsize }}))
> +			return false;


-- 
Chuck Lever

  reply	other threads:[~2025-10-27 13:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-26 18:00 [PATCH] xdrgen: handle _XdrString in union encoder/decoder Khushal Chitturi
2025-10-27 13:53 ` Chuck Lever [this message]
2025-10-28 14:53 ` [PATCH v2] " Khushal Chitturi
2025-10-28 19:00   ` Chuck Lever
2025-10-28 22:24   ` NeilBrown
2025-10-29  6:12   ` [PATCH v3] " Khushal Chitturi

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=fc196a91-4cc3-4fc3-a728-567399cc8185@oracle.com \
    --to=chuck.lever@oracle.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=kc9282016@gmail.com \
    --cc=kc928206@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=netdev@vger.kernel.org \
    --cc=okorniev@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=tom@talpey.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).