From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 2AFEF4C8FFE for ; Thu, 3 Sep 2026 15:04:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788447842; cv=none; b=kFarciqnKh2CuDbhbOvT8RDKcb4nXvOVDaVVkX5ppjV6NoswMCy6i+de+Oa8y3W+x7SQcR6LxMNCK9gdDfZa9kfwoaosOB4td1xVVqa9QyTVqx7bfQu5zfFJ0Zh/7UrARjV3RU/qx6nIfd+8q1pFYq1RLcfBABeuBVg2GioFP1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788447842; c=relaxed/simple; bh=ElxLIbZi1wPQY8N0ps+afLQYwYWXEMmDPJo9IND+3Ms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u5NoFtEKLDmWqz/0YkY/nGPPatR7D/mMMPdVn1fA53ofnCFwBYKw7ZCZNXr3dPPODyNwtuRg9d4JVecnRfUyXl2bwpyXZ5iPerUvh2TEVfv8DCSMcvm8XS1b+b8vVumIel9yq8zvTh2FftUrikaYNI8nkb+guevzH7V9aoHz8eU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LLG57jqO; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LLG57jqO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82FFF1F00A3D; Thu, 3 Sep 2026 15:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788447841; bh=aWmNUCHiruWy+yb8ofyiinpe6rEdlyUcn4Jjn2hkFI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LLG57jqOR9Xg4WH0sysAdz/7bKqidk6Q/+w6zH1xEzc1tyqZXW/a2DAJqz/RNoLk2 4zSLF35ry+1Pwc6Lq59LPb9QeQ4RVQM3vTR7dXTjYMKu6Cr+I/tNNa9OgG74lGMURF TBsLkpGlygUlLZdBRMwreWAYexCkp78n47cpOj7sQjWyUfybrpGFAUsoym3GVWoWV/ +cGWd0GUwpzNDnqci+bAVvVpzH5mlNLYNjAGg1PsomD4eOkT1gizqZGZBBdeDoL/mA cvvItdm4wviw6tQ1Z2oMjAlG8Bk21dFwEzQT9gufIkfFc7bnNbMm/0roXUhY4mMlId YE6q7PoxRg3UA== From: Chuck Lever To: NeilBrown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Subject: [PATCH v1 10/10] xdrgen: Stream optional-data aggregate lists during encode Date: Thu, 3 Sep 2026 11:03:51 -0400 Message-ID: <20260903150351.9572-11-cel@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260903150351.9572-1-cel@kernel.org> References: <20260903150351.9572-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The optional-data aggregate encoder loops cursor.count times, so the begin hook must report the element count before the first element is written. A producer that reads its elements while the reply is encoded -- NFSv2 READDIR streaming directory entries straight into the send buffer -- does not know that count in advance, and would have to materialize the whole list just to satisfy the loop bound. An optional-data list carries no count on the wire, so nothing forces one on the encoder. Drive it from the item hook instead: a false return ends the list, and the framing writes the terminator. The counted-array form and its hook contract are unchanged. No in-tree spec marks an optional-data member yet, so no generated code changes here. Signed-off-by: Chuck Lever --- include/linux/sunrpc/xdrgen/_defs.h | 25 ++++++++++++------- tools/net/sunrpc/xdrgen/README | 11 +++++--- .../C/struct/encoder/aggregate_optional.j2 | 6 ++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/linux/sunrpc/xdrgen/_defs.h b/include/linux/sunrpc/xdrgen/_defs.h index f4375d73c5ca..be77e9c57296 100644 --- a/include/linux/sunrpc/xdrgen/_defs.h +++ b/include/linux/sunrpc/xdrgen/_defs.h @@ -30,15 +30,22 @@ typedef struct { } opaque; /* - * Cursor a hook-driven aggregate codec hands to its application hooks, - * one element at a time, in place of a materialized C array. The - * generated framing owns it. @xdr is the RPC layer's stream; @ctx is - * that stream's xdrgen_ctx, the svc_rqst on the server. @index is - * the current element and @count the wire array length: a decoder - * fills @count from the wire before the begin hook runs, an - * encoder's begin hook sets it. @member_id selects among a type's - * marked members. The begin/item/end contract is under "Pragma - * aggregate" in tools/net/sunrpc/xdrgen/README. + * Cursor a hook-driven aggregate codec hands to its begin/item/end + * hooks, one element at a time, in place of a materialized C array. + * The generated framing owns it. @xdr is the RPC layer's stream and + * @ctx its xdrgen_ctx, the svc_rqst on the server. @index is the + * current element; @member_id selects among a type's marked members. + * For a counted array @count is the wire length: a decoder fills it + * before the begin hook runs, an encoder's begin hook sets it. The + * hook contract is under "Pragma aggregate" in + * tools/net/sunrpc/xdrgen/README. + * + * An optional-data list ("type *name") carries no count. Its encoder + * pulls elements until the item hook returns false. False ends the + * list rather than failing the encode: the framing writes the + * value-follows terminator, so a producer that stops early leaves a + * valid truncated list on the wire. A producer that stops for a + * mid-list error reports that error through @ctx. */ struct xdrgen_aggregate_cursor { struct xdr_stream *xdr; diff --git a/tools/net/sunrpc/xdrgen/README b/tools/net/sunrpc/xdrgen/README index ae8a8050698b..958d068bcad0 100644 --- a/tools/net/sunrpc/xdrgen/README +++ b/tools/net/sunrpc/xdrgen/README @@ -173,8 +173,13 @@ carries a u32 element count, so the framing writes that count and bound-checks it. An optional-data list carries no count: each element is prefixed by a value-follows TRUE and the sequence is closed by a FALSE, which the framing writes after the last -element. For the optional-data form xdrgen generates a working -encoder only; the decoder it emits does not decode the list. +element. That form has no count to loop on, so its encoder pulls +elements until the item hook returns false. False ends the list +rather than failing the encode: a producer stops when its source +is exhausted or when a reply budget fills. For the optional-data +form xdrgen +generates a working encoder only; the decoder it emits does not +decode the list. For example: @@ -197,7 +202,7 @@ member: For a variable-length array, a decoder fills the cursor's count from the wire before calling the begin hook, and an encoder's begin hook sets that count for the framing to bound-check and emit. An -optional-data list's encoder begin hook sets the count as well; its +optional-data list's encoder does not read the count and its decoder never fills it. Once a begin hook has succeeded its end hook runs, so that it can release what begin took; the end hook receives the running success flag. diff --git a/tools/net/sunrpc/xdrgen/templates/C/struct/encoder/aggregate_optional.j2 b/tools/net/sunrpc/xdrgen/templates/C/struct/encoder/aggregate_optional.j2 index d45b823225f7..4f35b6976109 100644 --- a/tools/net/sunrpc/xdrgen/templates/C/struct/encoder/aggregate_optional.j2 +++ b/tools/net/sunrpc/xdrgen/templates/C/struct/encoder/aggregate_optional.j2 @@ -12,13 +12,11 @@ if (!{{ hook }}_encode_begin(&cursor)) return false; - for (cursor.index = 0; cursor.index < cursor.count; cursor.index++) { + for (cursor.index = 0; ; cursor.index++) { {{ classifier }}{{ c_type }} element = {}; - if (!{{ hook }}_encode(&cursor, &element)) { - ok = false; + if (!{{ hook }}_encode(&cursor, &element)) break; - } if (!xdrgen_encode_{{ type }}(xdr, &element)) { ok = false; break; -- 2.55.0