Skip to content

Commit a52458b

Browse files
NeilBrownamschuma-ntap
authored andcommitted
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>
1 parent 684f39b commit a52458b

33 files changed

+261
-343
lines changed

fs/lockd/clntproc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int nlm_wait_on_grace(wait_queue_head_t *queue)
256256
* Generic NLM call
257257
*/
258258
static int
259-
nlmclnt_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc)
259+
nlmclnt_call(const struct cred *cred, struct nlm_rqst *req, u32 proc)
260260
{
261261
struct nlm_host *host = req->a_host;
262262
struct rpc_clnt *clnt;
@@ -401,7 +401,7 @@ int nlm_async_reply(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *t
401401
* completion in order to be able to correctly track the lock
402402
* state.
403403
*/
404-
static int nlmclnt_async_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
404+
static int nlmclnt_async_call(const struct cred *cred, struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
405405
{
406406
struct rpc_message msg = {
407407
.rpc_argp = &req->a_args,
@@ -510,7 +510,7 @@ static int do_vfs_lock(struct file_lock *fl)
510510
static int
511511
nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
512512
{
513-
struct rpc_cred *cred = nfs_file_cred(fl->fl_file);
513+
const struct cred *cred = nfs_file_cred(fl->fl_file);
514514
struct nlm_host *host = req->a_host;
515515
struct nlm_res *resp = &req->a_res;
516516
struct nlm_wait *block = NULL;

fs/nfs/blocklayout/blocklayout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static int decode_sector_number(__be32 **rp, sector_t *sp)
584584

585585
static struct nfs4_deviceid_node *
586586
bl_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,
588588
gfp_t gfp_mask)
589589
{
590590
struct nfs4_deviceid_node *node;

fs/nfs/delegation.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

2727
static void nfs_free_delegation(struct nfs_delegation *delegation)
2828
{
29-
if (delegation->cred) {
30-
put_rpccred(delegation->cred);
31-
delegation->cred = NULL;
32-
}
29+
put_cred(delegation->cred);
30+
delegation->cred = NULL;
3331
kfree_rcu(delegation, rcu);
3432
}
3533

@@ -178,13 +176,13 @@ static int nfs_delegation_claim_opens(struct inode *inode,
178176
* @pagemod_limit: write delegation "space_limit"
179177
*
180178
*/
181-
void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
179+
void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
182180
fmode_t type,
183181
const nfs4_stateid *stateid,
184182
unsigned long pagemod_limit)
185183
{
186184
struct nfs_delegation *delegation;
187-
struct rpc_cred *oldcred = NULL;
185+
const struct cred *oldcred = NULL;
188186

189187
rcu_read_lock();
190188
delegation = rcu_dereference(NFS_I(inode)->delegation);
@@ -195,12 +193,12 @@ void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
195193
delegation->type = type;
196194
delegation->pagemod_limit = pagemod_limit;
197195
oldcred = delegation->cred;
198-
delegation->cred = get_rpccred(cred);
196+
delegation->cred = get_cred(cred);
199197
clear_bit(NFS_DELEGATION_NEED_RECLAIM,
200198
&delegation->flags);
201199
spin_unlock(&delegation->lock);
202200
rcu_read_unlock();
203-
put_rpccred(oldcred);
201+
put_cred(oldcred);
204202
trace_nfs4_reclaim_delegation(inode, type);
205203
return;
206204
}
@@ -341,7 +339,7 @@ nfs_update_inplace_delegation(struct nfs_delegation *delegation,
341339
*
342340
* Returns zero on success, or a negative errno value.
343341
*/
344-
int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred,
342+
int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
345343
fmode_t type,
346344
const nfs4_stateid *stateid,
347345
unsigned long pagemod_limit)
@@ -360,7 +358,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred,
360358
delegation->type = type;
361359
delegation->pagemod_limit = pagemod_limit;
362360
delegation->change_attr = inode_peek_iversion_raw(inode);
363-
delegation->cred = get_rpccred(cred);
361+
delegation->cred = get_cred(cred);
364362
delegation->inode = inode;
365363
delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
366364
spin_lock_init(&delegation->lock);
@@ -1047,7 +1045,7 @@ void nfs_reap_expired_delegations(struct nfs_client *clp)
10471045
struct nfs_delegation *delegation;
10481046
struct nfs_server *server;
10491047
struct inode *inode;
1050-
struct rpc_cred *cred;
1048+
const struct cred *cred;
10511049
nfs4_stateid stateid;
10521050

10531051
restart:
@@ -1069,7 +1067,7 @@ void nfs_reap_expired_delegations(struct nfs_client *clp)
10691067
nfs_sb_deactive(server->super);
10701068
goto restart;
10711069
}
1072-
cred = get_rpccred_rcu(delegation->cred);
1070+
cred = get_cred_rcu(delegation->cred);
10731071
nfs4_stateid_copy(&stateid, &delegation->stateid);
10741072
clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
10751073
rcu_read_unlock();
@@ -1078,7 +1076,7 @@ void nfs_reap_expired_delegations(struct nfs_client *clp)
10781076
nfs_revoke_delegation(inode, &stateid);
10791077
nfs_inode_find_state_and_recover(inode, &stateid);
10801078
}
1081-
put_rpccred(cred);
1079+
put_cred(cred);
10821080
if (nfs4_server_rebooted(clp)) {
10831081
nfs_inode_mark_test_expired_delegation(server,inode);
10841082
iput(inode);
@@ -1173,7 +1171,7 @@ bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
11731171
* otherwise "false" is returned.
11741172
*/
11751173
bool 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)
11771175
{
11781176
struct nfs_inode *nfsi = NFS_I(inode);
11791177
struct nfs_delegation *delegation;
@@ -1187,7 +1185,7 @@ bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags,
11871185
nfs4_stateid_copy(dst, &delegation->stateid);
11881186
nfs_mark_delegation_referenced(delegation);
11891187
if (cred)
1190-
*cred = get_rpccred(delegation->cred);
1188+
*cred = get_cred(delegation->cred);
11911189
}
11921190
rcu_read_unlock();
11931191
return ret;

fs/nfs/delegation.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
struct nfs_delegation {
1717
struct list_head super_list;
18-
struct rpc_cred *cred;
18+
const struct cred *cred;
1919
struct inode *inode;
2020
nfs4_stateid stateid;
2121
fmode_t type;
@@ -36,9 +36,9 @@ enum {
3636
NFS_DELEGATION_TEST_EXPIRED,
3737
};
3838

39-
int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred,
39+
int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
4040
fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit);
41-
void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
41+
void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
4242
fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit);
4343
int nfs4_inode_return_delegation(struct inode *inode);
4444
int 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);
6060
void nfs_reap_expired_delegations(struct nfs_client *clp);
6161

6262
/* NFSv4 delegation-related procedures */
63-
int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync);
63+
int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync);
6464
int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type);
6565
int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid);
66-
bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, struct rpc_cred **cred);
66+
bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, const struct cred **cred);
6767
bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode);
6868

