delegation.c (efeda80da38d0b4afd77a12bd4a44f657567d26c) delegation.c (8c75593c6eee0f661ddf25dfde0e6ad2a84be7a9)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/fs/nfs/delegation.c
4 *
5 * Copyright (C) 2004 Trond Myklebust
6 *
7 * NFS file delegation management
8 *

--- 33 unchanged lines hidden (view full) ---

42 if (!test_and_set_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
43 delegation->stateid.type = NFS4_INVALID_STATEID_TYPE;
44 atomic_long_dec(&nfs_active_delegations);
45 if (!test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
46 nfs_clear_verifier_delegated(delegation->inode);
47 }
48}
49
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/fs/nfs/delegation.c
4 *
5 * Copyright (C) 2004 Trond Myklebust
6 *
7 * NFS file delegation management
8 *

--- 33 unchanged lines hidden (view full) ---

42 if (!test_and_set_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
43 delegation->stateid.type = NFS4_INVALID_STATEID_TYPE;
44 atomic_long_dec(&nfs_active_delegations);
45 if (!test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
46 nfs_clear_verifier_delegated(delegation->inode);
47 }
48}
49
50static struct nfs_delegation *nfs_get_delegation(struct nfs_delegation *delegation)
51{
52 refcount_inc(&delegation->refcount);
53 return delegation;
54}
55
56static void nfs_put_delegation(struct nfs_delegation *delegation)
57{
58 if (refcount_dec_and_test(&delegation->refcount))
59 __nfs_free_delegation(delegation);
60}
61
50static void nfs_free_delegation(struct nfs_delegation *delegation)
51{
52 nfs_mark_delegation_revoked(delegation);
62static void nfs_free_delegation(struct nfs_delegation *delegation)
63{
64 nfs_mark_delegation_revoked(delegation);
53 __nfs_free_delegation(delegation);
65 nfs_put_delegation(delegation);
54}
55
56/**
57 * nfs_mark_delegation_referenced - set delegation's REFERENCED flag
58 * @delegation: delegation to process
59 *
60 */
61void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)

--- 208 unchanged lines hidden (view full) ---

270nfs_start_delegation_return_locked(struct nfs_inode *nfsi)
271{
272 struct nfs_delegation *ret = NULL;
273 struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation);
274
275 if (delegation == NULL)
276 goto out;
277 spin_lock(&delegation->lock);
66}
67
68/**
69 * nfs_mark_delegation_referenced - set delegation's REFERENCED flag
70 * @delegation: delegation to process
71 *
72 */
73void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)

--- 208 unchanged lines hidden (view full) ---

282nfs_start_delegation_return_locked(struct nfs_inode *nfsi)
283{
284 struct nfs_delegation *ret = NULL;
285 struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation);
286
287 if (delegation == NULL)
288 goto out;
289 spin_lock(&delegation->lock);
278 if (!test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
279 ret = delegation;
290 if (!test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
291 /* Refcount matched in nfs_end_delegation_return() */
292 ret = nfs_get_delegation(delegation);
293 }
280 spin_unlock(&delegation->lock);
281 if (ret)
282 nfs_clear_verifier_delegated(&nfsi->vfs_inode);
283out:
284 return ret;
285}
286
287static struct nfs_delegation *

--- 104 unchanged lines hidden (view full) ---

392 struct nfs_delegation *delegation, *old_delegation;
393 struct nfs_delegation *freeme = NULL;
394 int status = 0;
395
396 delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
397 if (delegation == NULL)
398 return -ENOMEM;
399 nfs4_stateid_copy(&delegation->stateid, stateid);
294 spin_unlock(&delegation->lock);
295 if (ret)
296 nfs_clear_verifier_delegated(&nfsi->vfs_inode);
297out:
298 return ret;
299}
300
301static struct nfs_delegation *

--- 104 unchanged lines hidden (view full) ---

406 struct nfs_delegation *delegation, *old_delegation;
407 struct nfs_delegation *freeme = NULL;
408 int status = 0;
409
410 delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
411 if (delegation == NULL)
412 return -ENOMEM;
413 nfs4_stateid_copy(&delegation->stateid, stateid);
414 refcount_set(&delegation->refcount, 1);
400 delegation->type = type;
401 delegation->pagemod_limit = pagemod_limit;
402 delegation->change_attr = inode_peek_iversion_raw(inode);
403 delegation->cred = get_cred(cred);
404 delegation->inode = inode;
405 delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
406 spin_lock_init(&delegation->lock);
407

