xdrgen: Discard pass-through lines
Subsystems (3)
Chuck Lever
maintainercover xdrgen: Discard pass-through lines
The intent is to replace Documentation/sunrpc/xdr/nfs4_1.x over time with a file closer to what the RFC publishes.
The NFSv4.1 XDR in RFC 5662 has five % lines inside struct and enum bodies. xdrgen takes a % line only between definitions, so xdrgen cannot currently parse the RFC's XDR.
Commit 6bc85baba4b0 ("xdrgen: Implement pass-through lines in specifications") made xdrgen copy % text into the generated code, as rpcgen does. But the %-passthrough lines that appear in RFC 5662 target only user space C output. The #include line is not valid outside of Unix user space, for example, and is certainly not valid if the desired output is Python or Rust. The use of %typedef in RFC 5662 is also problematic for similar reasons.
Thus there's no use in passing those lines through to xdrgen output. After this series is applied, xdrgen discards whatever appears on a %-passthrough line. A % line is no longer a production in xdrgen's grammar. The lexer ignores % lines as it ignores C comments, so the grammar's definitions now match RFC 4506 Section 6.3 except for program and pragma definitions.
---
Chuck Lever (7):
xdrgen: Emit a header guard that is a valid identifier
xdrgen: Do not emit an empty enum of procedure numbers
xdrgen: Reject inline struct, enum and union types
xdrgen: Discard pass-through lines
xdrgen: Document that xdrgen discards % lines
xdrgen: Document where the grammar departs from RFC 4506
xdrgen: Correct the grammar file name in the README
fs/nfsd/nfs4xdr_gen.c | 13 --- include/linux/sunrpc/xdrgen/nfs4_1.h | 13 --- tools/net/sunrpc/xdrgen/README | 50 ++++++++- tools/net/sunrpc/xdrgen/generators/__init__.py | 3 +- tools/net/sunrpc/xdrgen/generators/header_top.py | 2 + tools/net/sunrpc/xdrgen/generators/passthru.py | 26 ----- tools/net/sunrpc/xdrgen/generators/program.py | 3 + tools/net/sunrpc/xdrgen/grammars/xdr.lark | 4 +- tools/net/sunrpc/xdrgen/subcmds/definitions.py | 5 +- tools/net/sunrpc/xdrgen/subcmds/source.py | 21 +--- .../templates/C/header_top/declaration/header.j2 | 2 +- .../xdrgen/templates/C/passthru/definition.j2 | 3 - .../sunrpc/xdrgen/templates/C/passthru/source.j2 | 3 - .../xdrgen/tests/inline-enum-discriminant.err | 2 + .../sunrpc/xdrgen/tests/inline-enum-discriminant.x | 4 + .../net/sunrpc/xdrgen/tests/inline-enum-member.err | 2 + tools/net/sunrpc/xdrgen/tests/inline-enum-member.x | 3 + .../sunrpc/xdrgen/tests/inline-enum-procarg.err | 2 + .../net/sunrpc/xdrgen/tests/inline-enum-procarg.x | 5 + .../sunrpc/xdrgen/tests/inline-enum-typedef.err | 2 + .../net/sunrpc/xdrgen/tests/inline-enum-typedef.x | 1 + .../xdrgen/tests/inline-struct-discriminant.err | 2 + .../xdrgen/tests/inline-struct-discriminant.x | 4 + .../sunrpc/xdrgen/tests/inline-struct-member.err | 2 + .../net/sunrpc/xdrgen/tests/inline-struct-member.x | 3 + .../sunrpc/xdrgen/tests/inline-struct-procarg.err | 2 + .../sunrpc/xdrgen/tests/inline-struct-procarg.x | 5 + .../sunrpc/xdrgen/tests/inline-struct-typedef.err | 2 + .../sunrpc/xdrgen/tests/inline-struct-typedef.x | 1 + .../xdrgen/tests/inline-union-discriminant.err | 2 + .../xdrgen/tests/inline-union-discriminant.x | 4 + .../sunrpc/xdrgen/tests/inline-union-member.err | 2 + .../net/sunrpc/xdrgen/tests/inline-union-member.x | 3 + .../sunrpc/xdrgen/tests/inline-union-procarg.err | 2 + .../net/sunrpc/xdrgen/tests/inline-union-procarg.x | 5 + .../sunrpc/xdrgen/tests/inline-union-typedef.err | 2 + .../net/sunrpc/xdrgen/tests/inline-union-typedef.x | 1 + .../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/tests/run-tests.sh | 97 +++++++++++++++++ .../net/sunrpc/xdrgen/tests/test.declarations.out | 16 +++ tools/net/sunrpc/xdrgen/tests/test.definitions.out | 47 ++++++++ .../net/sunrpc/xdrgen/tests/test.source-client.out | 112 +++++++++++++++++++ .../net/sunrpc/xdrgen/tests/test.source-server.out | 108 +++++++++++++++++++ tools/net/sunrpc/xdrgen/xdr_ast.py | 43 ++------ 48 files changed, 843 insertions(+), 123 deletions(-)
---
base-commit: 36fd4049e3c2bb901118e11be63bf7a7922bea8c
change-id: 20261130-xdrgen-passthru-ea8328ec8d80
Best regards,
Signature · 1 line
Chuck Lever <[email protected]>
Chuck Lever
maintainerPATCH 1/7 xdrgen: Emit a header guard that is a valid identifier
The guard macro in a generated header is the stem of the .x file name in upper case. A file name that contains a hyphen or a period, such as nfs4-1.x, produces "#ifndef _LINUX_XDRGEN_NFS4-1_DEF_H", which does not compile.
Replace each character that cannot appear in a C identifier with an underscore.
--- tools/net/sunrpc/xdrgen/generators/__init__.py | 3 ++- tools/net/sunrpc/xdrgen/generators/header_top.py | 2 ++ tools/net/sunrpc/xdrgen/templates/C/header_top/declaration/header.j2 | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
tools/net/sunrpc/xdrgen/generators/__init__.py +2 -1
@@ -2,6 +2,7 @@ """Define a base code generator class""" +import re from pathlib import Path from jinja2 import Environment, FileSystemLoader, Template
@@ -52,7 +53,7 @@ def find_xdr_program_name(root: Specification) -> str: def header_guard_infix(filename: str) -> str: """Extract the header guard infix from the specification filename""" - return Path(filename).stem.upper() + return re.sub(r"\W", "_", Path(filename).stem).upper() def kernel_c_type(spec: _XdrTypeSpecifier) -> str:
tools/net/sunrpc/xdrgen/generators/header_top.py +2 -0
@@ -5,6 +5,7 @@ import os.path import time +from pathlib import Path from generators import Boilerplate, header_guard_infix from generators import create_jinja2_environment, get_jinja2_template
@@ -25,6 +26,7 @@ class XdrHeaderTopGenerator(Boilerplate): print( template.render( infix=header_guard_infix(filename), + header=Path(filename).stem.lower(), filename=filename, mtime=time.ctime(os.path.getmtime(filename)), )
tools/net/sunrpc/xdrgen/templates/C/header_top/declaration/header.j2 +1 -1
@@ -11,4 +11,4 @@ #include <linux/sunrpc/xdr.h> #include <linux/sunrpc/xdrgen/_defs.h> #include <linux/sunrpc/xdrgen/_builtins.h> -#include <linux/sunrpc/xdrgen/{{ infix.lower() }}.h> +#include <linux/sunrpc/xdrgen/{{ header }}.h>
Signature · 1 line
2.56.0
Chuck Lever
maintainerPATCH 2/7 xdrgen: Do not emit an empty enum of procedure numbers
In reply to Chuck Leveremit_version_definitions() opens and closes the enum of procedure numbers for an RPC version even when pragma exclude directives name every procedure in that version. The result is "enum { };", which is not valid C.
Emit nothing for a version when all of its procedures are excluded.
--- tools/net/sunrpc/xdrgen/generators/program.py | 3 +++ 1 file changed, 3 insertions(+)
tools/net/sunrpc/xdrgen/generators/program.py +3 -0
@@ -14,6 +14,9 @@ def emit_version_definitions( environment: Environment, program: str, version: _RpcVersion ) -> None: """Emit procedure numbers for each RPC version's procedures""" + if all(procedure.name in excluded_apis for procedure in version.procedures): + return + template = environment.get_template("definition/open.j2") print(template.render(program=program.upper()))
Signature · 1 line
2.56.0
Chuck Lever
maintainerPATCH 3/7 xdrgen: Reject inline struct, enum and union types
In reply to Chuck Leverxdrgen accepts a struct, enum or union body in place of a type name, but has no code to generate one. type_specifier discards the body and returns a built-in type named after the grammar rule. Most positions then fail with "Undefined type 'struct_type_spec'", but a procedure argument or result passes lint and reaches the generators with the rule name as a type name.
Reject the form in type_specifier, which every position goes through, and raise a semantic error at the offending source location. No in-tree .x file uses an inline type.
Add tests/run-tests.sh. It runs a negative case for each kind of inline type in each of four positions, plus the bad-*.x files, which had no runner. Any other .x file is a positive case compared against recorded .out files. The recorded output for test.x is a snapshot of current behavior, not reviewed output. run-tests.sh --update rewrites the .out files after a generator fix.
--- .../xdrgen/tests/inline-enum-discriminant.err | 2 + .../sunrpc/xdrgen/tests/inline-enum-discriminant.x | 4 + .../net/sunrpc/xdrgen/tests/inline-enum-member.err | 2 + tools/net/sunrpc/xdrgen/tests/inline-enum-member.x | 3 + .../sunrpc/xdrgen/tests/inline-enum-procarg.err | 2 + .../net/sunrpc/xdrgen/tests/inline-enum-procarg.x | 5 + .../sunrpc/xdrgen/tests/inline-enum-typedef.err | 2 + .../net/sunrpc/xdrgen/tests/inline-enum-typedef.x | 1 + .../xdrgen/tests/inline-struct-discriminant.err | 2 + .../xdrgen/tests/inline-struct-discriminant.x | 4 + .../sunrpc/xdrgen/tests/inline-struct-member.err | 2 + .../net/sunrpc/xdrgen/tests/inline-struct-member.x | 3 + .../sunrpc/xdrgen/tests/inline-struct-procarg.err | 2 + .../sunrpc/xdrgen/tests/inline-struct-procarg.x | 5 + .../sunrpc/xdrgen/tests/inline-struct-typedef.err | 2 + .../sunrpc/xdrgen/tests/inline-struct-typedef.x | 1 + .../xdrgen/tests/inline-union-discriminant.err | 2 + .../xdrgen/tests/inline-union-discriminant.x | 4 + .../sunrpc/xdrgen/tests/inline-union-member.err | 2 + .../net/sunrpc/xdrgen/tests/inline-union-member.x | 3 + .../sunrpc/xdrgen/tests/inline-union-procarg.err | 2 + .../net/sunrpc/xdrgen/tests/inline-union-procarg.x | 5 + .../sunrpc/xdrgen/tests/inline-union-typedef.err | 2 + .../net/sunrpc/xdrgen/tests/inline-union-typedef.x | 1 + tools/net/sunrpc/xdrgen/tests/run-tests.sh | 97 ++++++++++++++++++ .../net/sunrpc/xdrgen/tests/test.declarations.out | 16 +++ tools/net/sunrpc/xdrgen/tests/test.definitions.out | 47 +++++++++ .../net/sunrpc/xdrgen/tests/test.source-client.out | 112 +++++++++++++++++++++ .../net/sunrpc/xdrgen/tests/test.source-server.out | 108 ++++++++++++++++++++ tools/net/sunrpc/xdrgen/xdr_ast.py | 6 ++ 30 files changed, 449 insertions(+)
tools/net/sunrpc/xdrgen/tests/inline-enum-discriminant.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-enum-discriminant.x:1:21: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-enum-discriminant.x new file +4 -0
@@ -0,0 +1,4 @@ +union outer switch (enum { A = 0 } d) { +case 0: + int y; +};
tools/net/sunrpc/xdrgen/tests/inline-enum-member.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-enum-member.x:2:2: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-enum-member.x new file +3 -0
@@ -0,0 +1,3 @@ +struct outer { + enum { A = 0 } m; +};
tools/net/sunrpc/xdrgen/tests/inline-enum-procarg.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-enum-procarg.x:3:9: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-enum-procarg.x new file +5 -0
@@ -0,0 +1,5 @@ +program P { + version V { + int F(enum { A = 0 }) = 1; + } = 1; +} = 100;
tools/net/sunrpc/xdrgen/tests/inline-enum-typedef.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-enum-typedef.x:1:9: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-enum-typedef.x new file +1 -0
@@ -0,0 +1 @@ +typedef enum { A = 0 } inline_t;
tools/net/sunrpc/xdrgen/tests/inline-struct-discriminant.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-struct-discriminant.x:1:21: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-struct-discriminant.x new file +4 -0
@@ -0,0 +1,4 @@ +union outer switch (struct { int x; } d) { +case 0: + int y; +};
tools/net/sunrpc/xdrgen/tests/inline-struct-member.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-struct-member.x:2:2: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-struct-member.x new file +3 -0
@@ -0,0 +1,3 @@ +struct outer { + struct { int x; } m; +};
tools/net/sunrpc/xdrgen/tests/inline-struct-procarg.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-struct-procarg.x:3:9: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-struct-procarg.x new file +5 -0
@@ -0,0 +1,5 @@ +program P { + version V { + int F(struct { int x; }) = 1; + } = 1; +} = 100;
tools/net/sunrpc/xdrgen/tests/inline-struct-typedef.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-struct-typedef.x:1:9: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-struct-typedef.x new file +1 -0
@@ -0,0 +1 @@ +typedef struct { int x; } inline_t;
tools/net/sunrpc/xdrgen/tests/inline-union-discriminant.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-union-discriminant.x:1:21: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-union-discriminant.x new file +4 -0
@@ -0,0 +1,4 @@ +union outer switch (union switch (int e) { case 0: int x; } d) { +case 0: + int y; +};
tools/net/sunrpc/xdrgen/tests/inline-union-member.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-union-member.x:2:2: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-union-member.x new file +3 -0
@@ -0,0 +1,3 @@ +struct outer { + union switch (int d) { case 0: int x; } m; +};
tools/net/sunrpc/xdrgen/tests/inline-union-procarg.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-union-procarg.x:3:9: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-union-procarg.x new file +5 -0
@@ -0,0 +1,5 @@ +program P { + version V { + int F(union switch (int d) { case 0: int x; }) = 1; + } = 1; +} = 100;
tools/net/sunrpc/xdrgen/tests/inline-union-typedef.err new file +2 -0
@@ -0,0 +1,2 @@ +inline-union-typedef.x:1:9: semantic error +inline struct, enum and union types are not supported; define a named type
tools/net/sunrpc/xdrgen/tests/inline-union-typedef.x new file +1 -0
@@ -0,0 +1 @@ +typedef union switch (int d) { case 0: int x; } inline_t;
tools/net/sunrpc/xdrgen/tests/run-tests.sh new file +97 -0
97 lines not on this page · raw message
tools/net/sunrpc/xdrgen/tests/test.declarations.out new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Generated by xdrgen. Manual edits will be lost. */ +/* XDR specification file: test.x */ +/* XDR specification modification time: Thu Jan 1 00:00:00 2026 */ + +#ifndef _LINUX_XDRGEN_TEST_DECL_H +#define _LINUX_XDRGEN_TEST_DECL_H + +#include <linux/types.h> + +#include <linux/sunrpc/xdr.h> +#include <linux/sunrpc/xdrgen/_defs.h> +#include <linux/sunrpc/xdrgen/_builtins.h> +#include <linux/sunrpc/xdrgen/test.h> + +#endif /* _LINUX_XDRGEN_TEST_DECL_H */
tools/net/sunrpc/xdrgen/tests/test.definitions.out new file +47 -0
47 lines not on this page · raw message
tools/net/sunrpc/xdrgen/tests/test.source-client.out new file +112 -0
112 lines not on this page · raw message
tools/net/sunrpc/xdrgen/tests/test.source-server.out new file +108 -0
108 lines not on this page · raw message
tools/net/sunrpc/xdrgen/xdr_ast.py +6 -0
@@ -624,6 +624,12 @@ class ParseToAst(Transformer): return _XdrDefinedType(type_name=name) name = children[0].data.value + if name in ("enum_type_spec", "struct_type_spec", "union_type_spec"): + raise XdrSemanticError( + "inline struct, enum and union types are not supported; " + "define a named type", + children[0].meta, + ) return _XdrBuiltInType(type_name=name) def constant_def(self, children):
Signature · 1 line
2.56.0
Chuck Lever
maintainerPATCH 4/7 xdrgen: Discard pass-through lines
In reply to Chuck LeverRFC 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 <rpc/auth_sys.h>, 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.
--- 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(-)
fs/nfsd/nfs4xdr_gen.c +0 -13
@@ -411,10 +411,6 @@ xdrgen_decode_fattr4_open_arguments(struct xdr_stream *xdr, fattr4_open_argumentreturn 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_delegreturn 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_accesreturn true; } -/* -* New for POSIX ACL extension -*/ -static bool __maybe_unused xdrgen_decode_notify_type4 (struct xdr_stream *xdr,notify_type4 *ptr) {
include/linux/sunrpc/xdrgen/nfs4_1.h +0 -13
@@ -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 };
tools/net/sunrpc/xdrgen/generators/passthru.py deleted +0 -26
@@ -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))
tools/net/sunrpc/xdrgen/grammars/xdr.lark +1 -3
@@ -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
tools/net/sunrpc/xdrgen/subcmds/definitions.py +1 -4
@@ -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)
tools/net/sunrpc/xdrgen/subcmds/source.py +5 -16
@@ -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
tools/net/sunrpc/xdrgen/templates/C/passthru/definition.j2 deleted +0 -3
@@ -1,3 +0,0 @@ -{# SPDX-License-Identifier: GPL-2.0 #} - -{{ content }}
tools/net/sunrpc/xdrgen/templates/C/passthru/source.j2 deleted +0 -3
@@ -1,3 +0,0 @@ -{# SPDX-License-Identifier: GPL-2.0 #} - -{{ content }}
tools/net/sunrpc/xdrgen/tests/passthru.declarations.out new file +20 -0
@@ -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 <linux/types.h> + +#include <linux/sunrpc/xdr.h> +#include <linux/sunrpc/xdrgen/_defs.h> +#include <linux/sunrpc/xdrgen/_builtins.h> +#include <linux/sunrpc/xdrgen/passthru.h> + +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 */
tools/net/sunrpc/xdrgen/tests/passthru.definitions.out new file +49 -0
49 lines not on this page · raw message
tools/net/sunrpc/xdrgen/tests/passthru.source-client.out new file +109 -0
109 lines not on this page · raw message
tools/net/sunrpc/xdrgen/tests/passthru.source-server.out new file +119 -0
119 lines not on this page · raw message
tools/net/sunrpc/xdrgen/tests/passthru.x new file +35 -0
@@ -0,0 +1,35 @@ +%#include <rpc/auth_sys.h> +%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<PT_MAX>; +}; + +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;
tools/net/sunrpc/xdrgen/xdr_ast.py +0 -37
@@ -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
Signature · 1 line
2.56.0
Chuck Lever
maintainerPATCH 5/7 xdrgen: Document that xdrgen discards % lines
In reply to Chuck LeverThe README does not mention % lines, so nothing in the tree explains that xdrgen accepts them and then discards their text. A .x author who knows rpcgen expects the text in the generated code, and expects a %typedef to make a type name usable. xdrgen reports that type as undefined.
Add a section that covers both points and the one place xdrgen is more lenient than rpcgen about where the % can sit.
--- tools/net/sunrpc/xdrgen/README | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
tools/net/sunrpc/xdrgen/README +17 -0
@@ -143,6 +143,23 @@ a compiler that can optimize in a number of ways, including: And so on. +Pass-through lines +------------------ + +rpcgen copies the text of a line that starts with "%" to its output +without the "%". This is not part of the XDR language. Neither RFC +4506 nor any other XDR RFC defines it. .x files written for rpcgen +contain "%" lines, including the XDR extracted from NFS RFCs, so +xdrgen accepts them. Such a file can still need other changes before +xdrgen parses the file. + +xdrgen discards a "%" and the rest of its line, as xdrgen discards a +C comment. The text is C source meant for a user space build, and +xdrgen does not parse it. A type that only a "%typedef" line names is +undefined to xdrgen. Define the type in XDR instead. + +Unlike rpcgen, xdrgen does not require the "%" to be in column 0. + Pragmas -------
Signature · 1 line
2.56.0
Chuck Lever
maintainerPATCH 6/7 xdrgen: Document where the grammar departs from RFC 4506
In reply to Chuck LeverThe README states that the RFC 4506 grammar "has been adapted for use by the Python Lark module", but not how. A .x author cannot tell from the README which constructs xdrgen adds to the RFC's language, which RFC constructs xdrgen refuses, or why.
Add a section that lists each difference and notes, item by item, whether rpcgen behaves the same way. The additional type specifiers are there because legacy RFCs use them. The pragma directives let a .x file stay close to the RFC it was extracted from while still carrying the requirements of the local implementation.
--- tools/net/sunrpc/xdrgen/README | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
tools/net/sunrpc/xdrgen/README +27 -0
@@ -143,6 +143,33 @@ a compiler that can optimize in a number of ways, including: And so on. +Differences from RFC 4506 +------------------------- + +xdrgen's input language follows RFC 4506 Section 6.3, with these +differences: + + - "long", "short", "unsigned long" and "unsigned short" are accepted + as type specifiers, as rpcgen accepts them. RFC 4506 does not + define them, but legacy RFCs use them. RFC 1813, for example, + defines uint32 as "unsigned long". + - "program" and "version" definitions are accepted, as rpcgen accepts + them. They belong to the RPC language in RFC 5531 Section 12, not + to RFC 4506. + - "pragma" directives are accepted. rpcgen does not accept them. A + pragma states a requirement of the local implementation without + changing the XDR around it, so the .x file stays close to the RFC + it was extracted from. See "Pragmas" below. + - "%" lines are accepted and discarded. rpcgen copies their text to + its output. See "Pass-through lines" below. + - The value of a "const" definition can be an identifier, as in + rpcgen. RFC 4506 requires a constant there. + - A decimal constant can carry a leading "+". rpcgen does not accept + one. + - A struct, enum or union body in place of a type name is rejected, + as rpcgen rejects it. RFC 4506 permits one. Define a named type + instead. + Pass-through lines ------------------
Signature · 1 line
2.56.0
Chuck Lever
maintainerPATCH 7/7 xdrgen: Correct the grammar file name in the README
In reply to Chuck LeverThe README locates the grammar in a file named xdr.ebnf in the top-level xdrgen directory. Commit 4b132aacb076 ("tools: Add xdrgen") added the grammar as grammars/xdr.lark, and xdrgen has never had an xdr.ebnf.
Name the file and its directory as they are in the tree.
--- tools/net/sunrpc/xdrgen/README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/net/sunrpc/xdrgen/README +3 -3
@@ -114,9 +114,9 @@ RFC 4506 Section 6 contains a BNF grammar of the XDR specification language. The grammar has been adapted for use by the Python Lark module. -The xdr.ebnf file in this directory contains the grammar used to -parse XDR specifications. xdrgen configures Lark using the grammar -in xdr.ebnf. Lark parses the target XDR specification using this +The xdr.lark file in the grammars/ directory contains the grammar used +to parse XDR specifications. xdrgen configures Lark using the grammar +in xdr.lark. Lark parses the target XDR specification using this grammar, creating a parse tree. xdrgen then transforms the parse tree into an abstract syntax tree.
Signature · 1 line
2.56.0