From patchwork Wed Jun 19 20:40:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 13704524 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 1ADBB15A846 for ; Wed, 19 Jun 2024 20:40: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=1718829652; cv=none; b=JlIzb3yN+p88UvxuHemkJy8/t37hMV++sKEhBARlXbS/6BXAOeP2G910FKIDki0D/o3pwXup8HYC9NdIi6C4szhX71y+2jIiYX5K2YYe8lP0Q+MjOuzPy5196UmSX9wXemH8PPvN6X59iHrwvkcboQOgHlgSQaobk3wkxe/6Avw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718829652; c=relaxed/simple; bh=gSkt/DMf7b/snDh0eNiJ4sFWKRcUs06jm3gDCgN8PoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J5xhrsZuvPcivjR4QPKxMXGPp9z6mzya+VdGCiJV3b/PhdkBwjdidayuNnmRJm691QQGoOH1s3lE1WeKqXdQx6dagXusAkypATroCMSybeLEaEXLz37ag1oXIhxiaqyaeP+PgFc6jpicCIL1k3XQ0LR76fj+KyEDVOR6CQ2pTTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tN1V9rPH; 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="tN1V9rPH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67C39C4AF07; Wed, 19 Jun 2024 20:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718829651; bh=gSkt/DMf7b/snDh0eNiJ4sFWKRcUs06jm3gDCgN8PoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tN1V9rPHrH6LfY5vd4omPtsMZkY9OkEg/AJGx10HhKxAWn7FeSOor7ANbOZJ2jgGD MrqVGvniJJY6+Djypw7LUAODaA18HkwZWvVWoCUmowxeMnWIjid2H6Iwy2bmwjl11G VP5uJR7Odaoth3UNGz985fkRcCwgunw1Shrz0cWSR4zKkpAWli5ScP0LdsxXfQGsah zPuVeHlnBqSEQaj0/iT8xQjpy+94KU/HNBalJKfAC48Dht3I0l/1dceyqAUX7+UZRj rjZuCmpLGy4z9T+/VYSsk9Pmuz0DA6QeuLMWlVve58dy7bEeMwVcxOKOK9K6NlL30W Fb9gUbyHYkIbw== From: Mike Snitzer To: linux-nfs@vger.kernel.org Cc: Jeff Layton , Chuck Lever , Trond Myklebust , NeilBrown , snitzer@hammerspace.com Subject: [PATCH v6 13/18] nfs/nfsd: consolidate {encode,decode}_opaque_fixed in nfs_xdr.h Date: Wed, 19 Jun 2024 16:40:27 -0400 Message-ID: <20240619204032.93740-14-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240619204032.93740-1-snitzer@kernel.org> References: <20240619204032.93740-1-snitzer@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Eliminates duplicate functions in various files. Signed-off-by: Mike Snitzer --- fs/nfs/flexfilelayout/flexfilelayout.c | 6 ------ fs/nfs/nfs3xdr.c | 9 --------- fs/nfs/nfs4xdr.c | 13 ------------- fs/nfsd/localio.c | 7 ++----- include/linux/nfs_xdr.h | 20 +++++++++++++++++++- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index ec6aaa110a7b..8b9096ad0663 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -2185,12 +2185,6 @@ static int ff_layout_encode_ioerr(struct xdr_stream *xdr, return ff_layout_encode_ds_ioerr(xdr, &ff_args->errors); } -static void -encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) -{ - WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); -} - static void ff_layout_encode_ff_iostat_head(struct xdr_stream *xdr, const nfs4_stateid *stateid, diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c index d2a17ecd12b8..95a2fb0733ae 100644 --- a/fs/nfs/nfs3xdr.c +++ b/fs/nfs/nfs3xdr.c @@ -2591,15 +2591,6 @@ static void nfs3_xdr_enc_getuuidargs(struct rpc_rqst *req, /* void function */ } -// FIXME: factor out from fs/nfs/nfs4xdr.c -static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) -{ - ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); - if (unlikely(ret < 0)) - return -EIO; - return 0; -} - static inline int nfs3_decode_getuuidresok(struct xdr_stream *xdr, struct nfs_getuuidres *result) { diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index d3b4fa3245f0..6b35b1d7d7ce 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -968,11 +968,6 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) return p; } -static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) -{ - WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); -} - static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) { WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0); @@ -4352,14 +4347,6 @@ static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) return 0; } -static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) -{ - ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); - if (unlikely(ret < 0)) - return -EIO; - return 0; -} - static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) { return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE); diff --git a/fs/nfsd/localio.c b/fs/nfsd/localio.c index 46b66e43b81b..4d4ff622133c 100644 --- a/fs/nfsd/localio.c +++ b/fs/nfsd/localio.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include "nfsd.h" @@ -275,11 +277,6 @@ static __be32 nfsd_proc_getuuid(struct svc_rqst *rqstp) #define NFS_getuuid_sz XDR_QUADLEN(UUID_SIZE) -static inline void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) -{ - WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); -} - static void encode_uuid(struct xdr_stream *xdr, uuid_t *src_uuid) { u8 uuid[UUID_SIZE]; diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index 2a438f4c2d6d..daa4115f6be6 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1826,6 +1826,24 @@ struct nfs_rpc_ops { void (*init_localioclient)(struct nfs_client *); }; +/* + * Helper functions used by NFS client and/or server + */ +static inline void encode_opaque_fixed(struct xdr_stream *xdr, + const void *buf, size_t len) +{ + WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); +} + +static inline int decode_opaque_fixed(struct xdr_stream *xdr, + void *buf, size_t len) +{ + ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); + if (unlikely(ret < 0)) + return -EIO; + return 0; +} + /* * Function vectors etc. for the NFS client */ @@ -1844,4 +1862,4 @@ extern const struct rpc_program nfslocalio_program3; extern const struct rpc_version nfslocalio_version4; extern const struct rpc_program nfslocalio_program4; -#endif +#endif /* _LINUX_NFS_XDR_H */