Skip to content

Commit 684f39b

Browse files
NeilBrownamschuma-ntap
authored andcommitted
NFS: struct nfs_open_dir_context: convert rpc_cred pointer to cred.
Use the common 'struct cred' to pass credentials for readdir. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent b68572e commit 684f39b

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

fs/nfs/dir.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const struct address_space_operations nfs_dir_aops = {
6767
.freepage = nfs_readdir_clear_array,
6868
};
6969

70-
static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir, struct rpc_cred *cred)
70+
static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir, const struct cred *cred)
7171
{
7272
struct nfs_inode *nfsi = NFS_I(dir);
7373
struct nfs_open_dir_context *ctx;
@@ -77,7 +77,7 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir
7777
ctx->attr_gencount = nfsi->attr_gencount;
7878
ctx->dir_cookie = 0;
7979
ctx->dup_cookie = 0;
80-
ctx->cred = get_rpccred(cred);
80+
ctx->cred = get_cred(cred);
8181
spin_lock(&dir->i_lock);
8282
list_add(&ctx->list, &nfsi->open_files);
8383
spin_unlock(&dir->i_lock);
@@ -91,7 +91,7 @@ static void put_nfs_open_dir_context(struct inode *dir, struct nfs_open_dir_cont
9191
spin_lock(&dir->i_lock);
9292
list_del(&ctx->list);
9393
spin_unlock(&dir->i_lock);
94-
put_rpccred(ctx->cred);
94+
put_cred(ctx->cred);
9595
kfree(ctx);
9696
}
9797

@@ -103,23 +103,18 @@ nfs_opendir(struct inode *inode, struct file *filp)
103103
{
104104
int res = 0;
105105
struct nfs_open_dir_context *ctx;
106-
struct rpc_cred *cred;
107106

108107
dfprintk(FILE, "NFS: open dir(%pD2)\n", filp);
109108

110109
nfs_inc_stats(inode, NFSIOS_VFSOPEN);
111110

112-
cred = rpc_lookup_cred();
113-
if (IS_ERR(cred))
114-
return PTR_ERR(cred);
115-
ctx = alloc_nfs_open_dir_context(inode, cred);
111+
ctx = alloc_nfs_open_dir_context(inode, current_cred());
116112
if (IS_ERR(ctx)) {
117113
res = PTR_ERR(ctx);
118114
goto out;
119115
}
120116
filp->private_data = ctx;
121117
out:
122-
put_rpccred(cred);
123118
return res;
124119
}
125120

@@ -334,7 +329,7 @@ int nfs_readdir_xdr_filler(struct page **pages, nfs_readdir_descriptor_t *desc,
334329
struct nfs_entry *entry, struct file *file, struct inode *inode)
335330
{
336331
struct nfs_open_dir_context *ctx = file->private_data;
337-
struct rpc_cred *cred = ctx->cred;
332+
const struct cred *cred = ctx->cred;
338333
unsigned long timestamp, gencount;
339334
int error;
340335

fs/nfs/nfs3proc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
614614
* readdirplus.
615615
*/
616616
static int
617-
nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
617+
nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
618618
u64 cookie, struct page **pages, unsigned int count, bool plus)
619619
{
620620
struct inode *dir = d_inode(dentry);
@@ -631,11 +631,15 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
631631
.verf = verf,
632632
.plus = plus
633633
};
634+
struct auth_cred acred = {
635+
.cred = cred,
636+
};
634637
struct rpc_message msg = {
635638
.rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
636639
.rpc_argp = &arg,
637640
.rpc_resp = &res,
638-
.rpc_cred = cred
641+
.rpc_cred = rpc_lookup_generic_cred(&acred,
642+
0, GFP_NOFS),
639643
};
640644
int status = -ENOMEM;
641645

@@ -645,6 +649,8 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
645649
dprintk("NFS call readdir%s %d\n",
646650
plus? "plus" : "", (unsigned int) cookie);
647651

652+
if (!msg.rpc_cred)
653+
return -ENOMEM;
648654
res.dir_attr = nfs_alloc_fattr();
649655
if (res.dir_attr == NULL)
650656
goto out;
@@ -656,6 +662,7 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
656662

657663
nfs_free_fattr(res.dir_attr);
658664
out:
665+
put_rpccred(msg.rpc_cred);
659666
dprintk("NFS reply readdir%s: %d\n",
660667
plus? "plus" : "", status);
661668
return status;

fs/nfs/nfs4proc.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,7 +4699,7 @@ static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
46994699
return err;
47004700
}
47014701

