Skip to content

Commit c645a88

Browse files
neilbrownJ. Bruce Fields
authored andcommitted
NFSD: drop support for ancient filehandles
Filehandles not in the "new" or "version 1" format have not been handed out for new mounts since Linux 2.4 which was released 20 years ago. I think it is safe to say that no such file handles are still in use, and that we can drop support for them. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent ef5825e commit c645a88

File tree

2 files changed

+54
-140
lines changed

2 files changed

+54
-140
lines changed

fs/nfsd/nfsfh.c

Lines changed: 51 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ static inline __be32 check_pseudo_root(struct svc_rqst *rqstp,
154154
static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
155155
{
156156
struct knfsd_fh *fh = &fhp->fh_handle;
157-
struct fid *fid = NULL, sfid;
157+
struct fid *fid = NULL;
158158
struct svc_export *exp;
159159
struct dentry *dentry;
160160
int fileid_type;
161161
int data_left = fh->fh_size/4;
162+
int len;
162163
__be32 error;
163164

164165
error = nfserr_stale;
@@ -167,48 +168,35 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
167168
if (rqstp->rq_vers == 4 && fh->fh_size == 0)
168169
return nfserr_nofilehandle;
169170

170-
if (fh->fh_version == 1) {
171-
int len;
172-
173-
if (--data_left < 0)
174-
return error;
175-
if (fh->fh_auth_type != 0)
176-
return error;
177-
len = key_len(fh->fh_fsid_type) / 4;
178-
if (len == 0)
179-
return error;
180-
if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
181-
/* deprecated, convert to type 3 */
182-
len = key_len(FSID_ENCODE_DEV)/4;
183-
fh->fh_fsid_type = FSID_ENCODE_DEV;
184-
/*
185-
* struct knfsd_fh uses host-endian fields, which are
186-
* sometimes used to hold net-endian values. This
187-
* confuses sparse, so we must use __force here to
188-
* keep it from complaining.
189-
*/
190-
fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl((__force __be32)fh->fh_fsid[0]),
191-
ntohl((__force __be32)fh->fh_fsid[1])));
192-
fh->fh_fsid[1] = fh->fh_fsid[2];
193-
}
194-
data_left -= len;
195-
if (data_left < 0)
196-
return error;
197-
exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_fsid);
198-
fid = (struct fid *)(fh->fh_fsid + len);
199-
} else {
200-
__u32 tfh[2];
201-
dev_t xdev;
202-
ino_t xino;
203-
204-
if (fh->fh_size != NFS_FHSIZE)
205-
return error;
206-
/* assume old filehandle format */
207-
xdev = old_decode_dev(fh->ofh_xdev);
208-
xino = u32_to_ino_t(fh->ofh_xino);
209-
mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
210-
exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
171+
if (fh->fh_version != 1)
172+
return error;
173+
174+
if (--data_left < 0)
175+
return error;
176+
if (fh->fh_auth_type != 0)
177+
return error;
178+
len = key_len(fh->fh_fsid_type) / 4;
179+
if (len == 0)
180+
return error;
181+
if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
182+
/* deprecated, convert to type 3 */
183+
len = key_len(FSID_ENCODE_DEV)/4;
184+
fh->fh_fsid_type = FSID_ENCODE_DEV;
185+
/*
186+
* struct knfsd_fh uses host-endian fields, which are
187+
* sometimes used to hold net-endian values. This
188+
* confuses sparse, so we must use __force here to
189+
* keep it from complaining.
190+
*/
191+
fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl((__force __be32)fh->fh_fsid[0]),
192+
ntohl((__force __be32)fh->fh_fsid[1])));
193+
fh->fh_fsid[1] = fh->fh_fsid[2];
211194
}
195+
data_left -= len;
196+
if (data_left < 0)
197+
return error;
198+
exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_fsid);
199+
fid = (struct fid *)(fh->fh_fsid + len);
212200

