diff mbox series

[v14,03/25] nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h

Message ID 20240829010424.83693-4-snitzer@kernel.org (mailing list archive)
State New
Headers show
Series nfs/nfsd: add support for LOCALIO | expand

Commit Message

Mike Snitzer Aug. 29, 2024, 1:03 a.m. UTC
Eliminates duplicate functions in various files to allow for
additional callers.

Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
 fs/nfs/flexfilelayout/flexfilelayout.c |  6 ------
 fs/nfs/nfs4xdr.c                       | 13 -------------
 include/linux/nfs_xdr.h                | 20 +++++++++++++++++++-
 3 files changed, 19 insertions(+), 20 deletions(-)

Comments

Jeff Layton Aug. 29, 2024, 2:19 p.m. UTC | #1
On Wed, 2024-08-28 at 21:03 -0400, Mike Snitzer wrote:
> Eliminates duplicate functions in various files to allow for
> additional callers.
> 
> Reviewed-by: NeilBrown <neilb@suse.de>
> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
> ---
>  fs/nfs/flexfilelayout/flexfilelayout.c |  6 ------
>  fs/nfs/nfs4xdr.c                       | 13 -------------
>  include/linux/nfs_xdr.h                | 20 +++++++++++++++++++-
>  3 files changed, 19 insertions(+), 20 deletions(-)
> 
> diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
> index 39ba9f4208aa..d4d551ffea7b 100644
> --- a/fs/nfs/flexfilelayout/flexfilelayout.c
> +++ b/fs/nfs/flexfilelayout/flexfilelayout.c
> @@ -2086,12 +2086,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/nfs4xdr.c b/fs/nfs/nfs4xdr.c
> index 971305bdaecb..6bf2d44e5d4e 100644
> --- a/fs/nfs/nfs4xdr.c
> +++ b/fs/nfs/nfs4xdr.c
> @@ -972,11 +972,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);
> @@ -4406,14 +4401,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/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
> index 45623af3e7b8..5e93fbfb785a 100644
> --- a/include/linux/nfs_xdr.h
> +++ b/include/linux/nfs_xdr.h
> @@ -1853,6 +1853,24 @@ struct nfs_rpc_ops {
>  	void	(*disable_swap)(struct inode *inode);
>  };
>  
> +/*
> + * 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
>   */
> @@ -1866,4 +1884,4 @@ extern const struct rpc_version nfs_version4;
>  extern const struct rpc_version nfsacl_version3;
>  extern const struct rpc_program nfsacl_program;
>  
> -#endif
> +#endif /* _LINUX_NFS_XDR_H */

Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 39ba9f4208aa..d4d551ffea7b 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -2086,12 +2086,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/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 971305bdaecb..6bf2d44e5d4e 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -972,11 +972,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);
@@ -4406,14 +4401,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/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 45623af3e7b8..5e93fbfb785a 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -1853,6 +1853,24 @@  struct nfs_rpc_ops {
 	void	(*disable_swap)(struct inode *inode);
 };
 
+/*
+ * 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
  */
@@ -1866,4 +1884,4 @@  extern const struct rpc_version nfs_version4;
 extern const struct rpc_version nfsacl_version3;
 extern const struct rpc_program nfsacl_program;
 
-#endif
+#endif /* _LINUX_NFS_XDR_H */