4702-
static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
4702+
static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred,
47034703
u64 cookie, struct page **pages, unsigned int count, bool plus)
47044704
{
47054705
struct inode *dir = d_inode(dentry);
@@ -4712,17 +4712,23 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
47124712
.plus = plus,
47134713
};
47144714
struct nfs4_readdir_res res;
4715+
struct auth_cred acred = {
4716+
.cred = cred,
4717+
};
47154718
struct rpc_message msg = {
47164719
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
47174720
.rpc_argp = &args,
47184721
.rpc_resp = &res,
4719-
.rpc_cred = cred,
4722+
.rpc_cred = rpc_lookup_generic_cred(&acred,
4723+
0, GFP_NOFS),
47204724
};
47214725
int status;
47224726

47234727
dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__,
47244728
dentry,
47254729
(unsigned long long)cookie);
4730+
if (!msg.rpc_cred)
4731+
return -ENOMEM;
47264732
nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
47274733
res.pgbase = args.pgbase;
47284734
status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
@@ -4733,11 +4739,12 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
47334739

47344740
nfs_invalidate_atime(dir);
47354741

4742+
put_rpccred(msg.rpc_cred);
47364743
dprintk("%s: returns %d\n", __func__, status);
47374744
return status;
47384745
}
47394746

4740-
static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
4747+
static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred,
47414748
u64 cookie, struct page **pages, unsigned int count, bool plus)
47424749
{
47434750
struct nfs4_exception exception = { };

fs/nfs/proc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ nfs_proc_rmdir(struct inode *dir, const struct qstr *name)
490490
* from nfs_readdir by calling the decode_entry function directly.
491491
*/
492492
static int
493-
nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
493+
nfs_proc_readdir(struct dentry *dentry, const struct cred *cred,
494494
u64 cookie, struct page **pages, unsigned int count, bool plus)
495495
{
496496
struct inode *dir = d_inode(dentry);
@@ -500,18 +500,25 @@ nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
500500
.count = count,
501501
.pages = pages,
502502
};
503+
struct auth_cred acred = {
504+
.cred = cred,
505+
};
503506
struct rpc_message msg = {
504507
.rpc_proc = &nfs_procedures[NFSPROC_READDIR],
505508
.rpc_argp = &arg,
506-
.rpc_cred = cred,
509+
.rpc_cred = rpc_lookup_generic_cred(&acred,
510+
0, GFP_NOFS),
507511
};
508512
int status;
509513

510514
dprintk("NFS call readdir %d\n", (unsigned int)cookie);
515+
if (!msg.rpc_cred)
516+
return -ENOMEM;
511517
status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
512518

513519
nfs_invalidate_atime(dir);
514520

521+
put_rpccred(msg.rpc_cred);
515522
dprintk("NFS reply readdir: %d\n", status);
516523
return status;
517524
}

include/linux/nfs_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct nfs_open_context {
8989

9090
struct nfs_open_dir_context {
9191
struct list_head list;
92-
struct rpc_cred *cred;
92+
const struct cred *cred;
9393
unsigned long attr_gencount;
9494
__u64 dir_cookie;
9595
__u64 dup_cookie;

include/linux/nfs_xdr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ struct nfs_rpc_ops {
16341634
unsigned int, struct iattr *);
16351635
int (*mkdir) (struct inode *, struct dentry *, struct iattr *);
16361636
int (*rmdir) (struct inode *, const struct qstr *);
1637-
int (*readdir) (struct dentry *, struct rpc_cred *,
1637+
int (*readdir) (struct dentry *, const struct cred *,
16381638
u64, struct page **, unsigned int, bool);
16391639
int (*mknod) (struct inode *, struct dentry *, struct iattr *,
16401640
dev_t);

0 commit comments

Comments
 (0)