Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796076072; b=hPyFWHowqVMtbGydtsQYEgOhN7xpqy5BT6FoI4N+EoA0rOpgsnMqLNNeQRDE0u0J7ibt kjHHKdr6ad+67YLyiKRo0naCzdqfGsWgJug2ya0j/ER6oEEvlq38RkjblXnQk5gafFnzw CdfWUA/p8DswJzhorcpBUA4MI17jgzD5oqUvAqBLoUZggAolDpBGvcEhnRIlPWlsbKn33 PE2c32/jTIBmzlRNSinCWTe7G/4XDu5Tvv6Z704dSn7vhIggcH2mhgXWF0q/dL3J714Vs h9q210w0f1jgLfzYofOOUrL7KZJjX12QOCG/3GKkRKz5Ti3zbqknWUxfzeuFVrnhGmA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796076072; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=+69cfAidrNZyqyO5GihNmQt/RRwvnDmNvXX5f2Fr0w8=; b=vd/aNEeo/Hb2b1WpAC7xruy/X/uQdOXsIxByBM2eZ1H6byeKnW1pUAZ8hoH7lp8/KbkG R9H8dMEDE9KvW2E+IGY+85uaU9AqwKXvsMPid08uClR41IWN241sFskhRZazX/E4kO3tQ DovUpzLGJ5mcMwNl2Rdmh3yAd5ZtmmuIOiIiejsx/oHP81RepHjnHbt3fsOwM5OXQuu8j wMrLS28QHizL4jpJGtP61LSejgi/26JR3wQeym0be91h+4cha/KXd4YazE6v0T3UB4Ar/ tEQvoFPh8FpogYP+JM3rgeJv97R0r2bGYg55c0u/bKNgqBWJ/81/3kPTD9K5P9xQs0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=D+InxZQm; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B145B606A31A for ; Mon, 30 Nov 2026 22:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=D+InxZQm Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAE761F00896; Mon, 30 Nov 2026 22:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796076072; bh=+69cfAidrNZyqyO5GihNmQt/RRwvnDmNvXX5f2Fr0w8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=D+InxZQmNJqEK03HUmz+SQqLBlY3RQbzm3MCvGm3g/pszFuANJ1H+cJcnPResuoWV F/kmkYSyAxZAxeAIPsbNRtzoa1+2HpplR7tigiEvyILUC0yFzEsx6LXdEwnL2cvbDB qxdKajSB4bG78+GA+wKV+anvwtRZ56c4LZ9A/cG1JzXFlyiEz0xaTajoTK4jhfwvVQ 4iQX3vH447na8JiezwG25aKe0Lyn2w32mx2l+i+wsxJEmw/+93UMMFesR3N6JBEElE 1EKlgrAgTBdOnok6gtB5AEi0IKjqi7OWxO9cvpy53+K9IxTsH1e374EUlU5j6aG9IW W0EV22dD4YLvg== From: Chuck Lever Date: Mon, 30 Nov 2026 17:00:57 -0500 Subject: [PATCH 4/7] xdrgen: Discard pass-through lines X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-xdrgen-passthru-v1-4-eb16e76fd3ee@kernel.org> References: <20261130-xdrgen-passthru-v1-0-eb16e76fd3ee@kernel.org> In-Reply-To: <20261130-xdrgen-passthru-v1-0-eb16e76fd3ee@kernel.org> To: Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: linux-nfs@vger.kernel.org, Chuck Lever X-Mailer: b4 0.17-dev-9c833 X-Developer-Signature: v=1; a=openpgp-sha256; l=23048; i=cel@kernel.org; h=from:subject:message-id; bh=OjZl7fCI0dSNfBtN+3NItw7WHztLcJY0SXPSn6bWqAU=; b=owEBbQKS/ZANAwAKATNqszNvZn+XAcsmYgBrDfIi2F4PnTlL3BYlxwaIl1gJbKhpfW9UsPEcC q9SihHuXhiJAjMEAAEKAB0WIQQosuWwEobfJDzyPv4zarMzb2Z/lwUCaw3yIgAKCRAzarMzb2Z/ l/ThD/9yjcy6OfkwEiWi9b/59RL7GHOxxo1IGiVW17Z7jY4S7bl+HrdPH+qyKqgfC5LXD8Wypkl DBL5HJOkPOTJUMf5gU8p1JOBOOAxv3iRENuJ1ZHoVa5xIcYF1MC8hoUMfVqiS2jFa5w4FDFUdyV wxwxa2+BrlZNrUldyYlnuhrg1zWPqj+cfSOgeUfZJZyXUWp56S/GcNcHgur5QSpgATpbRqmEzxI w6TK1ww/Bhc6HCxBKdNXFltYwIGPOI3l6rFpTVMIAiHbKLVd82zVwUmWA2ZcEIOCIbbH27iJLCV YDbzi0NFvHrQ31Y8KRAIJO51M8x1EUqxdTrck9fza2yBZPpWT3hTE6AB/I7LnC1hb0qJbgIg8P8 IfyMQbbH60aRNfdB5/g5UvId6wywa9zZP4bQFZa4TqIWUOFdJb4QbRdfCd7NmHSOC6Dx7P8gjvT 1qYvtO3D7hCRQ4wQvEdMZsL6wwx7l4GdDtKcYpEmOnUbtSkT/m3fwOIEhq7qkHKMszjkW+7Bj1c 8RcZ7w4JiMYo16QsEMxpz1YIY+rQuQgfIR31luHfIxJX2ZQNIMSo1I9+0ZUmv47ka6EDxTTvuxW UhCCU44YGc0U1UswnBiGlW/+h8+K8Z2voDVQzTVRQhixlViVFuW0bMiDaccNKNKadObRz9WXxiH g5NlPC6lp/hqGUw== X-Developer-Key: i=cel@kernel.org; a=openpgp; fpr=28B2E5B01286DF243CF23EFE336AB3336F667F97 RFC 5662 puts a % line inside struct layoutreturn_file4, inside enum nfs_opnum4 and inside enum nfs_cb_opnum4. xdrgen's grammar takes a pass-through line only between definitions, so xdrgen cannot parse the NFSv4.1 XDR as the RFC publishes it. xdrgen copies the text of each % line into the generated C, as rpcgen does. The kernel has no use for that text. Every % line under Documentation/sunrpc/xdr is part of a comment. The % lines in RFC 5662 and RFC 7863 that are not comments include , a user space header. A % line is C source, so xdrgen could not emit one when generating another language. Have the lexer ignore PASSTHRU tokens, as the lexer ignores C comments, and remove the code that emits them. After the change, a % line is legal wherever a comment is. Regenerate the NFSv4 files, which lose only the comments that the % lines in nfs4_1.x carried. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr_gen.c | 13 --- include/linux/sunrpc/xdrgen/nfs4_1.h | 13 --- tools/net/sunrpc/xdrgen/generators/passthru.py | 26 ----- tools/net/sunrpc/xdrgen/grammars/xdr.lark | 4 +- tools/net/sunrpc/xdrgen/subcmds/definitions.py | 5 +- tools/net/sunrpc/xdrgen/subcmds/source.py | 21 +--- .../xdrgen/templates/C/passthru/definition.j2 | 3 - .../sunrpc/xdrgen/templates/C/passthru/source.j2 | 3 - .../sunrpc/xdrgen/tests/passthru.declarations.out | 20 ++++ .../sunrpc/xdrgen/tests/passthru.definitions.out | 49 +++++++++ .../sunrpc/xdrgen/tests/passthru.source-client.out | 109 +++++++++++++++++++ .../sunrpc/xdrgen/tests/passthru.source-server.out | 119 +++++++++++++++++++++ tools/net/sunrpc/xdrgen/tests/passthru.x | 35 ++++++ tools/net/sunrpc/xdrgen/xdr_ast.py | 37 ------- 14 files changed, 339 insertions(+), 118 deletions(-) diff --git a/fs/nfsd/nfs4xdr_gen.c b/fs/nfsd/nfs4xdr_gen.c index d77835033a8c..258e861e8325 100644 --- a/fs/nfsd/nfs4xdr_gen.c +++ b/fs/nfsd/nfs4xdr_gen.c @@ -411,10 +411,6 @@ xdrgen_decode_fattr4_open_arguments(struct xdr_stream *xdr, fattr4_open_argument return xdrgen_decode_open_arguments4(xdr, ptr); } -/* - * Determine what OPEN supports. - */ - bool xdrgen_decode_fattr4_time_deleg_access(struct xdr_stream *xdr, fattr4_time_deleg_access *ptr) { @@ -427,11 +423,6 @@ xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg return xdrgen_decode_nfstime4(xdr, ptr); } -/* - * New RECOMMENDED Attribute for - * delegation caching of times - */ - static bool __maybe_unused xdrgen_decode_open_delegation_type4(struct xdr_stream *xdr, open_delegation_type4 *ptr) { @@ -570,10 +561,6 @@ xdrgen_decode_fattr4_posix_access_acl(struct xdr_stream *xdr, fattr4_posix_acces return true; } -/* - * New for POSIX ACL extension - */ - static bool __maybe_unused xdrgen_decode_notify_type4(struct xdr_stream *xdr, notify_type4 *ptr) { diff --git a/include/linux/sunrpc/xdrgen/nfs4_1.h b/include/linux/sunrpc/xdrgen/nfs4_1.h index bd3289a1d66a..a374645a1865 100644 --- a/include/linux/sunrpc/xdrgen/nfs4_1.h +++ b/include/linux/sunrpc/xdrgen/nfs4_1.h @@ -248,10 +248,6 @@ typedef enum open_args_createmode4 open_args_createmode4; typedef struct open_arguments4 fattr4_open_arguments; -/* - * Determine what OPEN supports. - */ - enum { FATTR4_OPEN_ARGUMENTS = 86 }; enum { OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010 }; @@ -260,11 +256,6 @@ typedef struct nfstime4 fattr4_time_deleg_access; typedef struct nfstime4 fattr4_time_deleg_modify; -/* - * New RECOMMENDED Attribute for - * delegation caching of times - */ - enum { FATTR4_TIME_DELEG_ACCESS = 84 }; enum { FATTR4_TIME_DELEG_MODIFY = 85 }; @@ -357,10 +348,6 @@ typedef struct { struct posixace4 *element; } fattr4_posix_access_acl; -/* - * New for POSIX ACL extension - */ - enum { FATTR4_ACL_TRUEFORM = 89 }; enum { FATTR4_ACL_TRUEFORM_SCOPE = 90 }; diff --git a/tools/net/sunrpc/xdrgen/generators/passthru.py b/tools/net/sunrpc/xdrgen/generators/passthru.py deleted file mode 100644 index cb17bd977f1e..000000000000 --- a/tools/net/sunrpc/xdrgen/generators/passthru.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python3 -# ex: set filetype=python: - -"""Generate code for XDR pass-through lines""" - -from generators import SourceGenerator, create_jinja2_environment -from xdr_ast import _XdrPassthru - - -class XdrPassthruGenerator(SourceGenerator): - """Generate source code for XDR pass-through content""" - - def __init__(self, language: str, peer: str): - """Initialize an instance of this class""" - self.environment = create_jinja2_environment(language, "passthru") - self.peer = peer - - def emit_definition(self, node: _XdrPassthru) -> None: - """Emit one pass-through line""" - template = self.environment.get_template("definition.j2") - print(template.render(content=node.content)) - - def emit_decoder(self, node: _XdrPassthru) -> None: - """Emit one pass-through line""" - template = self.environment.get_template("source.j2") - print(template.render(content=node.content)) diff --git a/tools/net/sunrpc/xdrgen/grammars/xdr.lark b/tools/net/sunrpc/xdrgen/grammars/xdr.lark index 64cd73df412c..ec5ba8beeb9e 100644 --- a/tools/net/sunrpc/xdrgen/grammars/xdr.lark +++ b/tools/net/sunrpc/xdrgen/grammars/xdr.lark @@ -78,9 +78,6 @@ definition : constant_def | type_def | program_def | pragma_def - | passthru_def - -passthru_def : PASSTHRU // // RPC program definitions not specified in RFC 4506 @@ -121,6 +118,7 @@ hexadecimal_constant : /0x([a-f]|[A-F]|[0-9])+/ octal_constant : /0[0-7]+/ PASSTHRU : /%.*/ +%ignore PASSTHRU %import common.C_COMMENT %ignore C_COMMENT diff --git a/tools/net/sunrpc/xdrgen/subcmds/definitions.py b/tools/net/sunrpc/xdrgen/subcmds/definitions.py index 77b666943a11..f5cc3ab21496 100644 --- a/tools/net/sunrpc/xdrgen/subcmds/definitions.py +++ b/tools/net/sunrpc/xdrgen/subcmds/definitions.py @@ -14,7 +14,6 @@ from generators.constant import XdrConstantGenerator from generators.enum import XdrEnumGenerator from generators.header_bottom import XdrHeaderBottomGenerator from generators.header_top import XdrHeaderTopGenerator -from generators.passthru import XdrPassthruGenerator from generators.pointer import XdrPointerGenerator from generators.program import XdrProgramGenerator from generators.typedef import XdrTypedefGenerator @@ -22,7 +21,7 @@ from generators.struct import XdrStructGenerator from generators.union import XdrUnionGenerator from xdr_ast import transform_parse_tree, Specification, XdrSemanticError -from xdr_ast import _RpcProgram, _XdrConstant, _XdrEnum, _XdrPassthru, _XdrPointer +from xdr_ast import _RpcProgram, _XdrConstant, _XdrEnum, _XdrPointer from xdr_ast import _XdrTypedef, _XdrStruct, _XdrUnion from xdr_parse import xdr_parser, set_xdr_annotate from xdr_parse import make_error_handler, XdrParseError @@ -48,8 +47,6 @@ def emit_header_definitions(root: Specification, language: str, peer: str) -> No gen = XdrStructGenerator(language, peer) elif isinstance(definition.value, _XdrUnion): gen = XdrUnionGenerator(language, peer) - elif isinstance(definition.value, _XdrPassthru): - gen = XdrPassthruGenerator(language, peer) else: continue gen.emit_definition(definition.value) diff --git a/tools/net/sunrpc/xdrgen/subcmds/source.py b/tools/net/sunrpc/xdrgen/subcmds/source.py index 16622cd343c9..296958910bf2 100644 --- a/tools/net/sunrpc/xdrgen/subcmds/source.py +++ b/tools/net/sunrpc/xdrgen/subcmds/source.py @@ -13,7 +13,6 @@ from lark.exceptions import VisitError from generators.source_top import XdrSourceTopGenerator from generators.enum import XdrEnumGenerator -from generators.passthru import XdrPassthruGenerator from generators.pointer import XdrPointerGenerator from generators.program import XdrProgramGenerator from generators.typedef import XdrTypedefGenerator @@ -21,7 +20,7 @@ from generators.struct import XdrStructGenerator from generators.union import XdrUnionGenerator from xdr_ast import transform_parse_tree, _RpcProgram, Specification -from xdr_ast import _XdrAst, _XdrEnum, _XdrPassthru, _XdrPointer +from xdr_ast import _XdrAst, _XdrEnum, _XdrPointer from xdr_ast import _XdrStruct, _XdrTypedef, _XdrUnion, XdrSemanticError from xdr_parse import xdr_parser, set_xdr_annotate, set_xdr_enum_validation @@ -76,14 +75,9 @@ def generate_server_source(filename: str, root: Specification, language: str) -> gen.emit_source(filename, root) for definition in root.definitions: - if isinstance(definition.value, _XdrPassthru): - passthru_gen = XdrPassthruGenerator(language, "server") - passthru_gen.emit_decoder(definition.value) - else: - emit_source_decoder(definition.value, language, "server") + emit_source_decoder(definition.value, language, "server") for definition in root.definitions: - if not isinstance(definition.value, _XdrPassthru): - emit_source_encoder(definition.value, language, "server") + emit_source_encoder(definition.value, language, "server") def generate_client_source(filename: str, root: Specification, language: str) -> None: @@ -93,14 +87,9 @@ def generate_client_source(filename: str, root: Specification, language: str) -> gen.emit_source(filename, root) for definition in root.definitions: - if isinstance(definition.value, _XdrPassthru): - passthru_gen = XdrPassthruGenerator(language, "client") - passthru_gen.emit_decoder(definition.value) - else: - emit_source_encoder(definition.value, language, "client") + emit_source_encoder(definition.value, language, "client") for definition in root.definitions: - if not isinstance(definition.value, _XdrPassthru): - emit_source_decoder(definition.value, language, "client") + emit_source_decoder(definition.value, language, "client") # cel: todo: client needs PROC macros diff --git a/tools/net/sunrpc/xdrgen/templates/C/passthru/definition.j2 b/tools/net/sunrpc/xdrgen/templates/C/passthru/definition.j2 deleted file mode 100644 index 900c7516a29c..000000000000 --- a/tools/net/sunrpc/xdrgen/templates/C/passthru/definition.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{# SPDX-License-Identifier: GPL-2.0 #} - -{{ content }} diff --git a/tools/net/sunrpc/xdrgen/templates/C/passthru/source.j2 b/tools/net/sunrpc/xdrgen/templates/C/passthru/source.j2 deleted file mode 100644 index 900c7516a29c..000000000000 --- a/tools/net/sunrpc/xdrgen/templates/C/passthru/source.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{# SPDX-License-Identifier: GPL-2.0 #} - -{{ content }} diff --git a/tools/net/sunrpc/xdrgen/tests/passthru.declarations.out b/tools/net/sunrpc/xdrgen/tests/passthru.declarations.out new file mode 100644 index 000000000000..e74a9726c4ef --- /dev/null +++ b/tools/net/sunrpc/xdrgen/tests/passthru.declarations.out @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Generated by xdrgen. Manual edits will be lost. */ +/* XDR specification file: passthru.x */ +/* XDR specification modification time: Thu Jan 1 00:00:00 2026 */ + +#ifndef _LINUX_XDRGEN_PASSTHRU_DECL_H +#define _LINUX_XDRGEN_PASSTHRU_DECL_H + +#include + +#include +#include +#include +#include + +bool pt_svc_decode_pt_args(struct svc_rqst *rqstp, struct xdr_stream *xdr); + +bool pt_svc_encode_pt_res(struct svc_rqst *rqstp, struct xdr_stream *xdr); + +#endif /* _LINUX_XDRGEN_PASSTHRU_DECL_H */ diff --git a/tools/net/sunrpc/xdrgen/tests/passthru.definitions.out b/tools/net/sunrpc/xdrgen/tests/passthru.definitions.out new file mode 100644 index 000000000000..66720af2bd23 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/tests/passthru.definitions.out @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Generated by xdrgen. Manual edits will be lost. */ +/* XDR specification file: passthru.x */ +/* XDR specification modification time: Thu Jan 1 00:00:00 2026 */ + +#ifndef _LINUX_XDRGEN_PASSTHRU_DEF_H +#define _LINUX_XDRGEN_PASSTHRU_DEF_H + +#include +#include + +enum { PT_MAX = 8 }; + +enum pt_kind { + PT_FIRST = 1, + PT_SECOND = 2, +}; + +typedef enum pt_kind pt_kind; + +struct pt_args { + u32 count; + opaque data; +}; + +struct pt_res { + pt_kind kind; + union { + unsigned_int value; + } u; +}; + +enum { + PT_OP = 1, +}; + +#ifndef PT_PROGRAM +#define PT_PROGRAM (200000) +#endif + +#define NONE_pt_kind_sz (XDR_int) +#define NONE_pt_args_sz \ + (XDR_unsigned_int + XDR_unsigned_int + XDR_QUADLEN(PT_MAX)) +#define NONE_pt_res_sz \ + (NONE_pt_kind_sz + XDR_unsigned_int) +#define NONE_MAX_ARGS_SZ \ + (NONE_pt_args_sz) + +#endif /* _LINUX_XDRGEN_PASSTHRU_DEF_H */ diff --git a/tools/net/sunrpc/xdrgen/tests/passthru.source-client.out b/tools/net/sunrpc/xdrgen/tests/passthru.source-client.out new file mode 100644 index 000000000000..a8bcd234d0a7 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/tests/passthru.source-client.out @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0 +// Generated by xdrgen. Manual edits will be lost. +// XDR specification file: passthru.x +// XDR specification modification time: Thu Jan 1 00:00:00 2026 + +#include + +#include +#include +#include + +#include + +static bool __maybe_unused +xdrgen_encode_pt_kind(struct xdr_stream *xdr, pt_kind value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} + +static bool __maybe_unused +xdrgen_encode_pt_args(struct xdr_stream *xdr, const struct pt_args *value) +{ + if (!xdrgen_encode_unsigned_int(xdr, value->count)) + return false; + if (value->data.len > PT_MAX) + return false; + if (xdr_stream_encode_opaque(xdr, value->data.data, value->data.len) < 0) + return false; + return true; +} + +static bool __maybe_unused +xdrgen_encode_pt_res(struct xdr_stream *xdr, const struct pt_res *ptr) +{ + if (!xdrgen_encode_pt_kind(xdr, ptr->kind)) + return false; + switch (ptr->kind) { + case PT_FIRST: + if (!xdrgen_encode_unsigned_int(xdr, ptr->u.value)) + return false; + break; + default: + break; + } + return true; +} + +static void pt_xdr_enc_pt_args(struct rpc_rqst *req, + struct xdr_stream *xdr, const void *data) +{ + const struct pt_args *args = data; + + xdrgen_encode_pt_args(xdr, args); +} + +static bool __maybe_unused +xdrgen_decode_pt_kind(struct xdr_stream *xdr, pt_kind *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + /* Compiler may optimize to a range check for dense enums */ + switch (val) { + case PT_FIRST: + case PT_SECOND: + break; + default: + return false; + } + *ptr = val; + return true; +} + +static bool __maybe_unused +xdrgen_decode_pt_args(struct xdr_stream *xdr, struct pt_args *ptr) +{ + if (!xdrgen_decode_unsigned_int(xdr, &ptr->count)) + return false; + if (!xdrgen_decode_opaque(xdr, &ptr->data, PT_MAX)) + return false; + return true; +} + +static bool __maybe_unused +xdrgen_decode_pt_res(struct xdr_stream *xdr, struct pt_res *ptr) +{ + if (!xdrgen_decode_pt_kind(xdr, &ptr->kind)) + return false; + switch (ptr->kind) { + case PT_FIRST: + if (!xdrgen_decode_unsigned_int(xdr, &ptr->u.value)) + return false; + break; + default: + break; + } + return true; +} + +static int pt_xdr_dec_pt_res(struct rpc_rqst *req, + struct xdr_stream *xdr, void *data) +{ + struct pt_res *result = data; + + if (!xdrgen_decode_pt_res(xdr, result)) + return -EIO; + return 0; +} diff --git a/tools/net/sunrpc/xdrgen/tests/passthru.source-server.out b/tools/net/sunrpc/xdrgen/tests/passthru.source-server.out new file mode 100644 index 000000000000..3462f05ba9ce --- /dev/null +++ b/tools/net/sunrpc/xdrgen/tests/passthru.source-server.out @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +// Generated by xdrgen. Manual edits will be lost. +// XDR specification file: passthru.x +// XDR specification modification time: Thu Jan 1 00:00:00 2026 + +#include + +#include "ptxdr_gen.h" + +static bool __maybe_unused +xdrgen_decode_pt_kind(struct xdr_stream *xdr, pt_kind *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + /* Compiler may optimize to a range check for dense enums */ + switch (val) { + case PT_FIRST: + case PT_SECOND: + break; + default: + return false; + } + *ptr = val; + return true; +} + +static bool __maybe_unused +xdrgen_decode_pt_args(struct xdr_stream *xdr, struct pt_args *ptr) +{ + if (!xdrgen_decode_unsigned_int(xdr, &ptr->count)) + return false; + if (!xdrgen_decode_opaque(xdr, &ptr->data, PT_MAX)) + return false; + return true; +} + +static bool __maybe_unused +xdrgen_decode_pt_res(struct xdr_stream *xdr, struct pt_res *ptr) +{ + if (!xdrgen_decode_pt_kind(xdr, &ptr->kind)) + return false; + switch (ptr->kind) { + case PT_FIRST: + if (!xdrgen_decode_unsigned_int(xdr, &ptr->u.value)) + return false; + break; + default: + break; + } + return true; +} + +/** + * pt_svc_decode_pt_args - Decode a pt_args argument + * @rqstp: RPC transaction context + * @xdr: source XDR data stream + * + * Return values: + * %true: procedure arguments decoded successfully + * %false: decode failed + */ +bool pt_svc_decode_pt_args(struct svc_rqst *rqstp, struct xdr_stream *xdr) +{ + struct pt_args *argp = rqstp->rq_argp; + + return xdrgen_decode_pt_args(xdr, argp); +} + +static bool __maybe_unused +xdrgen_encode_pt_kind(struct xdr_stream *xdr, pt_kind value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} + +static bool __maybe_unused +xdrgen_encode_pt_args(struct xdr_stream *xdr, const struct pt_args *value) +{ + if (!xdrgen_encode_unsigned_int(xdr, value->count)) + return false; + if (value->data.len > PT_MAX) + return false; + if (xdr_stream_encode_opaque(xdr, value->data.data, value->data.len) < 0) + return false; + return true; +} + +static bool __maybe_unused +xdrgen_encode_pt_res(struct xdr_stream *xdr, const struct pt_res *ptr) +{ + if (!xdrgen_encode_pt_kind(xdr, ptr->kind)) + return false; + switch (ptr->kind) { + case PT_FIRST: + if (!xdrgen_encode_unsigned_int(xdr, ptr->u.value)) + return false; + break; + default: + break; + } + return true; +} + +/** + * pt_svc_encode_pt_res - Encode a pt_res result + * @rqstp: RPC transaction context + * @xdr: target XDR data stream + * + * Return values: + * %true: procedure results encoded successfully + * %false: encode failed + */ +bool pt_svc_encode_pt_res(struct svc_rqst *rqstp, struct xdr_stream *xdr) +{ + struct pt_res *resp = rqstp->rq_resp; + + return xdrgen_encode_pt_res(xdr, resp); +} diff --git a/tools/net/sunrpc/xdrgen/tests/passthru.x b/tools/net/sunrpc/xdrgen/tests/passthru.x new file mode 100644 index 000000000000..e35c4ab76c3a --- /dev/null +++ b/tools/net/sunrpc/xdrgen/tests/passthru.x @@ -0,0 +1,35 @@ +%#include +%typedef struct authsys_parms authsys_parms; + +%/* +% * Between definitions +% */ +const PT_MAX = 8; + +enum pt_kind { + PT_FIRST = 1, +% /* Inside an enum body */ + PT_SECOND = 2 +}; + +struct pt_args { +% /* Ahead of the first member */ + unsigned int count; +%#define PT_INSIDE_A_STRUCT 1 + opaque data; +}; + +union pt_res switch (pt_kind kind) { +case PT_FIRST: +% /* Inside a union arm */ + unsigned int value; +default: + void; +}; + +program PT_PROGRAM { + version PT_V1 { +% /* Inside a version body */ + pt_res PT_OP(pt_args) = 1; + } = 1; +} = 200000; diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index 643b64fba3f8..0caa87d43a58 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -570,13 +570,6 @@ class _Pragma(_XdrAst): """Empty class for pragma directives""" -@dataclass -class _XdrPassthru(_XdrAst): - """Passthrough line to emit verbatim in output""" - - content: str - - @dataclass class Definition(_XdrAst, ast_utils.WithMeta): """Corresponds to 'definition' in the grammar""" @@ -865,39 +858,10 @@ class ParseToAst(Transformer): raise NotImplementedError("Directive not supported") return _Pragma() - def passthru_def(self, children): - """Instantiate one _XdrPassthru object""" - token = children[0] - content = token.value[1:] - return _XdrPassthru(content) - transformer = ast_utils.create_transformer(this_module, ParseToAst()) -def _merge_consecutive_passthru(definitions: List[Definition]) -> List[Definition]: - """Merge consecutive passthru definitions into single nodes""" - result = [] - i = 0 - while i < len(definitions): - if isinstance(definitions[i].value, _XdrPassthru): - lines = [definitions[i].value.content] - meta = definitions[i].meta - j = i + 1 - while j < len(definitions) and isinstance( - definitions[j].value, _XdrPassthru - ): - lines.append(definitions[j].value.content) - j += 1 - merged = _XdrPassthru("\n".join(lines)) - result.append(Definition(meta, merged)) - i = j - else: - result.append(definitions[i]) - i += 1 - return result - - def _meta_line(meta) -> int: """Return the 1-based source line for a node's meta, or 0 if unknown""" try: @@ -1473,7 +1437,6 @@ def _expand_procedure_types(root: "Specification") -> None: def transform_parse_tree(parse_tree): """Transform productions into an abstract syntax tree""" ast = transformer.transform(parse_tree) - ast.definitions = _merge_consecutive_passthru(ast.definitions) check_duplicate_definitions(ast) check_rpc_number_range(ast) # The pages checks consult argument_types and result_types, so -- 2.56.0