Lines Matching refs:delegation

3  * linux/fs/nfs/delegation.c
7 * NFS file delegation management
24 #include "delegation.h"
33 static void __nfs_free_delegation(struct nfs_delegation *delegation)
35 put_cred(delegation->cred);
36 delegation->cred = NULL;
37 kfree_rcu(delegation, rcu);
40 static void nfs_mark_delegation_revoked(struct nfs_delegation *delegation)
42 if (!test_and_set_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
43 delegation->stateid.type = NFS4_INVALID_STATEID_TYPE;
45 if (!test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
46 nfs_clear_verifier_delegated(delegation->inode);
50 static struct nfs_delegation *nfs_get_delegation(struct nfs_delegation *delegation)
52 refcount_inc(&delegation->refcount);
53 return delegation;
56 static void nfs_put_delegation(struct nfs_delegation *delegation)
58 if (refcount_dec_and_test(&delegation->refcount))
59 __nfs_free_delegation(delegation);
62 static void nfs_free_delegation(struct nfs_delegation *delegation)
64 nfs_mark_delegation_revoked(delegation);
65 nfs_put_delegation(delegation);
69 * nfs_mark_delegation_referenced - set delegation's REFERENCED flag
70 * @delegation: delegation to process
73 void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)
75 set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags);
79 struct nfs_delegation *delegation)
81 set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
86 nfs4_is_valid_delegation(const struct nfs_delegation *delegation,
89 if (delegation != NULL && (delegation->type & flags) == flags &&
90 !test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) &&
91 !test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
98 struct nfs_delegation *delegation;
100 delegation = rcu_dereference(NFS_I(inode)->delegation);
101 if (nfs4_is_valid_delegation(delegation, 0))
102 return delegation;
109 struct nfs_delegation *delegation;
114 delegation = rcu_dereference(NFS_I(inode)->delegation);
115 if (nfs4_is_valid_delegation(delegation, flags)) {
117 nfs_mark_delegation_referenced(delegation);
124 * nfs4_have_delegation - check if inode has a delegation, mark it
127 * @flags: delegation types to check for
129 * Returns one if inode has the indicated delegation, otherwise zero.
137 * nfs4_check_delegation - check if inode has a delegation, do not mark
218 * nfs_inode_reclaim_delegation - process a delegation reclaim request
221 * @type: delegation type
222 * @stateid: delegation stateid
223 * @pagemod_limit: write delegation "space_limit"
230 struct nfs_delegation *delegation;
234 delegation = rcu_dereference(NFS_I(inode)->delegation);
235 if (delegation != NULL) {
236 spin_lock(&delegation->lock);
237 nfs4_stateid_copy(&delegation->stateid, stateid);
238 delegation->type = type;
239 delegation->pagemod_limit = pagemod_limit;
240 oldcred = delegation->cred;
241 delegation->cred = get_cred(cred);
242 clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
244 &delegation->flags))
246 spin_unlock(&delegation->lock);
257 static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
262 if (!test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
263 spin_lock(&delegation->lock);
264 cred = get_cred(delegation->cred);
265 spin_unlock(&delegation->lock);
267 &delegation->stateid,
274 static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation)
278 spin_lock(&delegation->lock);
279 if (delegation->inode != NULL)
280 inode = igrab(delegation->inode);
282 set_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags);
283 spin_unlock(&delegation->lock);
291 struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation);
293 if (delegation == NULL)
295 spin_lock(&delegation->lock);
296 if (!test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
297 clear_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags);
299 ret = nfs_get_delegation(delegation);
301 spin_unlock(&delegation->lock);
311 struct nfs_delegation *delegation;
314 delegation = nfs_start_delegation_return_locked(nfsi);
316 return delegation;
319 static void nfs_abort_delegation_return(struct nfs_delegation *delegation,
323 spin_lock(&delegation->lock);
324 clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
326 set_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags);
329 spin_unlock(&delegation->lock);
334 struct nfs_delegation *delegation,
338 rcu_dereference_protected(nfsi->delegation,
341 if (deleg_cur == NULL || delegation != deleg_cur)
344 spin_lock(&delegation->lock);
345 if (!delegation->inode) {
346 spin_unlock(&delegation->lock);
349 list_del_rcu(&delegation->super_list);
350 delegation->inode = NULL;
351 rcu_assign_pointer(nfsi->delegation, NULL);
352 spin_unlock(&delegation->lock);
353 return delegation;
357 struct nfs_delegation *delegation,
363 delegation = nfs_detach_delegation_locked(nfsi, delegation, clp);
365 return delegation;
373 struct nfs_delegation *delegation;
376 delegation = rcu_dereference(nfsi->delegation);
377 if (delegation != NULL)
378 delegation = nfs_detach_delegation(nfsi, delegation, server);
380 return delegation;
384 nfs_update_delegation_cred(struct nfs_delegation *delegation,
389 if (cred_fscmp(delegation->cred, cred) != 0) {
390 old = xchg(&delegation->cred, get_cred(cred));
396 nfs_update_inplace_delegation(struct nfs_delegation *delegation,
399 if (nfs4_stateid_is_newer(&update->stateid, &delegation->stateid)) {
400 delegation->stateid.seqid = update->stateid.seqid;
402 delegation->type = update->type;
403 delegation->pagemod_limit = update->pagemod_limit;
404 if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
405 delegation->change_attr = update->change_attr;
406 nfs_update_delegation_cred(delegation, update->cred);
408 clear_bit(NFS_DELEGATION_REVOKED, &delegation->flags);
415 * nfs_inode_set_delegation - set up a delegation on an inode
416 * @inode: inode to which delegation applies
417 * @cred: cred to use for subsequent delegation processing
418 * @type: delegation type
419 * @stateid: delegation stateid
420 * @pagemod_limit: write delegation "space_limit"
432 struct nfs_delegation *delegation, *old_delegation;
436 delegation = kmalloc(sizeof(*delegation), GFP_KERNEL_ACCOUNT);
437 if (delegation == NULL)
439 nfs4_stateid_copy(&delegation->stateid, stateid);
440 refcount_set(&delegation->refcount, 1);
441 delegation->type = type;
442 delegation->pagemod_limit = pagemod_limit;
443 delegation->change_attr = inode_peek_iversion_raw(inode);
444 delegation->cred = get_cred(cred);
445 delegation->inode = inode;
446 delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
447 delegation->test_gen = 0;
448 spin_lock_init(&delegation->lock);
451 old_delegation = rcu_dereference_protected(nfsi->delegation,
455 /* Is this an update of the existing delegation? */
457 &delegation->stateid)) {
460 delegation);
468 * Allow for upgrades to a WRITE delegation, but
472 "a duplicate delegation!\n",
474 if (delegation->type == old_delegation->type ||
475 !(delegation->type & FMODE_WRITE)) {
476 freeme = delegation;
477 delegation = NULL;
490 * the delegation, then pre-emptively ask for a full attribute
504 list_add_tail_rcu(&delegation->super_list, &server->delegations);
505 rcu_assign_pointer(nfsi->delegation, delegation);
506 delegation = NULL;
513 if (delegation != NULL)
514 __nfs_free_delegation(delegation);
523 * Basic procedure for returning a delegation to the server
525 static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation *delegation, int issync)
531 if (delegation == NULL)
540 if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags))
542 err = nfs_delegation_claim_opens(inode, &delegation->stateid,
543 delegation->type);
553 nfs_abort_delegation_return(delegation, clp, err);
557 err = nfs_do_return_delegation(inode, delegation, issync);
560 nfs_put_delegation(delegation);
564 static bool nfs_delegation_need_return(struct nfs_delegation *delegation)
568 if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags))
570 else if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags)) {
573 spin_lock(&delegation->lock);
574 inode = delegation->inode;
577 spin_unlock(&delegation->lock);
580 clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags);
581 if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags) ||
582 test_bit(NFS_DELEGATION_RETURN_DELAYED, &delegation->flags) ||
583 test_bit(NFS_DELEGATION_REVOKED, &delegation->flags))
592 struct nfs_delegation *delegation;
603 * list delegation in the server from the delegations
605 * prev is an RCU-protected pointer to a delegation which
610 delegation = NULL;
613 delegation = rcu_dereference(NFS_I(place_holder)->delegation);
614 if (!delegation || delegation != place_holder_deleg)
615 delegation = list_entry_rcu(server->delegations.next,
617 list_for_each_entry_from_rcu(delegation, &server->delegations, super_list) {
620 if (test_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags))
622 if (!nfs_delegation_need_return(delegation)) {
623 if (nfs4_is_valid_delegation(delegation, 0))
624 prev = delegation;
637 inode = nfs_delegation_grab_inode(delegation);
643 delegation = nfs_start_delegation_return_locked(NFS_I(inode));
648 err = nfs_end_delegation_return(inode, delegation, 0);
717 * nfs_inode_evict_delegation - return delegation, don't reclaim opens
720 * Does not protect against delegation reclaims, therefore really only safe
722 * the delegation structure.
726 struct nfs_delegation *delegation;
728 delegation = nfs_inode_detach_delegation(inode);
729 if (delegation != NULL) {
730 set_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
731 set_bit(NFS_DELEGATION_INODE_FREEING, &delegation->flags);
732 nfs_do_return_delegation(inode, delegation, 1);
733 nfs_free_delegation(delegation);
738 * nfs4_inode_return_delegation - synchronously return a delegation
742 * assumption that if we need to return the delegation, then
750 struct nfs_delegation *delegation;
752 delegation = nfs_start_delegation_return(nfsi);
753 if (delegation != NULL) {
758 return nfs_end_delegation_return(inode, delegation, 1);
764 * nfs4_inode_return_delegation_on_close - asynchronously return a delegation
768 * inode delegation needs to be returned immediately.
772 struct nfs_delegation *delegation;
778 delegation = nfs4_get_valid_delegation(inode);
779 if (!delegation)
781 if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags) ||
783 spin_lock(&delegation->lock);
784 if (delegation->inode &&
786 !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
787 clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags);
789 ret = nfs_get_delegation(delegation);
791 spin_unlock(&delegation->lock);
804 * Make the inode writeable by returning the delegation if necessary
810 struct nfs_delegation *delegation;
813 delegation = nfs4_get_valid_delegation(inode);
814 if (delegation == NULL ||
816 (delegation->type & FMODE_WRITE))) {
825 struct nfs_delegation *delegation)
827 set_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags);
833 struct nfs_delegation *delegation;
836 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
837 nfs_mark_return_delegation(server, delegation);
896 struct nfs_delegation *delegation;
898 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
899 if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE))
901 if (delegation->type & flags)
902 nfs_mark_return_if_closed_delegation(server, delegation);
920 struct nfs_delegation *delegation;
925 delegation = rcu_dereference(NFS_I(inode)->delegation);
926 if (delegation == NULL)
929 nfs4_stateid_copy(&tmp, &delegation->stateid);
932 if (!nfs4_stateid_match_other(stateid, &delegation->stateid))
934 spin_lock(&delegation->lock);
936 if (nfs4_stateid_is_newer(&delegation->stateid, stateid)) {
937 spin_unlock(&delegation->lock);
940 delegation->stateid.seqid = stateid->seqid;
942 spin_unlock(&delegation->lock);
944 nfs_mark_delegation_revoked(delegation);
962 struct nfs_delegation *delegation;
968 delegation = rcu_dereference(NFS_I(inode)->delegation);
969 if (!delegation)
972 spin_lock(&delegation->lock);
973 if (!nfs4_stateid_match_other(stateid, &delegation->stateid))
976 /* If delegation->stateid is newer, dont mark as returned */
977 if (nfs4_stateid_is_newer(&delegation->stateid, stateid))
979 if (delegation->stateid.seqid != stateid->seqid)
980 delegation->stateid.seqid = stateid->seqid;
983 nfs_mark_delegation_revoked(delegation);
986 clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
988 spin_unlock(&delegation->lock);
998 * @flags: delegation types to expire
1009 struct nfs_delegation *delegation;
1011 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
1012 if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags))
1014 nfs_mark_return_if_closed_delegation(server, delegation);
1036 * nfs_async_inode_return_delegation - asynchronously return a delegation
1047 struct nfs_delegation *delegation;
1050 delegation = nfs4_get_valid_delegation(inode);
1051 if (delegation == NULL)
1054 !clp->cl_mvops->match_stateid(&delegation->stateid, stateid))
1056 nfs_mark_return_delegation(server, delegation);
1073 struct nfs_delegation *delegation;
1077 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
1078 spin_lock(&delegation->lock);
1079 if (delegation->inode != NULL &&
1080 !test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) &&
1081 nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
1084 res = igrab(delegation->inode);
1086 spin_unlock(&delegation->lock);
1096 spin_unlock(&delegation->lock);
1102 * nfs_delegation_find_inode - retrieve the inode associated with a delegation
1104 * @fhandle: filehandle from a delegation recall
1129 struct nfs_delegation *delegation;
1131 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
1133 * If the delegation may have been admin revoked, then we
1136 if (test_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags))
1138 set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
1160 struct nfs_delegation *delegation;
1165 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
1167 &delegation->flags) ||
1169 &delegation->flags) ||
1171 &delegation->flags) == 0)
1173 inode = nfs_delegation_grab_inode(delegation);
1176 delegation = nfs_start_delegation_return_locked(NFS_I(inode));
1178 if (delegation != NULL) {
1179 if (nfs_detach_delegation(NFS_I(inode), delegation,
1181 nfs_free_delegation(delegation);
1183 nfs_put_delegation(delegation);
1212 struct nfs_delegation *delegation)
1214 if (delegation->stateid.type == NFS4_INVALID_STATEID_TYPE)
1216 clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
1217 set_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
1224 struct nfs_delegation *delegation;
1227 delegation = rcu_dereference(NFS_I(inode)->delegation);
1228 if (delegation)
1229 nfs_mark_test_expired_delegation(server, delegation);
1236 struct nfs_delegation *delegation;
1238 list_for_each_entry_rcu(delegation, &server->delegations, super_list)
1239 nfs_mark_test_expired_delegation(server, delegation);
1290 struct nfs_delegation *delegation;
1299 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
1301 &delegation->flags) ||
1303 &delegation->flags) ||
1305 &delegation->flags) == 0 ||
1306 delegation->test_gen == gen)
1308 inode = nfs_delegation_grab_inode(delegation);
1311 spin_lock(&delegation->lock);
1312 cred = get_cred_rcu(delegation->cred);
1313 nfs4_stateid_copy(&stateid, &delegation->stateid);
1314 spin_unlock(&delegation->lock);
1315 delegation->test_gen = gen;
1316 clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
1352 struct nfs_delegation *delegation;
1356 delegation = rcu_dereference(NFS_I(inode)->delegation);
1357 if (delegation &&
1358 nfs4_stateid_match_or_older(&delegation->stateid, stateid) &&
1359 !test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
1360 nfs_mark_test_expired_delegation(NFS_SERVER(inode), delegation);
1391 * nfs4_refresh_delegation_stateid - Update delegation stateid seqid
1395 * Returns "true" and updates "dst->seqid" * if inode had a delegation
1396 * that matches our delegation stateid. Otherwise "false" is returned.
1400 struct nfs_delegation *delegation;
1406 delegation = rcu_dereference(NFS_I(inode)->delegation);
1407 if (delegation != NULL &&
1408 nfs4_stateid_match_other(dst, &delegation->stateid) &&
1409 nfs4_stateid_is_newer(&delegation->stateid, dst) &&
1410 !test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
1411 dst->seqid = delegation->stateid.seqid;
1422 * @flags: delegation type requirement
1426 * Returns "true" and fills in "dst->data" * if inode had a delegation,
1433 struct nfs_delegation *delegation;
1438 delegation = rcu_dereference(nfsi->delegation);
1439 if (!delegation)
1441 spin_lock(&delegation->lock);
1442 ret = nfs4_is_valid_delegation(delegation, flags);
1444 nfs4_stateid_copy(dst, &delegation->stateid);
1445 nfs_mark_delegation_referenced(delegation);
1447 *cred = get_cred(delegation->cred);
1449 spin_unlock(&delegation->lock);
1460 * against the delegation 'space_limit' field to see if
1466 struct nfs_delegation *delegation;
1470 delegation = rcu_dereference(nfsi->delegation);
1471 if (delegation == NULL || !(delegation->type & FMODE_WRITE))
1473 if (atomic_long_read(&nfsi->nrequests) < delegation->pagemod_limit)