Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1385432rdb; Mon, 2 Oct 2023 08:03:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdisWTIoDg8YrBfNoNcCVwHgL2JWA2ktm4HcSRDaRgrdiTYsaJIXvqHEYrL8Gl8kDbP3LW X-Received: by 2002:a05:6a21:66cb:b0:160:ec7e:ec07 with SMTP id ze11-20020a056a2166cb00b00160ec7eec07mr10713215pzb.58.1696259033151; Mon, 02 Oct 2023 08:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696259033; cv=none; d=google.com; s=arc-20160816; b=ARNO1zabiKB8Ca8jzrKPPymgLxHbQpEg2V7w0i9BxQx39HSADEmjEIYO0wh35O/JId IL+G/1OWdm4j/Kf3e14gRiaZLt4Q9qXvCGW8vPxUU5BiJO6EC5XBVEOAR8mOuFZyGxp/ vLfrucXV14ViFXzHOgICGR4USp6xpBTlpw8F0CCP3dbXjJzD+SzGK1K1vfvLrW0/VLEz hYA/6iFRI5OsxBP6XvYeGGYP4nnd/T/9fBG9u26f83JR7DPSNGtIbowx39tfOQlgvBGb 5sicApBHPjhEsa6Bs7AtIwl1HRxGjQsMv6Ll22KV6U5Xn5gVCQN82cU5qay8QZNdu0pL V8sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=FAr5ekNjOah/t1cxbB4sLM0/zqMeIJGVKiqHCVxHFVA=; fh=v8a13lpFSZWlL4AptTEJnmXnlqoWXhGCGCgvrcnCT9I=; b=qB+v6/Qwiky073JahYe0k+2r5MS40OFA3zJ2hUtr9P3kwYP+54kpASJzM4xFuC28bq 8phFUFPAVkR6cPUJHAo2LdaDl29Alg2ZcZzjPQeZ7u/IdEex8FCZtOA7A6YYpasq9atk 422jGd8AGwG1zkUSNYk9zvSLJVvaVyEIsLEwnsTCmiqtTR1G0osEdvUeLqAEongFiGEf muWHy/RLrFthp1J6/8joowiODGkCGEcpwHtzlStzg/iUR5u5fL7FS4gaebZpX3oo4+6J uHIEGwn6zAiNwFQYRduqhuxyZlDApbkBC/YqEj3fYvKgo5jqrPMYzwHd6xXI0HTtQfNR ERfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KBbSPnu0; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id cp24-20020a056a00349800b00690ca3d66bbsi26951343pfb.262.2023.10.02.08.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 08:03:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KBbSPnu0; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 625738072824; Mon, 2 Oct 2023 07:51:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237860AbjJBOvm (ORCPT + 99 others); Mon, 2 Oct 2023 10:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237875AbjJBOvl (ORCPT ); Mon, 2 Oct 2023 10:51:41 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FB52B8 for ; Mon, 2 Oct 2023 07:51:38 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BDE7C433C9; Mon, 2 Oct 2023 14:51:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696258298; bh=jSAf2uLBVHRO+A8Zet2h3ZWYDeFN0+UkCxTBIlRDi4Q=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KBbSPnu0O0Fm6ljgQ3W6M2ImXZODM7/o4PiO7MsFUobgWTnQ8gJe2vrtWAUsSh7k+ DtZZ8lMryTAabUgRsHUoiSebICnSsLhWdM81Vza6r60IgE8e2gOYRNipV9d8f+xDMQ FFTTGVit4ueLeqTGOVz8fI9DqlSUP/hbN2/hS1QSRamicMZrSzTQVanGTGLBisoJw/ r1RHc8rBO1S/V7g1sVjZGMN/aJ6ZHeft7q5VJep3Y8d5wl9QGJKwxGOSlxNCDTZDka DtRtYm7vKoabEpG8ATD1yDLuo20PQlt0lKQlvm8Iq0kTOPqYteE+ZOosNISRiH/48W ubAIwp8BvhwIw== Subject: [PATCH v1 4/4] NFSD: Clean up nfsd4_encode_sequence() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Mon, 02 Oct 2023 10:51:37 -0400 Message-ID: <169625829708.1640.1086998477611708664.stgit@klimt.1015granger.net> In-Reply-To: <169625819958.1640.14102064750083176117.stgit@klimt.1015granger.net> References: <169625819958.1640.14102064750083176117.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 02 Oct 2023 07:51:42 -0700 (PDT) From: Chuck Lever De-duplicate open-coded encoding of the sessionid, and convert the rest of the function to use conventional XDR utility functions. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 37 +++++++++++++++++++++++++------------ fs/nfsd/xdr4.h | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 505f397a6e5b..f1f0b707c7d9 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4849,22 +4849,35 @@ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, { struct nfsd4_sequence *seq = &u->sequence; struct xdr_stream *xdr = resp->xdr; - __be32 *p; - p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20); - if (!p) - return nfserr_resource; - p = xdr_encode_opaque_fixed(p, seq->sessionid.data, - NFS4_MAX_SESSIONID_LEN); - *p++ = cpu_to_be32(seq->seqid); - *p++ = cpu_to_be32(seq->slotid); + /* sr_sessionid */ + nfserr = nfsd4_encode_sessionid4(xdr, &seq->sessionid); + if (nfserr != nfs_ok) + return nfserr; + /* sr_sequenceid */ + nfserr = nfsd4_encode_sequenceid4(xdr, seq->seqid); + if (nfserr != nfs_ok) + return nfserr; + /* sr_slotid */ + nfserr = nfsd4_encode_slotid4(xdr, seq->slotid); + if (nfserr != nfs_ok) + return nfserr; /* Note slotid's are numbered from zero: */ - *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */ - *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */ - *p++ = cpu_to_be32(seq->status_flags); + /* sr_highest_slotid */ + nfserr = nfsd4_encode_slotid4(xdr, seq->maxslots - 1); + if (nfserr != nfs_ok) + return nfserr; + /* sr_target_highest_slotid */ + nfserr = nfsd4_encode_slotid4(xdr, seq->maxslots - 1); + if (nfserr != nfs_ok) + return nfserr; + /* sr_status_flags */ + nfserr = nfsd4_encode_uint32_t(xdr, seq->status_flags); + if (nfserr != nfs_ok) + return nfserr; resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */ - return 0; + return nfs_ok; } static __be32 diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 7983eb679ba7..cd124969589e 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -97,6 +97,7 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val) #define nfsd4_encode_mode4(x, v) nfsd4_encode_uint32_t(x, v) #define nfsd4_encode_nfs_lease4(x, v) nfsd4_encode_uint32_t(x, v) #define nfsd4_encode_sequenceid4(x, v) nfsd4_encode_uint32_t(x, v) +#define nfsd4_encode_slotid4(x, v) nfsd4_encode_uint32_t(x, v) /** * nfsd4_encode_uint64_t - Encode an XDR uint64_t type result