All of lore.kernel.org
 help / color / mirror / Atom feed
From: cel@kernel.org
To: Neil Brown <neilb@suse.de>, Jeff Layton <jlayton@kernel.org>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>, Chuck Lever <chuck.lever@oracle.com>
Subject: [PATCH 05/16] xdrgen: XDR width for fixed-length opaque
Date: Thu,  3 Oct 2024 11:01:47 -0400	[thread overview]
Message-ID: <20241003150151.81951-6-cel@kernel.org> (raw)
In-Reply-To: <20241003150151.81951-1-cel@kernel.org>

From: Chuck Lever <chuck.lever@oracle.com>

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 <chuck.lever@oracle.com>
---
 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):
-- 
2.46.2


  parent reply	other threads:[~2024-10-03 15:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-03 15:01 [PATCH 00/16] xdrgen: Emit maxsize macros cel
2024-10-03 15:01 ` [PATCH 01/16] xdrgen: Refactor transformer arms cel
2024-10-03 15:01 ` [PATCH 02/16] xdrgen: Track constant values cel
2024-10-03 15:01 ` [PATCH 03/16] xdrgen: Keep track of on-the-wire data type widths cel
2024-10-03 15:01 ` [PATCH 04/16] xdrgen: XDR widths for enum types cel
2024-10-03 15:01 ` cel [this message]
2024-10-03 15:01 ` [PATCH 06/16] xdrgen: XDR width for variable-length opaque cel
2024-10-03 15:01 ` [PATCH 07/16] xdrgen: XDR width for a string cel
2024-10-03 15:01 ` [PATCH 08/16] xdrgen: XDR width for fixed-length array cel
2024-10-03 15:01 ` [PATCH 09/16] xdrgen: XDR width for variable-length array cel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241003150151.81951-6-cel@kernel.org \
    --to=cel@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=dai.ngo@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.