All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Move NFS filehandle defs into separate include
@ 2026-07-20 14:14 Chuck Lever
  2026-07-20 14:14 ` [PATCH 1/3] NFS: Add linux/nfs_fh.h Chuck Lever
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chuck Lever @ 2026-07-20 14:14 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey; +Cc: linux-nfs

struct nfs_fh is defined in linux/nfs.h, which also pulls in cred.h,
a pair of sunrpc headers, and uapi/linux/nfs.h. A consumer that
wants nothing but the file handle definition drags all of those
items with it.

Relocate struct nfs_fh and its helpers to a new minimal header:
linux/nfs_fh.h. This series introduces two consumers for this
header. More will follow in subsequent series.

Chuck Lever (3):
  NFS: Add linux/nfs_fh.h
  lockd: Switch linux/nfs.h to linux/nfs_fh.h
  NFSD: Use struct knfsd_fh in struct pnfs_ff_layout

 fs/lockd/svc.c              |  1 -
 fs/lockd/trace.h            |  1 -
 fs/lockd/xdr.h              |  2 +-
 fs/nfsd/flexfilelayout.c    |  3 +-
 fs/nfsd/flexfilelayoutxdr.c |  4 +--
 fs/nfsd/flexfilelayoutxdr.h |  3 +-
 include/linux/nfs.h         | 39 ++---------------------
 include/linux/nfs_fh.h      | 63 +++++++++++++++++++++++++++++++++++++
 8 files changed, 71 insertions(+), 45 deletions(-)
 create mode 100644 include/linux/nfs_fh.h

-- 
2.54.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] NFS: Add linux/nfs_fh.h
  2026-07-20 14:14 [PATCH 0/3] Move NFS filehandle defs into separate include Chuck Lever
@ 2026-07-20 14:14 ` Chuck Lever
  2026-07-20 14:14 ` [PATCH 2/3] lockd: Switch linux/nfs.h to linux/nfs_fh.h Chuck Lever
  2026-07-20 14:14 ` [PATCH 3/3] NFSD: Use struct knfsd_fh in struct pnfs_ff_layout Chuck Lever
  2 siblings, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2026-07-20 14:14 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey; +Cc: linux-nfs

Plenty of spots around the kernel need the full definition of struct
nfs_fh but not the cred, sunrpc, and uapi dependencies that
linux/nfs.h pulls in along with it.

Relocate struct nfs_fh to its own header, and include that header in
linux/nfs.h so existing consumers keep building. Over time, consumers
can then replace

  #include <linux/nfs.h>

with

  #include <linux/nfs_fh.h>

While relocating the code, add kernel-doc comments for the FH
operations and convert nfs_compare_fh() to return bool.

Signed-off-by: Chuck Lever <cel@kernel.org>
---
 include/linux/nfs.h    | 39 ++------------------------
 include/linux/nfs_fh.h | 63 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 37 deletions(-)
 create mode 100644 include/linux/nfs_fh.h

diff --git a/include/linux/nfs.h b/include/linux/nfs.h
index 0906a0b40c6a..0e2a0b1e3061 100644
--- a/include/linux/nfs.h
+++ b/include/linux/nfs.h
@@ -11,8 +11,8 @@
 #include <linux/cred.h>
 #include <linux/sunrpc/auth.h>
 #include <linux/sunrpc/msg_prot.h>
-#include <linux/string.h>
-#include <linux/crc32.h>
+#include <linux/nfs_fh.h>
+
 #include <uapi/linux/nfs.h>
 
 /* The LOCALIO program is entirely private to Linux and is
@@ -22,30 +22,6 @@
 #define LOCALIOPROC_NULL		0
 #define LOCALIOPROC_UUID_IS_LOCAL	1
 
-/*
- * This is the kernel NFS client file handle representation
- */
-#define NFS_MAXFHSIZE		128
-struct nfs_fh {
-	unsigned short		size;
-	unsigned char		data[NFS_MAXFHSIZE];
-};
-
-/*
- * Returns a zero iff the size and data fields match.
- * Checks only "size" bytes in the data field.
- */
-static inline int nfs_compare_fh(const struct nfs_fh *a, const struct nfs_fh *b)
-{
-	return a->size != b->size || memcmp(a->data, b->data, a->size) != 0;
-}
-
-static inline void nfs_copy_fh(struct nfs_fh *target, const struct nfs_fh *source)
-{
-	target->size = source->size;
-	memcpy(target->data, source->data, source->size);
-}
-
 enum nfs3_stable_how {
 	NFS_UNSTABLE = 0,
 	NFS_DATA_SYNC = 1,
@@ -55,15 +31,4 @@ enum nfs3_stable_how {
 	NFS_INVALID_STABLE_HOW = -1
 };
 
-/**
- * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
- * @fh - pointer to filehandle
- *
- * returns a crc32 hash for the filehandle that is compatible with
- * the one displayed by "wireshark".
- */
-static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
-{
-	return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
-}
 #endif /* _LINUX_NFS_H */
diff --git a/include/linux/nfs_fh.h b/include/linux/nfs_fh.h
new file mode 100644
index 000000000000..49dfc5ec60fe
--- /dev/null
+++ b/include/linux/nfs_fh.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * struct nfs_fh is an NFS version-agnostic data structure that
+ * stores an NFS file handle. It is also commonly used in NFS
+ * related APIs.
+ */
+#ifndef _LINUX_NFS_FH_H
+#define _LINUX_NFS_FH_H
+
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/crc32.h>
+
+/*
+ * The largest file handle size today is an NFSv4 file handle,
+ * which can be up to 128 octets long.
+ */
+#define NFS_MAXFHSIZE		128
+struct nfs_fh {
+	unsigned short		size;
+	unsigned char		data[NFS_MAXFHSIZE];
+};
+
+/**
+ * nfs_compare_fh - Compare two NFS file handles
+ * @a: An NFS file handle to be compared
+ * @b: An NFS file handle to be compared
+ *
+ * Checks only "size" bytes in each data field.
+ *
+ * Return: %false if the two file handles are equal, otherwise %true
+ */
+static inline bool nfs_compare_fh(const struct nfs_fh *a, const struct nfs_fh *b)
+{
+	return a->size != b->size || memcmp(a->data, b->data, a->size) != 0;
+}
+
+/**
+ * nfs_copy_fh - Copy an NFS file handle
+ * @target: Destination file handle
+ * @source: Source file handle
+ *
+ * Copies source->size bytes of file handle data into target.
+ */
+static inline void nfs_copy_fh(struct nfs_fh *target, const struct nfs_fh *source)
+{
+	target->size = source->size;
+	memcpy(target->data, source->data, source->size);
+}
+
+/**
+ * nfs_fhandle_hash - Calculate the crc32 hash for the filehandle
+ * @fh: An NFS file handle to hash
+ *
+ * Return: a crc32 hash for the filehandle that is compatible with
+ * the one displayed by "wireshark"
+ */
+static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
+{
+	return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
+}
+
+#endif /* _LINUX_NFS_FH_H */
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] lockd: Switch linux/nfs.h to linux/nfs_fh.h
  2026-07-20 14:14 [PATCH 0/3] Move NFS filehandle defs into separate include Chuck Lever
  2026-07-20 14:14 ` [PATCH 1/3] NFS: Add linux/nfs_fh.h Chuck Lever
@ 2026-07-20 14:14 ` Chuck Lever
  2026-07-20 14:14 ` [PATCH 3/3] NFSD: Use struct knfsd_fh in struct pnfs_ff_layout Chuck Lever
  2 siblings, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2026-07-20 14:14 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey; +Cc: linux-nfs

lockd references "struct nfs_fh" but none of the other definitions
in linux/nfs.h. That header also pulls in cred.h, several sunrpc
headers, and uapi/linux/nfs.h, none of which lockd needs. A new
linux/nfs_fh.h provides "struct nfs_fh" and its helpers without the
rest of that surface.

Switch lockd's xdr.h to linux/nfs_fh.h, and drop the now-redundant
linux/nfs.h includes from svc.c and trace.h.

Signed-off-by: Chuck Lever <cel@kernel.org>
---
 fs/lockd/svc.c   | 1 -
 fs/lockd/trace.h | 1 -
 fs/lockd/xdr.h   | 2 +-
 3 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
index ee90e743064a..f0e1a58c9106 100644
--- a/fs/lockd/svc.c
+++ b/fs/lockd/svc.c
@@ -36,7 +36,6 @@
 #include <net/ip.h>
 #include <net/addrconf.h>
 #include <net/ipv6.h>
-#include <linux/nfs.h>
 
 #include "lockd.h"
 #include "netns.h"
diff --git a/fs/lockd/trace.h b/fs/lockd/trace.h
index a11d04e8c835..1f79955ea0f5 100644
--- a/fs/lockd/trace.h
+++ b/fs/lockd/trace.h
@@ -7,7 +7,6 @@
 
 #include <linux/tracepoint.h>
 #include <linux/crc32.h>
-#include <linux/nfs.h>
 
 #include "lockd.h"
 
diff --git a/fs/lockd/xdr.h b/fs/lockd/xdr.h
index a1126cca98c6..56b9796aa39d 100644
--- a/fs/lockd/xdr.h
+++ b/fs/lockd/xdr.h
@@ -10,7 +10,7 @@
 
 #include <linux/fs.h>
 #include <linux/filelock.h>
-#include <linux/nfs.h>
+#include <linux/nfs_fh.h>
 #include <linux/sunrpc/xdr.h>
 
 #define SM_MAXSTRLEN		1024
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] NFSD: Use struct knfsd_fh in struct pnfs_ff_layout
  2026-07-20 14:14 [PATCH 0/3] Move NFS filehandle defs into separate include Chuck Lever
  2026-07-20 14:14 ` [PATCH 1/3] NFS: Add linux/nfs_fh.h Chuck Lever
  2026-07-20 14:14 ` [PATCH 2/3] lockd: Switch linux/nfs.h to linux/nfs_fh.h Chuck Lever
@ 2026-07-20 14:14 ` Chuck Lever
  2 siblings, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2026-07-20 14:14 UTC (permalink / raw)
  To: NeilBrown, Jeff Layton, Olga Kornievskaia, Dai Ngo, Tom Talpey
  Cc: linux-nfs, Thomas Haynes

The file handle held in struct pnfs_ff_layout is copied directly out
of a struct svc_fh, whose fh_handle member is a struct knfsd_fh.
Storing the layout's copy as struct nfs_fh instead forced an
open-coded field-by-field copy between two unrelated structures.

Hold the layout's file handle in struct knfsd_fh so the copy uses the
canonical fh_copy_shallow() helper and server code no longer reaches
into a separate file handle representation.

Cc: Thomas Haynes <loghyr@hammerspace.com>
Signed-off-by: Chuck Lever <cel@kernel.org>
---
 fs/nfsd/flexfilelayout.c    | 3 +--
 fs/nfsd/flexfilelayoutxdr.c | 4 ++--
 fs/nfsd/flexfilelayoutxdr.h | 3 ++-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/flexfilelayout.c b/fs/nfsd/flexfilelayout.c
index 9f532418cac8..89298e77daa6 100644
--- a/fs/nfsd/flexfilelayout.c
+++ b/fs/nfsd/flexfilelayout.c
@@ -62,8 +62,7 @@ nfsd4_ff_proc_layoutget(struct svc_rqst *rqstp, struct inode *inode,
 	if (error)
 		goto out_error;
 
-	fl->fh.size = fhp->fh_handle.fh_size;
-	memcpy(fl->fh.data, &fhp->fh_handle.fh_raw, fl->fh.size);
+	fh_copy_shallow(&fl->fh, &fhp->fh_handle);
 
 	/* Give whole file layout segments */
 	seg->offset = 0;
diff --git a/fs/nfsd/flexfilelayoutxdr.c b/fs/nfsd/flexfilelayoutxdr.c
index 97d8a28dd3a0..5c48d35f4bd8 100644
--- a/fs/nfsd/flexfilelayoutxdr.c
+++ b/fs/nfsd/flexfilelayoutxdr.c
@@ -31,7 +31,7 @@ nfsd4_ff_encode_layoutget(struct xdr_stream *xdr,
 	struct ff_idmap uid;
 	struct ff_idmap gid;
 
-	fh_len = 4 + xdr_align_size(fl->fh.size);
+	fh_len = 4 + xdr_align_size(fl->fh.fh_size);
 
 	uid.len = sprintf(uid.buf, "%u", from_kuid(&init_user_ns, fl->uid));
 	gid.len = sprintf(gid.buf, "%u", from_kgid(&init_user_ns, fl->gid));
@@ -69,7 +69,7 @@ nfsd4_ff_encode_layoutget(struct xdr_stream *xdr,
 				    sizeof(stateid_opaque_t));
 
 	*p++ = cpu_to_be32(1);			/* single file handle */
-	p = xdr_encode_opaque(p, fl->fh.data, fl->fh.size);
+	p = xdr_encode_opaque(p, fl->fh.fh_raw, fl->fh.fh_size);
 
 	p = xdr_encode_opaque(p, uid.buf, uid.len);
 	p = xdr_encode_opaque(p, gid.buf, gid.len);
diff --git a/fs/nfsd/flexfilelayoutxdr.h b/fs/nfsd/flexfilelayoutxdr.h
index 6d5a1066a903..92752092e2f8 100644
--- a/fs/nfsd/flexfilelayoutxdr.h
+++ b/fs/nfsd/flexfilelayoutxdr.h
@@ -6,6 +6,7 @@
 #define _NFSD_FLEXFILELAYOUTXDR_H 1
 
 #include <linux/inet.h>
+#include "nfsfh.h"
 #include "xdr4.h"
 
 #define FF_FLAGS_NO_LAYOUTCOMMIT 1
@@ -39,7 +40,7 @@ struct pnfs_ff_layout {
 	kgid_t				gid;
 	struct nfsd4_deviceid		deviceid;
 	stateid_t			stateid;
-	struct nfs_fh			fh;
+	struct knfsd_fh			fh;
 };
 
 __be32 nfsd4_ff_encode_getdeviceinfo(struct xdr_stream *xdr,
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-20 14:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 14:14 [PATCH 0/3] Move NFS filehandle defs into separate include Chuck Lever
2026-07-20 14:14 ` [PATCH 1/3] NFS: Add linux/nfs_fh.h Chuck Lever
2026-07-20 14:14 ` [PATCH 2/3] lockd: Switch linux/nfs.h to linux/nfs_fh.h Chuck Lever
2026-07-20 14:14 ` [PATCH 3/3] NFSD: Use struct knfsd_fh in struct pnfs_ff_layout Chuck Lever

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.