213201
error = nfserr_stale;
214202
if (IS_ERR(exp)) {
@@ -253,18 +241,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
253241
if (rqstp->rq_vers > 2)
254242
error = nfserr_badhandle;
255243

256-
if (fh->fh_version != 1) {
257-
sfid.i32.ino = fh->ofh_ino;
258-
sfid.i32.gen = fh->ofh_generation;
259-
sfid.i32.parent_ino = fh->ofh_dirino;
260-
fid = &sfid;
261-
data_left = 3;
262-
if (fh->ofh_dirino == 0)
263-
fileid_type = FILEID_INO32_GEN;
264-
else
265-
fileid_type = FILEID_INO32_GEN_PARENT;
266-
} else
267-
fileid_type = fh->fh_fileid_type;
244+
fileid_type = fh->fh_fileid_type;
268245

269246
if (fileid_type == FILEID_ROOT)
270247
dentry = dget(exp->ex_path.dentry);
@@ -452,20 +429,6 @@ static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
452429
}
453430
}
454431

455-
/*
456-
* for composing old style file handles
457-
*/
458-
static inline void _fh_update_old(struct dentry *dentry,
459-
struct svc_export *exp,
460-
struct knfsd_fh *fh)
461-
{
462-
fh->ofh_ino = ino_t_to_u32(d_inode(dentry)->i_ino);
463-
fh->ofh_generation = d_inode(dentry)->i_generation;
464-
if (d_is_dir(dentry) ||
465-
(exp->ex_flags & NFSEXP_NOSUBTREECHECK))
466-
fh->ofh_dirino = 0;
467-
}
468-
469432
static bool is_root_export(struct svc_export *exp)
470433
{
471434
return exp->ex_path.dentry == exp->ex_path.dentry->d_sb->s_root;
@@ -562,9 +525,6 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
562525
/* ref_fh is a reference file handle.
563526
* if it is non-null and for the same filesystem, then we should compose
564527
* a filehandle which is of the same version, where possible.
565-
* Currently, that means that if ref_fh->fh_handle.fh_version == 0xca
566-
* Then create a 32byte filehandle using nfs_fhbase_old
567-
*
568528
*/
569529

570530
struct inode * inode = d_inode(dentry);
@@ -600,35 +560,21 @@ fh_compose(struct svc_fh *fhp, struct svc_export *exp, struct dentry *dentry,
600560
fhp->fh_dentry = dget(dentry); /* our internal copy */
601561
fhp->fh_export = exp_get(exp);
602562

603-
if (fhp->fh_handle.fh_version == 0xca) {
604-
/* old style filehandle please */
605-
memset(&fhp->fh_handle.fh_base, 0, NFS_FHSIZE);
606-
fhp->fh_handle.fh_size = NFS_FHSIZE;
607-
fhp->fh_handle.ofh_dcookie = 0xfeebbaca;
608-
fhp->fh_handle.ofh_dev = old_encode_dev(ex_dev);
609-
fhp->fh_handle.ofh_xdev = fhp->fh_handle.ofh_dev;
610-
fhp->fh_handle.ofh_xino =
611-
ino_t_to_u32(d_inode(exp->ex_path.dentry)->i_ino);
612-
fhp->fh_handle.ofh_dirino = ino_t_to_u32(parent_ino(dentry));
613-
if (inode)
614-
_fh_update_old(dentry, exp, &fhp->fh_handle);
615-
} else {
616-
fhp->fh_handle.fh_size =
617-
key_len(fhp->fh_handle.fh_fsid_type) + 4;
618-
fhp->fh_handle.fh_auth_type = 0;
619-
620-
mk_fsid(fhp->fh_handle.fh_fsid_type,
621-
fhp->fh_handle.fh_fsid,
622-
ex_dev,
623-
d_inode(exp->ex_path.dentry)->i_ino,
624-
exp->ex_fsid, exp->ex_uuid);
625-
626-
if (inode)
627-
_fh_update(fhp, exp, dentry);
628-
if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID) {
629-
fh_put(fhp);
630-
return nfserr_opnotsupp;
631-
}
563+
fhp->fh_handle.fh_size =
564+
key_len(fhp->fh_handle.fh_fsid_type) + 4;
565+
fhp->fh_handle.fh_auth_type = 0;
566+
567+
mk_fsid(fhp->fh_handle.fh_fsid_type,
568+
fhp->fh_handle.fh_fsid,
569+
ex_dev,
570+
d_inode(exp->ex_path.dentry)->i_ino,
571+
exp->ex_fsid, exp->ex_uuid);
572+
573+
if (inode)
574+
_fh_update(fhp, exp, dentry);
575+
if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID) {
576+
fh_put(fhp);
577+
return nfserr_opnotsupp;
632578
}
633579

634580
return 0;
@@ -649,16 +595,12 @@ fh_update(struct svc_fh *fhp)
649595
dentry = fhp->fh_dentry;
650596
if (d_really_is_negative(dentry))
651597
goto out_negative;
652-
if (fhp->fh_handle.fh_version != 1) {
653-
_fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
654-
} else {
655-
if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
656-
return 0;
598+
if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
599+
return 0;
657600

658-
_fh_update(fhp, fhp->fh_export, dentry);
659-
if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID)
660-
return nfserr_opnotsupp;
661-
}
601+
_fh_update(fhp, fhp->fh_export, dentry);
602+
if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID)
603+
return nfserr_opnotsupp;
662604
return 0;
663605
out_bad:
664606
printk(KERN_ERR "fh_update: fh not verified!\n");

