From patchwork Thu Oct 3 18:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821431 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 979F51AB6C3 for ; Thu, 3 Oct 2024 18:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981718; cv=none; b=XUkSF/ujhnbkxdiLChXXhf2S5D2YNhOxppq3WuKfUOAn8607UBvb1X9RRnMBFXDotm7e2CtPRcXn6EIrgwfL13bxESLNrfZbVdrvZP6AqG/MF8ksjAcmGYMCSze0CdVXVVRzsLD1iO0aVtbNA4k4qfaYnIrK0+k4k8kV8I3zCgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981718; c=relaxed/simple; bh=gRs3qK/pMAHS5JndlfkrrZYNxpjLyrlsQBN+cRdHt40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MPq2rCxrtk5doz2hF7odg/LfnmiD6bkncWaKlUWlGm0/CPbVysuK5CVqVIjQ04dhsNqgIaH7YLnLsU58JEdOcATxHnLjrsb0UVXXYjUpFoefaTtJ0sHSexOYRq6dA0NyvlDD81nrQiZscalXwV+8ThxiJ/sIiX4TajNYY77N1ag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FHpK8Wqk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FHpK8Wqk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 720EAC4CEC5; Thu, 3 Oct 2024 18:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981718; bh=gRs3qK/pMAHS5JndlfkrrZYNxpjLyrlsQBN+cRdHt40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FHpK8WqkW6bICR7lt4hVeJfs1aFaa4asoQ5EEwzqh3L8xGRql23qlIlFZ7cN2c525 3eFV5fBJtNExhb2oRgvbUcD3E4wKqBnMdA1Pm2qq605Jd8JqzGqGX0w+5vioOBNi6M D+JwYCRG2k+1HKRE8J95mymuvrpWUd3POJ8bzzBdAvNQLD7KhglrtYECBIj16p7QwH 6u/4Lvj9cg84YRjO429fMo4wj3fwgZfFG44ygcciE98pR/w/Ix7d15RXlPoGCcrq14 oQETNuKlUgQEXQgmPwDXnJxXqjIHC96I9CiFYNOO6m0PWe2ayQPRlhza2mw1LGBJU+ d1zntuoWqVuWQ== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 01/16] xdrgen: Refactor transformer arms Date: Thu, 3 Oct 2024 14:54:31 -0400 Message-ID: <20241003185446.82984-2-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Clean up: Add a __post_init__ function to the data classes that need to update the "structs" and "pass_by_reference" sets. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 57 +++++++++++++++++------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index d5f0535ec84c..68f09945f2c4 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -51,13 +51,17 @@ class _XdrTypeSpecifier(_XdrAst): """Corresponds to 'type_specifier' in the XDR language grammar""" type_name: str - c_classifier: str + c_classifier: str = "" @dataclass class _XdrDefinedType(_XdrTypeSpecifier): """Corresponds to a type defined by the input specification""" + def __post_init__(self): + if self.type_name in structs: + self.c_classifier = "struct " + @dataclass class _XdrBuiltInType(_XdrTypeSpecifier): @@ -124,6 +128,10 @@ class _XdrOptionalData(_XdrDeclaration): spec: _XdrTypeSpecifier template: str = "optional_data" + def __post_init__(self): + structs.add(self.name) + pass_by_reference.add(self.name) + @dataclass class _XdrBasic(_XdrDeclaration): @@ -174,6 +182,10 @@ class _XdrStruct(_XdrAst): name: str fields: List[_XdrDeclaration] + def __post_init__(self): + structs.add(self.name) + pass_by_reference.add(self.name) + @dataclass class _XdrPointer(_XdrAst): @@ -182,6 +194,10 @@ class _XdrPointer(_XdrAst): name: str fields: List[_XdrDeclaration] + def __post_init__(self): + structs.add(self.name) + pass_by_reference.add(self.name) + @dataclass class _XdrTypedef(_XdrAst): @@ -189,6 +205,15 @@ class _XdrTypedef(_XdrAst): declaration: _XdrDeclaration + def __post_init__(self): + if not isinstance(self.declaration, _XdrBasic): + return + + new_type = self.declaration + if isinstance(new_type.spec, _XdrDefinedType): + if new_type.spec.type_name in pass_by_reference: + pass_by_reference.add(new_type.name) + @dataclass class _XdrCaseSpec(_XdrAst): @@ -216,6 +241,10 @@ class _XdrUnion(_XdrAst): cases: List[_XdrCaseSpec] default: _XdrDeclaration + def __post_init__(self): + structs.add(self.name) + pass_by_reference.add(self.name) + @dataclass class _RpcProcedure(_XdrAst): @@ -290,22 +319,13 @@ class ParseToAst(Transformer): return _XdrConstantValue(value) def type_specifier(self, children): - """Instantiate one type_specifier object""" - c_classifier = "" + """Instantiate one _XdrTypeSpecifier object""" if isinstance(children[0], _XdrIdentifier): name = children[0].symbol - if name in structs: - c_classifier = "struct " - return _XdrDefinedType( - type_name=name, - c_classifier=c_classifier, - ) + return _XdrDefinedType(type_name=name) name = children[0].data.value - return _XdrBuiltInType( - type_name=name, - c_classifier=c_classifier, - ) + return _XdrBuiltInType(type_name=name) def constant_def(self, children): """Instantiate one _XdrConstant object""" @@ -380,8 +400,6 @@ class ParseToAst(Transformer): """Instantiate one _XdrOptionalData declaration object""" spec = children[0] name = children[1].symbol - structs.add(name) - pass_by_reference.add(name) return _XdrOptionalData(name, spec) @@ -400,8 +418,6 @@ class ParseToAst(Transformer): def struct(self, children): """Instantiate one _XdrStruct object""" name = children[0].symbol - structs.add(name) - pass_by_reference.add(name) fields = children[1].children last_field = fields[-1] @@ -416,11 +432,6 @@ class ParseToAst(Transformer): def typedef(self, children): """Instantiate one _XdrTypedef object""" new_type = children[0] - if isinstance(new_type, _XdrBasic) and isinstance( - new_type.spec, _XdrDefinedType - ): - if new_type.spec.type_name in pass_by_reference: - pass_by_reference.add(new_type.name) return _XdrTypedef(new_type) @@ -442,8 +453,6 @@ class ParseToAst(Transformer): def union(self, children): """Instantiate one _XdrUnion object""" name = children[0].symbol - structs.add(name) - pass_by_reference.add(name) body = children[1] discriminant = body.children[0].children[0] From patchwork Thu Oct 3 18:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821432 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 303861ABEA6 for ; Thu, 3 Oct 2024 18:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981730; cv=none; b=KNQZEA/e5Zt5Whct7YrFDSCeydW4wKQR48OHjH875HvWZBN4yhsa91APanty0VlkAJ5NlLf2oRyVGcvyRzYnMkvYggccZ6xU/Acr3PE4f+pt4krIxeYlOTC/TvMzBKKNmgPi+jxjTX65QzlAlZMR0yl+vla9BGF8Ycot7XXhlg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981730; c=relaxed/simple; bh=Bk6ELu4MeGgeda4QU7tKlTn/kVW80wjJBNqAYlXaxgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AjDxUtJeIyAzQKWL7QggKiL44489/zoo+pAu3pw6Sbbqx2ciyMWTxZY9kd3Kz+F1AM/jjZNc7ZEhXxL5cKMgefq5jVAI+yGf7ICTBILYPefLuJw+3hlgfwnjJWc3DYCkxck6tUqQwmcjN0gLMZzLjw+6Eg5zcJTbe+Qw5fTYC4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iafuo+Dt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iafuo+Dt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0882EC4CEC5; Thu, 3 Oct 2024 18:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981729; bh=Bk6ELu4MeGgeda4QU7tKlTn/kVW80wjJBNqAYlXaxgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iafuo+Dt+avuyOf30PhN8wfz2/TFyJ/JCSUT28IPFJEyVRJw6NFsQIreDV93cJzqY PRVD4Py4wf2/QurS5Ptq6MRviu162fSR1YENERG4ffaxNwjqeK5cf1TxKgtysS5sJw oP6vTG67668rWVOjeyFAO3Lyfyf31lNUCIHrXI5w39ovD+TO5TQcLKkZwKLRftiwPn MfuFY8dv5Pmjpl7FdsrOq6xDGjhbhDzIYP4fzCWEv+jyd6dxfJo7bhmzj22b0p5LCl 6JfXSHQlNViDMhnib/PbLfRoYx3I4hvFTTdSwAbXIry+S9Dk9UcumotfRr++5mTdgu frKg38heMXHUg== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 02/16] xdrgen: Track constant values Date: Thu, 3 Oct 2024 14:54:32 -0400 Message-ID: <20241003185446.82984-3-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever In order to compute the numeric on-the-wire width of XDR types, xdrgen needs to keep track of the numeric value of constants that are defined in the input specification so it can perform calculations with those values. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index 68f09945f2c4..b7df45f47707 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -19,6 +19,8 @@ public_apis = [] structs = set() pass_by_reference = set() +constants = {} + @dataclass class _XdrAst(ast_utils.Ast): @@ -156,6 +158,10 @@ class _XdrConstant(_XdrAst): name: str value: str + def __post_init__(self): + if self.value not in constants: + constants[self.name] = int(self.value, 0) + @dataclass class _XdrEnumerator(_XdrAst): @@ -164,6 +170,10 @@ class _XdrEnumerator(_XdrAst): name: str value: str + def __post_init__(self): + if self.value not in constants: + constants[self.name] = int(self.value, 0) + @dataclass class _XdrEnum(_XdrAst): From patchwork Thu Oct 3 18:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821433 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F8F11AB515 for ; Thu, 3 Oct 2024 18:55:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981741; cv=none; b=cPQCnLzqWZmfylSbYddVUnnbFZO466UK6Y3PSNp2qY/ljYW2IhktahhHZobpvCcN9ZrgC2kWGIrbPi9Tv4oNxTGI1DPNO93ENeMPlbZuJDMbqLKiJYAV+vuwhKbMfpFZA3WUTBWppjgLyGXQIvktFG1NlAfe+kRtJxLuenF+x5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981741; c=relaxed/simple; bh=5Fxm3WlxwUd6LYcPwTxxa5VUv2bnYW6sxcIdtPqTwWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m55ONS1/USycGj1PUGymviQBQk9NUM4BpGPqt3xbdoR9YyvfiTef7kULyWtePh5fYRFEc+N4nuy3MQKmRaaIX2UBAj1SXo3Tm7lCyzZgILEB89G0HnA+hPvsqohlpp/QqX0p4E9sa/xCb04avFXNk/VobbaVdSY1/Z4a3Yhb/vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DbbGbdoK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DbbGbdoK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4876C4CEC5; Thu, 3 Oct 2024 18:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981741; bh=5Fxm3WlxwUd6LYcPwTxxa5VUv2bnYW6sxcIdtPqTwWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DbbGbdoK52m+0oGetbP6zDN5MQSWfxxNvmdAvoAfN6hrIhPRWKJM+aIr6LW44OfwR ceeIKHIF3KWHOiFyQnMdekNJLc9sGWoN4oDN0bVNHwnkAXwNw3P1gte7vKf7YN0uBG QXDSKKrTfwAed/pqjs2OPFGy7RYT9Cn/G3mj6Pp+hRPWETJquKpuAEUJah3f1KWEsX YU1hQ6FVUQDn3vRQkbTIi/xZYOF8zHRslZm4jAZKP0dYyMwgpYL9g0xZCwgf0hyohJ PTKmw9w1dO/z6uC2F3Y8zIqypN/NaSjHsv1n1nWyaSezXQu0O9gDVpA/SE6Au3l1oq uAVrqlQqSBKRw== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 03/16] xdrgen: Keep track of on-the-wire data type widths Date: Thu, 3 Oct 2024 14:54:33 -0400 Message-ID: <20241003185446.82984-4-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever The generic parts of the RPC layer need to know the widths (in XDR_UNIT increments) of the XDR data types defined for each protocol. As a first step, add dictionaries to keep track of the symbolic and actual maximum XDR width of XDR types. This makes it straightforward to look up the width of a type by its name. The built-in dictionaries are pre-loaded with the widths of the built-in XDR types as defined in RFC 4506. Signed-off-by: Chuck Lever --- include/linux/sunrpc/xdrgen/_defs.h | 9 ++++++ tools/net/sunrpc/xdrgen/xdr_ast.py | 43 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/linux/sunrpc/xdrgen/_defs.h b/include/linux/sunrpc/xdrgen/_defs.h index be9e62371758..20c7270aa64d 100644 --- a/include/linux/sunrpc/xdrgen/_defs.h +++ b/include/linux/sunrpc/xdrgen/_defs.h @@ -23,4 +23,13 @@ typedef struct { u8 *data; } opaque; +#define XDR_void (0) +#define XDR_bool (1) +#define XDR_int (1) +#define XDR_unsigned_int (1) +#define XDR_long (1) +#define XDR_unsigned_long (1) +#define XDR_hyper (2) +#define XDR_unsigned_hyper (2) + #endif /* _SUNRPC_XDRGEN__DEFS_H_ */ diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index b7df45f47707..f1d93a1d0ed8 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -21,6 +21,31 @@ pass_by_reference = set() constants = {} +symbolic_widths = { + "void": ["XDR_void"], + "bool": ["XDR_bool"], + "int": ["XDR_int"], + "unsigned_int": ["XDR_unsigned_int"], + "long": ["XDR_long"], + "unsigned_long": ["XDR_unsigned_long"], + "hyper": ["XDR_hyper"], + "unsigned_hyper": ["XDR_unsigned_hyper"], +} + +# Numeric XDR widths are tracked in a dictionary that is keyed +# by type_name because sometimes a caller has nothing more than +# the type_name to use to figure out the numeric width. +max_widths = { + "void": 0, + "bool": 1, + "int": 1, + "unsigned_int": 1, + "long": 1, + "unsigned_long": 1, + "hyper": 2, + "unsigned_hyper": 2, +} + @dataclass class _XdrAst(ast_utils.Ast): @@ -60,15 +85,24 @@ class _XdrTypeSpecifier(_XdrAst): class _XdrDefinedType(_XdrTypeSpecifier): """Corresponds to a type defined by the input specification""" + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return [get_header_name().upper() + "_" + self.type_name + "_sz"] + def __post_init__(self): if self.type_name in structs: self.c_classifier = "struct " + symbolic_widths[self.type_name] = self.symbolic_width() @dataclass class _XdrBuiltInType(_XdrTypeSpecifier): """Corresponds to a built-in XDR type""" + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return symbolic_widths[self.type_name] + @dataclass class _XdrDeclaration(_XdrAst): @@ -148,8 +182,17 @@ class _XdrBasic(_XdrDeclaration): class _XdrVoid(_XdrDeclaration): """A void declaration""" + name: str = "void" template: str = "void" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return 0 + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return [] + @dataclass class _XdrConstant(_XdrAst): From patchwork Thu Oct 3 18:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821434 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6D731AB506 for ; Thu, 3 Oct 2024 18:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981752; cv=none; b=o1aLv21jeYBwIgsUlY49YoajbqOEJ6oS+9SM9CO/YwKoXHB++RP06sOu6T8vQOxXekUM40e6X5RNUa15vvyXk+jhRZCrxjnNjIeYMUfp4WgMTaHUjoV6YefOHhUn9YVbZkSgswOiLPvKL4f2Q+CotUYRKG6Zu0a6sr5F2cCcdZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981752; c=relaxed/simple; bh=SoSWvT0n8eQFx0vdcmEa/oaMA3v+0uKf/pAk5pq1oZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TYnzGe+2wmbv7U/9H09YQqf711ld498UhJ60IKm3mBTJR5v4fR1/mNEQ/qBkPohQ5lljh0YJg+B6qJo093UXCd7mD0L9v8C/sNG+Ursro5L33sgZeCgEV7J2HPwuk3gswNFZAcGTGIVRJDQiWYzOlfj0Lmpx/tDfnXPSmAczxIM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LKewUetz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LKewUetz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DFBBC4CEC5; Thu, 3 Oct 2024 18:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981751; bh=SoSWvT0n8eQFx0vdcmEa/oaMA3v+0uKf/pAk5pq1oZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LKewUetzV702WNuJ9Gn+g7G6Kkf9pJGQif0Ju4ZlcZEo9hCIpiT3fVMCmel7Daadc 9S4OOlaQ+3cwjagfsAIFjAsAuSeuBKM95uT1ZTMWM9jcYGP7ZdyqHs/n08eFaLnWfa U2vJjjq8FWMTTJH/NzPNDuO5xwOxr2vIjq9+xA08TE3Ibd9GKhQIdFsHBunI/616fe qTZ9Oyk9LsYu8kKM0bLX5cjoj9q2nruM7Vw38Bmi1B9Qax85WVRFBtYlUgiVBmo7xR 5QTsoz7fnez9rti9xcZ+SsGkfBZUTm/QCbCb5hF5PN4GjlkUVmHB83VVAac2lOJ0g1 pvZNCTBVe7fVA== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 04/16] xdrgen: XDR widths for enum types Date: Thu, 3 Oct 2024 14:54:34 -0400 Message-ID: <20241003185446.82984-5-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever RFC 4506 says that an XDR enum is represented as a signed integer on the wire; thus its width is 1 XDR_UNIT. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index f1d93a1d0ed8..fbee954c7f70 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -227,6 +227,18 @@ class _XdrEnum(_XdrAst): maximum: int enumerators: List[_XdrEnumerator] + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return 1 + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return ["XDR_int"] + + def __post_init__(self): + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() + @dataclass class _XdrStruct(_XdrAst): From patchwork Thu Oct 3 18:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821435 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A73161AAE2F for ; Thu, 3 Oct 2024 18:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981761; cv=none; b=rRG97i16kw0X+tbqF+qfH7Ww6GOjKmBrwXlauoAdktxAaMXWX9ooaTdl3gqSnKpV0KOw51hYwWEaersaM5/y34h4ZyRCTtd6v8rw9QXp/c6oqPywxmWEWUZVXPae9FDNhCZnFJyEXnaAPmVDaHHvpGokkBPI02xxs/VzFezU/pE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981761; c=relaxed/simple; bh=zVPNu+hait7j1cpUDsk2WqOtmmz2VyWXZW/4CWdhAEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YJAv1sxN9pc0a6YZ6o19kn0t7lIkgwk+uokuDjN7UPYfbUYFqOHgQfVQITun4zkKcfJmrk/+e5zfh7mJackecgCVHFiApLnWrv+X8XyVEMNC0CeLicd/pTqVj5W5/GKt+/cFpX4TDg080ktvLAG7iOgIXBxCYHi6CHi4g+zmPoc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TxOS/zbZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TxOS/zbZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 931B6C4CEC5; Thu, 3 Oct 2024 18:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981761; bh=zVPNu+hait7j1cpUDsk2WqOtmmz2VyWXZW/4CWdhAEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TxOS/zbZIkDAe+7nrh0B6vVUos2e3I2Z4AtR1bF7D3Zn6i8Zi5RCFSB+k4ICOypzE fI4WX3RjtMe4pJv03ASOQPcATZRiMru34HFfOIp2TXzJhuiRTTIhbduYCATj5oV5Ks M4vNxuEAEkd78c/Jhbo/U/lJnw8z1nbXQJ36x3I2FkMd5xEzT/vi72/wKY7vvZUlUs qI+rw2Xk9XoUxVbncaCEdSUu9F+t+WW8cR1/wBwK0gQDuE6w9zIF5YaVl+pwq+RovH NWi/SaiJD1jsX2tCa/thj/Bb475VoR2lJxk2+qFXLgTBglE+sCsgiGjoDZ7oxiHF16 /S0QUyaPMJFjA== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 05/16] xdrgen: XDR width for fixed-length opaque Date: Thu, 3 Oct 2024 14:54:35 -0400 Message-ID: <20241003185446.82984-6-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever The XDR width for a fixed-length opaque is the byte size of the opaque rounded up to the next XDR_UNIT, divided by XDR_UNIT. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index fbee954c7f70..9fe7fa688caa 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -21,6 +21,16 @@ pass_by_reference = set() constants = {} + +def xdr_quadlen(val: str) -> int: + """Return integer XDR width of an XDR type""" + if val in constants: + octets = constants[val] + else: + octets = int(val) + return int((octets + 3) / 4) + + symbolic_widths = { "void": ["XDR_void"], "bool": ["XDR_bool"], @@ -117,6 +127,18 @@ class _XdrFixedLengthOpaque(_XdrDeclaration): size: str template: str = "fixed_length_opaque" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return xdr_quadlen(self.size) + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return ["XDR_QUADLEN(" + self.size + ")"] + + def __post_init__(self): + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() + @dataclass class _XdrVariableLengthOpaque(_XdrDeclaration): From patchwork Thu Oct 3 18:54:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821436 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 975511AB6D3 for ; Thu, 3 Oct 2024 18:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981771; cv=none; b=gD3KlcCheZYqtV+er85Qcolh7ZMrgYcT/1ShS1bpC7bLVgI8m6P85/BwpeftIx5q02c4OMmhpBF1SLROmAXCzWKQ4PMyPh/D3dsSMlrpybQIdijPrgRL3lvdJ50McmqoSjeLRCU8GxNYa9dCxq5XtkZFwz5TyAB/GeokxnNZd8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981771; c=relaxed/simple; bh=pRnpR6P5t42iIkCEFsBPKe8PwabUnPoOZMinZ/zFYto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SaI+M8NdMwWKLnwCGnWc5P0oFDlF9RnsczyhIGxZ/rmDMawNXIHymH4WA9/uizx0cPBwbFz6jqY4DZVN8oyCV7dVL2WZOFj5mfim7Z4fRS+QgXkjb9+F1g6/SGvdo/XIQBX8Vsunf43gmZvTfNg5KvcjNx4mF+aTIGNWLZ/Os6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EPMgnuvf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EPMgnuvf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75B29C4CEC5; Thu, 3 Oct 2024 18:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981771; bh=pRnpR6P5t42iIkCEFsBPKe8PwabUnPoOZMinZ/zFYto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPMgnuvfFZiKDOuX8Si4HZcGJLBHjYlO0NdbTTlqLj9Ik8Z67cO/GpoXfttKBgMnE zOYUN8kt26k+iI9YKTy0KZg2zGO9+aJP6y5RyIC1gCOM7xxjCFdpuLWPX+N9mDzKHp srjX8ojMzqkbdlL97VLdxDQd46aghFe/kaR1PS2HMA7NXgyl5a9KfwBAbCF4HdiqKh cs/bN+7jDi0aJHBLnCrD8For0/YKqBicaUtgOC73WzaBL7et95cq53a2dAVc5yzUaM P8pkH1ekrE75tYWFIyGQL03EphX793szBbc94xijMMhMXrLRdFLrUBVo7UVXXk2IBJ 7cHQNtDNPTXkw== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 06/16] xdrgen: XDR width for variable-length opaque Date: Thu, 3 Oct 2024 14:54:36 -0400 Message-ID: <20241003185446.82984-7-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever The byte size of a variable-length opaque is conveyed in an unsigned integer. If there is a specified maximum size, that is included in the type's widths list. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index 9fe7fa688caa..94cdcfb36e77 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -148,6 +148,21 @@ class _XdrVariableLengthOpaque(_XdrDeclaration): maxsize: str template: str = "variable_length_opaque" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return 1 + xdr_quadlen(self.maxsize) + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + widths = ["XDR_unsigned_int"] + if self.maxsize != "0": + widths.append("XDR_QUADLEN(" + self.maxsize + ")") + return widths + + def __post_init__(self): + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() + @dataclass class _XdrString(_XdrDeclaration): From patchwork Thu Oct 3 18:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821437 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8283F19F134 for ; Thu, 3 Oct 2024 18:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981781; cv=none; b=qAe0oZ8a+3oSp3CSrONHBls1Vyzt5eLgSADkjNWuj6XQ2DEH3GModkEWmUHHRJABm3x3ce/21ETYzz/LO5l5MdpywvIitfFLieFNqKUNb9n6g+XfINPmg8AVe/9ov+M0UUJaRmu0n+WV7YYJVd6Nk/VJDztP3iasmt61oCJkqwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981781; c=relaxed/simple; bh=B1K+TALLHIEHvj5rQFKCTcCLrKzUGlUJX2BnsjrwRdI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EzVy+eQoXIEIEmoShgedJDSFCjS9hnTeY7AULF0PcKhOk0N9fBbqqk+aXAjxa6GZehbmwuqq7ldQ2wdPsICe+r0RLpk/2KQbX1l1V1pj9ErjVpIFG12ItIXqvY+ta/nb1nd/wQB8VDdJ06M81yX76quxtXu660awIUGVi8ssTr0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wc+ar5Cu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wc+ar5Cu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75906C4CECC; Thu, 3 Oct 2024 18:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981781; bh=B1K+TALLHIEHvj5rQFKCTcCLrKzUGlUJX2BnsjrwRdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wc+ar5Cu3hcwlWkt3coYM9z4/w/yijoPiKRQlKzWOiSxnSdcEQ75gIpIrk3FuC02e n5+L2lVzsqKLUQPu0ilYFPUJzeiNFWLO5oPDnaKXbyeQAVIA5uEnlMDWUDfiqia74y Um5ithdcZI3VmS7DNCvbcnodOdsHVH1hnRzMFk5N6JiL0qlFeg6tduuvvcKt5n/K4v bAk19PeAAUd+7cW89gwuar0jK8Jwuec2Tmwi3muaLSoCE/UepAKPN1FoYNz/DHoqQ5 InQLag7TucS2vC4hYi1WZwxLKRmQKdw+crvnx8wZhrrXVOAUJ1l/cEpxahnZRLoTiE dS4iXaFNGdjoQ== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 07/16] xdrgen: XDR width for a string Date: Thu, 3 Oct 2024 14:54:37 -0400 Message-ID: <20241003185446.82984-8-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever A string works like a variable-length opaque. See Section 4.11 of RFC 4506. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index 94cdcfb36e77..d5f48c094729 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -172,6 +172,21 @@ class _XdrString(_XdrDeclaration): maxsize: str template: str = "string" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return 1 + xdr_quadlen(self.maxsize) + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + widths = ["XDR_unsigned_int"] + if self.maxsize != "0": + widths.append("XDR_QUADLEN(" + self.maxsize + ")") + return widths + + def __post_init__(self): + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() + @dataclass class _XdrFixedLengthArray(_XdrDeclaration): From patchwork Thu Oct 3 18:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821438 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38B1D6A33F for ; Thu, 3 Oct 2024 18:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981791; cv=none; b=V/vLTDpmMMXaYEbJ9qYpB/kjEAJKIstg+i9ezFzYRRfc9DnsmGnrf8PVvGc3qXWAh99x/qoQTKVt5NdnKt+Tp1moJn5I7npLyk6Ft6rpuZjO224Tu/4gusjEG6W4RCb7dD8Un3rHCNMVUcJpPLWGjc7qRZWCLTag80RXYNEn7B4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981791; c=relaxed/simple; bh=nqS0Fn7I2oTlrMlM/WcOIsUdT7xMf9K3lZTtNZxR9HM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T6mR5Sjnpqe1Fl7AJ5tzmx/NSckTfiIAuYlM2sgaWXxb47ZtWtfHhVUnIcEOjpvQCX7qY2qwqh7lB75JiydvcdPXpX9hnwmeNN42cv6l6WZXAn0YmQVaM8qhpjkE4EK2lSoFMBXFpjun2XoQNUKe8RRLHdVNjZ8cvpDlbQNKWyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p5ZkZSKf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p5ZkZSKf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 693F9C4CEC5; Thu, 3 Oct 2024 18:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981791; bh=nqS0Fn7I2oTlrMlM/WcOIsUdT7xMf9K3lZTtNZxR9HM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5ZkZSKf7ZwRQlXfSGZ+U5muwx920na6VLSkbTw9lvzhfRPNaQ4aJghjlYB2yK9Bb UqAs3PH3a3K37Nf9XYRvuUq8ug/vasVH5LEr7wwHiDD2UDc+RhEpB3XDVBgEAQmktp NOrd4m41dbGFMpMeG6lz5HA6saDdHonmRkOfaBDJPMEkhFZtavKxA5+becmDNGLtVM hg+zK22B5Wjqi07sEaiG/cUF7asO8VQUZCakKkbT/2/03HmMaUgcO4eNRGu0JQUnjO DCsbg3HIJN70+U05Y5jxzROh8j1ghxKTXa3KRPTgnAoVmeR87tu+vGqUeUUJi8EiPa q9BK7NhR+bu6Q== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 08/16] xdrgen: XDR width for fixed-length array Date: Thu, 3 Oct 2024 14:54:38 -0400 Message-ID: <20241003185446.82984-9-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index d5f48c094729..e9bc81e83b48 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -197,6 +197,19 @@ class _XdrFixedLengthArray(_XdrDeclaration): size: str template: str = "fixed_length_array" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return xdr_quadlen(self.size) * max_widths[self.spec.type_name] + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + item_width = " + ".join(symbolic_widths[self.spec.type_name]) + return ["(" + self.size + " * (" + item_width + "))"] + + def __post_init__(self): + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() + @dataclass class _XdrVariableLengthArray(_XdrDeclaration): From patchwork Thu Oct 3 18:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821439 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B13176EB4A for ; Thu, 3 Oct 2024 18:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981802; cv=none; b=Uv1GRrI3ECUxkALL0JHdZcxX4XcN4dNHJKzw1YzS2n5xfiQu7snBRfH3HOuEgzsrAd2SND7OlmPJkR+7tSrM10BzVMi/6Syv0mIgFtqHRt+sKoPknSppoeP2PA+ZIMlHltt8sObcVi4zS0DrgDmmM4DzbVZZfktuA4rVkpDKGEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981802; c=relaxed/simple; bh=0+PUm9bD/Z9aDEFRgodi0+MqUkWZ9gSLz8zL+lzVuG0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D9FrDQmCxPS6ZDZ1RhZJiuaysOx/fX68AZUJHjmTeXc0rgtjeURr2B8R0zwTnh4AkBIyS/BumLR7rCellwQDylag7EPPNuNGGaMo8M6GcIIVTjsUGPjHqDq3QrWBKZs6kV+CIkOiP11neghdQWerCJGLcME68m+hUwP8Lr7qIDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HMVb/gHp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HMVb/gHp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FF98C4CEC5; Thu, 3 Oct 2024 18:56:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981801; bh=0+PUm9bD/Z9aDEFRgodi0+MqUkWZ9gSLz8zL+lzVuG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HMVb/gHpDoiLn1klLsE+8fWPpFJmLPDebzSTYfEVIBn/aksirfpq42VZ1SGypV3vK N5rkpwX1XfQ5SGg5HbEnV/f2sGvM98L1E4jdp377zJUm5lAO4U/AP90xdLyp+gcNL0 2Zy+h/QJFBzKiwsQLkktTPOD0OePCpIYQu+8S/yYC5MWu+aNX37uaTG4Y1JSXY9a7G n65B4DeDpAp5QOqZX515BRElwT6JwuPNV55PAqKGqNn2dnh0iRHISXRYPqs4clmf4v 8tES4uHtZS+Qtow5DBEFTQOcPFR1NFGBGf52t4S9QpXD11vOMHcnd6COgO75cjOAMy C0E2mFGfHrPFQ== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 09/16] xdrgen: XDR width for variable-length array Date: Thu, 3 Oct 2024 14:54:39 -0400 Message-ID: <20241003185446.82984-10-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index e9bc81e83b48..cb89d5d9987c 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -220,6 +220,22 @@ class _XdrVariableLengthArray(_XdrDeclaration): maxsize: str template: str = "variable_length_array" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return 1 + (xdr_quadlen(self.maxsize) * max_widths[self.spec.type_name]) + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + widths = ["XDR_unsigned_int"] + if self.maxsize != "0": + item_width = " + ".join(symbolic_widths[self.spec.type_name]) + widths.append("(" + self.maxsize + " * (" + item_width + "))") + return widths + + def __post_init__(self): + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() + @dataclass class _XdrOptionalData(_XdrDeclaration): From patchwork Thu Oct 3 18:54:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821440 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE1986A33F for ; Thu, 3 Oct 2024 18:56:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981811; cv=none; b=tA1bt/LlYAX/nam03rMig+KarjcFqcKBje7VicLr3sLfXQ0o5A/4t234p+yzmfH+nxhdLnxKX16/viZtVcU3EeU6vk7ckvLCqQU0qmeFXsSPAbnTR361HINMMNSsOWFpX6qppxxfxKGWV+zsKL4sfdhAn9RclMPHZsDSfseLF3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981811; c=relaxed/simple; bh=VlkWZ5yxXxxeF3BNsOuwrIwljypf4ALEdO+nPNEhZV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NEBwbgeSqaxbClaOTDLTBUxbXew3XtReNghFvwKZ9AiuVWUTOfrJPj+dBz8/vvxxflttUiF9ySYF2Hd8/nSuQirm1k7XfgSnS2Krd0FJYfU4NYJ0pkDxrYhmIVmZ2X7YwAcYsbWz12jnG2k9gM9okw0NSgaiudU8gSkCAV+Ss6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bEPrtnA6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bEPrtnA6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89415C4CEC5; Thu, 3 Oct 2024 18:56:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981811; bh=VlkWZ5yxXxxeF3BNsOuwrIwljypf4ALEdO+nPNEhZV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bEPrtnA6HF+c0TGS8yeJbvbSgQB6kXIwRInA9h+rw3pxDYe3U5U5do4CUDt2W+Uuy Bjph0DGU3OvhR0777welzz0MIDUUgkmw77hvjLdFE5uCkQVihKN1pbYSIaAiPOGeWY bB4F5vKHokKxO/DHxTCed0+rGYsVANJkN9xZ18nY5O5hWfLk2NMEzWwDuzzHyYbzkw qtmLTU7jD6hG9QYZ25wU3YdBs94ZBkPw1lkdkEEN1N7wyC76r2gHI2YQo1co1Rw3Yl qHCmH5DjSJQzdNb5DA7U+dh9JVIKJqMEsXGFUEcucujzoj2yX4+kT0AkQOjUD3B81N YZUTy3NkWqorg== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 10/16] xdrgen: XDR width for optional_data type Date: Thu, 3 Oct 2024 14:54:40 -0400 Message-ID: <20241003185446.82984-11-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index cb89d5d9987c..f2ef78654e36 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -245,9 +245,19 @@ class _XdrOptionalData(_XdrDeclaration): spec: _XdrTypeSpecifier template: str = "optional_data" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return 1 + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return ["XDR_bool"] + def __post_init__(self): structs.add(self.name) pass_by_reference.add(self.name) + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() @dataclass From patchwork Thu Oct 3 18:54:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821441 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 830796A33F for ; Thu, 3 Oct 2024 18:57:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981821; cv=none; b=je4NN8dGvvFuJKTGJ6exLM63cSOqeVPMNeOi+8LyQacqU5mxexNtIekcW+M+VjIKLfpipEfriSMqXeyOArcOrm6cAWavFMyUZe82qA99noYp3ZrOYWzCrPD8zCp9BASyj7CqxDzRCxkZ+8nuifQO1nSGEtw/ZKvR0R5tt9BbPdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981821; c=relaxed/simple; bh=c6Esw2UeMukJLvdz6V+zscUfk2VMSDxNx171EBgTBPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XJ6ILcXABiOXXgHjH/f2N7BYQORNqlBzhKnNxd4k1c+PQs5sJV0Tb8MM32k46aMG1rmfNxBcFYSH2fvaYwmAEdS1F0sqXFDpmfBDHwaBtyodsSEkjvQOu0T3C0YaGQXnNyiN5IgA4nDEvUDL/6f9HzDfSEM9pxcwk2B0CWDAg9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f774wOrR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f774wOrR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71AEBC4CEC5; Thu, 3 Oct 2024 18:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981821; bh=c6Esw2UeMukJLvdz6V+zscUfk2VMSDxNx171EBgTBPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f774wOrR9UL9EiG6BSBJxrACysywK03Wp3ken+XKEwLOGmEN6LeWyHJ1120EEPyGe zUKwHmBwxvq7JEVnwiQ/G6q1Qzf3xkVbasEvTD5NTfVQRQrmKLGuajacuWvCVnv+KP 9a+q3BiiW5yeRR/fJfwT47ovtfwTu4KyUWAsL8t7j3UdeQ2vfpLlq1JYIxtkv9l85U 8QOonIPawygkrxze3CGM3SfOJAgfZsXlyEktU1Ry8ATHGnbrV+GOWqocwTJxUBADWv Ijr00b+GSc61jwTihkprkfSP7Xwi+GXs6zBtk+QYiyqdopm7kTCZdQgyzXcM7Os2a1 1qulUSOmx0LWw== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 11/16] xdrgen: XDR width for typedef Date: Thu, 3 Oct 2024 14:54:41 -0400 Message-ID: <20241003185446.82984-12-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever The XDR width of a typedef is the same as the width of the base type. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 34 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index f2ef78654e36..8996f26cbd55 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -268,6 +268,18 @@ class _XdrBasic(_XdrDeclaration): spec: _XdrTypeSpecifier template: str = "basic" + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return max_widths[self.spec.type_name] + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return symbolic_widths[self.spec.type_name] + + def __post_init__(self): + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() + @dataclass class _XdrVoid(_XdrDeclaration): @@ -361,14 +373,22 @@ class _XdrTypedef(_XdrAst): declaration: _XdrDeclaration - def __post_init__(self): - if not isinstance(self.declaration, _XdrBasic): - return + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + return self.declaration.max_width() - new_type = self.declaration - if isinstance(new_type.spec, _XdrDefinedType): - if new_type.spec.type_name in pass_by_reference: - pass_by_reference.add(new_type.name) + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + return self.declaration.symbolic_width() + + def __post_init__(self): + if isinstance(self.declaration, _XdrBasic): + new_type = self.declaration + if isinstance(new_type.spec, _XdrDefinedType): + if new_type.spec.type_name in pass_by_reference: + pass_by_reference.add(new_type.name) + max_widths[new_type.name] = self.max_width() + symbolic_widths[new_type.name] = self.symbolic_width() @dataclass From patchwork Thu Oct 3 18:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821442 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B6D71AB506 for ; Thu, 3 Oct 2024 18:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981831; cv=none; b=RPsWJyITcSdZH8JDP8mzRHoIsjzmhEX5jJZt51dIO5v/PYPBktBXe2U+N+0naIdFVUJOl9nx7o/XC99azifh3dsdNhOdjr91ESzt18cfKzWS2jlthCyJRcunR0ewmyn41InDtkr3gyEQL3Y0AkZHmL2UTTmtisAZtL3S6KIzMQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981831; c=relaxed/simple; bh=RiS6mY/x/ZknGZnGnU0tpz3Kqu9pfk3vIe1I6jXSeqc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gSDWFqXqaP6dnp/pH+nslaAFF41Db8+ihfUkeV+Nw0hCYAEPkcWcUTOAETQxNdaBSqkTWmcUmmrXgHf8yVF3QEKOIDl4U7DgaDL18JZQGjGZWMmCYZnlvYDDgoVRrynjg4H4pnkKkmvOgSEDv0KmnJQdqztT2m4OArPYMPML0Fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bs3Wtz4a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bs3Wtz4a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BBC5C4CEC5; Thu, 3 Oct 2024 18:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981831; bh=RiS6mY/x/ZknGZnGnU0tpz3Kqu9pfk3vIe1I6jXSeqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bs3Wtz4aiX9wbgULGLzb3kjcgjPhFz0Z/wlNI9wAKeVkc+Msw852sUV8hKwANnboK EltI2ND/m19ig/LCs/JLfyCuo38CHD2vtHHPDT7qy7MnL3DFj92ZNJEpHBlAzJy+js QDAM9SjdnSaWveMeaZaabW7QjHr0tc184UQEGlAjeKViT80SMetiTRokj82l+fa3qL /v5DcbVdpyNdtq578+Hq8i8NcW03wNlTDqKANXQSvHn2Y42UiRp8A6BDSFkBzw3VME uZIj5DSm0TuJCyTg1oT2HyASDWFvn3FtjUFkMwZP8FWRXxrSL2IiUBIJh0ZPj/owAM Ev8DbqtTY/zzQ== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 12/16] xdrgen: XDR width for struct types Date: Thu, 3 Oct 2024 14:54:42 -0400 Message-ID: <20241003185446.82984-13-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever The XDR width of a struct type is the sum of the widths of each of the struct's fields. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index 8996f26cbd55..f34b147c8dfd 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -350,9 +350,25 @@ class _XdrStruct(_XdrAst): name: str fields: List[_XdrDeclaration] + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + width = 0 + for field in self.fields: + width += field.max_width() + return width + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + widths = [] + for field in self.fields: + widths += field.symbolic_width() + return widths + def __post_init__(self): structs.add(self.name) pass_by_reference.add(self.name) + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() @dataclass From patchwork Thu Oct 3 18:54:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821443 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3850A6A33F for ; Thu, 3 Oct 2024 18:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981841; cv=none; b=fvfnonxVUz/AaMWFJrF/HoGDCX/CBNGcPiQ8altaxVxZlXLLvjOskmQIwRP3rb03uZI1jcQ82MXsUO+a1RsdqUGPhRxAB1k304fGAVXWiwxGj6HKtvTQj+6HUhzIUL4g+oYrSmnvh09c0VPsnZF5fUajxb3nTd2tbHaw7UM/Nb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981841; c=relaxed/simple; bh=eHKYDsi8arSciN1UWzAd+EN+iaio0ctyad/aKcGYhJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=suLXG5+pPNrWc2ZGRkD1E38FzkujN0CHR1IAoq/4T0jaifcSdVwu9mNItNhC6IttfK0xy9m8zsT4Rgb6sKKoGw9/9Ndja6qXdGb23yQ8/YcJC7NPiFa0kH532quI55lGVWgkOht3+P5GYhj1iB2qgLRlIVbnHqN/nIdV1LEHgLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cjIaQtVy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cjIaQtVy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BED6C4CEC5; Thu, 3 Oct 2024 18:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981841; bh=eHKYDsi8arSciN1UWzAd+EN+iaio0ctyad/aKcGYhJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cjIaQtVyG4LDqsFQc2pCCaEAVEEBXrjQ8Jhqoi+th0meWTTZwShe3kI0aYdG7xXql 29o6t8SmGcEEt/5FOrbxUHzfn89NbdoRhbUwdjLNXHx6/TNgs3taTozZeGjlnBZEvR sC3COKq/Nm1QbMJbRmF9xy5oOAgStvcnygcDDW7Ow6wcoCsOeUFvdkzCCnVuE9tVzt YqHTFbZOqlKBIoesCrQJVr/8muUe0NsJmsOYf1QzpjoqiDvWS60+Uy2XaCtVLIg8NS phoONR/jV/0Fx0DlJ0c5GHQaHleyy45UTQhnjpzVuyLUq1VYPko6QJFOt53IjZ3jD+ v4R2dW47kW7XQ== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 13/16] xdrgen: XDR width for pointer types Date: Thu, 3 Oct 2024 14:54:43 -0400 Message-ID: <20241003185446.82984-14-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever The XDR width of a pointer type is the sum of the widths of each of the struct's fields, except for the last field. The width of the implicit boolean "value follows" field is added as well. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index f34b147c8dfd..8d53c889eee8 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -378,9 +378,26 @@ class _XdrPointer(_XdrAst): name: str fields: List[_XdrDeclaration] + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + width = 1 + for field in self.fields[0:-1]: + width += field.max_width() + return width + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + widths = [] + widths += ["XDR_bool"] + for field in self.fields[0:-1]: + widths += field.symbolic_width() + return widths + def __post_init__(self): structs.add(self.name) pass_by_reference.add(self.name) + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() @dataclass From patchwork Thu Oct 3 18:54:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821444 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2662D22F19 for ; Thu, 3 Oct 2024 18:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981851; cv=none; b=h5Q4pwIeDVgpXWoYQp0J85SrcMT6ma01X1ANJPNghPi+OdUB6iv1sofQlQw29gH0I7X18bd54oPAjHeXUOkeIfsxjQuBwzTi6IPHlPx6TIPcwhMROXD6lKEJ00n+mAM+/qIvX6agAulhdR1vf6miKIfjGEol76GA0KDSNFBpOwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981851; c=relaxed/simple; bh=A7CwuIw0S9h+lC2aNEw2fKCO4c8FITOoODYDMlmJt8g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sj83qwiesHTKuzWZ1PDStPJE+UkSrttakZyx33ZXw3XwI69kWgUcdT4TbNX8FK0ZiRpOneL/DX/+GZVwWZfH4mMTEffSfJhBTEGxpuE8As9aBchmRiQU2tzbFa2UHWdvdBD3685hGy1LSEFZGv/iiux8xV6M8DGb3uk7KNm5v7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U4+EyAPd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U4+EyAPd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 520F7C4CEC5; Thu, 3 Oct 2024 18:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981851; bh=A7CwuIw0S9h+lC2aNEw2fKCO4c8FITOoODYDMlmJt8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4+EyAPdx18BzHT/vHk9TM4sinOnsIBUADO6vArLoTgX690+LYn/qCUbndAUSzZPd D/C+3oaEgYKDV3OHY7ebtsBRzbWWYzU3M0lUW8Y1zCb/e3Y8LJEFTyXnHGpQynCGf7 CCxQi0FHdRe8X/5V5bYmv0PEBeGXZYY0O3bG+KIjNUMzEI2RXINWPmx0BG2PXDiYuF Rz4+v3BR51hAUiPT0REd7coKZUkTZVer96konTOZhx5TD/z+uGbaC6xz8Xdzhexjwt fXj6wQGsGuppXiED02rY9RIPgp1MCIks1CeAls1l/IqnAP/Dq1so0RUvR2L0fAKbKG lgIVGVaLEtwRg== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 14/16] xdrgen: XDR width for union types Date: Thu, 3 Oct 2024 14:54:44 -0400 Message-ID: <20241003185446.82984-15-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Not yet complete. The tool doesn't do any math yet. Thus, even though the maximum XDR width of a union is the width of the union enumerator plus the width of its largest arm, we're using the sum of all the elements of the union for the moment. This means that buffer size requirements are overestimated, and that the generated maxsize macro cannot yet be used for determining data element alignment in the XDR buffer. Signed-off-by: Chuck Lever --- tools/net/sunrpc/xdrgen/xdr_ast.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py index 8d53c889eee8..5233e73c7046 100644 --- a/tools/net/sunrpc/xdrgen/xdr_ast.py +++ b/tools/net/sunrpc/xdrgen/xdr_ast.py @@ -450,9 +450,35 @@ class _XdrUnion(_XdrAst): cases: List[_XdrCaseSpec] default: _XdrDeclaration + def max_width(self) -> int: + """Return width of type in XDR_UNITS""" + max_width = 0 + for case in self.cases: + if case.arm.max_width() > max_width: + max_width = case.arm.max_width() + if self.default: + if self.default.arm.max_width() > max_width: + max_width = self.default.arm.max_width() + return 1 + max_width + + def symbolic_width(self) -> List: + """Return list containing XDR width of type's components""" + max_width = 0 + for case in self.cases: + if case.arm.max_width() > max_width: + max_width = case.arm.max_width() + width = case.arm.symbolic_width() + if self.default: + if self.default.arm.max_width() > max_width: + max_width = self.default.arm.max_width() + width = self.default.arm.symbolic_width() + return symbolic_widths[self.discriminant.name] + width + def __post_init__(self): structs.add(self.name) pass_by_reference.add(self.name) + max_widths[self.name] = self.max_width() + symbolic_widths[self.name] = self.symbolic_width() @dataclass From patchwork Thu Oct 3 18:54:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821445 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E2F81AAE2F for ; Thu, 3 Oct 2024 18:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981861; cv=none; b=Qo48JkamgSskz/Oo/3PMDJe213N6aAj4/jSIXJv8OxCYmA4NZe8NayAcBzeRVJ8Z3/z7aSx+BYpxe+O9c6jNMoZjjdcp9lO9/8eIghtZcAKIoCUM+K2EqxQv02ou2ZzI86XB0zL1yuEQFcD0WwZWA5CgrqzJOKxDBc3rrFaqhwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981861; c=relaxed/simple; bh=5u5ySJcNqX2kDBi5mx70Jl9oDiWTQq26iSBlKP9iQKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jhuQJOgju0oh6VPgyGvMBmPdLRSCvxu26TE+xHotPEpvqLeaOLvP5wPfT96E327riRQstQUSvqVL/J8sqyKO2jrUoHp4H65YHAW91UU+uf1LXphA714yuhY73FOcys2BWgZhcRcnkOcsZamB4ihYHsZ4gVvf2MMzBYChpespFEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S8qMYIWZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S8qMYIWZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D60BC4CECC; Thu, 3 Oct 2024 18:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981861; bh=5u5ySJcNqX2kDBi5mx70Jl9oDiWTQq26iSBlKP9iQKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S8qMYIWZKW5oTr3u+vzS/82iE0qBOAGEnm4CqRaebzHnuQW0NO1KJPXTXj5ffLMdG KD/tTR0vP+F09SIdDnN9yNKFzdjfNxFAH+vBkMri8bKMvurdu4zWmcWzfl6bEhn2ws /MH+bvRJnHai/3WwV/xnWM2nkPum5sgTwQE6QKZzbImaHBeY0LmIxVMYSpGp/YIc86 m/d9GPp+bC0es3w8FS8ESQNp4Puq3aDOPF65d1LcjMtU1RP9GTSCxilLMkkkto/AQ+ F02eoLGqjZALmyIWemWCFlyRSludTWWvOjQNPSM/g7bHKL8x42bXh5vkxrTqWEcXK5 mA6SSYKoFQ1Iw== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 15/16] xdrgen: Add generator code for XDR width macros Date: Thu, 3 Oct 2024 14:54:45 -0400 Message-ID: <20241003185446.82984-16-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Introduce logic in the code generators to emit maxsize (XDR width) definitions. In C, these are pre-processor macros. Signed-off-by: Chuck Lever --- .../net/sunrpc/xdrgen/generators/__init__.py | 4 ++++ tools/net/sunrpc/xdrgen/generators/enum.py | 13 +++++++++++- tools/net/sunrpc/xdrgen/generators/pointer.py | 18 ++++++++++++++++- tools/net/sunrpc/xdrgen/generators/struct.py | 18 ++++++++++++++++- tools/net/sunrpc/xdrgen/generators/typedef.py | 18 ++++++++++++++++- tools/net/sunrpc/xdrgen/generators/union.py | 20 +++++++++++++++++-- .../xdrgen/templates/C/enum/maxsize/enum.j2 | 2 ++ .../templates/C/pointer/maxsize/pointer.j2 | 3 +++ .../templates/C/struct/maxsize/struct.j2 | 3 +++ .../templates/C/typedef/maxsize/basic.j2 | 3 +++ .../C/typedef/maxsize/fixed_length_opaque.j2 | 2 ++ .../templates/C/typedef/maxsize/string.j2 | 2 ++ .../typedef/maxsize/variable_length_array.j2 | 2 ++ .../typedef/maxsize/variable_length_opaque.j2 | 2 ++ .../xdrgen/templates/C/union/maxsize/union.j2 | 3 +++ 15 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 tools/net/sunrpc/xdrgen/templates/C/enum/maxsize/enum.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/pointer/maxsize/pointer.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/struct/maxsize/struct.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/basic.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/fixed_length_opaque.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/string.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_array.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_opaque.j2 create mode 100644 tools/net/sunrpc/xdrgen/templates/C/union/maxsize/union.j2 diff --git a/tools/net/sunrpc/xdrgen/generators/__init__.py b/tools/net/sunrpc/xdrgen/generators/__init__.py index fd2457461274..b98574a36a4a 100644 --- a/tools/net/sunrpc/xdrgen/generators/__init__.py +++ b/tools/net/sunrpc/xdrgen/generators/__init__.py @@ -111,3 +111,7 @@ class SourceGenerator: def emit_encoder(self, node: _XdrAst) -> None: """Emit one encoder function for this XDR type""" raise NotImplementedError("Encoder generation not supported") + + def emit_maxsize(self, node: _XdrAst) -> None: + """Emit one maxsize macro for this XDR type""" + raise NotImplementedError("Maxsize macro generation not supported") diff --git a/tools/net/sunrpc/xdrgen/generators/enum.py b/tools/net/sunrpc/xdrgen/generators/enum.py index e63f45b8eb74..e62f715d3996 100644 --- a/tools/net/sunrpc/xdrgen/generators/enum.py +++ b/tools/net/sunrpc/xdrgen/generators/enum.py @@ -4,7 +4,7 @@ """Generate code to handle XDR enum types""" from generators import SourceGenerator, create_jinja2_environment -from xdr_ast import _XdrEnum, public_apis, big_endian +from xdr_ast import _XdrEnum, public_apis, big_endian, get_header_name class XdrEnumGenerator(SourceGenerator): @@ -51,3 +51,14 @@ class XdrEnumGenerator(SourceGenerator): else: template = self.environment.get_template("encoder/enum.j2") print(template.render(name=node.name)) + + def emit_maxsize(self, node: _XdrEnum) -> None: + """Emit one maxsize macro for an XDR enum type""" + macro_name = get_header_name().upper() + "_" + node.name + "_sz" + template = self.environment.get_template("maxsize/enum.j2") + print( + template.render( + macro=macro_name, + width=" + ".join(node.symbolic_width()), + ) + ) diff --git a/tools/net/sunrpc/xdrgen/generators/pointer.py b/tools/net/sunrpc/xdrgen/generators/pointer.py index 0aa3d35203f5..6dbda60ad2db 100644 --- a/tools/net/sunrpc/xdrgen/generators/pointer.py +++ b/tools/net/sunrpc/xdrgen/generators/pointer.py @@ -12,7 +12,7 @@ from xdr_ast import _XdrBasic, _XdrString from xdr_ast import _XdrFixedLengthOpaque, _XdrVariableLengthOpaque from xdr_ast import _XdrFixedLengthArray, _XdrVariableLengthArray from xdr_ast import _XdrOptionalData, _XdrPointer, _XdrDeclaration -from xdr_ast import public_apis +from xdr_ast import public_apis, get_header_name def emit_pointer_declaration(environment: Environment, node: _XdrPointer) -> None: @@ -247,6 +247,18 @@ def emit_pointer_encoder(environment: Environment, node: _XdrPointer) -> None: print(template.render()) +def emit_pointer_maxsize(environment: Environment, node: _XdrPointer) -> None: + """Emit one maxsize macro for an XDR pointer type""" + macro_name = get_header_name().upper() + "_" + node.name + "_sz" + template = get_jinja2_template(environment, "maxsize", "pointer") + print( + template.render( + macro=macro_name, + width=" + ".join(node.symbolic_width()), + ) + ) + + class XdrPointerGenerator(SourceGenerator): """Generate source code for XDR pointer""" @@ -270,3 +282,7 @@ class XdrPointerGenerator(SourceGenerator): def emit_encoder(self, node: _XdrPointer) -> None: """Emit one encoder function for an XDR pointer type""" emit_pointer_encoder(self.environment, node) + + def emit_maxsize(self, node: _XdrPointer) -> None: + """Emit one maxsize macro for an XDR pointer type""" + emit_pointer_maxsize(self.environment, node) diff --git a/tools/net/sunrpc/xdrgen/generators/struct.py b/tools/net/sunrpc/xdrgen/generators/struct.py index 6dd7f4d7cd53..64911de46f62 100644 --- a/tools/net/sunrpc/xdrgen/generators/struct.py +++ b/tools/net/sunrpc/xdrgen/generators/struct.py @@ -12,7 +12,7 @@ from xdr_ast import _XdrBasic, _XdrString from xdr_ast import _XdrFixedLengthOpaque, _XdrVariableLengthOpaque from xdr_ast import _XdrFixedLengthArray, _XdrVariableLengthArray from xdr_ast import _XdrOptionalData, _XdrStruct, _XdrDeclaration -from xdr_ast import public_apis +from xdr_ast import public_apis, get_header_name def emit_struct_declaration(environment: Environment, node: _XdrStruct) -> None: @@ -247,6 +247,18 @@ def emit_struct_encoder(environment: Environment, node: _XdrStruct) -> None: print(template.render()) +def emit_struct_maxsize(environment: Environment, node: _XdrStruct) -> None: + """Emit one maxsize macro for an XDR struct type""" + macro_name = get_header_name().upper() + "_" + node.name + "_sz" + template = get_jinja2_template(environment, "maxsize", "struct") + print( + template.render( + macro=macro_name, + width=" + ".join(node.symbolic_width()), + ) + ) + + class XdrStructGenerator(SourceGenerator): """Generate source code for XDR structs""" @@ -270,3 +282,7 @@ class XdrStructGenerator(SourceGenerator): def emit_encoder(self, node: _XdrStruct) -> None: """Emit one encoder function for an XDR struct type""" emit_struct_encoder(self.environment, node) + + def emit_maxsize(self, node: _XdrStruct) -> None: + """Emit one maxsize macro for an XDR struct type""" + emit_struct_maxsize(self.environment, node) diff --git a/tools/net/sunrpc/xdrgen/generators/typedef.py b/tools/net/sunrpc/xdrgen/generators/typedef.py index 6ea98445f5c8..fab72e9d6915 100644 --- a/tools/net/sunrpc/xdrgen/generators/typedef.py +++ b/tools/net/sunrpc/xdrgen/generators/typedef.py @@ -12,7 +12,7 @@ from xdr_ast import _XdrBasic, _XdrTypedef, _XdrString from xdr_ast import _XdrFixedLengthOpaque, _XdrVariableLengthOpaque from xdr_ast import _XdrFixedLengthArray, _XdrVariableLengthArray from xdr_ast import _XdrOptionalData, _XdrVoid, _XdrDeclaration -from xdr_ast import public_apis +from xdr_ast import public_apis, get_header_name def emit_typedef_declaration(environment: Environment, node: _XdrDeclaration) -> None: @@ -230,6 +230,18 @@ def emit_typedef_encoder(environment: Environment, node: _XdrDeclaration) -> Non raise NotImplementedError("typedef: type not recognized") +def emit_typedef_maxsize(environment: Environment, node: _XdrDeclaration) -> None: + """Emit a maxsize macro for an XDR typedef""" + macro_name = get_header_name().upper() + "_" + node.name + "_sz" + template = get_jinja2_template(environment, "maxsize", node.template) + print( + template.render( + macro=macro_name, + width=" + ".join(node.symbolic_width()), + ) + ) + + class XdrTypedefGenerator(SourceGenerator): """Generate source code for XDR typedefs""" @@ -253,3 +265,7 @@ class XdrTypedefGenerator(SourceGenerator): def emit_encoder(self, node: _XdrTypedef) -> None: """Emit one encoder function for an XDR typedef""" emit_typedef_encoder(self.environment, node.declaration) + + def emit_maxsize(self, node: _XdrTypedef) -> None: + """Emit one maxsize macro for an XDR typedef""" + emit_typedef_maxsize(self.environment, node.declaration) diff --git a/tools/net/sunrpc/xdrgen/generators/union.py b/tools/net/sunrpc/xdrgen/generators/union.py index 4522a5b7a943..2cca00e279cd 100644 --- a/tools/net/sunrpc/xdrgen/generators/union.py +++ b/tools/net/sunrpc/xdrgen/generators/union.py @@ -8,8 +8,8 @@ from jinja2 import Environment from generators import SourceGenerator from generators import create_jinja2_environment, get_jinja2_template -from xdr_ast import _XdrBasic, _XdrUnion, _XdrVoid, big_endian -from xdr_ast import _XdrDeclaration, _XdrCaseSpec, public_apis +from xdr_ast import _XdrBasic, _XdrUnion, _XdrVoid, get_header_name +from xdr_ast import _XdrDeclaration, _XdrCaseSpec, public_apis, big_endian def emit_union_declaration(environment: Environment, node: _XdrUnion) -> None: @@ -234,6 +234,18 @@ def emit_union_encoder(environment, node: _XdrUnion) -> None: print(template.render()) +def emit_union_maxsize(environment: Environment, node: _XdrUnion) -> None: + """Emit one maxsize macro for an XDR union type""" + macro_name = get_header_name().upper() + "_" + node.name + "_sz" + template = get_jinja2_template(environment, "maxsize", "union") + print( + template.render( + macro=macro_name, + width=" + ".join(node.symbolic_width()), + ) + ) + + class XdrUnionGenerator(SourceGenerator): """Generate source code for XDR unions""" @@ -257,3 +269,7 @@ class XdrUnionGenerator(SourceGenerator): def emit_encoder(self, node: _XdrUnion) -> None: """Emit one encoder function for an XDR union""" emit_union_encoder(self.environment, node) + + def emit_maxsize(self, node: _XdrUnion) -> None: + """Emit one maxsize macro for an XDR union""" + emit_union_maxsize(self.environment, node) diff --git a/tools/net/sunrpc/xdrgen/templates/C/enum/maxsize/enum.j2 b/tools/net/sunrpc/xdrgen/templates/C/enum/maxsize/enum.j2 new file mode 100644 index 000000000000..45c1d4c21b22 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/enum/maxsize/enum.j2 @@ -0,0 +1,2 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/pointer/maxsize/pointer.j2 b/tools/net/sunrpc/xdrgen/templates/C/pointer/maxsize/pointer.j2 new file mode 100644 index 000000000000..9f3bfb47d2f4 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/pointer/maxsize/pointer.j2 @@ -0,0 +1,3 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} \ + ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/struct/maxsize/struct.j2 b/tools/net/sunrpc/xdrgen/templates/C/struct/maxsize/struct.j2 new file mode 100644 index 000000000000..9f3bfb47d2f4 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/struct/maxsize/struct.j2 @@ -0,0 +1,3 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} \ + ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/basic.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/basic.j2 new file mode 100644 index 000000000000..9f3bfb47d2f4 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/basic.j2 @@ -0,0 +1,3 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} \ + ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/fixed_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/fixed_length_opaque.j2 new file mode 100644 index 000000000000..45c1d4c21b22 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/fixed_length_opaque.j2 @@ -0,0 +1,2 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/string.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/string.j2 new file mode 100644 index 000000000000..45c1d4c21b22 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/string.j2 @@ -0,0 +1,2 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_array.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_array.j2 new file mode 100644 index 000000000000..45c1d4c21b22 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_array.j2 @@ -0,0 +1,2 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_opaque.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_opaque.j2 new file mode 100644 index 000000000000..45c1d4c21b22 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/variable_length_opaque.j2 @@ -0,0 +1,2 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} ({{ width }}) diff --git a/tools/net/sunrpc/xdrgen/templates/C/union/maxsize/union.j2 b/tools/net/sunrpc/xdrgen/templates/C/union/maxsize/union.j2 new file mode 100644 index 000000000000..9f3bfb47d2f4 --- /dev/null +++ b/tools/net/sunrpc/xdrgen/templates/C/union/maxsize/union.j2 @@ -0,0 +1,3 @@ +{# SPDX-License-Identifier: GPL-2.0 #} +#define {{ '{:<31}'.format(macro) }} \ + ({{ width }}) From patchwork Thu Oct 3 18:54:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13821446 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EC1322F19 for ; Thu, 3 Oct 2024 18:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981871; cv=none; b=reqGiJYDmMdfIvb+tKyY+Vyuz36JcKpn9/aUpGpLmZe/5wnAVdb9Vw9YWuD/CSz0REDb8e71uG5+Ibj0vzsXuC5CSxru+7w5RotQBM7T/OIPAsjBsrry1mmyFgazd8LW/cTAFZWdG+UtTiujHX7Q+0Sp1HGsdeHbVNUzbZJX5YI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727981871; c=relaxed/simple; bh=H7DStBXojbtO5NqvQ3kmL8wP5q2TC7czGheuTBTyS8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LWj7G1/NPyWxyVmSBEldY4qiU6eJvqCaBMaGadOGelbdF7+kn1FqE/N+0keDGWnLEex9PS0AKyxCPtYJqTFdnhnv1oAiZficTuGOkF/zeW/QjUVLnCOXMV1PZKepV4I4M0NB6ttIP1f350EnKz7kFybLHwp29p1oLUjs+jSZN3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YXt/ZCcM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YXt/ZCcM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70DC8C4CEC5; Thu, 3 Oct 2024 18:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727981871; bh=H7DStBXojbtO5NqvQ3kmL8wP5q2TC7czGheuTBTyS8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YXt/ZCcMD9Dv5AugEasFYqlDo2tV4DQO/586tkH4o+93V4QdZns+fMYy4MEs7vmDo eCflKgAa30McgEB2oqKsfeVA2Yj+XZnBYN1cTmGOd+vKhy5qepRFOp0eMMH8kD5yXd v4mpz+SUuo0RmaqLTFLfpSWrbivs/cVc/k+xhgo7FPcCopE9COw8BQBWcIZc1r/aVM Wor5UnY7zLh8DyzYzYqZVlsu9F4xvwuZiAc9dPjnba9aMjhUv0eH03peMHVZEg40+A dLRtqZRWHdg4rNb2EeeKYTUIArowtx2wuF8Rwiss4DDrPJNHbM3ZKSorhp257Ysjiy bVrLjrTttUojQ== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 16/16] xdrgen: emit maxsize macros Date: Thu, 3 Oct 2024 14:54:46 -0400 Message-ID: <20241003185446.82984-17-cel@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241003185446.82984-1-cel@kernel.org> References: <20241003185446.82984-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever Add "definitions" subcommand logic to emit maxsize macros in generated code. Signed-off-by: Chuck Lever --- .../net/sunrpc/xdrgen/subcmds/definitions.py | 24 ++++++++++++++++--- tools/net/sunrpc/xdrgen/subcmds/source.py | 3 +-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tools/net/sunrpc/xdrgen/subcmds/definitions.py b/tools/net/sunrpc/xdrgen/subcmds/definitions.py index 5cd13d53221f..c956e27f37c0 100644 --- a/tools/net/sunrpc/xdrgen/subcmds/definitions.py +++ b/tools/net/sunrpc/xdrgen/subcmds/definitions.py @@ -28,9 +28,7 @@ from xdr_parse import xdr_parser, set_xdr_annotate logger.setLevel(logging.INFO) -def emit_header_definitions( - root: Specification, language: str, peer: str -) -> None: +def emit_header_definitions(root: Specification, language: str, peer: str) -> None: """Emit header definitions""" for definition in root.definitions: if isinstance(definition.value, _XdrConstant): @@ -52,6 +50,25 @@ def emit_header_definitions( gen.emit_definition(definition.value) +def emit_header_maxsize(root: Specification, language: str, peer: str) -> None: + """Emit header maxsize macros""" + print("") + for definition in root.definitions: + if isinstance(definition.value, _XdrEnum): + gen = XdrEnumGenerator(language, peer) + elif isinstance(definition.value, _XdrPointer): + gen = XdrPointerGenerator(language, peer) + elif isinstance(definition.value, _XdrTypedef): + gen = XdrTypedefGenerator(language, peer) + elif isinstance(definition.value, _XdrStruct): + gen = XdrStructGenerator(language, peer) + elif isinstance(definition.value, _XdrUnion): + gen = XdrUnionGenerator(language, peer) + else: + continue + gen.emit_maxsize(definition.value) + + def handle_parse_error(e: UnexpectedInput) -> bool: """Simple parse error reporting, no recovery attempted""" print(e) @@ -71,6 +88,7 @@ def subcmd(args: Namespace) -> int: gen.emit_definition(args.filename, ast) emit_header_definitions(ast, args.language, args.peer) + emit_header_maxsize(ast, args.language, args.peer) gen = XdrHeaderBottomGenerator(args.language, args.peer) gen.emit_definition(args.filename, ast) diff --git a/tools/net/sunrpc/xdrgen/subcmds/source.py b/tools/net/sunrpc/xdrgen/subcmds/source.py index 00c04ad15b89..2024954748f0 100644 --- a/tools/net/sunrpc/xdrgen/subcmds/source.py +++ b/tools/net/sunrpc/xdrgen/subcmds/source.py @@ -83,8 +83,7 @@ def generate_client_source(filename: str, root: Specification, language: str) -> gen = XdrSourceTopGenerator(language, "client") gen.emit_source(filename, root) - # cel: todo: client needs XDR size macros - + print("") for definition in root.definitions: emit_source_encoder(definition.value, language, "client") for definition in root.definitions: