Skip to contentSkip to conversation

Move NFS filehandle defs into separate include

PATCH New Chuck Lever 1 participant 4 messages Jul 20

Subsystems (2)
lore
Share & tools
lore

Chuck Lever

author maintainer
#0 lore raw

cover Move NFS filehandle defs into separate include

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
Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH 1/3 NFS: Add linux/nfs_fh.h

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.

---
 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
include/linux/nfs.h +2 -37
index 0906a0b40c6a..0e2a0b1e3061 100644
@@ -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 */
include/linux/nfs_fh.h new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.54.0
author maintainer
#2 lore raw

PATCH 2/3 lockd: Switch linux/nfs.h to linux/nfs_fh.h

In reply to Chuck Lever

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.

---
 fs/lockd/svc.c   | 1 -
 fs/lockd/trace.h | 1 -
 fs/lockd/xdr.h   | 2 +-
 3 files changed, 1 insertion(+), 3 deletions(-)
fs/lockd/svc.c +0 -1
index ee90e743064a..f0e1a58c9106 100644
@@ -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"
fs/lockd/trace.h +0 -1
index a11d04e8c835..1f79955ea0f5 100644
@@ -7,7 +7,6 @@
 
 #include <linux/tracepoint.h>
 #include <linux/crc32.h>
-#include <linux/nfs.h>
 
 #include "lockd.h"
 
fs/lockd/xdr.h +1 -1
index a1126cca98c6..56b9796aa39d 100644
@@ -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
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH 3/3 NFSD: Use struct knfsd_fh in struct pnfs_ff_layout

In reply to Chuck Lever

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.

---
 fs/nfsd/flexfilelayout.c    | 3 +--
 fs/nfsd/flexfilelayoutxdr.c | 4 ++--
 fs/nfsd/flexfilelayoutxdr.h | 3 ++-
 3 files changed, 5 insertions(+), 5 deletions(-)
fs/nfsd/flexfilelayout.c +1 -2
index 9f532418cac8..89298e77daa6 100644
@@ -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;
fs/nfsd/flexfilelayoutxdr.c +2 -2
index 97d8a28dd3a0..5c48d35f4bd8 100644
@@ -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);
fs/nfsd/flexfilelayoutxdr.h +2 -1
index 6d5a1066a903..92752092e2f8 100644
@@ -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,
Signature · 1 line
2.54.0