summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2018-12-02 19:30:31 -0500
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2018-12-19 13:52:46 -0500
commita52458b48af142bcc2b72fe810c0db20cfae7fdd (patch)
treecb77d59d5fdf3d50e69500b8cc7cba1c7199272f
parent684f39b4cf5186bb0660e686f94296688b24fb32 (diff)
NFS/NFSD/SUNRPC: replace generic creds with 'struct cred'.
SUNRPC has two sorts of credentials, both of which appear as "struct rpc_cred". There are "generic credentials" which are supplied by clients such as NFS and passed in 'struct rpc_message' to indicate which user should be used to authorize the request, and there are low-level credentials such as AUTH_NULL, AUTH_UNIX, AUTH_GSS which describe the credential to be sent over the wires. This patch replaces all the generic credentials by 'struct cred' pointers - the credential structure used throughout Linux. For machine credentials, there is a special 'struct cred *' pointer which is statically allocated and recognized where needed as having a special meaning. A look-up of a low-level cred will map this to a machine credential. Signed-off-by: NeilBrown <neilb@suse.com> Acked-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
-rw-r--r--fs/lockd/clntproc.c6
-rw-r--r--fs/nfs/blocklayout/blocklayout.c2
-rw-r--r--fs/nfs/delegation.c28
-rw-r--r--fs/nfs/delegation.h10
-rw-r--r--fs/nfs/flexfilelayout/flexfilelayout.c33
-rw-r--r--fs/nfs/flexfilelayout/flexfilelayout.h8
-rw-r--r--fs/nfs/flexfilelayout/flexfilelayoutdev.c16
-rw-r--r--fs/nfs/inode.c11
-rw-r--r--fs/nfs/internal.h8
-rw-r--r--fs/nfs/nfs3proc.c18
-rw-r--r--fs/nfs/nfs4_fs.h56
-rw-r--r--fs/nfs/nfs4client.c4
-rw-r--r--fs/nfs/nfs4proc.c167
-rw-r--r--fs/nfs/nfs4renewd.c4
-rw-r--r--fs/nfs/nfs4session.c5
-rw-r--r--fs/nfs/nfs4state.c92
-rw-r--r--fs/nfs/pagelist.c2
-rw-r--r--fs/nfs/pnfs.c14
-rw-r--r--fs/nfs/pnfs.h10
-rw-r--r--fs/nfs/pnfs_dev.c4
-rw-r--r--fs/nfs/pnfs_nfs.c2
-rw-r--r--fs/nfs/proc.c9
-rw-r--r--fs/nfs/unlink.c15
-rw-r--r--fs/nfs/write.c2
-rw-r--r--fs/nfsd/nfs4callback.c16
-rw-r--r--fs/nfsd/state.h2
-rw-r--r--include/linux/nfs_fs.h6
-rw-r--r--include/linux/nfs_xdr.h14
-rw-r--r--include/linux/sunrpc/auth.h18
-rw-r--r--include/linux/sunrpc/sched.h2
-rw-r--r--net/sunrpc/auth.c14
-rw-r--r--net/sunrpc/clnt.c4
-rw-r--r--net/sunrpc/sched.c2
33 files changed, 261 insertions, 343 deletions
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index d20b92f271c2..7c80c28df971 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -256,7 +256,7 @@ static int nlm_wait_on_grace(wait_queue_head_t *queue)
256 * Generic NLM call 256 * Generic NLM call
257 */ 257 */
258static int 258static int
259nlmclnt_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc) 259nlmclnt_call(const struct cred *cred, struct nlm_rqst *req, u32 proc)
260{ 260{
261 struct nlm_host *host = req->a_host; 261 struct nlm_host *host = req->a_host;
262 struct rpc_clnt *clnt; 262 struct rpc_clnt *clnt;
@@ -401,7 +401,7 @@ int nlm_async_reply(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *t
401 * completion in order to be able to correctly track the lock 401 * completion in order to be able to correctly track the lock
402 * state. 402 * state.
403 */ 403 */
404static int nlmclnt_async_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops) 404static int nlmclnt_async_call(const struct cred *cred, struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
405{ 405{
406 struct rpc_message msg = { 406 struct rpc_message msg = {
407 .rpc_argp = &req->a_args, 407 .rpc_argp = &req->a_args,
@@ -510,7 +510,7 @@ static int do_vfs_lock(struct file_lock *fl)
510static int 510static int
511nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl) 511nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
512{ 512{
513 struct rpc_cred *cred = nfs_file_cred(fl->fl_file); 513 const struct cred *cred = nfs_file_cred(fl->fl_file);
514 struct nlm_host *host = req->a_host; 514 struct nlm_host *host = req->a_host;
515 struct nlm_res *resp = &req->a_res; 515 struct nlm_res *resp = &req->a_res;
516 struct nlm_wait *block = NULL; 516 struct nlm_wait *block = NULL;
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index d3781cd983f6..690221747b47 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -584,7 +584,7 @@ static int decode_sector_number(__be32 **rp, sector_t *sp)
584 584
585static struct nfs4_deviceid_node * 585static struct nfs4_deviceid_node *
586bl_find_get_deviceid(struct nfs_server *server, 586bl_find_get_deviceid(struct nfs_server *server,
587 const struct nfs4_deviceid *id, struct rpc_cred *cred, 587 const struct nfs4_deviceid *id, const struct cred *cred,
588 gfp_t gfp_mask) 588 gfp_t gfp_mask)
589{ 589{
590 struct nfs4_deviceid_node *node; 590 struct nfs4_deviceid_node *node;
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 6ec2f78c1e19..885363ca8569 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -26,10 +26,8 @@
26 26
27static void nfs_free_delegation(struct nfs_delegation *delegation) 27static void nfs_free_delegation(struct nfs_delegation *delegation)
28{ 28{
29 if (delegation->cred) { 29 put_cred(delegation->cred);
30 put_rpccred(delegation->cred); 30 delegation->cred = NULL;
31 delegation->cred = NULL;
32 }
33 kfree_rcu(delegation, rcu); 31 kfree_rcu(delegation, rcu);
34} 32}
35 33
@@ -178,13 +176,13 @@ again:
178 * @pagemod_limit: write delegation "space_limit" 176 * @pagemod_limit: write delegation "space_limit"
179 * 177 *
180 */ 178 */
181void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, 179void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
182 fmode_t type, 180 fmode_t type,
183 const nfs4_stateid *stateid, 181 const nfs4_stateid *stateid,
184 unsigned long pagemod_limit) 182 unsigned long pagemod_limit)
185{ 183{
186 struct nfs_delegation *delegation; 184 struct nfs_delegation *delegation;
187 struct rpc_cred *oldcred = NULL; 185 const struct cred *oldcred = NULL;
188 186
189 rcu_read_lock(); 187 rcu_read_lock();
190 delegation = rcu_dereference(NFS_I(inode)->delegation); 188 delegation = rcu_dereference(NFS_I(inode)->delegation);
@@ -195,12 +193,12 @@ void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
195 delegation->type = type; 193 delegation->type = type;
196 delegation->pagemod_limit = pagemod_limit; 194 delegation->pagemod_limit = pagemod_limit;
197 oldcred = delegation->cred; 195 oldcred = delegation->cred;
198 delegation->cred = get_rpccred(cred); 196 delegation->cred = get_cred(cred);
199 clear_bit(NFS_DELEGATION_NEED_RECLAIM, 197 clear_bit(NFS_DELEGATION_NEED_RECLAIM,
200 &delegation->flags); 198 &delegation->flags);
201 spin_unlock(&delegation->lock); 199 spin_unlock(&delegation->lock);
202 rcu_read_unlock(); 200 rcu_read_unlock();
203 put_rpccred(oldcred); 201 put_cred(oldcred);
204 trace_nfs4_reclaim_delegation(inode, type); 202 trace_nfs4_reclaim_delegation(inode, type);
205 return; 203 return;
206 } 204 }
@@ -341,7 +339,7 @@ nfs_update_inplace_delegation(struct nfs_delegation *delegation,
341 * 339 *
342 * Returns zero on success, or a negative errno value. 340 * Returns zero on success, or a negative errno value.
343 */ 341 */
344int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, 342int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
345 fmode_t type, 343 fmode_t type,
346 const nfs4_stateid *stateid, 344 const nfs4_stateid *stateid,
347 unsigned long pagemod_limit) 345 unsigned long pagemod_limit)
@@ -360,7 +358,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred,
360 delegation->type = type; 358 delegation->type = type;
361 delegation->pagemod_limit = pagemod_limit; 359 delegation->pagemod_limit = pagemod_limit;
362 delegation->change_attr = inode_peek_iversion_raw(inode); 360 delegation->change_attr = inode_peek_iversion_raw(inode);
363 delegation->cred = get_rpccred(cred); 361 delegation->cred = get_cred(cred);
364 delegation->inode = inode; 362 delegation->inode = inode;
365 delegation->flags = 1<<NFS_DELEGATION_REFERENCED; 363 delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
366 spin_lock_init(&delegation->lock); 364 spin_lock_init(&delegation->lock);
@@ -1047,7 +1045,7 @@ void nfs_reap_expired_delegations(struct nfs_client *clp)
1047 struct nfs_delegation *delegation; 1045 struct nfs_delegation *delegation;
1048 struct nfs_server *server; 1046 struct nfs_server *server;
1049 struct inode *inode; 1047 struct inode *inode;
1050 struct rpc_cred *cred; 1048 const struct cred *cred;
1051 nfs4_stateid stateid; 1049 nfs4_stateid stateid;
1052 1050
1053restart: 1051restart:
@@ -1069,7 +1067,7 @@ restart:
1069 nfs_sb_deactive(server->super); 1067 nfs_sb_deactive(server->super);
1070 goto restart; 1068 goto restart;
1071 } 1069 }
1072 cred = get_rpccred_rcu(delegation->cred); 1070 cred = get_cred_rcu(delegation->cred);
1073 nfs4_stateid_copy(&stateid, &delegation->stateid); 1071 nfs4_stateid_copy(&stateid, &delegation->stateid);
1074 clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags); 1072 clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
1075 rcu_read_unlock(); 1073 rcu_read_unlock();
@@ -1078,7 +1076,7 @@ restart:
1078 nfs_revoke_delegation(inode, &stateid); 1076 nfs_revoke_delegation(inode, &stateid);
1079 nfs_inode_find_state_and_recover(inode, &stateid); 1077 nfs_inode_find_state_and_recover(inode, &stateid);
1080 } 1078 }
1081 put_rpccred(cred); 1079 put_cred(cred);
1082 if (nfs4_server_rebooted(clp)) { 1080 if (nfs4_server_rebooted(clp)) {
1083 nfs_inode_mark_test_expired_delegation(server,inode); 1081 nfs_inode_mark_test_expired_delegation(server,inode);
1084 iput(inode); 1082 iput(inode);
@@ -1173,7 +1171,7 @@ out:
1173 * otherwise "false" is returned. 1171 * otherwise "false" is returned.
1174 */ 1172 */
1175bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, 1173bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags,
1176 nfs4_stateid *dst, struct rpc_cred **cred) 1174 nfs4_stateid *dst, const struct cred **cred)
1177{ 1175{
1178 struct nfs_inode *nfsi = NFS_I(inode); 1176 struct nfs_inode *nfsi = NFS_I(inode);
1179 struct nfs_delegation *delegation; 1177 struct nfs_delegation *delegation;
@@ -1187,7 +1185,7 @@ bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags,
1187 nfs4_stateid_copy(dst, &delegation->stateid); 1185 nfs4_stateid_copy(dst, &delegation->stateid);
1188 nfs_mark_delegation_referenced(delegation); 1186 nfs_mark_delegation_referenced(delegation);
1189 if (cred) 1187 if (cred)
1190 *cred = get_rpccred(delegation->cred); 1188 *cred = get_cred(delegation->cred);
1191 } 1189 }
1192 rcu_read_unlock(); 1190 rcu_read_unlock();
1193 return ret; 1191 return ret;
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index bb1ef8c37af4..dcbf3394ba0e 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -15,7 +15,7 @@
15 */ 15 */
16struct nfs_delegation { 16struct nfs_delegation {
17 struct list_head super_list; 17 struct list_head super_list;
18 struct rpc_cred *cred; 18 const struct cred *cred;
19 struct inode *inode; 19 struct inode *inode;
20 nfs4_stateid stateid; 20 nfs4_stateid stateid;
21 fmode_t type; 21 fmode_t type;
@@ -36,9 +36,9 @@ enum {
36 NFS_DELEGATION_TEST_EXPIRED, 36 NFS_DELEGATION_TEST_EXPIRED,
37}; 37};
38 38
39int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, 39int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
40 fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit); 40 fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit);
41void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, 41void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
42 fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit); 42 fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit);
43int nfs4_inode_return_delegation(struct inode *inode); 43int nfs4_inode_return_delegation(struct inode *inode);
44int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid); 44int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
@@ -60,10 +60,10 @@ void nfs_mark_test_expired_all_delegations(struct nfs_client *clp);
60void nfs_reap_expired_delegations(struct nfs_client *clp); 60void nfs_reap_expired_delegations(struct nfs_client *clp);
61 61
62/* NFSv4 delegation-related procedures */ 62/* NFSv4 delegation-related procedures */
63int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync); 63int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync);
64int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type); 64int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type);
65int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid); 65int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid);
66bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, struct rpc_cred **cred); 66bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, const struct cred **cred);
67bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode); 67bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode);
68 68
69void nfs_mark_delegation_referenced(struct nfs_delegation *delegation); 69void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 1d1c5d127928..63abe705f4ca 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -224,16 +224,14 @@ static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
224 224
225static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror) 225static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
226{ 226{
227 struct rpc_cred *cred; 227 const struct cred *cred;
228 228
229 ff_layout_remove_mirror(mirror); 229 ff_layout_remove_mirror(mirror);
230 kfree(mirror->fh_versions); 230 kfree(mirror->fh_versions);
231 cred = rcu_access_pointer(mirror->ro_cred); 231 cred = rcu_access_pointer(mirror->ro_cred);
232 if (cred) 232 put_cred(cred);
233 put_rpccred(cred);
234 cred = rcu_access_pointer(mirror->rw_cred); 233 cred = rcu_access_pointer(mirror->rw_cred);
235 if (cred) 234 put_cred(cred);
236 put_rpccred(cred);
237 nfs4_ff_layout_put_deviceid(mirror->mirror_ds); 235 nfs4_ff_layout_put_deviceid(mirror->mirror_ds);
238 kfree(mirror); 236 kfree(mirror);
239} 237}
@@ -411,9 +409,8 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
411 409
412 for (i = 0; i < fls->mirror_array_cnt; i++) { 410 for (i = 0; i < fls->mirror_array_cnt; i++) {
413 struct nfs4_ff_layout_mirror *mirror; 411 struct nfs4_ff_layout_mirror *mirror;
414 struct auth_cred acred = {};
415 struct rpc_cred __rcu *cred;
416 struct cred *kcred; 412 struct cred *kcred;
413 const struct cred *cred;
417 kuid_t uid; 414 kuid_t uid;
418 kgid_t gid; 415 kgid_t gid;
419 u32 ds_count, fh_count, id; 416 u32 ds_count, fh_count, id;
@@ -504,15 +501,7 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
504 goto out_err_free; 501 goto out_err_free;
505 kcred->fsuid = uid; 502 kcred->fsuid = uid;
506 kcred->fsgid = gid; 503 kcred->fsgid = gid;
507 acred.cred = kcred; 504 cred = kcred;
508
509 /* find the cred for it */
510 rcu_assign_pointer(cred, rpc_lookup_generic_cred(&acred, 0, gfp_flags));
511 put_cred(kcred);
512 if (IS_ERR(cred)) {
513 rc = PTR_ERR(cred);
514 goto out_err_free;
515 }
516 505
517 if (lgr->range.iomode == IOMODE_READ) 506 if (lgr->range.iomode == IOMODE_READ)
518 rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred); 507 rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
@@ -1714,7 +1703,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
1714 struct pnfs_layout_segment *lseg = hdr->lseg; 1703 struct pnfs_layout_segment *lseg = hdr->lseg;
1715 struct nfs4_pnfs_ds *ds; 1704 struct nfs4_pnfs_ds *ds;
1716 struct rpc_clnt *ds_clnt; 1705 struct rpc_clnt *ds_clnt;
1717 struct rpc_cred *ds_cred; 1706 const struct cred *ds_cred;
1718 loff_t offset = hdr->args.offset; 1707 loff_t offset = hdr->args.offset;
1719 u32 idx = hdr->pgio_mirror_idx; 1708 u32 idx = hdr->pgio_mirror_idx;
1720 int vers; 1709 int vers;
@@ -1765,7 +1754,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
1765 vers == 3 ? &ff_layout_read_call_ops_v3 : 1754 vers == 3 ? &ff_layout_read_call_ops_v3 :
1766 &ff_layout_read_call_ops_v4, 1755 &ff_layout_read_call_ops_v4,
1767 0, RPC_TASK_SOFTCONN); 1756 0, RPC_TASK_SOFTCONN);
1768 put_rpccred(ds_cred); 1757 put_cred(ds_cred);
1769 return PNFS_ATTEMPTED; 1758 return PNFS_ATTEMPTED;
1770 1759
1771out_failed: 1760out_failed:
@@ -1781,7 +1770,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
1781 struct pnfs_layout_segment *lseg = hdr->lseg; 1770 struct pnfs_layout_segment *lseg = hdr->lseg;
1782 struct nfs4_pnfs_ds *ds; 1771 struct nfs4_pnfs_ds *ds;
1783 struct rpc_clnt *ds_clnt; 1772 struct rpc_clnt *ds_clnt;
1784 struct rpc_cred *ds_cred; 1773 const struct cred *ds_cred;
1785 loff_t offset = hdr->args.offset; 1774 loff_t offset = hdr->args.offset;
1786 int vers; 1775 int vers;
1787 struct nfs_fh *fh; 1776 struct nfs_fh *fh;
@@ -1830,7 +1819,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
1830 vers == 3 ? &ff_layout_write_call_ops_v3 : 1819 vers == 3 ? &ff_layout_write_call_ops_v3 :
1831 &ff_layout_write_call_ops_v4, 1820 &ff_layout_write_call_ops_v4,
1832 sync, RPC_TASK_SOFTCONN); 1821 sync, RPC_TASK_SOFTCONN);
1833 put_rpccred(ds_cred); 1822 put_cred(ds_cred);
1834 return PNFS_ATTEMPTED; 1823 return PNFS_ATTEMPTED;
1835 1824
1836out_failed: 1825out_failed:
@@ -1860,7 +1849,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
1860 struct pnfs_layout_segment *lseg = data->lseg; 1849 struct pnfs_layout_segment *lseg = data->lseg;
1861 struct nfs4_pnfs_ds *ds; 1850 struct nfs4_pnfs_ds *ds;
1862 struct rpc_clnt *ds_clnt; 1851 struct rpc_clnt *ds_clnt;
1863 struct rpc_cred *ds_cred; 1852 const struct cred *ds_cred;
1864 u32 idx; 1853 u32 idx;
1865 int vers, ret; 1854 int vers, ret;
1866 struct nfs_fh *fh; 1855 struct nfs_fh *fh;
@@ -1900,7 +1889,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
1900 vers == 3 ? &ff_layout_commit_call_ops_v3 : 1889 vers == 3 ? &ff_layout_commit_call_ops_v3 :
1901 &ff_layout_commit_call_ops_v4, 1890 &ff_layout_commit_call_ops_v4,
1902 how, RPC_TASK_SOFTCONN); 1891 how, RPC_TASK_SOFTCONN);
1903 put_rpccred(ds_cred); 1892 put_cred(ds_cred);
1904 return ret; 1893 return ret;
1905out_err: 1894out_err:
1906 pnfs_generic_prepare_to_resend_writes(data); 1895 pnfs_generic_prepare_to_resend_writes(data);
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.h b/fs/nfs/flexfilelayout/flexfilelayout.h
index de50a342d5a5..c2626bad466b 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.h
+++ b/fs/nfs/flexfilelayout/flexfilelayout.h
@@ -81,8 +81,8 @@ struct nfs4_ff_layout_mirror {
81 u32 fh_versions_cnt; 81 u32 fh_versions_cnt;
82 struct nfs_fh *fh_versions; 82 struct nfs_fh *fh_versions;
83 nfs4_stateid stateid; 83 nfs4_stateid stateid;
84 struct rpc_cred __rcu *ro_cred; 84 const struct cred __rcu *ro_cred;
85 struct rpc_cred __rcu *rw_cred; 85 const struct cred __rcu *rw_cred;
86 refcount_t ref; 86 refcount_t ref;
87 spinlock_t lock; 87 spinlock_t lock;
88 unsigned long flags; 88 unsigned long flags;
@@ -229,8 +229,8 @@ nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg,
229 u32 ds_idx, 229 u32 ds_idx,
230 struct nfs_client *ds_clp, 230 struct nfs_client *ds_clp,
231 struct inode *inode); 231 struct inode *inode);
232struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, 232const struct cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg,
233 u32 ds_idx, struct rpc_cred *mdscred); 233 u32 ds_idx, const struct cred *mdscred);
234bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg); 234bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg);
235bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg); 235bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg);
236 236
diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
index d23347389626..11766a74216d 100644
--- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c
+++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
@@ -330,10 +330,10 @@ int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
330 return 0; 330 return 0;
331} 331}
332 332
333static struct rpc_cred * 333static const struct cred *
334ff_layout_get_mirror_cred(struct nfs4_ff_layout_mirror *mirror, u32 iomode) 334ff_layout_get_mirror_cred(struct nfs4_ff_layout_mirror *mirror, u32 iomode)
335{ 335{
336 struct rpc_cred *cred, __rcu **pcred; 336 const struct cred *cred, __rcu **pcred;
337 337
338 if (iomode == IOMODE_READ) 338 if (iomode == IOMODE_READ)
339 pcred = &mirror->ro_cred; 339 pcred = &mirror->ro_cred;
@@ -346,7 +346,7 @@ ff_layout_get_mirror_cred(struct nfs4_ff_layout_mirror *mirror, u32 iomode)
346 if (!cred) 346 if (!cred)
347 break; 347 break;
348 348
349 cred = get_rpccred_rcu(cred); 349 cred = get_cred_rcu(cred);
350 } while(!cred); 350 } while(!cred);
351 rcu_read_unlock(); 351 rcu_read_unlock();
352 return cred; 352 return cred;
@@ -465,19 +465,19 @@ out:
465 return ds; 465 return ds;
466} 466}
467 467
468struct rpc_cred * 468const struct cred *
469ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, u32 ds_idx, 469ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, u32 ds_idx,
470 struct rpc_cred *mdscred) 470 const struct cred *mdscred)
471{ 471{
472 struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx); 472 struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
473 struct rpc_cred *cred; 473 const struct cred *cred;
474 474
475 if (mirror && !mirror->mirror_ds->ds_versions[0].tightly_coupled) { 475 if (mirror && !mirror->mirror_ds->ds_versions[0].tightly_coupled) {
476 cred = ff_layout_get_mirror_cred(mirror, lseg->pls_range.iomode); 476 cred = ff_layout_get_mirror_cred(mirror, lseg->pls_range.iomode);
477 if (!cred) 477 if (!cred)
478 cred = get_rpccred(mdscred); 478 cred = get_cred(mdscred);
479 } else { 479 } else {
480 cred = get_rpccred(mdscred); 480 cred = get_cred(mdscred);
481 } 481 }
482 return cred; 482 return cred;
483} 483}
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index aea015743172..094775ea0781 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -950,13 +950,11 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry,
950 struct file *filp) 950 struct file *filp)
951{ 951{
952 struct nfs_open_context *ctx; 952 struct nfs_open_context *ctx;
953 struct rpc_cred *cred = rpc_lookup_cred(); 953 const struct cred *cred = get_current_cred();
954 if (IS_ERR(cred))
955 return ERR_CAST(cred);
956 954
957 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 955 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
958 if (!ctx) { 956 if (!ctx) {
959 put_rpccred(cred); 957 put_cred(cred);
960 return ERR_PTR(-ENOMEM); 958 return ERR_PTR(-ENOMEM);
961 } 959 }
962 nfs_sb_active(dentry->d_sb); 960 nfs_sb_active(dentry->d_sb);
@@ -998,8 +996,7 @@ static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
998 } 996 }
999 if (inode != NULL) 997 if (inode != NULL)
1000 NFS_PROTO(inode)->close_context(ctx, is_sync); 998 NFS_PROTO(inode)->close_context(ctx, is_sync);
1001 if (ctx->cred != NULL) 999 put_cred(ctx->cred);
1002 put_rpccred(ctx->cred);
1003 dput(ctx->dentry); 1000 dput(ctx->dentry);
1004 nfs_sb_deactive(sb); 1001 nfs_sb_deactive(sb);
1005 put_rpccred(ctx->ll_cred); 1002 put_rpccred(ctx->ll_cred);
@@ -1044,7 +1041,7 @@ EXPORT_SYMBOL_GPL(nfs_file_set_open_context);
1044/* 1041/*
1045 * Given an inode, search for an open context with the desired characteristics 1042 * Given an inode, search for an open context with the desired characteristics
1046 */ 1043 */
1047struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode) 1044struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode)
1048{ 1045{
1049 struct nfs_inode *nfsi = NFS_I(inode); 1046 struct nfs_inode *nfsi = NFS_I(inode);
1050 struct nfs_open_context *pos, *ctx = NULL; 1047 struct nfs_open_context *pos, *ctx = NULL;
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index ecb6d4317ab4..78d83b4bc398 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -254,7 +254,7 @@ struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
254void nfs_pgio_header_free(struct nfs_pgio_header *); 254void nfs_pgio_header_free(struct nfs_pgio_header *);
255int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); 255int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
256int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, 256int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
257 struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops, 257 const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
258 const struct rpc_call_ops *call_ops, int how, int flags); 258 const struct rpc_call_ops *call_ops, int how, int flags);
259void nfs_free_request(struct nfs_page *req); 259void nfs_free_request(struct nfs_page *req);
260struct nfs_pgio_mirror * 260struct nfs_pgio_mirror *
@@ -269,7 +269,7 @@ static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
269static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1, 269static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
270 const struct nfs_open_context *ctx2) 270 const struct nfs_open_context *ctx2)
271{ 271{
272 return ctx1->cred == ctx2->cred && ctx1->state == ctx2->state; 272 return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
273} 273}
274 274
275/* nfs2xdr.c */ 275/* nfs2xdr.c */
@@ -564,10 +564,10 @@ extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
564 const struct nfs_client_initdata *); 564 const struct nfs_client_initdata *);
565extern int nfs40_walk_client_list(struct nfs_client *clp, 565extern int nfs40_walk_client_list(struct nfs_client *clp,
566 struct nfs_client **result, 566 struct nfs_client **result,
567 struct rpc_cred *cred); 567 const struct cred *cred);
568extern int nfs41_walk_client_list(struct nfs_client *clp, 568extern int nfs41_walk_client_list(struct nfs_client *clp,
569 struct nfs_client **result, 569 struct nfs_client **result,
570 struct rpc_cred *cred); 570 const struct cred *cred);
571extern int nfs4_test_session_trunk(struct rpc_clnt *, 571extern int nfs4_test_session_trunk(struct rpc_clnt *,
572 struct rpc_xprt *, 572 struct rpc_xprt *,
573 void *); 573 void *);
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index a2e9e09c3772..a3ad2d46fd42 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -195,20 +195,15 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
195 .access = entry->mask, 195 .access = entry->mask,
196 }; 196 };
197 struct nfs3_accessres res; 197 struct nfs3_accessres res;
198 struct auth_cred acred = {
199 .cred = entry->cred,
200 };
201 struct rpc_message msg = { 198 struct rpc_message msg = {
202 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS], 199 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
203 .rpc_argp = &arg, 200 .rpc_argp = &arg,
204 .rpc_resp = &res, 201 .rpc_resp = &res,
205 .rpc_cred = rpc_lookup_generic_cred(&acred, 0, GFP_NOFS), 202 .rpc_cred = entry->cred,
206 }; 203 };
207 int status = -ENOMEM; 204 int status = -ENOMEM;
208 205
209 dprintk("NFS call access\n"); 206 dprintk("NFS call access\n");
210 if (!msg.rpc_cred)
211 goto out;
212 res.fattr = nfs_alloc_fattr(); 207 res.fattr = nfs_alloc_fattr();
213 if (res.fattr == NULL) 208 if (res.fattr == NULL)
214 goto out; 209 goto out;
@@ -219,8 +214,6 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
219 nfs_access_set_mask(entry, res.access); 214 nfs_access_set_mask(entry, res.access);
220 nfs_free_fattr(res.fattr); 215 nfs_free_fattr(res.fattr);
221out: 216out:
222 if (msg.rpc_cred)
223 put_rpccred(msg.rpc_cred);
224 dprintk("NFS reply access: %d\n", status); 217 dprintk("NFS reply access: %d\n", status);
225 return status; 218 return status;
226} 219}
@@ -631,15 +624,11 @@ nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
631 .verf = verf, 624 .verf = verf,
632 .plus = plus 625 .plus = plus
633 }; 626 };
634 struct auth_cred acred = {
635 .cred = cred,
636 };
637 struct rpc_message msg = { 627 struct rpc_message msg = {
638 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR], 628 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
639 .rpc_argp = &arg, 629 .rpc_argp = &arg,
640 .rpc_resp = &res, 630 .rpc_resp = &res,
641 .rpc_cred = rpc_lookup_generic_cred(&acred, 631 .rpc_cred = cred,
642 0, GFP_NOFS),
643 }; 632 };
644 int status = -ENOMEM; 633 int status = -ENOMEM;
645 634
@@ -649,8 +638,6 @@ nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
649 dprintk("NFS call readdir%s %d\n", 638 dprintk("NFS call readdir%s %d\n",
650 plus? "plus" : "", (unsigned int) cookie); 639 plus? "plus" : "", (unsigned int) cookie);
651 640
652 if (!msg.rpc_cred)
653 return -ENOMEM;
654 res.dir_attr = nfs_alloc_fattr(); 641 res.dir_attr = nfs_alloc_fattr();
655 if (res.dir_attr == NULL) 642 if (res.dir_attr == NULL)
656 goto out; 643 goto out;
@@ -662,7 +649,6 @@ nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
662 649
663 nfs_free_fattr(res.dir_attr); 650 nfs_free_fattr(res.dir_attr);
664out: 651out:
665 put_rpccred(msg.rpc_cred);
666 dprintk("NFS reply readdir%s: %d\n", 652 dprintk("NFS reply readdir%s: %d\n",
667 plus? "plus" : "", status); 653 plus? "plus" : "", status);
668 return status; 654 return status;
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index eab41490ce58..993378a8f14f 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -62,7 +62,7 @@ struct nfs4_minor_version_ops {
62 void (*free_lock_state)(struct nfs_server *, 62 void (*free_lock_state)(struct nfs_server *,
63 struct nfs4_lock_state *); 63 struct nfs4_lock_state *);
64 int (*test_and_free_expired)(struct nfs_server *, 64 int (*test_and_free_expired)(struct nfs_server *,
65 nfs4_stateid *, struct rpc_cred *); 65 nfs4_stateid *, const struct cred *);
66 struct nfs_seqid * 66 struct nfs_seqid *
67 (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); 67 (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
68 int (*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *); 68 int (*session_trunk)(struct rpc_clnt *, struct rpc_xprt *, void *);
@@ -107,7 +107,7 @@ struct nfs4_state_owner {
107 unsigned long so_expires; 107 unsigned long so_expires;
108 struct rb_node so_server_node; 108 struct rb_node so_server_node;
109 109
110 struct rpc_cred *so_cred; /* Associated cred */ 110 const struct cred *so_cred; /* Associated cred */
111 111
112 spinlock_t so_lock; 112 spinlock_t so_lock;
113 atomic_t so_count; 113 atomic_t so_count;
@@ -212,10 +212,10 @@ struct nfs4_state_recovery_ops {
212 int state_flag_bit; 212 int state_flag_bit;
213 int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *); 213 int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
214 int (*recover_lock)(struct nfs4_state *, struct file_lock *); 214 int (*recover_lock)(struct nfs4_state *, struct file_lock *);
215 int (*establish_clid)(struct nfs_client *, struct rpc_cred *); 215 int (*establish_clid)(struct nfs_client *, const struct cred *);
216 int (*reclaim_complete)(struct nfs_client *, struct rpc_cred *); 216 int (*reclaim_complete)(struct nfs_client *, const struct cred *);
217 int (*detect_trunking)(struct nfs_client *, struct nfs_client **, 217 int (*detect_trunking)(struct nfs_client *, struct nfs_client **,
218 struct rpc_cred *); 218 const struct cred *);
219}; 219};
220 220
221struct nfs4_opendata { 221struct nfs4_opendata {
@@ -245,19 +245,19 @@ struct nfs4_opendata {
245 245
246struct nfs4_add_xprt_data { 246struct nfs4_add_xprt_data {
247 struct nfs_client *clp; 247 struct nfs_client *clp;
248 struct rpc_cred *cred; 248 const struct cred *cred;
249}; 249};
250 250
251struct nfs4_state_maintenance_ops { 251struct nfs4_state_maintenance_ops {
252 int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *, unsigned); 252 int (*sched_state_renewal)(struct nfs_client *, const struct cred *, unsigned);
253 struct rpc_cred * (*get_state_renewal_cred)(struct nfs_client *); 253 const struct cred * (*get_state_renewal_cred)(struct nfs_client *);
254 int (*renew_lease)(struct nfs_client *, struct rpc_cred *); 254 int (*renew_lease)(struct nfs_client *, const struct cred *);
255}; 255};
256 256
257struct nfs4_mig_recovery_ops { 257struct nfs4_mig_recovery_ops {
258 int (*get_locations)(struct inode *, struct nfs4_fs_locations *, 258 int (*get_locations)(struct inode *, struct nfs4_fs_locations *,
259 struct page *, struct rpc_cred *); 259 struct page *, const struct cred *);
260 int (*fsid_present)(struct inode *, struct rpc_cred *); 260 int (*fsid_present)(struct inode *, const struct cred *);
261}; 261};
262 262
263extern const struct dentry_operations nfs4_dentry_operations; 263extern const struct dentry_operations nfs4_dentry_operations;
@@ -286,21 +286,21 @@ extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
286 struct rpc_message *, struct nfs4_sequence_args *, 286 struct rpc_message *, struct nfs4_sequence_args *,
287 struct nfs4_sequence_res *, int); 287 struct nfs4_sequence_res *, int);
288extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int); 288extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
289extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *); 289extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
290extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *); 290extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *);
291extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool); 291extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
292extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, struct rpc_cred *cred); 292extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
293extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred); 293extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
294extern int nfs4_destroy_clientid(struct nfs_client *clp); 294extern int nfs4_destroy_clientid(struct nfs_client *clp);
295extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); 295extern int nfs4_init_clientid(struct nfs_client *, const struct cred *);
296extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); 296extern int nfs41_init_clientid(struct nfs_client *, const struct cred *);
297extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait); 297extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait);
298extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 298extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
299extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *, 299extern int nfs4_proc_fs_locations(struct rpc_clnt *, struct inode *, const struct qstr *,
300 struct nfs4_fs_locations *, struct page *); 300 struct nfs4_fs_locations *, struct page *);
301extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *, 301extern int nfs4_proc_get_locations(struct inode *, struct nfs4_fs_locations *,
302 struct page *page, struct rpc_cred *); 302 struct page *page, const struct cred *);
303extern int nfs4_proc_fsid_present(struct inode *, struct rpc_cred *); 303extern int nfs4_proc_fsid_present(struct inode *, const struct cred *);
304extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, const struct qstr *, 304extern struct rpc_clnt *nfs4_proc_lookup_mountpoint(struct inode *, const struct qstr *,
305 struct nfs_fh *, struct nfs_fattr *); 305 struct nfs_fh *, struct nfs_fattr *);
306extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *); 306extern int nfs4_proc_secinfo(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *);
@@ -312,8 +312,8 @@ extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
312 312
313#if defined(CONFIG_NFS_V4_1) 313#if defined(CONFIG_NFS_V4_1)
314extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *); 314extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
315extern int nfs4_proc_create_session(struct nfs_client *, struct rpc_cred *); 315extern int nfs4_proc_create_session(struct nfs_client *, const struct cred *);
316extern int nfs4_proc_destroy_session(struct nfs4_session *, struct rpc_cred *); 316extern int nfs4_proc_destroy_session(struct nfs4_session *, const struct cred *);
317extern int nfs4_proc_get_lease_time(struct nfs_client *clp, 317extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
318 struct nfs_fsinfo *fsinfo); 318 struct nfs_fsinfo *fsinfo);
319extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, 319extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data,
@@ -443,16 +443,16 @@ extern void nfs4_set_lease_period(struct nfs_client *clp,
443 443
444 444
445/* nfs4state.c */ 445/* nfs4state.c */
446struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp); 446const struct cred *nfs4_get_clid_cred(struct nfs_client *clp);
447struct rpc_cred *nfs4_get_machine_cred(struct nfs_client *clp); 447const struct cred *nfs4_get_machine_cred(struct nfs_client *clp);
448struct rpc_cred *nfs4_get_renew_cred(struct nfs_client *clp); 448const struct cred *nfs4_get_renew_cred(struct nfs_client *clp);
449int nfs4_discover_server_trunking(struct nfs_client *clp, 449int nfs4_discover_server_trunking(struct nfs_client *clp,
450 struct nfs_client **); 450 struct nfs_client **);
451int nfs40_discover_server_trunking(struct nfs_client *clp, 451int nfs40_discover_server_trunking(struct nfs_client *clp,
452 struct nfs_client **, struct rpc_cred *); 452 struct nfs_client **, const struct cred *);
453#if defined(CONFIG_NFS_V4_1) 453#if defined(CONFIG_NFS_V4_1)
454int nfs41_discover_server_trunking(struct nfs_client *clp, 454int nfs41_discover_server_trunking(struct nfs_client *clp,
455 struct nfs_client **, struct rpc_cred *); 455 struct nfs_client **, const struct cred *);
456extern void nfs4_schedule_session_recovery(struct nfs4_session *, int); 456extern void nfs4_schedule_session_recovery(struct nfs4_session *, int);
457extern void nfs41_notify_server(struct nfs_client *); 457extern void nfs41_notify_server(struct nfs_client *);
458#else 458#else
@@ -461,7 +461,7 @@ static inline void nfs4_schedule_session_recovery(struct nfs4_session *session,
461} 461}
462#endif /* CONFIG_NFS_V4_1 */ 462#endif /* CONFIG_NFS_V4_1 */
463 463
464extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t); 464extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, const struct cred *, gfp_t);
465extern void nfs4_put_state_owner(struct nfs4_state_owner *); 465extern void nfs4_put_state_owner(struct nfs4_state_owner *);
466extern void nfs4_purge_state_owners(struct nfs_server *); 466extern void nfs4_purge_state_owners(struct nfs_server *);
467extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *); 467extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
@@ -487,7 +487,7 @@ extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
487extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 487extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
488extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, 488extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
489 const struct nfs_lock_context *, nfs4_stateid *, 489 const struct nfs_lock_context *, nfs4_stateid *,
490 struct rpc_cred **); 490 const struct cred **);
491extern bool nfs4_refresh_open_stateid(nfs4_stateid *dst, 491extern bool nfs4_refresh_open_stateid(nfs4_stateid *dst,
492 struct nfs4_state *state); 492 struct nfs4_state *state);
493extern bool nfs4_copy_open_stateid(nfs4_stateid *dst, 493extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index 8f53455c4765..2548405da1f7 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -545,7 +545,7 @@ static int nfs4_match_client(struct nfs_client *pos, struct nfs_client *new,
545 */ 545 */
546int nfs40_walk_client_list(struct nfs_client *new, 546int nfs40_walk_client_list(struct nfs_client *new,
547 struct nfs_client **result, 547 struct nfs_client **result,
548 struct rpc_cred *cred) 548 const struct cred *cred)
549{ 549{
550 struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id); 550 struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id);
551 struct nfs_client *pos, *prev = NULL; 551 struct nfs_client *pos, *prev = NULL;
@@ -711,7 +711,7 @@ out_err:
711 */ 711 */
712int nfs41_walk_client_list(struct nfs_client *new, 712int nfs41_walk_client_list(struct nfs_client *new,
713 struct nfs_client **result, 713 struct nfs_client **result,
714 struct rpc_cred *cred) 714 const struct cred *cred)
715{ 715{
716 struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id); 716 struct nfs_net *nn = net_generic(new->cl_net, nfs_net_id);
717 struct nfs_client *pos, *prev = NULL; 717 struct nfs_client *pos, *prev = NULL;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 80cedb007c3c..7d1f080e7de1 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -93,19 +93,19 @@ static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinf
93static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); 93static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
94static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode); 94static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode);
95static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); 95static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode);
96static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, 96static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
97 struct nfs_fattr *fattr, struct iattr *sattr, 97 struct nfs_fattr *fattr, struct iattr *sattr,
98 struct nfs_open_context *ctx, struct nfs4_label *ilabel, 98 struct nfs_open_context *ctx, struct nfs4_label *ilabel,
99 struct nfs4_label *olabel); 99 struct nfs4_label *olabel);
100#ifdef CONFIG_NFS_V4_1 100#ifdef CONFIG_NFS_V4_1
101static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, 101static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
102 struct rpc_cred *cred, 102 const struct cred *cred,
103 struct nfs4_slot *slot, 103 struct nfs4_slot *slot,
104 bool is_privileged); 104 bool is_privileged);
105static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, 105static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *,
106 struct rpc_cred *); 106 const struct cred *);
107static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, 107static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *,
108 struct rpc_cred *, bool); 108 const struct cred *, bool);
109#endif 109#endif
110 110
111#ifdef CONFIG_NFS_V4_SECURITY_LABEL 111#ifdef CONFIG_NFS_V4_SECURITY_LABEL
@@ -361,7 +361,7 @@ static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dent
361 361
362static void nfs4_test_and_free_stateid(struct nfs_server *server, 362static void nfs4_test_and_free_stateid(struct nfs_server *server,
363 nfs4_stateid *stateid, 363 nfs4_stateid *stateid,
364 struct rpc_cred *cred) 364 const struct cred *cred)
365{ 365{
366 const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; 366 const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops;
367 367
@@ -370,7 +370,7 @@ static void nfs4_test_and_free_stateid(struct nfs_server *server,
370 370
371static void __nfs4_free_revoked_stateid(struct nfs_server *server, 371static void __nfs4_free_revoked_stateid(struct nfs_server *server,
372 nfs4_stateid *stateid, 372 nfs4_stateid *stateid,
373 struct rpc_cred *cred) 373 const struct cred *cred)
374{ 374{
375 stateid->type = NFS4_REVOKED_STATEID_TYPE; 375 stateid->type = NFS4_REVOKED_STATEID_TYPE;
376 nfs4_test_and_free_stateid(server, stateid, cred); 376 nfs4_test_and_free_stateid(server, stateid, cred);
@@ -378,7 +378,7 @@ static void __nfs4_free_revoked_stateid(struct nfs_server *server,
378 378
379static void nfs4_free_revoked_stateid(struct nfs_server *server, 379static void nfs4_free_revoked_stateid(struct nfs_server *server,
380 const nfs4_stateid *stateid, 380 const nfs4_stateid *stateid,
381 struct rpc_cred *cred) 381 const struct cred *cred)
382{ 382{
383 nfs4_stateid tmp; 383 nfs4_stateid tmp;
384 384
@@ -908,7 +908,7 @@ static const struct rpc_call_ops nfs41_call_sync_ops = {
908 908
909static void 909static void
910nfs4_sequence_process_interrupted(struct nfs_client *client, 910nfs4_sequence_process_interrupted(struct nfs_client *client,
911 struct nfs4_slot *slot, struct rpc_cred *cred) 911 struct nfs4_slot *slot, const struct cred *cred)
912{ 912{
913 struct rpc_task *task; 913 struct rpc_task *task;
914 914
@@ -939,7 +939,7 @@ EXPORT_SYMBOL_GPL(nfs4_sequence_done);
939 939
940static void 940static void
941nfs4_sequence_process_interrupted(struct nfs_client *client, 941nfs4_sequence_process_interrupted(struct nfs_client *client,
942 struct nfs4_slot *slot, struct rpc_cred *cred) 942 struct nfs4_slot *slot, const struct cred *cred)
943{ 943{
944 WARN_ON_ONCE(1); 944 WARN_ON_ONCE(1);
945 slot->interrupted = 0; 945 slot->interrupted = 0;
@@ -1772,7 +1772,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1772 rcu_read_unlock(); 1772 rcu_read_unlock();
1773 nfs_release_seqid(opendata->o_arg.seqid); 1773 nfs_release_seqid(opendata->o_arg.seqid);
1774 if (!opendata->is_recover) { 1774 if (!opendata->is_recover) {
1775 ret = nfs_may_open(state->inode, state->owner->so_cred->cr_cred, open_mode); 1775 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1776 if (ret != 0) 1776 if (ret != 0)
1777 goto out; 1777 goto out;
1778 } 1778 }
@@ -2484,7 +2484,7 @@ static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
2484 * Note that in the non-execute case, we want to turn off permission 2484 * Note that in the non-execute case, we want to turn off permission
2485 * checking if we just created a new file (POSIX open() semantics). 2485 * checking if we just created a new file (POSIX open() semantics).
2486 */ 2486 */
2487static int nfs4_opendata_access(struct rpc_cred *cred, 2487static int nfs4_opendata_access(const struct cred *cred,
2488 struct nfs4_opendata *opendata, 2488 struct nfs4_opendata *opendata,
2489 struct nfs4_state *state, fmode_t fmode, 2489 struct nfs4_state *state, fmode_t fmode,
2490 int openflags) 2490 int openflags)
@@ -2511,7 +2511,7 @@ static int nfs4_opendata_access(struct rpc_cred *cred,
2511 } else if ((fmode & FMODE_READ) && !opendata->file_created) 2511 } else if ((fmode & FMODE_READ) && !opendata->file_created)
2512 mask = NFS4_ACCESS_READ; 2512 mask = NFS4_ACCESS_READ;
2513 2513
2514 cache.cred = cred->cr_cred; 2514 cache.cred = cred;
2515 nfs_access_set_mask(&cache, opendata->o_res.access_result); 2515 nfs_access_set_mask(&cache, opendata->o_res.access_result);
2516 nfs_access_add_cache(state->inode, &cache); 2516 nfs_access_add_cache(state->inode, &cache);
2517 2517
@@ -2651,7 +2651,7 @@ static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st
2651 2651
2652static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, 2652static int nfs40_test_and_free_expired_stateid(struct nfs_server *server,
2653 nfs4_stateid *stateid, 2653 nfs4_stateid *stateid,
2654 struct rpc_cred *cred) 2654 const struct cred *cred)
2655{ 2655{
2656 return -NFS4ERR_BAD_STATEID; 2656 return -NFS4ERR_BAD_STATEID;
2657} 2657}
@@ -2659,7 +2659,7 @@ static int nfs40_test_and_free_expired_stateid(struct nfs_server *server,
2659#if defined(CONFIG_NFS_V4_1) 2659#if defined(CONFIG_NFS_V4_1)
2660static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, 2660static int nfs41_test_and_free_expired_stateid(struct nfs_server *server,
2661 nfs4_stateid *stateid, 2661 nfs4_stateid *stateid,
2662 struct rpc_cred *cred) 2662 const struct cred *cred)
2663{ 2663{
2664 int status; 2664 int status;
2665 2665
@@ -2693,7 +2693,7 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state)
2693 struct nfs_server *server = NFS_SERVER(state->inode); 2693 struct nfs_server *server = NFS_SERVER(state->inode);
2694 nfs4_stateid stateid; 2694 nfs4_stateid stateid;
2695 struct nfs_delegation *delegation; 2695 struct nfs_delegation *delegation;
2696 struct rpc_cred *cred; 2696 const struct cred *cred = NULL;
2697 int status; 2697 int status;
2698 2698
2699 /* Get the delegation credential for use by test/free_stateid */ 2699 /* Get the delegation credential for use by test/free_stateid */
@@ -2718,14 +2718,16 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state)
2718 return; 2718 return;
2719 } 2719 }
2720 2720
2721 cred = get_rpccred(delegation->cred); 2721 if (delegation->cred)
2722 cred = get_cred(delegation->cred);
2722 rcu_read_unlock(); 2723 rcu_read_unlock();
2723 status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); 2724 status = nfs41_test_and_free_expired_stateid(server, &stateid, cred);
2724 trace_nfs4_test_delegation_stateid(state, NULL, status); 2725 trace_nfs4_test_delegation_stateid(state, NULL, status);
2725 if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) 2726 if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID)
2726 nfs_finish_clear_delegation_stateid(state, &stateid); 2727 nfs_finish_clear_delegation_stateid(state, &stateid);
2727 2728
2728 put_rpccred(cred); 2729 if (delegation->cred)
2730 put_cred(cred);
2729} 2731}
2730 2732
2731/** 2733/**
@@ -2748,7 +2750,7 @@ static int nfs41_check_expired_locks(struct nfs4_state *state)
2748 spin_lock(&state->state_lock); 2750 spin_lock(&state->state_lock);
2749 list_for_each_entry(lsp, &state->lock_states, ls_locks) { 2751 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
2750 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { 2752 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
2751 struct rpc_cred *cred = lsp->ls_state->owner->so_cred; 2753 const struct cred *cred = lsp->ls_state->owner->so_cred;
2752 2754
2753 refcount_inc(&lsp->ls_count); 2755 refcount_inc(&lsp->ls_count);
2754 spin_unlock(&state->state_lock); 2756 spin_unlock(&state->state_lock);
@@ -2792,7 +2794,7 @@ static int nfs41_check_open_stateid(struct nfs4_state *state)
2792{ 2794{
2793 struct nfs_server *server = NFS_SERVER(state->inode); 2795 struct nfs_server *server = NFS_SERVER(state->inode);
2794 nfs4_stateid *stateid = &state->open_stateid; 2796 nfs4_stateid *stateid = &state->open_stateid;
2795 struct rpc_cred *cred = state->owner->so_cred; 2797 const struct cred *cred = state->owner->so_cred;
2796 int status; 2798 int status;
2797 2799
2798 if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { 2800 if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) {
@@ -2950,7 +2952,7 @@ static int _nfs4_do_open(struct inode *dir,
2950 struct nfs_server *server = NFS_SERVER(dir); 2952 struct nfs_server *server = NFS_SERVER(dir);
2951 struct nfs4_opendata *opendata; 2953 struct nfs4_opendata *opendata;
2952 struct dentry *dentry = ctx->dentry; 2954 struct dentry *dentry = ctx->dentry;
2953 struct rpc_cred *cred = ctx->cred; 2955 const struct cred *cred = ctx->cred;
2954 struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; 2956 struct nfs4_threshold **ctx_th = &ctx->mdsthreshold;
2955 fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); 2957 fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC);
2956 enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; 2958 enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL;
@@ -3120,7 +3122,7 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir,
3120static int _nfs4_do_setattr(struct inode *inode, 3122static int _nfs4_do_setattr(struct inode *inode,
3121 struct nfs_setattrargs *arg, 3123 struct nfs_setattrargs *arg,
3122 struct nfs_setattrres *res, 3124 struct nfs_setattrres *res,
3123 struct rpc_cred *cred, 3125 const struct cred *cred,
3124 struct nfs_open_context *ctx) 3126 struct nfs_open_context *ctx)
3125{ 3127{
3126 struct nfs_server *server = NFS_SERVER(inode); 3128 struct nfs_server *server = NFS_SERVER(inode);
@@ -3130,7 +3132,7 @@ static int _nfs4_do_setattr(struct inode *inode,
3130 .rpc_resp = res, 3132 .rpc_resp = res,
3131 .rpc_cred = cred, 3133 .rpc_cred = cred,
3132 }; 3134 };
3133 struct rpc_cred *delegation_cred = NULL; 3135 const struct cred *delegation_cred = NULL;
3134 unsigned long timestamp = jiffies; 3136 unsigned long timestamp = jiffies;
3135 bool truncate; 3137 bool truncate;
3136 int status; 3138 int status;
@@ -3165,14 +3167,14 @@ zero_stateid:
3165 3167
3166 status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); 3168 status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1);
3167 3169
3168 put_rpccred(delegation_cred); 3170 put_cred(delegation_cred);
3169 if (status == 0 && ctx != NULL) 3171 if (status == 0 && ctx != NULL)
3170 renew_lease(server, timestamp); 3172 renew_lease(server, timestamp);
3171 trace_nfs4_setattr(inode, &arg->stateid, status); 3173 trace_nfs4_setattr(inode, &arg->stateid, status);
3172 return status; 3174 return status;
3173} 3175}
3174 3176
3175static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, 3177static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
3176 struct nfs_fattr *fattr, struct iattr *sattr, 3178 struct nfs_fattr *fattr, struct iattr *sattr,
3177 struct nfs_open_context *ctx, struct nfs4_label *ilabel, 3179 struct nfs_open_context *ctx, struct nfs4_label *ilabel,
3178 struct nfs4_label *olabel) 3180 struct nfs4_label *olabel)
@@ -3973,7 +3975,7 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
3973 struct iattr *sattr) 3975 struct iattr *sattr)
3974{ 3976{
3975 struct inode *inode = d_inode(dentry); 3977 struct inode *inode = d_inode(dentry);
3976 struct rpc_cred *cred = NULL; 3978 const struct cred *cred = NULL;
3977 struct nfs_open_context *ctx = NULL; 3979 struct nfs_open_context *ctx = NULL;
3978 struct nfs4_label *label = NULL; 3980 struct nfs4_label *label = NULL;
3979 int status; 3981 int status;
@@ -4188,28 +4190,20 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
4188 struct nfs4_accessres res = { 4190 struct nfs4_accessres res = {
4189 .server = server, 4191 .server = server,
4190 }; 4192 };
4191 struct auth_cred acred = {
4192 .cred = entry->cred,
4193 };
4194 struct rpc_message msg = { 4193 struct rpc_message msg = {
4195 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], 4194 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
4196 .rpc_argp = &args, 4195 .rpc_argp = &args,
4197 .rpc_resp = &res, 4196 .rpc_resp = &res,
4198 .rpc_cred = rpc_lookup_generic_cred(&acred, 0, GFP_NOFS), 4197 .rpc_cred = entry->cred,
4199 }; 4198 };
4200 int status = 0; 4199 int status = 0;
4201 4200
4202 if (!msg.rpc_cred)
4203 return -ENOMEM;
4204 if (!nfs4_have_delegation(inode, FMODE_READ)) { 4201 if (!nfs4_have_delegation(inode, FMODE_READ)) {
4205 res.fattr = nfs_alloc_fattr(); 4202 res.fattr = nfs_alloc_fattr();
4206 if (res.fattr == NULL) { 4203 if (res.fattr == NULL)
4207 put_rpccred(msg.rpc_cred);
4208 return -ENOMEM; 4204 return -ENOMEM;
4209 }
4210 args.bitmask = server->cache_consistency_bitmask; 4205 args.bitmask = server->cache_consistency_bitmask;
4211 } 4206 }
4212
4213 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); 4207 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
4214 if (!status) { 4208 if (!status) {
4215 nfs_access_set_mask(entry, res.access); 4209 nfs_access_set_mask(entry, res.access);
@@ -4217,7 +4211,6 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
4217 nfs_refresh_inode(inode, res.fattr); 4211 nfs_refresh_inode(inode, res.fattr);
4218 } 4212 }
4219 nfs_free_fattr(res.fattr); 4213 nfs_free_fattr(res.fattr);
4220 put_rpccred(msg.rpc_cred);
4221 return status; 4214 return status;
4222} 4215}
4223 4216
@@ -4712,23 +4705,17 @@ static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred,
4712 .plus = plus, 4705 .plus = plus,
4713 }; 4706 };
4714 struct nfs4_readdir_res res; 4707 struct nfs4_readdir_res res;
4715 struct auth_cred acred = {
4716 .cred = cred,
4717 };
4718 struct rpc_message msg = { 4708 struct rpc_message msg = {
4719 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], 4709 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
4720 .rpc_argp = &args, 4710 .rpc_argp = &args,
4721 .rpc_resp = &res, 4711 .rpc_resp = &res,
4722 .rpc_cred = rpc_lookup_generic_cred(&acred, 4712 .rpc_cred = cred,
4723 0, GFP_NOFS),
4724 }; 4713 };
4725 int status; 4714 int status;
4726 4715
4727 dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, 4716 dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__,
4728 dentry, 4717 dentry,
4729 (unsigned long long)cookie); 4718 (unsigned long long)cookie);
4730 if (!msg.rpc_cred)
4731 return -ENOMEM;
4732 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); 4719 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
4733 res.pgbase = args.pgbase; 4720 res.pgbase = args.pgbase;
4734 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); 4721 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
@@ -4739,7 +4726,6 @@ static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred,
4739 4726
4740 nfs_invalidate_atime(dir); 4727 nfs_invalidate_atime(dir);
4741 4728
4742 put_rpccred(msg.rpc_cred);
4743 dprintk("%s: returns %d\n", __func__, status); 4729 dprintk("%s: returns %d\n", __func__, status);
4744 return status; 4730 return status;
4745} 4731}
@@ -5272,7 +5258,7 @@ static const struct rpc_call_ops nfs4_renew_ops = {
5272 .rpc_release = nfs4_renew_release, 5258 .rpc_release = nfs4_renew_release,
5273}; 5259};
5274 5260
5275static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) 5261static int nfs4_proc_async_renew(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags)
5276{ 5262{
5277 struct rpc_message msg = { 5263 struct rpc_message msg = {
5278 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], 5264 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
@@ -5296,7 +5282,7 @@ static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred,
5296 &nfs4_renew_ops, data); 5282 &nfs4_renew_ops, data);
5297} 5283}
5298 5284
5299static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) 5285static int nfs4_proc_renew(struct nfs_client *clp, const struct cred *cred)
5300{ 5286{
5301 struct rpc_message msg = { 5287 struct rpc_message msg = {
5302 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], 5288 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
@@ -5711,7 +5697,6 @@ nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen)
5711{ 5697{
5712 struct nfs4_label ilabel, *olabel = NULL; 5698 struct nfs4_label ilabel, *olabel = NULL;
5713 struct nfs_fattr fattr; 5699 struct nfs_fattr fattr;
5714 struct rpc_cred *cred;
5715 int status; 5700 int status;
5716 5701
5717 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) 5702 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL))
@@ -5724,10 +5709,6 @@ nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen)
5724 ilabel.label = (char *)buf; 5709 ilabel.label = (char *)buf;
5725 ilabel.len = buflen; 5710 ilabel.len = buflen;
5726 5711
5727 cred = rpc_lookup_cred();
5728 if (IS_ERR(cred))
5729 return PTR_ERR(cred);
5730
5731 olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); 5712 olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
5732 if (IS_ERR(olabel)) { 5713 if (IS_ERR(olabel)) {
5733 status = -PTR_ERR(olabel); 5714 status = -PTR_ERR(olabel);
@@ -5740,7 +5721,6 @@ nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen)
5740 5721
5741 nfs4_label_free(olabel); 5722 nfs4_label_free(olabel);
5742out: 5723out:
5743 put_rpccred(cred);
5744 return status; 5724 return status;
5745} 5725}
5746#endif /* CONFIG_NFS_V4_SECURITY_LABEL */ 5726#endif /* CONFIG_NFS_V4_SECURITY_LABEL */
@@ -5909,13 +5889,13 @@ static const struct rpc_call_ops nfs4_setclientid_ops = {
5909 * @clp: state data structure 5889 * @clp: state data structure
5910 * @program: RPC program for NFSv4 callback service 5890 * @program: RPC program for NFSv4 callback service
5911 * @port: IP port number for NFS4 callback service 5891 * @port: IP port number for NFS4 callback service
5912 * @cred: RPC credential to use for this call 5892 * @cred: credential to use for this call
5913 * @res: where to place the result 5893 * @res: where to place the result
5914 * 5894 *
5915 * Returns zero, a negative errno, or a negative NFS4ERR status code. 5895 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5916 */ 5896 */
5917int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, 5897int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
5918 unsigned short port, struct rpc_cred *cred, 5898 unsigned short port, const struct cred *cred,
5919 struct nfs4_setclientid_res *res) 5899 struct nfs4_setclientid_res *res)
5920{ 5900{
5921 nfs4_verifier sc_verifier; 5901 nfs4_verifier sc_verifier;
@@ -5984,13 +5964,13 @@ out:
5984 * nfs4_proc_setclientid_confirm - Confirm client ID 5964 * nfs4_proc_setclientid_confirm - Confirm client ID
5985 * @clp: state data structure 5965 * @clp: state data structure
5986 * @res: result of a previous SETCLIENTID 5966 * @res: result of a previous SETCLIENTID
5987 * @cred: RPC credential to use for this call 5967 * @cred: credential to use for this call
5988 * 5968 *
5989 * Returns zero, a negative errno, or a negative NFS4ERR status code. 5969 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5990 */ 5970 */
5991int nfs4_proc_setclientid_confirm(struct nfs_client *clp, 5971int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
5992 struct nfs4_setclientid_res *arg, 5972 struct nfs4_setclientid_res *arg,
5993 struct rpc_cred *cred) 5973 const struct cred *cred)
5994{ 5974{
5995 struct rpc_message msg = { 5975 struct rpc_message msg = {
5996 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], 5976 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
@@ -6153,7 +6133,7 @@ static const struct rpc_call_ops nfs4_delegreturn_ops = {
6153 .rpc_release = nfs4_delegreturn_release, 6133 .rpc_release = nfs4_delegreturn_release,
6154}; 6134};
6155 6135
6156static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) 6136static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync)
6157{ 6137{
6158 struct nfs4_delegreturndata *data; 6138 struct nfs4_delegreturndata *data;
6159 struct nfs_server *server = NFS_SERVER(inode); 6139 struct nfs_server *server = NFS_SERVER(inode);
@@ -6220,7 +6200,7 @@ out:
6220 return status; 6200 return status;
6221} 6201}
6222 6202
6223int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) 6203int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync)
6224{ 6204{
6225 struct nfs_server *server = NFS_SERVER(inode); 6205 struct nfs_server *server = NFS_SERVER(inode);
6226 struct nfs4_exception exception = { }; 6206 struct nfs4_exception exception = { };
@@ -7281,7 +7261,7 @@ int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
7281 */ 7261 */
7282static int _nfs40_proc_get_locations(struct inode *inode, 7262static int _nfs40_proc_get_locations(struct inode *inode,
7283 struct nfs4_fs_locations *locations, 7263 struct nfs4_fs_locations *locations,
7284 struct page *page, struct rpc_cred *cred) 7264 struct page *page, const struct cred *cred)
7285{ 7265{
7286 struct nfs_server *server = NFS_SERVER(inode); 7266 struct nfs_server *server = NFS_SERVER(inode);
7287 struct rpc_clnt *clnt = server->client; 7267 struct rpc_clnt *clnt = server->client;
@@ -7338,7 +7318,7 @@ static int _nfs40_proc_get_locations(struct inode *inode,
7338 */ 7318 */
7339static int _nfs41_proc_get_locations(struct inode *inode, 7319static int _nfs41_proc_get_locations(struct inode *inode,
7340 struct nfs4_fs_locations *locations, 7320 struct nfs4_fs_locations *locations,
7341 struct page *page, struct rpc_cred *cred) 7321 struct page *page, const struct cred *cred)
7342{ 7322{
7343 struct nfs_server *server = NFS_SERVER(inode); 7323 struct nfs_server *server = NFS_SERVER(inode);
7344 struct rpc_clnt *clnt = server->client; 7324 struct rpc_clnt *clnt = server->client;
@@ -7397,7 +7377,7 @@ static int _nfs41_proc_get_locations(struct inode *inode,
7397 */ 7377 */
7398int nfs4_proc_get_locations(struct inode *inode, 7378int nfs4_proc_get_locations(struct inode *inode,
7399 struct nfs4_fs_locations *locations, 7379 struct nfs4_fs_locations *locations,
7400 struct page *page, struct rpc_cred *cred) 7380 struct page *page, const struct cred *cred)
7401{ 7381{
7402 struct nfs_server *server = NFS_SERVER(inode); 7382 struct nfs_server *server = NFS_SERVER(inode);
7403 struct nfs_client *clp = server->nfs_client; 7383 struct nfs_client *clp = server->nfs_client;
@@ -7428,7 +7408,7 @@ int nfs4_proc_get_locations(struct inode *inode,
7428 * is appended to this compound to identify the client ID which is 7408 * is appended to this compound to identify the client ID which is
7429 * performing recovery. 7409 * performing recovery.
7430 */ 7410 */
7431static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) 7411static int _nfs40_proc_fsid_present(struct inode *inode, const struct cred *cred)
7432{ 7412{
7433 struct nfs_server *server = NFS_SERVER(inode); 7413 struct nfs_server *server = NFS_SERVER(inode);
7434 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 7414 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
@@ -7474,7 +7454,7 @@ static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred)
7474 * this operation is identified in the SEQUENCE operation in this 7454 * this operation is identified in the SEQUENCE operation in this
7475 * compound. 7455 * compound.
7476 */ 7456 */
7477static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) 7457static int _nfs41_proc_fsid_present(struct inode *inode, const struct cred *cred)
7478{ 7458{
7479 struct nfs_server *server = NFS_SERVER(inode); 7459 struct nfs_server *server = NFS_SERVER(inode);
7480 struct rpc_clnt *clnt = server->client; 7460 struct rpc_clnt *clnt = server->client;
@@ -7521,7 +7501,7 @@ static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred)
7521 * NFS4ERR code if some error occurred on the server, or a 7501 * NFS4ERR code if some error occurred on the server, or a
7522 * negative errno if a local failure occurred. 7502 * negative errno if a local failure occurred.
7523 */ 7503 */
7524int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) 7504int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred)
7525{ 7505{
7526 struct nfs_server *server = NFS_SERVER(inode); 7506 struct nfs_server *server = NFS_SERVER(inode);
7527 struct nfs_client *clp = server->nfs_client; 7507 struct nfs_client *clp = server->nfs_client;
@@ -7568,7 +7548,7 @@ static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct
7568 .rpc_resp = &res, 7548 .rpc_resp = &res,
7569 }; 7549 };
7570 struct rpc_clnt *clnt = NFS_SERVER(dir)->client; 7550 struct rpc_clnt *clnt = NFS_SERVER(dir)->client;
7571 struct rpc_cred *cred = NULL; 7551 const struct cred *cred = NULL;
7572 7552
7573 if (use_integrity) { 7553 if (use_integrity) {
7574 clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; 7554 clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient;
@@ -7585,8 +7565,7 @@ static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct
7585 &res.seq_res, 0); 7565 &res.seq_res, 0);
7586 dprintk("NFS reply secinfo: %d\n", status); 7566 dprintk("NFS reply secinfo: %d\n", status);
7587 7567
7588 if (cred) 7568 put_cred(cred);
7589 put_rpccred(cred);
7590 7569
7591 return status; 7570 return status;
7592} 7571}
@@ -7667,7 +7646,7 @@ static
7667int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, 7646int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt,
7668 struct rpc_xprt *xprt, 7647 struct rpc_xprt *xprt,
7669 struct nfs_client *clp, 7648 struct nfs_client *clp,
7670 struct rpc_cred *cred) 7649 const struct cred *cred)
7671{ 7650{
7672 int status; 7651 int status;
7673 struct nfs41_bind_conn_to_session_args args = { 7652 struct nfs41_bind_conn_to_session_args args = {
@@ -7729,7 +7708,7 @@ int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt,
7729 7708
7730struct rpc_bind_conn_calldata { 7709struct rpc_bind_conn_calldata {
7731 struct nfs_client *clp; 7710 struct nfs_client *clp;
7732 struct rpc_cred *cred; 7711 const struct cred *cred;
7733}; 7712};
7734 7713
7735static int 7714static int
@@ -7742,7 +7721,7 @@ nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt *clnt,
7742 return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); 7721 return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred);
7743} 7722}
7744 7723
7745int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) 7724int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, const struct cred *cred)
7746{ 7725{
7747 struct rpc_bind_conn_calldata data = { 7726 struct rpc_bind_conn_calldata data = {
7748 .clp = clp, 7727 .clp = clp,
@@ -7908,7 +7887,7 @@ static const struct rpc_call_ops nfs4_exchange_id_call_ops = {
7908 * Wrapper for EXCHANGE_ID operation. 7887 * Wrapper for EXCHANGE_ID operation.
7909 */ 7888 */
7910static struct rpc_task * 7889static struct rpc_task *
7911nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, 7890nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred,
7912 u32 sp4_how, struct rpc_xprt *xprt) 7891 u32 sp4_how, struct rpc_xprt *xprt)
7913{ 7892{
7914 struct rpc_message msg = { 7893 struct rpc_message msg = {
@@ -8004,7 +7983,7 @@ out:
8004 * 7983 *
8005 * Wrapper for EXCHANGE_ID operation. 7984 * Wrapper for EXCHANGE_ID operation.
8006 */ 7985 */
8007static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, 7986static int _nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred,
8008 u32 sp4_how) 7987 u32 sp4_how)
8009{ 7988{
8010 struct rpc_task *task; 7989 struct rpc_task *task;
@@ -8071,7 +8050,7 @@ out:
8071 * 8050 *
8072 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. 8051 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used.
8073 */ 8052 */
8074int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) 8053int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred)
8075{ 8054{
8076 rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; 8055 rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor;
8077 int status; 8056 int status;
@@ -8133,7 +8112,7 @@ int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt,
8133EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); 8112EXPORT_SYMBOL_GPL(nfs4_test_session_trunk);
8134 8113
8135static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, 8114static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
8136 struct rpc_cred *cred) 8115 const struct cred *cred)
8137{ 8116{
8138 struct rpc_message msg = { 8117 struct rpc_message msg = {
8139 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], 8118 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID],
@@ -8151,7 +8130,7 @@ static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
8151} 8130}
8152 8131
8153static int nfs4_proc_destroy_clientid(struct nfs_client *clp, 8132static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
8154 struct rpc_cred *cred) 8133 const struct cred *cred)
8155{ 8134{
8156 unsigned int loop; 8135 unsigned int loop;
8157 int ret; 8136 int ret;
@@ -8172,7 +8151,7 @@ static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
8172 8151
8173int nfs4_destroy_clientid(struct nfs_client *clp) 8152int nfs4_destroy_clientid(struct nfs_client *clp)
8174{ 8153{
8175 struct rpc_cred *cred; 8154 const struct cred *cred;
8176 int ret = 0; 8155 int ret = 0;
8177 8156
8178 if (clp->cl_mvops->minor_version < 1) 8157 if (clp->cl_mvops->minor_version < 1)
@@ -8183,8 +8162,7 @@ int nfs4_destroy_clientid(struct nfs_client *clp)
8183 goto out; 8162 goto out;
8184 cred = nfs4_get_clid_cred(clp); 8163 cred = nfs4_get_clid_cred(clp);
8185 ret = nfs4_proc_destroy_clientid(clp, cred); 8164 ret = nfs4_proc_destroy_clientid(clp, cred);
8186 if (cred) 8165 put_cred(cred);
8187 put_rpccred(cred);
8188 switch (ret) { 8166 switch (ret) {
8189 case 0: 8167 case 0:
8190 case -NFS4ERR_STALE_CLIENTID: 8168 case -NFS4ERR_STALE_CLIENTID:
@@ -8400,7 +8378,7 @@ static void nfs4_update_session(struct nfs4_session *session,
8400} 8378}
8401 8379
8402static int _nfs4_proc_create_session(struct nfs_client *clp, 8380static int _nfs4_proc_create_session(struct nfs_client *clp,
8403 struct rpc_cred *cred) 8381 const struct cred *cred)
8404{ 8382{
8405 struct nfs4_session *session = clp->cl_session; 8383 struct nfs4_session *session = clp->cl_session;
8406 struct nfs41_create_session_args args = { 8384 struct nfs41_create_session_args args = {
@@ -8452,7 +8430,7 @@ out:
8452 * It is the responsibility of the caller to verify the session is 8430 * It is the responsibility of the caller to verify the session is
8453 * expired before calling this routine. 8431 * expired before calling this routine.
8454 */ 8432 */
8455int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred) 8433int nfs4_proc_create_session(struct nfs_client *clp, const struct cred *cred)
8456{ 8434{
8457 int status; 8435 int status;
8458 unsigned *ptr; 8436 unsigned *ptr;
@@ -8483,7 +8461,7 @@ out:
8483 * The caller must serialize access to this routine. 8461 * The caller must serialize access to this routine.
8484 */ 8462 */
8485int nfs4_proc_destroy_session(struct nfs4_session *session, 8463int nfs4_proc_destroy_session(struct nfs4_session *session,
8486 struct rpc_cred *cred) 8464 const struct cred *cred)
8487{ 8465{
8488 struct rpc_message msg = { 8466 struct rpc_message msg = {
8489 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], 8467 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION],
@@ -8585,7 +8563,7 @@ static const struct rpc_call_ops nfs41_sequence_ops = {
8585}; 8563};
8586 8564
8587static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, 8565static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
8588 struct rpc_cred *cred, 8566 const struct cred *cred,
8589 struct nfs4_slot *slot, 8567 struct nfs4_slot *slot,
8590 bool is_privileged) 8568 bool is_privileged)
8591{ 8569{
@@ -8628,7 +8606,7 @@ out_err:
8628 return ret; 8606 return ret;
8629} 8607}
8630 8608
8631static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) 8609static int nfs41_proc_async_sequence(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags)
8632{ 8610{
8633 struct rpc_task *task; 8611 struct rpc_task *task;
8634 int ret = 0; 8612 int ret = 0;
@@ -8644,7 +8622,7 @@ static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cr
8644 return ret; 8622 return ret;
8645} 8623}
8646 8624
8647static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) 8625static int nfs4_proc_sequence(struct nfs_client *clp, const struct cred *cred)
8648{ 8626{
8649 struct rpc_task *task; 8627 struct rpc_task *task;
8650 int ret; 8628 int ret;
@@ -8740,7 +8718,7 @@ static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
8740 * Issue a global reclaim complete. 8718 * Issue a global reclaim complete.
8741 */ 8719 */
8742static int nfs41_proc_reclaim_complete(struct nfs_client *clp, 8720static int nfs41_proc_reclaim_complete(struct nfs_client *clp,
8743 struct rpc_cred *cred) 8721 const struct cred *cred)
8744{ 8722{
8745 struct nfs4_reclaim_complete_data *calldata; 8723 struct nfs4_reclaim_complete_data *calldata;
8746 struct rpc_task *task; 8724 struct rpc_task *task;
@@ -9093,7 +9071,7 @@ int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync)
9093static int 9071static int
9094_nfs4_proc_getdeviceinfo(struct nfs_server *server, 9072_nfs4_proc_getdeviceinfo(struct nfs_server *server,
9095 struct pnfs_device *pdev, 9073 struct pnfs_device *pdev,
9096 struct rpc_cred *cred) 9074 const struct cred *cred)
9097{ 9075{
9098 struct nfs4_getdeviceinfo_args args = { 9076 struct nfs4_getdeviceinfo_args args = {
9099 .pdev = pdev, 9077 .pdev = pdev,
@@ -9125,7 +9103,7 @@ _nfs4_proc_getdeviceinfo(struct nfs_server *server,
9125 9103
9126int nfs4_proc_getdeviceinfo(struct nfs_server *server, 9104int nfs4_proc_getdeviceinfo(struct nfs_server *server,
9127 struct pnfs_device *pdev, 9105 struct pnfs_device *pdev,
9128 struct rpc_cred *cred) 9106 const struct cred *cred)
9129{ 9107{
9130 struct nfs4_exception exception = { }; 9108 struct nfs4_exception exception = { };
9131 int err; 9109 int err;
@@ -9182,7 +9160,7 @@ static void nfs4_layoutcommit_release(void *calldata)
9182 pnfs_cleanup_layoutcommit(data); 9160 pnfs_cleanup_layoutcommit(data);
9183 nfs_post_op_update_inode_force_wcc(data->args.inode, 9161 nfs_post_op_update_inode_force_wcc(data->args.inode,
9184 data->res.fattr); 9162 data->res.fattr);
9185 put_rpccred(data->cred); 9163 put_cred(data->cred);
9186 nfs_iput_and_deactive(data->inode); 9164 nfs_iput_and_deactive(data->inode);
9187 kfree(data); 9165 kfree(data);
9188} 9166}
@@ -9258,7 +9236,7 @@ _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
9258 .rpc_resp = &res, 9236 .rpc_resp = &res,
9259 }; 9237 };
9260 struct rpc_clnt *clnt = server->client; 9238 struct rpc_clnt *clnt = server->client;
9261 struct rpc_cred *cred = NULL; 9239 const struct cred *cred = NULL;
9262 int status; 9240 int status;
9263 9241
9264 if (use_integrity) { 9242 if (use_integrity) {
@@ -9272,8 +9250,7 @@ _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
9272 &res.seq_res, 0); 9250 &res.seq_res, 0);
9273 dprintk("<-- %s status=%d\n", __func__, status); 9251 dprintk("<-- %s status=%d\n", __func__, status);
9274 9252
9275 if (cred) 9253 put_cred(cred);
9276 put_rpccred(cred);
9277 9254
9278 return status; 9255 return status;
9279} 9256}
@@ -9386,7 +9363,7 @@ out:
9386 9363
9387static int _nfs41_test_stateid(struct nfs_server *server, 9364static int _nfs41_test_stateid(struct nfs_server *server,
9388 nfs4_stateid *stateid, 9365 nfs4_stateid *stateid,
9389 struct rpc_cred *cred) 9366 const struct cred *cred)
9390{ 9367{
9391 int status; 9368 int status;
9392 struct nfs41_test_stateid_args args = { 9369 struct nfs41_test_stateid_args args = {
@@ -9447,7 +9424,7 @@ static void nfs4_handle_delay_or_session_error(struct nfs_server *server,
9447 */ 9424 */
9448static int nfs41_test_stateid(struct nfs_server *server, 9425static int nfs41_test_stateid(struct nfs_server *server,
9449 nfs4_stateid *stateid, 9426 nfs4_stateid *stateid,
9450 struct rpc_cred *cred) 9427 const struct cred *cred)
9451{ 9428{
9452 struct nfs4_exception exception = { }; 9429 struct nfs4_exception exception = { };
9453 int err; 9430 int err;
@@ -9509,7 +9486,7 @@ static const struct rpc_call_ops nfs41_free_stateid_ops = {
9509 */ 9486 */
9510static int nfs41_free_stateid(struct nfs_server *server, 9487static int nfs41_free_stateid(struct nfs_server *server,
9511 const nfs4_stateid *stateid, 9488 const nfs4_stateid *stateid,
9512 struct rpc_cred *cred, 9489 const struct cred *cred,
9513 bool privileged) 9490 bool privileged)
9514{ 9491{
9515 struct rpc_message msg = { 9492 struct rpc_message msg = {
@@ -9550,7 +9527,7 @@ static int nfs41_free_stateid(struct nfs_server *server,
9550static void 9527static void
9551nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) 9528nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp)
9552{ 9529{
9553 struct rpc_cred *cred = lsp->ls_state->owner->so_cred; 9530 const struct cred *cred = lsp->ls_state->owner->so_cred;
9554 9531
9555 nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); 9532 nfs41_free_stateid(server, &lsp->ls_stateid, cred, false);
9556 nfs4_free_lock_state(server, lsp); 9533 nfs4_free_lock_state(server, lsp);
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c
index 8880cd958210..6ea431b067dd 100644
--- a/fs/nfs/nfs4renewd.c
+++ b/fs/nfs/nfs4renewd.c
@@ -57,7 +57,7 @@ nfs4_renew_state(struct work_struct *work)
57 const struct nfs4_state_maintenance_ops *ops; 57 const struct nfs4_state_maintenance_ops *ops;
58 struct nfs_client *clp = 58 struct nfs_client *clp =
59 container_of(work, struct nfs_client, cl_renewd.work); 59 container_of(work, struct nfs_client, cl_renewd.work);
60 struct rpc_cred *cred; 60 const struct cred *cred;
61 long lease; 61 long lease;
62 unsigned long last, now; 62 unsigned long last, now;
63 unsigned renew_flags = 0; 63 unsigned renew_flags = 0;
@@ -90,7 +90,7 @@ nfs4_renew_state(struct work_struct *work)
90 90
91 /* Queue an asynchronous RENEW. */ 91 /* Queue an asynchronous RENEW. */
92 ret = ops->sched_state_renewal(clp, cred, renew_flags); 92 ret = ops->sched_state_renewal(clp, cred, renew_flags);
93 put_rpccred(cred); 93 put_cred(cred);
94 switch (ret) { 94 switch (ret) {
95 default: 95 default:
96 goto out_exp; 96 goto out_exp;
diff --git a/fs/nfs/nfs4session.c b/fs/nfs/nfs4session.c
index 769b85655c4b..a5489d70a724 100644
--- a/fs/nfs/nfs4session.c
+++ b/fs/nfs/nfs4session.c
@@ -573,12 +573,11 @@ static void nfs4_destroy_session_slot_tables(struct nfs4_session *session)
573void nfs4_destroy_session(struct nfs4_session *session) 573void nfs4_destroy_session(struct nfs4_session *session)
574{ 574{
575 struct rpc_xprt *xprt; 575 struct rpc_xprt *xprt;
576 struct rpc_cred *cred; 576 const struct cred *cred;
577 577
578 cred = nfs4_get_clid_cred(session->clp); 578 cred = nfs4_get_clid_cred(session->clp);
579 nfs4_proc_destroy_session(session, cred); 579 nfs4_proc_destroy_session(session, cred);
580 if (cred) 580 put_cred(cred);
581 put_rpccred(cred);
582 581
583 rcu_read_lock(); 582 rcu_read_lock();
584 xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); 583 xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt);
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 6304c79dbcd1..9555a8a9200a 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -87,7 +87,7 @@ const nfs4_stateid current_stateid = {
87 87
88static DEFINE_MUTEX(nfs_clid_init_mutex); 88static DEFINE_MUTEX(nfs_clid_init_mutex);
89 89
90int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) 90int nfs4_init_clientid(struct nfs_client *clp, const struct cred *cred)
91{ 91{
92 struct nfs4_setclientid_res clid = { 92 struct nfs4_setclientid_res clid = {
93 .clientid = clp->cl_clientid, 93 .clientid = clp->cl_clientid,
@@ -134,7 +134,7 @@ out:
134 */ 134 */
135int nfs40_discover_server_trunking(struct nfs_client *clp, 135int nfs40_discover_server_trunking(struct nfs_client *clp,
136 struct nfs_client **result, 136 struct nfs_client **result,
137 struct rpc_cred *cred) 137 const struct cred *cred)
138{ 138{
139 struct nfs4_setclientid_res clid = { 139 struct nfs4_setclientid_res clid = {
140 .clientid = clp->cl_clientid, 140 .clientid = clp->cl_clientid,
@@ -164,9 +164,9 @@ out:
164 return status; 164 return status;
165} 165}
166 166
167struct rpc_cred *nfs4_get_machine_cred(struct nfs_client *clp) 167const struct cred *nfs4_get_machine_cred(struct nfs_client *clp)
168{ 168{
169 return get_rpccred(rpc_machine_cred()); 169 return get_cred(rpc_machine_cred());
170} 170}
171 171
172static void nfs4_root_machine_cred(struct nfs_client *clp) 172static void nfs4_root_machine_cred(struct nfs_client *clp)
@@ -177,10 +177,10 @@ static void nfs4_root_machine_cred(struct nfs_client *clp)
177 clp->cl_rpcclient->cl_principal = NULL; 177 clp->cl_rpcclient->cl_principal = NULL;
178} 178}
179 179
180static struct rpc_cred * 180static const struct cred *
181nfs4_get_renew_cred_server_locked(struct nfs_server *server) 181nfs4_get_renew_cred_server_locked(struct nfs_server *server)
182{ 182{
183 struct rpc_cred *cred = NULL; 183 const struct cred *cred = NULL;
184 struct nfs4_state_owner *sp; 184 struct nfs4_state_owner *sp;
185 struct rb_node *pos; 185 struct rb_node *pos;
186 186
@@ -190,7 +190,7 @@ nfs4_get_renew_cred_server_locked(struct nfs_server *server)
190 sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); 190 sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
191 if (list_empty(&sp->so_states)) 191 if (list_empty(&sp->so_states))
192 continue; 192 continue;
193 cred = get_rpccred(sp->so_cred); 193 cred = get_cred(sp->so_cred);
194 break; 194 break;
195 } 195 }
196 return cred; 196 return cred;
@@ -203,9 +203,9 @@ nfs4_get_renew_cred_server_locked(struct nfs_server *server)
203 * Returns an rpc_cred with reference count bumped, or NULL. 203 * Returns an rpc_cred with reference count bumped, or NULL.
204 * Caller must hold clp->cl_lock. 204 * Caller must hold clp->cl_lock.
205 */ 205 */
206struct rpc_cred *nfs4_get_renew_cred(struct nfs_client *clp) 206const struct cred *nfs4_get_renew_cred(struct nfs_client *clp)
207{ 207{
208 struct rpc_cred *cred = NULL; 208 const struct cred *cred = NULL;
209 struct nfs_server *server; 209 struct nfs_server *server;
210 210
211 /* Use machine credentials if available */ 211 /* Use machine credentials if available */
@@ -312,7 +312,7 @@ static void nfs41_finish_session_reset(struct nfs_client *clp)
312 nfs41_setup_state_renewal(clp); 312 nfs41_setup_state_renewal(clp);
313} 313}
314 314
315int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) 315int nfs41_init_clientid(struct nfs_client *clp, const struct cred *cred)
316{ 316{
317 int status; 317 int status;
318 318
@@ -347,7 +347,7 @@ out:
347 */ 347 */
348int nfs41_discover_server_trunking(struct nfs_client *clp, 348int nfs41_discover_server_trunking(struct nfs_client *clp,
349 struct nfs_client **result, 349 struct nfs_client **result,
350 struct rpc_cred *cred) 350 const struct cred *cred)
351{ 351{
352 int status; 352 int status;
353 353
@@ -385,30 +385,32 @@ int nfs41_discover_server_trunking(struct nfs_client *clp,
385 * nfs4_get_clid_cred - Acquire credential for a setclientid operation 385 * nfs4_get_clid_cred - Acquire credential for a setclientid operation
386 * @clp: client state handle 386 * @clp: client state handle
387 * 387 *
388 * Returns an rpc_cred with reference count bumped, or NULL. 388 * Returns a cred with reference count bumped, or NULL.
389 */ 389 */
390struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp) 390const struct cred *nfs4_get_clid_cred(struct nfs_client *clp)
391{ 391{
392 struct rpc_cred *cred; 392 const struct cred *cred;
393 393
394 cred = nfs4_get_machine_cred(clp); 394 cred = nfs4_get_machine_cred(clp);
395 return cred; 395 return cred;
396} 396}
397 397
398static struct nfs4_state_owner * 398static struct nfs4_state_owner *
399nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred) 399nfs4_find_state_owner_locked(struct nfs_server *server, const struct cred *cred)
400{ 400{
401 struct rb_node **p = &server->state_owners.rb_node, 401 struct rb_node **p = &server->state_owners.rb_node,
402 *parent = NULL; 402 *parent = NULL;
403 struct nfs4_state_owner *sp; 403 struct nfs4_state_owner *sp;
404 int cmp;
404 405
405 while (*p != NULL) { 406 while (*p != NULL) {
406 parent = *p; 407 parent = *p;
407 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); 408 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
409 cmp = cred_fscmp(cred, sp->so_cred);
408 410
409 if (cred < sp->so_cred) 411 if (cmp < 0)
410 p = &parent->rb_left; 412 p = &parent->rb_left;
411 else if (cred > sp->so_cred) 413 else if (cmp > 0)
412 p = &parent->rb_right; 414 p = &parent->rb_right;
413 else { 415 else {
414 if (!list_empty(&sp->so_lru)) 416 if (!list_empty(&sp->so_lru))
@@ -427,14 +429,16 @@ nfs4_insert_state_owner_locked(struct nfs4_state_owner *new)
427 struct rb_node **p = &server->state_owners.rb_node, 429 struct rb_node **p = &server->state_owners.rb_node,
428 *parent = NULL; 430 *parent = NULL;
429 struct nfs4_state_owner *sp; 431 struct nfs4_state_owner *sp;
432 int cmp;
430 433
431 while (*p != NULL) { 434 while (*p != NULL) {
432 parent = *p; 435 parent = *p;
433 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); 436 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
437 cmp = cred_fscmp(new->so_cred, sp->so_cred);
434 438
435 if (new->so_cred < sp->so_cred) 439 if (cmp < 0)
436 p = &parent->rb_left; 440 p = &parent->rb_left;
437 else if (new->so_cred > sp->so_cred) 441 else if (cmp > 0)
438 p = &parent->rb_right; 442 p = &parent->rb_right;
439 else { 443 else {
440 if (!list_empty(&sp->so_lru)) 444 if (!list_empty(&sp->so_lru))
@@ -481,7 +485,7 @@ nfs4_destroy_seqid_counter(struct nfs_seqid_counter *sc)
481 */ 485 */
482static struct nfs4_state_owner * 486static struct nfs4_state_owner *
483nfs4_alloc_state_owner(struct nfs_server *server, 487nfs4_alloc_state_owner(struct nfs_server *server,
484 struct rpc_cred *cred, 488 const struct cred *cred,
485 gfp_t gfp_flags) 489 gfp_t gfp_flags)
486{ 490{
487 struct nfs4_state_owner *sp; 491 struct nfs4_state_owner *sp;
@@ -496,7 +500,7 @@ nfs4_alloc_state_owner(struct nfs_server *server,
496 return NULL; 500 return NULL;
497 } 501 }
498 sp->so_server = server; 502 sp->so_server = server;
499 sp->so_cred = get_rpccred(cred); 503 sp->so_cred = get_cred(cred);
500 spin_lock_init(&sp->so_lock); 504 spin_lock_init(&sp->so_lock);
501 INIT_LIST_HEAD(&sp->so_states); 505 INIT_LIST_HEAD(&sp->so_states);
502 nfs4_init_seqid_counter(&sp->so_seqid); 506 nfs4_init_seqid_counter(&sp->so_seqid);
@@ -525,7 +529,7 @@ nfs4_reset_state_owner(struct nfs4_state_owner *sp)
525static void nfs4_free_state_owner(struct nfs4_state_owner *sp) 529static void nfs4_free_state_owner(struct nfs4_state_owner *sp)
526{ 530{
527 nfs4_destroy_seqid_counter(&sp->so_seqid); 531 nfs4_destroy_seqid_counter(&sp->so_seqid);
528 put_rpccred(sp->so_cred); 532 put_cred(sp->so_cred);
529 ida_simple_remove(&sp->so_server->openowner_id, sp->so_seqid.owner_id); 533 ida_simple_remove(&sp->so_server->openowner_id, sp->so_seqid.owner_id);
530 kfree(sp); 534 kfree(sp);
531} 535}
@@ -563,7 +567,7 @@ static void nfs4_gc_state_owners(struct nfs_server *server)
563 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. 567 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL.
564 */ 568 */
565struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, 569struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
566 struct rpc_cred *cred, 570 const struct cred *cred,
567 gfp_t gfp_flags) 571 gfp_t gfp_flags)
568{ 572{
569 struct nfs_client *clp = server->nfs_client; 573 struct nfs_client *clp = server->nfs_client;
@@ -1032,7 +1036,7 @@ bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
1032 */ 1036 */
1033int nfs4_select_rw_stateid(struct nfs4_state *state, 1037int nfs4_select_rw_stateid(struct nfs4_state *state,
1034 fmode_t fmode, const struct nfs_lock_context *l_ctx, 1038 fmode_t fmode, const struct nfs_lock_context *l_ctx,
1035 nfs4_stateid *dst, struct rpc_cred **cred) 1039 nfs4_stateid *dst, const struct cred **cred)
1036{ 1040{
1037 int ret; 1041 int ret;
1038 1042
@@ -1732,7 +1736,7 @@ static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp)
1732 1736
1733static int nfs4_reclaim_complete(struct nfs_client *clp, 1737static int nfs4_reclaim_complete(struct nfs_client *clp,
1734 const struct nfs4_state_recovery_ops *ops, 1738 const struct nfs4_state_recovery_ops *ops,
1735 struct rpc_cred *cred) 1739 const struct cred *cred)
1736{ 1740{
1737 /* Notify the server we're done reclaiming our state */ 1741 /* Notify the server we're done reclaiming our state */
1738 if (ops->reclaim_complete) 1742 if (ops->reclaim_complete)
@@ -1783,7 +1787,7 @@ static int nfs4_state_clear_reclaim_reboot(struct nfs_client *clp)
1783static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp) 1787static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
1784{ 1788{
1785 const struct nfs4_state_recovery_ops *ops; 1789 const struct nfs4_state_recovery_ops *ops;
1786 struct rpc_cred *cred; 1790 const struct cred *cred;
1787 int err; 1791 int err;
1788 1792
1789 if (!nfs4_state_clear_reclaim_reboot(clp)) 1793 if (!nfs4_state_clear_reclaim_reboot(clp))
@@ -1791,7 +1795,7 @@ static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
1791 ops = clp->cl_mvops->reboot_recovery_ops; 1795 ops = clp->cl_mvops->reboot_recovery_ops;
1792 cred = nfs4_get_clid_cred(clp); 1796 cred = nfs4_get_clid_cred(clp);
1793 err = nfs4_reclaim_complete(clp, ops, cred); 1797 err = nfs4_reclaim_complete(clp, ops, cred);
1794 put_rpccred(cred); 1798 put_cred(cred);
1795 if (err == -NFS4ERR_CONN_NOT_BOUND_TO_SESSION) 1799 if (err == -NFS4ERR_CONN_NOT_BOUND_TO_SESSION)
1796 set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state); 1800 set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
1797} 1801}
@@ -1887,7 +1891,7 @@ restart:
1887 1891
1888static int nfs4_check_lease(struct nfs_client *clp) 1892static int nfs4_check_lease(struct nfs_client *clp)
1889{ 1893{
1890 struct rpc_cred *cred; 1894 const struct cred *cred;
1891 const struct nfs4_state_maintenance_ops *ops = 1895 const struct nfs4_state_maintenance_ops *ops =
1892 clp->cl_mvops->state_renewal_ops; 1896 clp->cl_mvops->state_renewal_ops;
1893 int status; 1897 int status;
@@ -1903,7 +1907,7 @@ static int nfs4_check_lease(struct nfs_client *clp)
1903 goto out; 1907 goto out;
1904 } 1908 }
1905 status = ops->renew_lease(clp, cred); 1909 status = ops->renew_lease(clp, cred);
1906 put_rpccred(cred); 1910 put_cred(cred);
1907 if (status == -ETIMEDOUT) { 1911 if (status == -ETIMEDOUT) {
1908 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); 1912 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
1909 return 0; 1913 return 0;
@@ -1963,7 +1967,7 @@ static int nfs4_handle_reclaim_lease_error(struct nfs_client *clp, int status)
1963 1967
1964static int nfs4_establish_lease(struct nfs_client *clp) 1968static int nfs4_establish_lease(struct nfs_client *clp)
1965{ 1969{
1966 struct rpc_cred *cred; 1970 const struct cred *cred;
1967 const struct nfs4_state_recovery_ops *ops = 1971 const struct nfs4_state_recovery_ops *ops =
1968 clp->cl_mvops->reboot_recovery_ops; 1972 clp->cl_mvops->reboot_recovery_ops;
1969 int status; 1973 int status;
@@ -1975,7 +1979,7 @@ static int nfs4_establish_lease(struct nfs_client *clp)
1975 if (cred == NULL) 1979 if (cred == NULL)
1976 return -ENOENT; 1980 return -ENOENT;
1977 status = ops->establish_clid(clp, cred); 1981 status = ops->establish_clid(clp, cred);
1978 put_rpccred(cred); 1982 put_cred(cred);
1979 if (status != 0) 1983 if (status != 0)
1980 return status; 1984 return status;
1981 pnfs_destroy_all_layouts(clp); 1985 pnfs_destroy_all_layouts(clp);
@@ -2022,7 +2026,7 @@ static int nfs4_purge_lease(struct nfs_client *clp)
2022 * 2026 *
2023 * Returns zero or a negative NFS4ERR status code. 2027 * Returns zero or a negative NFS4ERR status code.
2024 */ 2028 */
2025static int nfs4_try_migration(struct nfs_server *server, struct rpc_cred *cred) 2029static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred)
2026{ 2030{
2027 struct nfs_client *clp = server->nfs_client; 2031 struct nfs_client *clp = server->nfs_client;
2028 struct nfs4_fs_locations *locations = NULL; 2032 struct nfs4_fs_locations *locations = NULL;
@@ -2092,7 +2096,7 @@ static int nfs4_handle_migration(struct nfs_client *clp)
2092 const struct nfs4_state_maintenance_ops *ops = 2096 const struct nfs4_state_maintenance_ops *ops =
2093 clp->cl_mvops->state_renewal_ops; 2097 clp->cl_mvops->state_renewal_ops;
2094 struct nfs_server *server; 2098 struct nfs_server *server;
2095 struct rpc_cred *cred; 2099 const struct cred *cred;
2096 2100
2097 dprintk("%s: migration reported on \"%s\"\n", __func__, 2101 dprintk("%s: migration reported on \"%s\"\n", __func__,
2098 clp->cl_hostname); 2102 clp->cl_hostname);
@@ -2118,13 +2122,13 @@ restart:
2118 rcu_read_unlock(); 2122 rcu_read_unlock();
2119 status = nfs4_try_migration(server, cred); 2123 status = nfs4_try_migration(server, cred);
2120 if (status < 0) { 2124 if (status < 0) {
2121 put_rpccred(cred); 2125 put_cred(cred);
2122 return status; 2126 return status;
2123 } 2127 }
2124 goto restart; 2128 goto restart;
2125 } 2129 }
2126 rcu_read_unlock(); 2130 rcu_read_unlock();
2127 put_rpccred(cred); 2131 put_cred(cred);
2128 return 0; 2132 return 0;
2129} 2133}
2130 2134
@@ -2138,7 +2142,7 @@ static int nfs4_handle_lease_moved(struct nfs_client *clp)
2138 const struct nfs4_state_maintenance_ops *ops = 2142 const struct nfs4_state_maintenance_ops *ops =
2139 clp->cl_mvops->state_renewal_ops; 2143 clp->cl_mvops->state_renewal_ops;
2140 struct nfs_server *server; 2144 struct nfs_server *server;
2141 struct rpc_cred *cred; 2145 const struct cred *cred;
2142 2146
2143 dprintk("%s: lease moved reported on \"%s\"\n", __func__, 2147 dprintk("%s: lease moved reported on \"%s\"\n", __func__,
2144 clp->cl_hostname); 2148 clp->cl_hostname);
@@ -2171,7 +2175,7 @@ restart:
2171 rcu_read_unlock(); 2175 rcu_read_unlock();
2172 2176
2173out: 2177out:
2174 put_rpccred(cred); 2178 put_cred(cred);
2175 return 0; 2179 return 0;
2176} 2180}
2177 2181
@@ -2194,7 +2198,7 @@ int nfs4_discover_server_trunking(struct nfs_client *clp,
2194 const struct nfs4_state_recovery_ops *ops = 2198 const struct nfs4_state_recovery_ops *ops =
2195 clp->cl_mvops->reboot_recovery_ops; 2199 clp->cl_mvops->reboot_recovery_ops;
2196 struct rpc_clnt *clnt; 2200 struct rpc_clnt *clnt;
2197 struct rpc_cred *cred; 2201 const struct cred *cred;
2198 int i, status; 2202 int i, status;
2199 2203
2200 dprintk("NFS: %s: testing '%s'\n", __func__, clp->cl_hostname); 2204 dprintk("NFS: %s: testing '%s'\n", __func__, clp->cl_hostname);
@@ -2210,7 +2214,7 @@ again:
2210 goto out_unlock; 2214 goto out_unlock;
2211 2215
2212 status = ops->detect_trunking(clp, result, cred); 2216 status = ops->detect_trunking(clp, result, cred);
2213 put_rpccred(cred); 2217 put_cred(cred);
2214 switch (status) { 2218 switch (status) {
2215 case 0: 2219 case 0:
2216 case -EINTR: 2220 case -EINTR:
@@ -2401,7 +2405,7 @@ out_recovery:
2401 2405
2402static int nfs4_reset_session(struct nfs_client *clp) 2406static int nfs4_reset_session(struct nfs_client *clp)
2403{ 2407{
2404 struct rpc_cred *cred; 2408 const struct cred *cred;
2405 int status; 2409 int status;
2406 2410
2407 if (!nfs4_has_session(clp)) 2411 if (!nfs4_has_session(clp))
@@ -2439,14 +2443,13 @@ static int nfs4_reset_session(struct nfs_client *clp)
2439 dprintk("%s: session reset was successful for server %s!\n", 2443 dprintk("%s: session reset was successful for server %s!\n",
2440 __func__, clp->cl_hostname); 2444 __func__, clp->cl_hostname);
2441out: 2445out:
2442 if (cred) 2446 put_cred(cred);
2443 put_rpccred(cred);
2444 return status; 2447 return status;
2445} 2448}
2446 2449
2447static int nfs4_bind_conn_to_session(struct nfs_client *clp) 2450static int nfs4_bind_conn_to_session(struct nfs_client *clp)
2448{ 2451{
2449 struct rpc_cred *cred; 2452 const struct cred *cred;
2450 int ret; 2453 int ret;
2451 2454
2452 if (!nfs4_has_session(clp)) 2455 if (!nfs4_has_session(clp))
@@ -2456,8 +2459,7 @@ static int nfs4_bind_conn_to_session(struct nfs_client *clp)
2456 return ret; 2459 return ret;
2457 cred = nfs4_get_clid_cred(clp); 2460 cred = nfs4_get_clid_cred(clp);
2458 ret = nfs4_proc_bind_conn_to_session(clp, cred); 2461 ret = nfs4_proc_bind_conn_to_session(clp, cred);
2459 if (cred) 2462 put_cred(cred);
2460 put_rpccred(cred);
2461 clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); 2463 clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
2462 switch (ret) { 2464 switch (ret) {
2463 case 0: 2465 case 0:
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 87f3da1fd850..e54d899c1848 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -587,7 +587,7 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata)
587} 587}
588 588
589int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, 589int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
590 struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops, 590 const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
591 const struct rpc_call_ops *call_ops, int how, int flags) 591 const struct rpc_call_ops *call_ops, int how, int flags)
592{ 592{
593 struct rpc_task *task; 593 struct rpc_task *task;
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 06cb90e9bc6e..53726da5c010 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -275,7 +275,7 @@ pnfs_free_layout_hdr(struct pnfs_layout_hdr *lo)
275 list_del_init(&lo->plh_layouts); 275 list_del_init(&lo->plh_layouts);
276 spin_unlock(&clp->cl_lock); 276 spin_unlock(&clp->cl_lock);
277 } 277 }
278 put_rpccred(lo->plh_lc_cred); 278 put_cred(lo->plh_lc_cred);
279 return ld->free_layout_hdr(lo); 279 return ld->free_layout_hdr(lo);
280} 280}
281 281
@@ -1038,7 +1038,7 @@ pnfs_alloc_init_layoutget_args(struct inode *ino,
1038 lgp->args.ctx = get_nfs_open_context(ctx); 1038 lgp->args.ctx = get_nfs_open_context(ctx);
1039 nfs4_stateid_copy(&lgp->args.stateid, stateid); 1039 nfs4_stateid_copy(&lgp->args.stateid, stateid);
1040 lgp->gfp_flags = gfp_flags; 1040 lgp->gfp_flags = gfp_flags;
1041 lgp->cred = get_rpccred(ctx->cred); 1041 lgp->cred = get_cred(ctx->cred);
1042 return lgp; 1042 return lgp;
1043} 1043}
1044 1044
@@ -1049,7 +1049,7 @@ void pnfs_layoutget_free(struct nfs4_layoutget *lgp)
1049 nfs4_free_pages(lgp->args.layout.pages, max_pages); 1049 nfs4_free_pages(lgp->args.layout.pages, max_pages);
1050 if (lgp->args.inode) 1050 if (lgp->args.inode)
1051 pnfs_put_layout_hdr(NFS_I(lgp->args.inode)->layout); 1051 pnfs_put_layout_hdr(NFS_I(lgp->args.inode)->layout);
1052 put_rpccred(lgp->cred); 1052 put_cred(lgp->cred);
1053 put_nfs_open_context(lgp->args.ctx); 1053 put_nfs_open_context(lgp->args.ctx);
1054 kfree(lgp); 1054 kfree(lgp);
1055} 1055}
@@ -1324,7 +1324,7 @@ pnfs_commit_and_return_layout(struct inode *inode)
1324bool pnfs_roc(struct inode *ino, 1324bool pnfs_roc(struct inode *ino,
1325 struct nfs4_layoutreturn_args *args, 1325 struct nfs4_layoutreturn_args *args,
1326 struct nfs4_layoutreturn_res *res, 1326 struct nfs4_layoutreturn_res *res,
1327 const struct rpc_cred *cred) 1327 const struct cred *cred)
1328{ 1328{
1329 struct nfs_inode *nfsi = NFS_I(ino); 1329 struct nfs_inode *nfsi = NFS_I(ino);
1330 struct nfs_open_context *ctx; 1330 struct nfs_open_context *ctx;
@@ -1583,7 +1583,7 @@ alloc_init_layout_hdr(struct inode *ino,
1583 INIT_LIST_HEAD(&lo->plh_return_segs); 1583 INIT_LIST_HEAD(&lo->plh_return_segs);
1584 INIT_LIST_HEAD(&lo->plh_bulk_destroy); 1584 INIT_LIST_HEAD(&lo->plh_bulk_destroy);
1585 lo->plh_inode = ino; 1585 lo->plh_inode = ino;
1586 lo->plh_lc_cred = get_rpccred(ctx->cred); 1586 lo->plh_lc_cred = get_cred(ctx->cred);
1587 lo->plh_flags |= 1 << NFS_LAYOUT_INVALID_STID; 1587 lo->plh_flags |= 1 << NFS_LAYOUT_INVALID_STID;
1588 return lo; 1588 return lo;
1589} 1589}
@@ -2928,7 +2928,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
2928 spin_unlock(&inode->i_lock); 2928 spin_unlock(&inode->i_lock);
2929 2929
2930 data->args.inode = inode; 2930 data->args.inode = inode;
2931 data->cred = get_rpccred(nfsi->layout->plh_lc_cred); 2931 data->cred = get_cred(nfsi->layout->plh_lc_cred);
2932 nfs_fattr_init(&data->fattr); 2932 nfs_fattr_init(&data->fattr);
2933 data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; 2933 data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask;
2934 data->res.fattr = &data->fattr; 2934 data->res.fattr = &data->fattr;
@@ -2941,7 +2941,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
2941 if (ld->prepare_layoutcommit) { 2941 if (ld->prepare_layoutcommit) {
2942 status = ld->prepare_layoutcommit(&data->args); 2942 status = ld->prepare_layoutcommit(&data->args);
2943 if (status) { 2943 if (status) {
2944 put_rpccred(data->cred); 2944 put_cred(data->cred);
2945 spin_lock(&inode->i_lock); 2945 spin_lock(&inode->i_lock);
2946 set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags); 2946 set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags);
2947 if (end_pos > nfsi->layout->plh_lwb) 2947 if (end_pos > nfsi->layout->plh_lwb)
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index e2e9fcd5341d..5e80a07b7bea 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -200,7 +200,7 @@ struct pnfs_layout_hdr {
200 u32 plh_return_seq; 200 u32 plh_return_seq;
201 enum pnfs_iomode plh_return_iomode; 201 enum pnfs_iomode plh_return_iomode;
202 loff_t plh_lwb; /* last write byte for layoutcommit */ 202 loff_t plh_lwb; /* last write byte for layoutcommit */
203 struct rpc_cred *plh_lc_cred; /* layoutcommit cred */ 203 const struct cred *plh_lc_cred; /* layoutcommit cred */
204 struct inode *plh_inode; 204 struct inode *plh_inode;
205}; 205};
206 206
@@ -230,7 +230,7 @@ extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *);
230extern size_t max_response_pages(struct nfs_server *server); 230extern size_t max_response_pages(struct nfs_server *server);
231extern int nfs4_proc_getdeviceinfo(struct nfs_server *server, 231extern int nfs4_proc_getdeviceinfo(struct nfs_server *server,
232 struct pnfs_device *dev, 232 struct pnfs_device *dev,
233 struct rpc_cred *cred); 233 const struct cred *cred);
234extern struct pnfs_layout_segment* nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout); 234extern struct pnfs_layout_segment* nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout);
235extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync); 235extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync);
236 236
@@ -280,7 +280,7 @@ int pnfs_mark_layout_stateid_invalid(struct pnfs_layout_hdr *lo,
280bool pnfs_roc(struct inode *ino, 280bool pnfs_roc(struct inode *ino,
281 struct nfs4_layoutreturn_args *args, 281 struct nfs4_layoutreturn_args *args,
282 struct nfs4_layoutreturn_res *res, 282 struct nfs4_layoutreturn_res *res,
283 const struct rpc_cred *cred); 283 const struct cred *cred);
284void pnfs_roc_release(struct nfs4_layoutreturn_args *args, 284void pnfs_roc_release(struct nfs4_layoutreturn_args *args,
285 struct nfs4_layoutreturn_res *res, 285 struct nfs4_layoutreturn_res *res,
286 int ret); 286 int ret);
@@ -343,7 +343,7 @@ struct nfs4_deviceid_node {
343 343
344struct nfs4_deviceid_node * 344struct nfs4_deviceid_node *
345nfs4_find_get_deviceid(struct nfs_server *server, 345nfs4_find_get_deviceid(struct nfs_server *server,
346 const struct nfs4_deviceid *id, struct rpc_cred *cred, 346 const struct nfs4_deviceid *id, const struct cred *cred,
347 gfp_t gfp_mask); 347 gfp_t gfp_mask);
348void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *); 348void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *);
349void nfs4_init_deviceid_node(struct nfs4_deviceid_node *, struct nfs_server *, 349void nfs4_init_deviceid_node(struct nfs4_deviceid_node *, struct nfs_server *,
@@ -694,7 +694,7 @@ static inline bool
694pnfs_roc(struct inode *ino, 694pnfs_roc(struct inode *ino,
695 struct nfs4_layoutreturn_args *args, 695 struct nfs4_layoutreturn_args *args,
696 struct nfs4_layoutreturn_res *res, 696 struct nfs4_layoutreturn_res *res,
697 const struct rpc_cred *cred) 697 const struct cred *cred)
698{ 698{
699 return false; 699 return false;
700} 700}
diff --git a/fs/nfs/pnfs_dev.c b/fs/nfs/pnfs_dev.c
index e8a07b3f9aaa..7fb59487ee90 100644
--- a/fs/nfs/pnfs_dev.c
+++ b/fs/nfs/pnfs_dev.c
@@ -94,7 +94,7 @@ _lookup_deviceid(const struct pnfs_layoutdriver_type *ld,
94static struct nfs4_deviceid_node * 94static struct nfs4_deviceid_node *
95nfs4_get_device_info(struct nfs_server *server, 95nfs4_get_device_info(struct nfs_server *server,
96 const struct nfs4_deviceid *dev_id, 96 const struct nfs4_deviceid *dev_id,
97 struct rpc_cred *cred, gfp_t gfp_flags) 97 const struct cred *cred, gfp_t gfp_flags)
98{ 98{
99 struct nfs4_deviceid_node *d = NULL; 99 struct nfs4_deviceid_node *d = NULL;
100 struct pnfs_device *pdev = NULL; 100 struct pnfs_device *pdev = NULL;
@@ -184,7 +184,7 @@ __nfs4_find_get_deviceid(struct nfs_server *server,
184 184
185struct nfs4_deviceid_node * 185struct nfs4_deviceid_node *
186nfs4_find_get_deviceid(struct nfs_server *server, 186nfs4_find_get_deviceid(struct nfs_server *server,
187 const struct nfs4_deviceid *id, struct rpc_cred *cred, 187 const struct nfs4_deviceid *id, const struct cred *cred,
188 gfp_t gfp_mask) 188 gfp_t gfp_mask)
189{ 189{
190 long hash = nfs4_deviceid_hash(id); 190 long hash = nfs4_deviceid_hash(id);
diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c
index d5e4d3cd8c7f..f5ad75fafc3c 100644
--- a/fs/nfs/pnfs_nfs.c
+++ b/fs/nfs/pnfs_nfs.c
@@ -686,7 +686,7 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv,
686 rpc_clnt_setup_test_and_add_xprt, 686 rpc_clnt_setup_test_and_add_xprt,
687 &rpcdata); 687 &rpcdata);
688 if (xprtdata.cred) 688 if (xprtdata.cred)
689 put_rpccred(xprtdata.cred); 689 put_cred(xprtdata.cred);
690 } else { 690 } else {
691 clp = nfs4_set_ds_client(mds_srv, 691 clp = nfs4_set_ds_client(mds_srv,
692 (struct sockaddr *)&da->da_addr, 692 (struct sockaddr *)&da->da_addr,
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index 1ba717bd20c4..5552fa8b6e12 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -500,25 +500,18 @@ nfs_proc_readdir(struct dentry *dentry, const struct cred *cred,
500 .count = count, 500 .count = count,
501 .pages = pages, 501 .pages = pages,
502 }; 502 };
503 struct auth_cred acred = {
504 .cred = cred,
505 };
506 struct rpc_message msg = { 503 struct rpc_message msg = {
507 .rpc_proc = &nfs_procedures[NFSPROC_READDIR], 504 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
508 .rpc_argp = &arg, 505 .rpc_argp = &arg,
509 .rpc_cred = rpc_lookup_generic_cred(&acred, 506 .rpc_cred = cred,
510 0, GFP_NOFS),
511 }; 507 };
512 int status; 508 int status;
513 509
514 dprintk("NFS call readdir %d\n", (unsigned int)cookie); 510 dprintk("NFS call readdir %d\n", (unsigned int)cookie);
515 if (!msg.rpc_cred)
516 return -ENOMEM;
517 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 511 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
518 512
519 nfs_invalidate_atime(dir); 513 nfs_invalidate_atime(dir);
520 514
521 put_rpccred(msg.rpc_cred);
522 dprintk("NFS reply readdir: %d\n", status); 515 dprintk("NFS reply readdir: %d\n", status);
523 return status; 516 return status;
524} 517}
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c
index fd61bf0fce63..a227ab7d6891 100644
--- a/fs/nfs/unlink.c
+++ b/fs/nfs/unlink.c
@@ -31,7 +31,7 @@
31static void 31static void
32nfs_free_unlinkdata(struct nfs_unlinkdata *data) 32nfs_free_unlinkdata(struct nfs_unlinkdata *data)
33{ 33{
34 put_rpccred(data->cred); 34 put_cred(data->cred);
35 kfree(data->args.name.name); 35 kfree(data->args.name.name);
36 kfree(data); 36 kfree(data);
37} 37}
@@ -177,11 +177,7 @@ nfs_async_unlink(struct dentry *dentry, const struct qstr *name)
177 goto out_free; 177 goto out_free;
178 data->args.name.len = name->len; 178 data->args.name.len = name->len;
179 179
180 data->cred = rpc_lookup_cred(); 180 data->cred = get_current_cred();
181 if (IS_ERR(data->cred)) {
182 status = PTR_ERR(data->cred);
183 goto out_free_name;
184 }
185 data->res.dir_attr = &data->dir_attr; 181 data->res.dir_attr = &data->dir_attr;
186 init_waitqueue_head(&data->wq); 182 init_waitqueue_head(&data->wq);
187 183
@@ -202,8 +198,7 @@ nfs_async_unlink(struct dentry *dentry, const struct qstr *name)
202 return 0; 198 return 0;
203out_unlock: 199out_unlock:
204 spin_unlock(&dentry->d_lock); 200 spin_unlock(&dentry->d_lock);
205 put_rpccred(data->cred); 201 put_cred(data->cred);
206out_free_name:
207 kfree(data->args.name.name); 202 kfree(data->args.name.name);
208out_free: 203out_free:
209 kfree(data); 204 kfree(data);
@@ -307,7 +302,7 @@ static void nfs_async_rename_release(void *calldata)
307 iput(data->old_dir); 302 iput(data->old_dir);
308 iput(data->new_dir); 303 iput(data->new_dir);
309 nfs_sb_deactive(sb); 304 nfs_sb_deactive(sb);
310 put_rpccred(data->cred); 305 put_cred(data->cred);
311 kfree(data); 306 kfree(data);
312} 307}
313 308
@@ -352,7 +347,7 @@ nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
352 return ERR_PTR(-ENOMEM); 347 return ERR_PTR(-ENOMEM);
353 task_setup_data.callback_data = data; 348 task_setup_data.callback_data = data;
354 349
355 data->cred = rpc_lookup_cred(); 350 data->cred = get_current_cred();
356 if (IS_ERR(data->cred)) { 351 if (IS_ERR(data->cred)) {
357 struct rpc_task *task = ERR_CAST(data->cred); 352 struct rpc_task *task = ERR_CAST(data->cred);
358 kfree(data); 353 kfree(data);
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index c1452f838131..76f33df51fbb 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1249,7 +1249,7 @@ bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode)
1249 struct rpc_auth *auth = NFS_SERVER(inode)->client->cl_auth; 1249 struct rpc_auth *auth = NFS_SERVER(inode)->client->cl_auth;
1250 struct rpc_cred *cred = ctx->ll_cred; 1250 struct rpc_cred *cred = ctx->ll_cred;
1251 struct auth_cred acred = { 1251 struct auth_cred acred = {
1252 .cred = ctx->cred->cr_cred, 1252 .cred = ctx->cred,
1253 }; 1253 };
1254 1254
1255 if (cred && !cred->cr_ops->crmatch(&acred, cred, 0)) { 1255 if (cred && !cred->cr_ops->crmatch(&acred, cred, 0)) {
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 1dcee1fd32d9..c74e4538d0eb 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -844,18 +844,15 @@ static int max_cb_time(struct net *net)
844 return max(nn->nfsd4_lease/10, (time_t)1) * HZ; 844 return max(nn->nfsd4_lease/10, (time_t)1) * HZ;
845} 845}
846 846
847static struct rpc_cred *get_backchannel_cred(struct nfs4_client *clp, struct rpc_clnt *client, struct nfsd4_session *ses) 847static const struct cred *get_backchannel_cred(struct nfs4_client *clp, struct rpc_clnt *client, struct nfsd4_session *ses)
848{ 848{
849 if (clp->cl_minorversion == 0) { 849 if (clp->cl_minorversion == 0) {
850 client->cl_principal = clp->cl_cred.cr_targ_princ ? 850 client->cl_principal = clp->cl_cred.cr_targ_princ ?
851 clp->cl_cred.cr_targ_princ : "nfs"; 851 clp->cl_cred.cr_targ_princ : "nfs";
852 852
853 return get_rpccred(rpc_machine_cred()); 853 return get_cred(rpc_machine_cred());
854 } else { 854 } else {
855 struct rpc_auth *auth = client->cl_auth;
856 struct auth_cred acred = {};
857 struct cred *kcred; 855 struct cred *kcred;
858 struct rpc_cred *ret;
859 856
860 kcred = prepare_kernel_cred(NULL); 857 kcred = prepare_kernel_cred(NULL);
861 if (!kcred) 858 if (!kcred)
@@ -863,10 +860,7 @@ static struct rpc_cred *get_backchannel_cred(struct nfs4_client *clp, struct rpc
863 860
864 kcred->uid = ses->se_cb_sec.uid; 861 kcred->uid = ses->se_cb_sec.uid;
865 kcred->gid = ses->se_cb_sec.gid; 862 kcred->gid = ses->se_cb_sec.gid;
866 acred.cred = kcred; 863 return kcred;
867 ret = auth->au_ops->lookup_cred(client->cl_auth, &acred, 0);
868 put_cred(kcred);
869 return ret;
870 } 864 }
871} 865}
872 866
@@ -889,7 +883,7 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c
889 .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), 883 .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET),
890 }; 884 };
891 struct rpc_clnt *client; 885 struct rpc_clnt *client;
892 struct rpc_cred *cred; 886 const struct cred *cred;
893 887
894 if (clp->cl_minorversion == 0) { 888 if (clp->cl_minorversion == 0) {
895 if (!clp->cl_cred.cr_principal && 889 if (!clp->cl_cred.cr_principal &&
@@ -1219,7 +1213,7 @@ static void nfsd4_process_cb_update(struct nfsd4_callback *cb)
1219 if (clp->cl_cb_client) { 1213 if (clp->cl_cb_client) {
1220 rpc_shutdown_client(clp->cl_cb_client); 1214 rpc_shutdown_client(clp->cl_cb_client);
1221 clp->cl_cb_client = NULL; 1215 clp->cl_cb_client = NULL;
1222 put_rpccred(clp->cl_cb_cred); 1216 put_cred(clp->cl_cb_cred);
1223 clp->cl_cb_cred = NULL; 1217 clp->cl_cb_cred = NULL;
1224 } 1218 }
1225 if (clp->cl_cb_conn.cb_xprt) { 1219 if (clp->cl_cb_conn.cb_xprt) {
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 6aacb325b6a0..396c76755b03 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -327,7 +327,7 @@ struct nfs4_client {
327#define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \ 327#define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \
328 1 << NFSD4_CLIENT_CB_KILL) 328 1 << NFSD4_CLIENT_CB_KILL)
329 unsigned long cl_flags; 329 unsigned long cl_flags;
330 struct rpc_cred *cl_cb_cred; 330 const struct cred *cl_cb_cred;
331 struct rpc_clnt *cl_cb_client; 331 struct rpc_clnt *cl_cb_client;
332 u32 cl_cb_ident; 332 u32 cl_cb_ident;
333#define NFSD4_CB_UP 0 333#define NFSD4_CB_UP 0
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 271015e55d0f..40e30376130b 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -70,7 +70,7 @@ struct nfs_open_context {
70 struct nfs_lock_context lock_context; 70 struct nfs_lock_context lock_context;
71 fl_owner_t flock_owner; 71 fl_owner_t flock_owner;
72 struct dentry *dentry; 72 struct dentry *dentry;
73 struct rpc_cred *cred; 73 const struct cred *cred;
74 struct rpc_cred *ll_cred; /* low-level cred - use to check for expiry */ 74 struct rpc_cred *ll_cred; /* low-level cred - use to check for expiry */
75 struct nfs4_state *state; 75 struct nfs4_state *state;
76 fmode_t mode; 76 fmode_t mode;
@@ -391,7 +391,7 @@ extern void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
391 struct nfs4_label *label); 391 struct nfs4_label *label);
392extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx); 392extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
393extern void put_nfs_open_context(struct nfs_open_context *ctx); 393extern void put_nfs_open_context(struct nfs_open_context *ctx);
394extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode); 394extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode);
395extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode, struct file *filp); 395extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode, struct file *filp);
396extern void nfs_inode_attach_open_context(struct nfs_open_context *ctx); 396extern void nfs_inode_attach_open_context(struct nfs_open_context *ctx);
397extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx); 397extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx);
@@ -462,7 +462,7 @@ static inline struct nfs_open_context *nfs_file_open_context(struct file *filp)
462 return filp->private_data; 462 return filp->private_data;
463} 463}
464 464
465static inline struct rpc_cred *nfs_file_cred(struct file *file) 465static inline const struct cred *nfs_file_cred(struct file *file)
466{ 466{
467 if (file != NULL) { 467 if (file != NULL) {
468 struct nfs_open_context *ctx = 468 struct nfs_open_context *ctx =
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index cd489e2e0979..441a93ebcac0 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -270,7 +270,7 @@ struct nfs4_layoutget_res {
270struct nfs4_layoutget { 270struct nfs4_layoutget {
271 struct nfs4_layoutget_args args; 271 struct nfs4_layoutget_args args;
272 struct nfs4_layoutget_res res; 272 struct nfs4_layoutget_res res;
273 struct rpc_cred *cred; 273 const struct cred *cred;
274 gfp_t gfp_flags; 274 gfp_t gfp_flags;
275}; 275};
276 276
@@ -309,7 +309,7 @@ struct nfs4_layoutcommit_data {
309 struct rpc_task task; 309 struct rpc_task task;
310 struct nfs_fattr fattr; 310 struct nfs_fattr fattr;
311 struct list_head lseg_list; 311 struct list_head lseg_list;
312 struct rpc_cred *cred; 312 const struct cred *cred;
313 struct inode *inode; 313 struct inode *inode;
314 struct nfs4_layoutcommit_args args; 314 struct nfs4_layoutcommit_args args;
315 struct nfs4_layoutcommit_res res; 315 struct nfs4_layoutcommit_res res;
@@ -334,7 +334,7 @@ struct nfs4_layoutreturn_res {
334struct nfs4_layoutreturn { 334struct nfs4_layoutreturn {
335 struct nfs4_layoutreturn_args args; 335 struct nfs4_layoutreturn_args args;
336 struct nfs4_layoutreturn_res res; 336 struct nfs4_layoutreturn_res res;
337 struct rpc_cred *cred; 337 const struct cred *cred;
338 struct nfs_client *clp; 338 struct nfs_client *clp;
339 struct inode *inode; 339 struct inode *inode;
340 int rpc_status; 340 int rpc_status;
@@ -1469,7 +1469,7 @@ enum {
1469struct nfs_io_completion; 1469struct nfs_io_completion;
1470struct nfs_pgio_header { 1470struct nfs_pgio_header {
1471 struct inode *inode; 1471 struct inode *inode;
1472 struct rpc_cred *cred; 1472 const struct cred *cred;
1473 struct list_head pages; 1473 struct list_head pages;
1474 struct nfs_page *req; 1474 struct nfs_page *req;
1475 struct nfs_writeverf verf; /* Used for writes */ 1475 struct nfs_writeverf verf; /* Used for writes */
@@ -1529,7 +1529,7 @@ struct nfs_commit_info {
1529struct nfs_commit_data { 1529struct nfs_commit_data {
1530 struct rpc_task task; 1530 struct rpc_task task;
1531 struct inode *inode; 1531 struct inode *inode;
1532 struct rpc_cred *cred; 1532 const struct cred *cred;
1533 struct nfs_fattr fattr; 1533 struct nfs_fattr fattr;
1534 struct nfs_writeverf verf; 1534 struct nfs_writeverf verf;
1535 struct list_head pages; /* Coalesced requests we wish to flush */ 1535 struct list_head pages; /* Coalesced requests we wish to flush */
@@ -1560,7 +1560,7 @@ struct nfs_unlinkdata {
1560 struct nfs_removeres res; 1560 struct nfs_removeres res;
1561 struct dentry *dentry; 1561 struct dentry *dentry;
1562 wait_queue_head_t wq; 1562 wait_queue_head_t wq;
1563 struct rpc_cred *cred; 1563 const struct cred *cred;
1564 struct nfs_fattr dir_attr; 1564 struct nfs_fattr dir_attr;
1565 long timeout; 1565 long timeout;
1566}; 1566};
@@ -1568,7 +1568,7 @@ struct nfs_unlinkdata {
1568struct nfs_renamedata { 1568struct nfs_renamedata {
1569 struct nfs_renameargs args; 1569 struct nfs_renameargs args;
1570 struct nfs_renameres res; 1570 struct nfs_renameres res;
1571 struct rpc_cred *cred; 1571 const struct cred *cred;
1572 struct inode *old_dir; 1572 struct inode *old_dir;
1573 struct dentry *old_dentry; 1573 struct dentry *old_dentry;
1574 struct nfs_fattr old_fattr; 1574 struct nfs_fattr old_fattr;
diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
index d8cf742f8032..a43e065a0b07 100644
--- a/include/linux/sunrpc/auth.h
+++ b/include/linux/sunrpc/auth.h
@@ -67,7 +67,7 @@ struct rpc_cred {
67#define RPCAUTH_CRED_HASHED 2 67#define RPCAUTH_CRED_HASHED 2
68#define RPCAUTH_CRED_NEGATIVE 3 68#define RPCAUTH_CRED_NEGATIVE 3
69 69
70struct rpc_cred *rpc_machine_cred(void); 70const struct cred *rpc_machine_cred(void);
71 71
72/* 72/*
73 * Client authentication handle 73 * Client authentication handle
@@ -196,21 +196,5 @@ struct rpc_cred *get_rpccred(struct rpc_cred *cred)
196 return NULL; 196 return NULL;
197} 197}
198 198
199/**
200 * get_rpccred_rcu - get a reference to a cred using rcu-protected pointer
201 * @cred: cred of which to take a reference
202 *
203 * In some cases, we may have a pointer to a credential to which we
204 * want to take a reference, but don't already have one. Because these
205 * objects are freed using RCU, we can access the cr_count while its
206 * on its way to destruction and only take a reference if it's not already
207 * zero.
208 */
209static inline struct rpc_cred *
210get_rpccred_rcu(struct rpc_cred *cred)
211{
212 return get_rpccred(cred);
213}
214
215#endif /* __KERNEL__ */ 199#endif /* __KERNEL__ */
216#endif /* _LINUX_SUNRPC_AUTH_H */ 200#endif /* _LINUX_SUNRPC_AUTH_H */
diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
index 4e2b893b83a8..219aa3910a0c 100644
--- a/include/linux/sunrpc/sched.h
+++ b/include/linux/sunrpc/sched.h
@@ -26,7 +26,7 @@ struct rpc_message {
26 const struct rpc_procinfo *rpc_proc; /* Procedure information */ 26 const struct rpc_procinfo *rpc_proc; /* Procedure information */
27 void * rpc_argp; /* Arguments */ 27 void * rpc_argp; /* Arguments */
28 void * rpc_resp; /* Result */ 28 void * rpc_resp; /* Result */
29 struct rpc_cred * rpc_cred; /* Credentials */ 29 const struct cred * rpc_cred; /* Credentials */
30}; 30};
31 31
32struct rpc_call_ops; 32struct rpc_call_ops;
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index cf23eed01b1c..ac8f824ec34f 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -39,15 +39,15 @@ static const struct rpc_authops __rcu *auth_flavors[RPC_AUTH_MAXFLAVOR] = {
39static LIST_HEAD(cred_unused); 39static LIST_HEAD(cred_unused);
40static unsigned long number_cred_unused; 40static unsigned long number_cred_unused;
41 41
42static struct rpc_cred machine_cred = { 42static struct cred machine_cred = {
43 .cr_count = REFCOUNT_INIT(1), 43 .usage = ATOMIC_INIT(1),
44}; 44};
45 45
46/* 46/*
47 * Return the machine_cred pointer to be used whenever 47 * Return the machine_cred pointer to be used whenever
48 * the a generic machine credential is needed. 48 * the a generic machine credential is needed.
49 */ 49 */
50struct rpc_cred *rpc_machine_cred(void) 50const struct cred *rpc_machine_cred(void)
51{ 51{
52 return &machine_cred; 52 return &machine_cred;
53} 53}
@@ -720,11 +720,15 @@ rpcauth_bind_new_cred(struct rpc_task *task, int lookupflags)
720} 720}
721 721
722static int 722static int
723rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags) 723rpcauth_bindcred(struct rpc_task *task, const struct cred *cred, int flags)
724{ 724{
725 struct rpc_rqst *req = task->tk_rqstp; 725 struct rpc_rqst *req = task->tk_rqstp;
726 struct rpc_cred *new = NULL; 726 struct rpc_cred *new = NULL;
727 int lookupflags = 0; 727 int lookupflags = 0;
728 struct rpc_auth *auth = task->tk_client->cl_auth;
729 struct auth_cred acred = {
730 .cred = cred,
731 };
728 732
729 if (flags & RPC_TASK_ASYNC) 733 if (flags & RPC_TASK_ASYNC)
730 lookupflags |= RPCAUTH_LOOKUP_NEW; 734 lookupflags |= RPCAUTH_LOOKUP_NEW;
@@ -733,7 +737,7 @@ rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags)
733 new = task->tk_op_cred->cr_ops->crbind(task, task->tk_op_cred, 737 new = task->tk_op_cred->cr_ops->crbind(task, task->tk_op_cred,
734 lookupflags); 738 lookupflags);
735 else if (cred != NULL && cred != &machine_cred) 739 else if (cred != NULL && cred != &machine_cred)
736 new = cred->cr_ops->crbind(task, cred, lookupflags); 740 new = auth->au_ops->lookup_cred(auth, &acred, lookupflags);
737 else if (cred == &machine_cred) 741 else if (cred == &machine_cred)
738 new = rpcauth_bind_machine_cred(task, lookupflags); 742 new = rpcauth_bind_machine_cred(task, lookupflags);
739 743
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 4cb697cfb377..cad26f816d20 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -1030,7 +1030,7 @@ rpc_task_set_rpc_message(struct rpc_task *task, const struct rpc_message *msg)
1030 task->tk_msg.rpc_argp = msg->rpc_argp; 1030 task->tk_msg.rpc_argp = msg->rpc_argp;
1031 task->tk_msg.rpc_resp = msg->rpc_resp; 1031 task->tk_msg.rpc_resp = msg->rpc_resp;
1032 if (msg->rpc_cred != NULL) 1032 if (msg->rpc_cred != NULL)
1033 task->tk_msg.rpc_cred = get_rpccred(msg->rpc_cred); 1033 task->tk_msg.rpc_cred = get_cred(msg->rpc_cred);
1034 } 1034 }
1035} 1035}
1036 1036
@@ -2542,7 +2542,7 @@ struct rpc_task *rpc_call_null_helper(struct rpc_clnt *clnt,
2542 .rpc_op_cred = cred, 2542 .rpc_op_cred = cred,
2543 .callback_ops = (ops != NULL) ? ops : &rpc_default_ops, 2543 .callback_ops = (ops != NULL) ? ops : &rpc_default_ops,
2544 .callback_data = data, 2544 .callback_data = data,
2545 .flags = flags, 2545 .flags = flags | RPC_TASK_NULLCREDS,
2546 }; 2546 };
2547 2547
2548 return rpc_run_task(&task_setup_data); 2548 return rpc_run_task(&task_setup_data);
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index c9f65037a6ad..adc3c40cc733 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -1074,7 +1074,7 @@ static void rpc_release_resources_task(struct rpc_task *task)
1074{ 1074{
1075 xprt_release(task); 1075 xprt_release(task);
1076 if (task->tk_msg.rpc_cred) { 1076 if (task->tk_msg.rpc_cred) {
1077 put_rpccred(task->tk_msg.rpc_cred); 1077 put_cred(task->tk_msg.rpc_cred);
1078 task->tk_msg.rpc_cred = NULL; 1078 task->tk_msg.rpc_cred = NULL;
1079 } 1079 }
1080 rpc_task_release_client(task); 1080 rpc_task_release_client(task);