--- 83 unchanged lines hidden (view full) ---

491
492 if (err) {
493 nfs_abort_delegation_return(delegation, clp);
494 goto out;
495 }
496
497 err = nfs_do_return_delegation(inode, delegation, issync);
498out:
415 delegation->type = type;
416 delegation->pagemod_limit = pagemod_limit;
417 delegation->change_attr = inode_peek_iversion_raw(inode);
418 delegation->cred = get_cred(cred);
419 delegation->inode = inode;
420 delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
421 spin_lock_init(&delegation->lock);
422

--- 83 unchanged lines hidden (view full) ---

506
507 if (err) {
508 nfs_abort_delegation_return(delegation, clp);
509 goto out;
510 }
511
512 err = nfs_do_return_delegation(inode, delegation, issync);
513out:
514 /* Refcount matched in nfs_start_delegation_return_locked() */
515 nfs_put_delegation(delegation);
499 return err;
500}
501
502static bool nfs_delegation_need_return(struct nfs_delegation *delegation)
503{
504 bool ret = false;
505
506 if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags))

--- 178 unchanged lines hidden (view full) ---

685 goto out;
686 if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags) ||
687 atomic_long_read(&nfs_active_delegations) >= nfs_delegation_watermark) {
688 spin_lock(&delegation->lock);
689 if (delegation->inode &&
690 list_empty(&NFS_I(inode)->open_files) &&
691 !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
692 clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags);
516 return err;
517}
518
519static bool nfs_delegation_need_return(struct nfs_delegation *delegation)
520{
521 bool ret = false;
522
523 if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags))

--- 178 unchanged lines hidden (view full) ---

702 goto out;
703 if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags) ||
704 atomic_long_read(&nfs_active_delegations) >= nfs_delegation_watermark) {
705 spin_lock(&delegation->lock);
706 if (delegation->inode &&
707 list_empty(&NFS_I(inode)->open_files) &&
708 !test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
709 clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags);
693 ret = delegation;
710 /* Refcount matched in nfs_end_delegation_return() */
711 ret = nfs_get_delegation(delegation);
694 }
695 spin_unlock(&delegation->lock);
696 if (ret)
697 nfs_clear_verifier_delegated(inode);
698 }
699out:
700 rcu_read_unlock();
701 nfs_end_delegation_return(inode, ret, 0);

--- 387 unchanged lines hidden (view full) ---

1089 if (inode == NULL) {
1090 rcu_read_unlock();
1091 nfs_sb_deactive(server->super);
1092 goto restart;
1093 }
1094 delegation = nfs_start_delegation_return_locked(NFS_I(inode));
1095 rcu_read_unlock();
1096 if (delegation != NULL) {
712 }
713 spin_unlock(&delegation->lock);
714 if (ret)
715 nfs_clear_verifier_delegated(inode);
716 }
717out:
718 rcu_read_unlock();
719 nfs_end_delegation_return(inode, ret, 0);

--- 387 unchanged lines hidden (view full) ---

1107 if (inode == NULL) {
1108 rcu_read_unlock();
1109 nfs_sb_deactive(server->super);
1110 goto restart;
1111 }
1112 delegation = nfs_start_delegation_return_locked(NFS_I(inode));
1113 rcu_read_unlock();
1114 if (delegation != NULL) {
1097 delegation = nfs_detach_delegation(NFS_I(inode),
1098 delegation, server);
1099 if (delegation != NULL)
1115 if (nfs_detach_delegation(NFS_I(inode), delegation,
1116 server) != NULL)
1100 nfs_free_delegation(delegation);
1117 nfs_free_delegation(delegation);
1118 /* Match nfs_start_delegation_return_locked */
1119 nfs_put_delegation(delegation);
1101 }
1102 iput(inode);
1103 nfs_sb_deactive(server->super);
1104 cond_resched();
1105 goto restart;
1106 }
1107 }
1108 rcu_read_unlock();

--- 271 unchanged lines hidden ---
1120 }
1121 iput(inode);
1122 nfs_sb_deactive(server->super);
1123 cond_resched();
1124 goto restart;
1125 }
1126 }
1127 rcu_read_unlock();

--- 271 unchanged lines hidden ---