Skip to content

Commit 8ad9248

Browse files
neilbrownbrauner
authored andcommitted
nfsd: Use lookup_one() rather than lookup_one_len()
nfsd uses some VFS interfaces (such as vfs_mkdir) which take an explicit mnt_idmap, and it passes &nop_mnt_idmap as nfsd doesn't yet support idmapped mounts. It also uses the lookup_one_len() family of functions which implicitly use &nop_mnt_idmap. This mixture of implicit and explicit could be confusing. When we eventually update nfsd to support idmap mounts it would be best if all places which need an idmap determined from the mount point were similar and easily found. So this patch changes nfsd to use lookup_one(), lookup_one_unlocked(), and lookup_one_positive_unlocked(), passing &nop_mnt_idmap. This has the benefit of removing some uses of the lookup_one_len functions where permission checking is actually needed. Many callers don't care about permission checking and using these function only where permission checking is needed is a valuable simplification. This change requires passing the name in a qstr. Currently this is a little clumsy, but if nfsd is changed to use qstr more broadly it will result in a net improvement. Signed-off-by: NeilBrown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 5741909 commit 8ad9248

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

fs/nfsd/nfs3proc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
284284

285285
inode_lock_nested(inode, I_MUTEX_PARENT);
286286

287-
child = lookup_one_len(argp->name, parent, argp->len);
287+
child = lookup_one(&nop_mnt_idmap,
288+
&QSTR_LEN(argp->name, argp->len),
289+
parent);
288290
if (IS_ERR(child)) {
289291
status = nfserrno(PTR_ERR(child));
290292
goto out;

fs/nfsd/nfs3xdr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,9 @@ compose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,
10011001
} else
10021002
dchild = dget(dparent);
10031003
} else
1004-
dchild = lookup_positive_unlocked(name, dparent, namlen);
1004+
dchild = lookup_one_positive_unlocked(&nop_mnt_idmap,
1005+
&QSTR_LEN(name, namlen),
1006+
dparent);
10051007
if (IS_ERR(dchild))
10061008
return rv;
10071009
if (d_mountpoint(dchild))

fs/nfsd/nfs4proc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
266266

267267
inode_lock_nested(inode, I_MUTEX_PARENT);
268268