6969
void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,14 @@ static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
224224

225225
static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
226226
{
227-
struct rpc_cred *cred;
227+
const struct cred *cred;
228228

229229
ff_layout_remove_mirror(mirror);
230230
kfree(mirror->fh_versions);
231231
cred = rcu_access_pointer(mirror->ro_cred);
232-
if (cred)
233-
put_rpccred(cred);
232+
put_cred(cred);
234233
cred = rcu_access_pointer(mirror->rw_cred);
235-
if (cred)
236-
put_rpccred(cred);
234+
put_cred(cred);
237235
nfs4_ff_layout_put_deviceid(mirror->mirror_ds);
238236
kfree(mirror);
239237
}
@@ -411,9 +409,8 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
411409

412410
for (i = 0; i < fls->mirror_array_cnt; i++) {
413411
struct nfs4_ff_layout_mirror *mirror;
414-
struct auth_cred acred = {};
415-
struct rpc_cred __rcu *cred;
416412
struct cred *kcred;
413+
const struct cred *cred;
417414
kuid_t uid;
418415
kgid_t gid;
419416
u32 ds_count, fh_count, id;
@@ -504,15 +501,7 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
504501
goto out_err_free;
505502
kcred->fsuid = uid;
506503
kcred->fsgid = gid;
507-
acred.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-
}
504+
cred = kcred;
516505

517506
if (lgr->range.iomode == IOMODE_READ)
518507
rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
@@ -1714,7 +1703,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
17141703
struct pnfs_layout_segment *lseg = hdr->lseg;
17151704
struct nfs4_pnfs_ds *ds;
17161705
struct rpc_clnt *ds_clnt;
1717-
struct rpc_cred *ds_cred;
1706+
const struct cred *ds_cred;
17181707
loff_t offset = hdr->args.offset;
17191708
u32 idx = hdr->pgio_mirror_idx;
17201709
int vers;
@@ -1765,7 +1754,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
17651754
vers == 3 ? &ff_layout_read_call_ops_v3 :
17661755
&ff_layout_read_call_ops_v4,
17671756
0, RPC_TASK_SOFTCONN);
1768-
put_rpccred(ds_cred);
1757+
put_cred(ds_cred);
17691758
return PNFS_ATTEMPTED;
17701759

17711760
out_failed:
@@ -1781,7 +1770,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
17811770
struct pnfs_layout_segment *lseg = hdr->lseg;
17821771
struct nfs4_pnfs_ds *ds;
17831772
struct rpc_clnt *ds_clnt;
1784-
struct rpc_cred *ds_cred;
1773+
const struct cred *ds_cred;
17851774
loff_t offset = hdr->args.offset;
17861775
int vers;
17871776
struct nfs_fh *fh;
@@ -1830,7 +1819,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
18301819
vers == 3 ? &ff_layout_write_call_ops_v3 :
18311820
&ff_layout_write_call_ops_v4,
18321821
sync, RPC_TASK_SOFTCONN);
1833-
put_rpccred(ds_cred);
1822+
put_cred(ds_cred);
18341823
return PNFS_ATTEMPTED;
18351824

