Skip to content

Commit 5409e46

Browse files
Christoph HellwigJ. Bruce Fields
authored andcommitted
nfsd: clean up fh_auth usage
Use fh_fsid when reffering to the fsid part of the filehandle. The variable length auth field envisioned in nfsfh wasn't ever implemented. Also clean up some lose ends around this and document the file handle format better. Btw, why do we even export nfsfh.h to userspace? The file handle very much is kernel private, and nothing in nfs-utils include the header either. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent ecc7455 commit 5409e46

2 files changed

Lines changed: 16 additions & 36 deletions

File tree

fs/nfsd/nfsfh.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
169169
data_left -= len;
170170
if (data_left < 0)
171171
return error;
172-
exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_auth);
173-
fid = (struct fid *)(fh->fh_auth + len);
172+
exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_fsid);
173+
fid = (struct fid *)(fh->fh_fsid + len);
174174
} else {
175175
__u32 tfh[2];
176176
dev_t xdev;
@@ -385,7 +385,7 @@ static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
385385
{
386386
if (dentry != exp->ex_path.dentry) {
387387
struct fid *fid = (struct fid *)
388-
(fhp->fh_handle.fh_auth + fhp->fh_handle.fh_size/4 - 1);
388+
(fhp->fh_handle.fh_fsid + fhp->fh_handle.fh_size/4 - 1);
389389
int maxsize = (fhp->fh_maxsize - fhp->fh_handle.fh_size)/4;
390390
int subtreecheck = !(exp->ex_flags & NFSEXP_NOSUBTREECHECK);
391391

@@ -513,7 +513,6 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
513513
*/
514514

515515
struct inode * inode = dentry->d_inode;
516-
__u32 *datap;
517516
dev_t ex_dev = exp_sb(exp)->s_dev;
518517

519518
dprintk("nfsd: fh_compose(exp %02x:%02x/%ld %pd2, ino=%ld)\n",
@@ -557,17 +556,16 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
557556
if (inode)
558557
_fh_update_old(dentry, exp, &fhp->fh_handle);
559558
} else {
560-
int len;
559+
fhp->fh_handle.fh_size =
560+
key_len(fhp->fh_handle.fh_fsid_type) + 4;
561561
fhp->fh_handle.fh_auth_type = 0;
562-
datap = fhp->fh_handle.fh_auth+0;
563-
mk_fsid(fhp->fh_handle.fh_fsid_type, datap, ex_dev,
562+
563+
mk_fsid(fhp->fh_handle.fh_fsid_type,
564+
fhp->fh_handle.fh_fsid,
565+
ex_dev,
564566
exp->ex_path.dentry->d_inode->i_ino,
565567
exp->ex_fsid, exp->ex_uuid);
566568

567-
len = key_len(fhp->fh_handle.fh_fsid_type);
568-
datap += len/4;
569-
fhp->fh_handle.fh_size = 4 + len;
570-
571569
if (inode)
572570
_fh_update(fhp, exp, dentry);
573571
if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID) {

include/uapi/linux/nfsd/nfsfh.h

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/*
2-
* include/linux/nfsd/nfsfh.h
3-
*
42
* This file describes the layout of the file handles as passed
53
* over the wire.
64
*
7-
* Earlier versions of knfsd used to sign file handles using keyed MD5
8-
* or SHA. I've removed this code, because it doesn't give you more
9-
* security than blocking external access to port 2049 on your firewall.
10-
*
115
* Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
126
*/
137

@@ -37,7 +31,7 @@ struct nfs_fhbase_old {
3731
};
3832

3933
/*
40-
* This is the new flexible, extensible style NFSv2/v3 file handle.
34+
* This is the new flexible, extensible style NFSv2/v3/v4 file handle.
4135
* by Neil Brown <neilb@cse.unsw.edu.au> - March 2000
4236
*
4337
* The file handle starts with a sequence of four-byte words.
@@ -47,14 +41,7 @@ struct nfs_fhbase_old {
4741
*
4842
* All four-byte values are in host-byte-order.
4943
*
50-
* The auth_type field specifies how the filehandle can be authenticated
51-
* This might allow a file to be confirmed to be in a writable part of a
52-
* filetree without checking the path from it up to the root.
53-
* Current values:
54-
* 0 - No authentication. fb_auth is 0 bytes long
55-
* Possible future values:
56-
* 1 - 4 bytes taken from MD5 hash of the remainer of the file handle
57-
* prefixed by a secret and with the important export flags.
44+
* The auth_type field is deprecated and must be set to 0.
5845
*
5946
* The fsid_type identifies how the filesystem (or export point) is
6047
* encoded.
@@ -71,14 +58,9 @@ struct nfs_fhbase_old {
7158
* 7 - 8 byte inode number and 16 byte uuid
7259
*
7360
* The fileid_type identified how the file within the filesystem is encoded.
74-
* This is (will be) passed to, and set by, the underlying filesystem if it supports
75-
* filehandle operations. The filesystem must not use the value '0' or '0xff' and may
76-
* only use the values 1 and 2 as defined below:
77-
* Current values:
78-
* 0 - The root, or export point, of the filesystem. fb_fileid is 0 bytes.
79-
* 1 - 32bit inode number, 32 bit generation number.
80-
* 2 - 32bit inode number, 32 bit generation number, 32 bit parent directory inode number.
81-
*
61+
* The values for this field are filesystem specific, exccept that
62+
* filesystems must not use the values '0' or '0xff'. 'See enum fid_type'
63+
* in include/linux/exportfs.h for currently registered values.
8264
*/
8365
struct nfs_fhbase_new {
8466
__u8 fb_version; /* == 1, even => nfs_fhbase_old */
@@ -114,9 +96,9 @@ struct knfsd_fh {
11496
#define fh_fsid_type fh_base.fh_new.fb_fsid_type
11597
#define fh_auth_type fh_base.fh_new.fb_auth_type
11698
#define fh_fileid_type fh_base.fh_new.fb_fileid_type
117-
#define fh_auth fh_base.fh_new.fb_auth
11899
#define fh_fsid fh_base.fh_new.fb_auth
119100

120-
101+
/* Do not use, provided for userspace compatiblity. */
102+
#define fh_auth fh_base.fh_new.fb_auth
121103

122104
#endif /* _UAPI_LINUX_NFSD_FH_H */

0 commit comments

Comments
 (0)