fs/nfsd/nfsfh.h

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,7 @@
1414
#include <linux/exportfs.h>
1515
#include <linux/nfs4.h>
1616

17-
18-
/*
19-
* This is the old "dentry style" Linux NFSv2 file handle.
20-
*
21-
* The xino and xdev fields are currently used to transport the
22-
* ino/dev of the exported inode.
23-
*/
24-
struct nfs_fhbase_old {
25-
u32 fb_dcookie; /* dentry cookie - always 0xfeebbaca */
26-
u32 fb_ino; /* our inode number */
27-
u32 fb_dirino; /* dir inode number, 0 for directories */
28-
u32 fb_dev; /* our device */
29-
u32 fb_xdev;
30-
u32 fb_xino;
31-
u32 fb_generation;
32-
};
33-
3417
/*
35-
* This is the new flexible, extensible style NFSv2/v3/v4 file handle.
36-
*
3718
* The file handle starts with a sequence of four-byte words.
3819
* The first word contains a version number (1) and three descriptor bytes
3920
* that tell how the remaining 3 variable length fields should be handled.
@@ -57,15 +38,15 @@ struct nfs_fhbase_old {
5738
* 6 - 16 byte uuid
5839
* 7 - 8 byte inode number and 16 byte uuid
5940
*
60-
* The fileid_type identified how the file within the filesystem is encoded.
41+
* The fileid_type identifies how the file within the filesystem is encoded.
6142
* The values for this field are filesystem specific, exccept that
6243
* filesystems must not use the values '0' or '0xff'. 'See enum fid_type'
6344
* in include/linux/exportfs.h for currently registered values.
6445
*/
6546
struct nfs_fhbase_new {
6647
union {
6748
struct {
68-
u8 fb_version_aux; /* == 1, even => nfs_fhbase_old */
49+
u8 fb_version_aux; /* == 1 */
6950
u8 fb_auth_type_aux;
7051
u8 fb_fsid_type_aux;
7152
u8 fb_fileid_type_aux;
@@ -74,7 +55,7 @@ struct nfs_fhbase_new {
7455
/* u32 fb_fileid[0]; floating */
7556
};
7657
struct {
77-
u8 fb_version; /* == 1, even => nfs_fhbase_old */
58+
u8 fb_version; /* == 1 */
7859
u8 fb_auth_type;
7960
u8 fb_fsid_type;
8061
u8 fb_fileid_type;
@@ -89,20 +70,11 @@ struct knfsd_fh {
8970
* a new file handle
9071
*/
9172
union {
92-
struct nfs_fhbase_old fh_old;
9373
u32 fh_pad[NFS4_FHSIZE/4];
9474
struct nfs_fhbase_new fh_new;
9575
} fh_base;
9676
};
9777

98-
#define ofh_dcookie fh_base.fh_old.fb_dcookie
99-
#define ofh_ino fh_base.fh_old.fb_ino
100-
#define ofh_dirino fh_base.fh_old.fb_dirino
101-
#define ofh_dev fh_base.fh_old.fb_dev
102-
#define ofh_xdev fh_base.fh_old.fb_xdev
103-
#define ofh_xino fh_base.fh_old.fb_xino
104-
#define ofh_generation fh_base.fh_old.fb_generation
105-
10678
#define fh_version fh_base.fh_new.fb_version
10779
#define fh_fsid_type fh_base.fh_new.fb_fsid_type
10880
#define fh_auth_type fh_base.fh_new.fb_auth_type

0 commit comments

Comments
 (0)