18361825
out_failed:
@@ -1860,7 +1849,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
18601849
struct pnfs_layout_segment *lseg = data->lseg;
18611850
struct nfs4_pnfs_ds *ds;
18621851
struct rpc_clnt *ds_clnt;
1863-
struct rpc_cred *ds_cred;
1852+
const struct cred *ds_cred;
18641853
u32 idx;
18651854
int vers, ret;
18661855
struct nfs_fh *fh;
@@ -1900,7 +1889,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
19001889
vers == 3 ? &ff_layout_commit_call_ops_v3 :
19011890
&ff_layout_commit_call_ops_v4,
19021891
how, RPC_TASK_SOFTCONN);
1903-
put_rpccred(ds_cred);
1892+
put_cred(ds_cred);
19041893
return ret;
19051894
out_err:
19061895
pnfs_generic_prepare_to_resend_writes(data);

fs/nfs/flexfilelayout/flexfilelayout.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ struct nfs4_ff_layout_mirror {
8181
u32 fh_versions_cnt;
8282
struct nfs_fh *fh_versions;
8383
nfs4_stateid stateid;
84-
struct rpc_cred __rcu *ro_cred;
85-
struct rpc_cred __rcu *rw_cred;
84+
const struct cred __rcu *ro_cred;
85+
const struct cred __rcu *rw_cred;
8686
refcount_t ref;
8787
spinlock_t lock;
8888
unsigned long flags;
@@ -229,8 +229,8 @@ nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg,
229229
u32 ds_idx,
230230
struct nfs_client *ds_clp,
231231
struct inode *inode);
232-
struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg,
233-
u32 ds_idx, struct rpc_cred *mdscred);
232+
const struct cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg,
233+
u32 ds_idx, const struct cred *mdscred);
234234
bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg);
235235
bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg);
236236

fs/nfs/flexfilelayout/flexfilelayoutdev.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
330330
return 0;
331331
}
332332

333-
static struct rpc_cred *
333+
static const struct cred *
334334
ff_layout_get_mirror_cred(struct nfs4_ff_layout_mirror *mirror, u32 iomode)
335335
{
336-
struct rpc_cred *cred, __rcu **pcred;
336+
const struct cred *cred, __rcu **pcred;
337337

338338
if (iomode == IOMODE_READ)
339339
pcred = &mirror->ro_cred;
@@ -346,7 +346,7 @@ ff_layout_get_mirror_cred(struct nfs4_ff_layout_mirror *mirror, u32 iomode)
346346
if (!cred)
347347
break;
348348

349-
cred = get_rpccred_rcu(cred);
349+
cred = get_cred_rcu(cred);
350350
} while(!cred);
351351
rcu_read_unlock();
352352
return cred;
@@ -465,19 +465,19 @@ nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx,
465465
return ds;
466466
}
467467

468-
struct rpc_cred *
468+
const struct cred *
469469
ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, u32 ds_idx,
470-
struct rpc_cred *mdscred)
470+
const struct cred *mdscred)
471471
{
472472
struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
473-
struct rpc_cred *cred;
473+
const struct cred *cred;
474474

475475
if (mirror && !mirror->mirror_ds->ds_versions[0].tightly_coupled) {
476476
cred = ff_layout_get_mirror_cred(mirror, lseg->pls_range.iomode);
477477
if (!cred)
478-
cred = get_rpccred(mdscred);
478+
cred = get_cred(mdscred);
479479
} else {
480-
cred = get_rpccred(mdscred);
480+
cred = get_cred(mdscred);
481481
}
482482
return cred;
483483
}

fs/nfs/inode.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,11 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry,
950950
struct file *filp)
951951
{
952952
struct nfs_open_context *ctx;
953-
struct rpc_cred *cred = rpc_lookup_cred();
954-
if (IS_ERR(cred))
955-
return ERR_CAST(cred);
953+
const struct cred *cred = get_current_cred();
956954

957955
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
958956
if (!ctx) {
959-
put_rpccred(cred);
957+
put_cred(cred);
960958
return ERR_PTR(-ENOMEM);
961959
}
962960
nfs_sb_active(dentry->d_sb);
@@ -998,8 +996,7 @@ static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
998996
}
999997
if (inode != NULL)
1000998
NFS_PROTO(inode)->close_context(ctx, is_sync);
1001-
if (ctx->cred != NULL)
1002-
put_rpccred(ctx->cred);
999+
put_cred(ctx->cred);
10031000
dput(ctx->dentry);
10041001
nfs_sb_deactive(sb);
10051002
put_rpccred(ctx->ll_cred);
@@ -1044,7 +1041,7 @@ EXPORT_SYMBOL_GPL(nfs_file_set_open_context);
10441041
/*
10451042
* Given an inode, search for an open context with the desired characteristics
10461043
*/
1047-
struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode)
1044+
struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode)
10481045
{
10491046
struct nfs_inode *nfsi = NFS_I(inode);
10501047
struct nfs_open_context *pos, *ctx = NULL;

0 commit comments

Comments
 (0)