Skip to content

Commit 9fd45c1

Browse files
neilbrownchucklever
authored andcommitted
nfsd: Pass 'cred' instead of 'rqstp' to some functions.
nfsd_permission(), exp_rdonly(), nfsd_setuser(), and nfsexp_flags() only ever need the cred out of rqstp, so pass it explicitly instead of the whole rqstp. This makes the interfaces cleaner. Signed-off-by: NeilBrown <neilb@suse.de> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent c55aeef commit 9fd45c1

8 files changed

Lines changed: 34 additions & 28 deletions

File tree

fs/nfsd/auth.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@
55
#include "nfsd.h"
66
#include "auth.h"
77

8-
int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
8+
int nfsexp_flags(struct svc_cred *cred, struct svc_export *exp)
99
{
1010
struct exp_flavor_info *f;
1111
struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
1212

1313
for (f = exp->ex_flavors; f < end; f++) {
14-
if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
14+
if (f->pseudoflavor == cred->cr_flavor)
1515
return f->flags;
1616
}
1717
return exp->ex_flags;
1818

1919
}
2020

21-
int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
21+
int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)
2222
{
2323
struct group_info *rqgi;
2424
struct group_info *gi;
2525
struct cred *new;
2626
int i;
27-
int flags = nfsexp_flags(rqstp, exp);
27+
int flags = nfsexp_flags(cred, exp);
2828

2929
/* discard any old override before preparing the new set */
3030
revert_creds(get_cred(current_real_cred()));
3131
new = prepare_creds();
3232
if (!new)
3333
return -ENOMEM;
3434

35-
new->fsuid = rqstp->rq_cred.cr_uid;
36-
new->fsgid = rqstp->rq_cred.cr_gid;
35+
new->fsuid = cred->cr_uid;
36+
new->fsgid = cred->cr_gid;
3737

38-
rqgi = rqstp->rq_cred.cr_group_info;
38+
rqgi = cred->cr_group_info;
3939

4040
if (flags & NFSEXP_ALLSQUASH) {
4141
new->fsuid = exp->ex_anon_uid;

fs/nfsd/auth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
* Set the current process's fsuid/fsgid etc to those of the NFS
1313
* client user
1414
*/
15-
int nfsd_setuser(struct svc_rqst *, struct svc_export *);
15+
int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp);
1616

1717
#endif /* LINUX_NFSD_AUTH_H */

fs/nfsd/export.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ struct svc_expkey {
9999
#define EX_NOHIDE(exp) ((exp)->ex_flags & NFSEXP_NOHIDE)
100100
#define EX_WGATHER(exp) ((exp)->ex_flags & NFSEXP_GATHERED_WRITES)
101101

102-
int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp);
102+
struct svc_cred;
103+
int nfsexp_flags(struct svc_cred *cred, struct svc_export *exp);
103104
__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
104105

105106
/*

fs/nfsd/nfs4state.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6891,7 +6891,8 @@ nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,
68916891

68926892
nf = nfs4_find_file(s, flags);
68936893
if (nf) {
6894-
status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
6894+
status = nfsd_permission(&rqstp->rq_cred,
6895+
fhp->fh_export, fhp->fh_dentry,
68956896
acc | NFSD_MAY_OWNER_OVERRIDE);
68966897
if (status) {
68976898
nfsd_file_put(nf);

fs/nfsd/nfsfh.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
102102
static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
103103
struct svc_export *exp)
104104
{
105-
int flags = nfsexp_flags(rqstp, exp);
105+
int flags = nfsexp_flags(&rqstp->rq_cred, exp);
106106

107107
/* Check if the request originated from a secure port. */
108108
if (!nfsd_originating_port_ok(rqstp, flags)) {
@@ -113,7 +113,7 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
113113
}
114114

115115
/* Set user creds for this exportpoint */
116-
return nfserrno(nfsd_setuser(rqstp, exp));
116+
return nfserrno(nfsd_setuser(&rqstp->rq_cred, exp));
117117
}
118118