269-
child = lookup_one_len(open->op_fname, parent, open->op_fnamelen);
269+
child = lookup_one(&nop_mnt_idmap,
270+
&QSTR_LEN(open->op_fname, open->op_fnamelen),
271+
parent);
270272
if (IS_ERR(child)) {
271273
status = nfserrno(PTR_ERR(child));
272274
goto out;

fs/nfsd/nfs4recover.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
218218
/* lock the parent */
219219
inode_lock(d_inode(dir));
220220

221-
dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
221+
dentry = lookup_one(&nop_mnt_idmap, &QSTR(dname), dir);
222222
if (IS_ERR(dentry)) {
223223
status = PTR_ERR(dentry);
224224
goto out_unlock;
@@ -316,7 +316,8 @@ nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
316316
list_for_each_entry_safe(entry, tmp, &ctx.names, list) {
317317
if (!status) {
318318
struct dentry *dentry;
319-
dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
319+
dentry = lookup_one(&nop_mnt_idmap,
320+
&QSTR(entry->name), dir);
320321
if (IS_ERR(dentry)) {
321322
status = PTR_ERR(dentry);
322323
break;
@@ -339,16 +340,16 @@ nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
339340
}
340341

341342
static int
342-
nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn)
343+
nfsd4_unlink_clid_dir(char *name, struct nfsd_net *nn)
343344
{
344345
struct dentry *dir, *dentry;
345346
int status;
346347

347-
dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);
348+
dprintk("NFSD: nfsd4_unlink_clid_dir. name %s\n", name);
348349

349350
dir = nn->rec_file->f_path.dentry;
350351
inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
351-
dentry = lookup_one_len(name, dir, namlen);
352+
dentry = lookup_one(&nop_mnt_idmap, &QSTR(name), dir);
352353
if (IS_ERR(dentry)) {
353354
status = PTR_ERR(dentry);
354355
goto out_unlock;
@@ -408,7 +409,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
408409
if (status < 0)
409410
goto out_drop_write;
410411

411-
status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1, nn);
412+
status = nfsd4_unlink_clid_dir(dname, nn);
412413
nfs4_reset_creds(original_cred);
413414
if (status == 0) {
414415
vfs_fsync(nn->rec_file, 0);

fs/nfsd/nfs4xdr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3812,7 +3812,9 @@ nfsd4_encode_entry4_fattr(struct nfsd4_readdir *cd, const char *name,
38123812
__be32 nfserr;
38133813
int ignore_crossmnt = 0;
38143814

3815-
dentry = lookup_positive_unlocked(name, cd->rd_fhp->fh_dentry, namlen);
3815+
dentry = lookup_one_positive_unlocked(&nop_mnt_idmap,
3816+
&QSTR_LEN(name, namlen),
3817+
cd->rd_fhp->fh_dentry);
38163818
if (IS_ERR(dentry))
38173819
return nfserrno(PTR_ERR(dentry));
38183820

fs/nfsd/nfsproc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ nfsd_proc_create(struct svc_rqst *rqstp)
312312
}
313313

314314
inode_lock_nested(dirfhp->fh_dentry->d_inode, I_MUTEX_PARENT);
315-
dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
315+
dchild = lookup_one(&nop_mnt_idmap, &QSTR_LEN(argp->name, argp->len),
316+
dirfhp->fh_dentry);
316317
if (IS_ERR(dchild)) {
317318
resp->status = nfserrno(PTR_ERR(dchild));
318319
goto out_unlock;
@@ -331,7 +332,7 @@ nfsd_proc_create(struct svc_rqst *rqstp)
331332
*/
332333
resp->status = nfserr_acces;
333334
if (!newfhp->fh_dentry) {
334-
printk(KERN_WARNING
335+
printk(KERN_WARNING
335336
"nfsd_proc_create: file handle not verified\n");
336337
goto out_unlock;
337338
}

fs/nfsd/vfs.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ nfsd_lookup_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp,
264264
goto out_nfserr;
265265
}
266266
} else {
267-
dentry = lookup_one_len_unlocked(name, dparent, len);
267+
dentry = lookup_one_unlocked(&nop_mnt_idmap,
268+
&QSTR_LEN(name, len), dparent);
268269
host_err = PTR_ERR(dentry);
269270
if (IS_ERR(dentry))
270271
goto out_nfserr;
@@ -922,7 +923,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
922923
* directories, but we never have and it doesn't seem to have
923924
* caused anyone a problem. If we were to change this, note
924925
* also that our filldir callbacks would need a variant of
925-
* lookup_one_len that doesn't check permissions.
926+
* lookup_one_positive_unlocked() that doesn't check permissions.
926927
*/
927928
if (type == S_IFREG)
928929
may_flags |= NFSD_MAY_OWNER_OVERRIDE;
@@ -1554,7 +1555,7 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
15541555
return nfserrno(host_err);
15551556

15561557
inode_lock_nested(dentry->d_inode, I_MUTEX_PARENT);
1557-
dchild = lookup_one_len(fname, dentry, flen);
1558+
dchild = lookup_one(&nop_mnt_idmap, &QSTR_LEN(fname, flen), dentry);
15581559
host_err = PTR_ERR(dchild);
15591560
if (IS_ERR(dchild)) {
15601561
err = nfserrno(host_err);
@@ -1659,7 +1660,7 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,
16591660

16601661
dentry = fhp->fh_dentry;
16611662
inode_lock_nested(dentry->d_inode, I_MUTEX_PARENT);
1662-
dnew = lookup_one_len(fname, dentry, flen);
1663+
dnew = lookup_one(&nop_mnt_idmap, &QSTR_LEN(fname, flen), dentry);
16631664
if (IS_ERR(dnew)) {
16641665
err = nfserrno(PTR_ERR(dnew));
16651666
inode_unlock(dentry->d_inode);
@@ -1734,7 +1735,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
17341735
dirp = d_inode(ddir);
17351736
inode_lock_nested(dirp, I_MUTEX_PARENT);
17361737

1737-
dnew = lookup_one_len(name, ddir, len);
1738+
dnew = lookup_one(&nop_mnt_idmap, &QSTR_LEN(name, len), ddir);
17381739
if (IS_ERR(dnew)) {
17391740
host_err = PTR_ERR(dnew);
17401741
goto out_unlock;
@@ -1867,7 +1868,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
18671868
if (err != nfs_ok)
18681869
goto out_unlock;
18691870

1870-
odentry = lookup_one_len(fname, fdentry, flen);
1871+
odentry = lookup_one(&nop_mnt_idmap, &QSTR_LEN(fname, flen), fdentry);
18711872
host_err = PTR_ERR(odentry);
18721873
if (IS_ERR(odentry))
18731874
goto out_nfserr;
@@ -1880,7 +1881,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
18801881
goto out_dput_old;
18811882
type = d_inode(odentry)->i_mode & S_IFMT;
18821883

1883-
ndentry = lookup_one_len(tname, tdentry, tlen);
1884+
ndentry = lookup_one(&nop_mnt_idmap, &QSTR_LEN(tname, tlen), tdentry);
18841885
host_err = PTR_ERR(ndentry);
18851886
if (IS_ERR(ndentry))
18861887
goto out_dput_old;
@@ -1998,7 +1999,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
19981999
dirp = d_inode(dentry);
19992000
inode_lock_nested(dirp, I_MUTEX_PARENT);
20002001

2001-
rdentry = lookup_one_len(fname, dentry, flen);
2002+
rdentry = lookup_one(&nop_mnt_idmap, &QSTR_LEN(fname, flen), dentry);
20022003
host_err = PTR_ERR(rdentry);
20032004
if (IS_ERR(rdentry))
20042005
goto out_unlock;

0 commit comments

Comments
 (0)