119119
static inline __be32 check_pseudo_root(struct svc_rqst *rqstp,
@@ -394,7 +394,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
394394

395395
skip_pseudoflavor_check:
396396
/* Finally, check access permissions. */
397-
error = nfsd_permission(rqstp, exp, dentry, access);
397+
error = nfsd_permission(&rqstp->rq_cred, exp, dentry, access);
398398
out:
399399
trace_nfsd_fh_verify_err(rqstp, fhp, type, access, error);
400400
if (error == nfserr_stale)

fs/nfsd/nfsproc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,11 @@ nfsd_proc_create(struct svc_rqst *rqstp)
331331
* echo thing > device-special-file-or-pipe
332332
* by doing a CREATE with type==0
333333
*/
334-
resp->status = nfsd_permission(rqstp,
335-
newfhp->fh_export,
336-
newfhp->fh_dentry,
337-
NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
334+
resp->status = nfsd_permission(
335+
&rqstp->rq_cred,
336+
newfhp->fh_export,
337+
newfhp->fh_dentry,
338+
NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
338339
if (resp->status && resp->status != nfserr_rofs)
339340
goto out_unlock;
340341
}

fs/nfsd/vfs.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ nfsd_get_write_access(struct svc_rqst *rqstp, struct svc_fh *fhp,
421421
if (iap->ia_size < inode->i_size) {
422422
__be32 err;
423423

424-
err = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
425-
NFSD_MAY_TRUNC | NFSD_MAY_OWNER_OVERRIDE);
424+
err = nfsd_permission(&rqstp->rq_cred,
425+
fhp->fh_export, fhp->fh_dentry,
426+
NFSD_MAY_TRUNC | NFSD_MAY_OWNER_OVERRIDE);
426427
if (err)
427428
return err;
428429
}
@@ -814,7 +815,8 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor
814815

815816
sresult |= map->access;
816817

817-
err2 = nfsd_permission(rqstp, export, dentry, map->how);
818+
err2 = nfsd_permission(&rqstp->rq_cred, export,
819+
dentry, map->how);
818820
switch (err2) {
819821
case nfs_ok:
820822
result |= map->access;
@@ -1475,7 +1477,8 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
14751477
dirp = d_inode(dentry);
14761478

14771479
dchild = dget(resfhp->fh_dentry);
1478-
err = nfsd_permission(rqstp, fhp->fh_export, dentry, NFSD_MAY_CREATE);
1480+
err = nfsd_permission(&rqstp->rq_cred, fhp->fh_export, dentry,
1481+
NFSD_MAY_CREATE);
14791482
if (err)
14801483
goto out;
14811484

@@ -2255,9 +2258,9 @@ nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat, in
22552258
return err;
22562259
}
22572260

2258-
static int exp_rdonly(struct svc_rqst *rqstp, struct svc_export *exp)
2261+
static int exp_rdonly(struct svc_cred *cred, struct svc_export *exp)
22592262
{
2260-
return nfsexp_flags(rqstp, exp) & NFSEXP_READONLY;
2263+
return nfsexp_flags(cred, exp) & NFSEXP_READONLY;
22612264
}
22622265

22632266
#ifdef CONFIG_NFSD_V4
@@ -2501,8 +2504,8 @@ nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
25012504
* Check for a user's access permissions to this inode.
25022505
*/
25032506
__be32
2504-
nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
2505-
struct dentry *dentry, int acc)
2507+
nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
2508+
struct dentry *dentry, int acc)
25062509
{
25072510
struct inode *inode = d_inode(dentry);
25082511
int err;
@@ -2533,7 +2536,7 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
25332536
*/
25342537
if (!(acc & NFSD_MAY_LOCAL_ACCESS))
25352538
if (acc & (NFSD_MAY_WRITE | NFSD_MAY_SATTR | NFSD_MAY_TRUNC)) {
2536-
if (exp_rdonly(rqstp, exp) ||
2539+
if (exp_rdonly(cred, exp) ||
25372540
__mnt_is_readonly(exp->ex_path.mnt))
25382541
return nfserr_rofs;
25392542
if (/* (acc & NFSD_MAY_WRITE) && */ IS_IMMUTABLE(inode))

fs/nfsd/vfs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ __be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *,
153153
__be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,
154154
struct kstatfs *, int access);
155155

156-
__be32 nfsd_permission(struct svc_rqst *, struct svc_export *,
157-
struct dentry *, int);
156+
__be32 nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
157+
struct dentry *dentry, int acc);
158158

159159
void nfsd_filp_close(struct file *fp);
160160

0 commit comments

Comments
 (0)