Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/delegation.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Trond Myklebust |
| 5 | * |
| 6 | * NFS file delegation management |
| 7 | * |
| 8 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/completion.h> |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 10 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/spinlock.h> |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 15 | #include <linux/iversion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <linux/nfs4.h> |
| 18 | #include <linux/nfs_fs.h> |
| 19 | #include <linux/nfs_xdr.h> |
| 20 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 21 | #include "nfs4_fs.h" |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 22 | #include "nfs4session.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "delegation.h" |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 24 | #include "internal.h" |
Trond Myklebust | ca8acf8 | 2013-08-13 10:36:56 -0400 | [diff] [blame] | 25 | #include "nfs4trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Trond Myklebust | 905f8d1 | 2007-08-06 12:18:34 -0400 | [diff] [blame] | 27 | static void nfs_free_delegation(struct nfs_delegation *delegation) |
| 28 | { |
Trond Myklebust | e00b8a2 | 2011-01-27 14:55:39 -0500 | [diff] [blame] | 29 | if (delegation->cred) { |
| 30 | put_rpccred(delegation->cred); |
| 31 | delegation->cred = NULL; |
| 32 | } |
Lai Jiangshan | 26f04dd | 2011-05-01 06:21:54 -0700 | [diff] [blame] | 33 | kfree_rcu(delegation, rcu); |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 36 | /** |
| 37 | * nfs_mark_delegation_referenced - set delegation's REFERENCED flag |
| 38 | * @delegation: delegation to process |
| 39 | * |
| 40 | */ |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 41 | void nfs_mark_delegation_referenced(struct nfs_delegation *delegation) |
| 42 | { |
| 43 | set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags); |
| 44 | } |
| 45 | |
Trond Myklebust | aa05c87 | 2016-09-22 13:38:54 -0400 | [diff] [blame] | 46 | static bool |
| 47 | nfs4_is_valid_delegation(const struct nfs_delegation *delegation, |
| 48 | fmode_t flags) |
| 49 | { |
| 50 | if (delegation != NULL && (delegation->type & flags) == flags && |
| 51 | !test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) && |
| 52 | !test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 53 | return true; |
| 54 | return false; |
| 55 | } |
| 56 | |
Peng Tao | 15bb3af | 2014-07-03 13:05:00 +0800 | [diff] [blame] | 57 | static int |
| 58 | nfs4_do_check_delegation(struct inode *inode, fmode_t flags, bool mark) |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 59 | { |
| 60 | struct nfs_delegation *delegation; |
| 61 | int ret = 0; |
| 62 | |
| 63 | flags &= FMODE_READ|FMODE_WRITE; |
| 64 | rcu_read_lock(); |
| 65 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | aa05c87 | 2016-09-22 13:38:54 -0400 | [diff] [blame] | 66 | if (nfs4_is_valid_delegation(delegation, flags)) { |
Peng Tao | 15bb3af | 2014-07-03 13:05:00 +0800 | [diff] [blame] | 67 | if (mark) |
| 68 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 69 | ret = 1; |
| 70 | } |
| 71 | rcu_read_unlock(); |
| 72 | return ret; |
| 73 | } |
Peng Tao | 15bb3af | 2014-07-03 13:05:00 +0800 | [diff] [blame] | 74 | /** |
| 75 | * nfs_have_delegation - check if inode has a delegation, mark it |
| 76 | * NFS_DELEGATION_REFERENCED if there is one. |
| 77 | * @inode: inode to check |
| 78 | * @flags: delegation types to check for |
| 79 | * |
| 80 | * Returns one if inode has the indicated delegation, otherwise zero. |
| 81 | */ |
| 82 | int nfs4_have_delegation(struct inode *inode, fmode_t flags) |
| 83 | { |
| 84 | return nfs4_do_check_delegation(inode, flags, true); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * nfs4_check_delegation - check if inode has a delegation, do not mark |
| 89 | * NFS_DELEGATION_REFERENCED if it has one. |
| 90 | */ |
| 91 | int nfs4_check_delegation(struct inode *inode, fmode_t flags) |
| 92 | { |
| 93 | return nfs4_do_check_delegation(inode, flags, false); |
| 94 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 95 | |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 96 | static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 97 | { |
| 98 | struct inode *inode = state->inode; |
| 99 | struct file_lock *fl; |
Jeff Layton | bd61e0a | 2015-01-16 15:05:55 -0500 | [diff] [blame] | 100 | struct file_lock_context *flctx = inode->i_flctx; |
| 101 | struct list_head *list; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 102 | int status = 0; |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 103 | |
Jeff Layton | bd61e0a | 2015-01-16 15:05:55 -0500 | [diff] [blame] | 104 | if (flctx == NULL) |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 105 | goto out; |
Jeff Layton | 314d7cc | 2013-04-10 15:36:48 -0400 | [diff] [blame] | 106 | |
Jeff Layton | bd61e0a | 2015-01-16 15:05:55 -0500 | [diff] [blame] | 107 | list = &flctx->flc_posix; |
Jeff Layton | 6109c85 | 2015-01-16 15:05:57 -0500 | [diff] [blame] | 108 | spin_lock(&flctx->flc_lock); |
Jeff Layton | bd61e0a | 2015-01-16 15:05:55 -0500 | [diff] [blame] | 109 | restart: |
| 110 | list_for_each_entry(fl, list, fl_list) { |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 111 | if (nfs_file_open_context(fl->fl_file) != ctx) |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 112 | continue; |
Jeff Layton | 6109c85 | 2015-01-16 15:05:57 -0500 | [diff] [blame] | 113 | spin_unlock(&flctx->flc_lock); |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 114 | status = nfs4_lock_delegation_recall(fl, state, stateid); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 115 | if (status < 0) |
Trond Myklebust | 3f09df7 | 2009-06-17 13:23:00 -0700 | [diff] [blame] | 116 | goto out; |
Jeff Layton | 6109c85 | 2015-01-16 15:05:57 -0500 | [diff] [blame] | 117 | spin_lock(&flctx->flc_lock); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 118 | } |
Jeff Layton | bd61e0a | 2015-01-16 15:05:55 -0500 | [diff] [blame] | 119 | if (list == &flctx->flc_posix) { |
| 120 | list = &flctx->flc_flock; |
| 121 | goto restart; |
Jeff Layton | 5263e31 | 2015-01-16 15:05:55 -0500 | [diff] [blame] | 122 | } |
Jeff Layton | 6109c85 | 2015-01-16 15:05:57 -0500 | [diff] [blame] | 123 | spin_unlock(&flctx->flc_lock); |
Trond Myklebust | 3f09df7 | 2009-06-17 13:23:00 -0700 | [diff] [blame] | 124 | out: |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 125 | return status; |
| 126 | } |
| 127 | |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 128 | static int nfs_delegation_claim_opens(struct inode *inode, |
| 129 | const nfs4_stateid *stateid, fmode_t type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 131 | struct nfs_inode *nfsi = NFS_I(inode); |
| 132 | struct nfs_open_context *ctx; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 133 | struct nfs4_state_owner *sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | struct nfs4_state *state; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 135 | unsigned int seq; |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 136 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | again: |
| 139 | spin_lock(&inode->i_lock); |
| 140 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 141 | state = ctx->state; |
| 142 | if (state == NULL) |
| 143 | continue; |
| 144 | if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) |
| 145 | continue; |
Trond Myklebust | f8ebf7a | 2014-10-17 23:02:52 +0300 | [diff] [blame] | 146 | if (!nfs4_valid_open_stateid(state)) |
| 147 | continue; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 148 | if (!nfs4_stateid_match(&state->stateid, stateid)) |
Trond Myklebust | 9016302 | 2007-07-05 14:55:18 -0400 | [diff] [blame] | 149 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | get_nfs_open_context(ctx); |
| 151 | spin_unlock(&inode->i_lock); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 152 | sp = state->owner; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 153 | /* Block nfs4_proc_unlck */ |
| 154 | mutex_lock(&sp->so_delegreturn_mutex); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 155 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 156 | err = nfs4_open_delegation_recall(ctx, state, stateid, type); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 157 | if (!err) |
Trond Myklebust | db4f2e6 | 2013-04-01 15:56:46 -0400 | [diff] [blame] | 158 | err = nfs_delegation_claim_locks(ctx, state, stateid); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 159 | if (!err && read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
| 160 | err = -EAGAIN; |
Trond Myklebust | 65b62a2 | 2013-02-07 10:54:07 -0500 | [diff] [blame] | 161 | mutex_unlock(&sp->so_delegreturn_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | put_nfs_open_context(ctx); |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 163 | if (err != 0) |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 164 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | goto again; |
| 166 | } |
| 167 | spin_unlock(&inode->i_lock); |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 168 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 171 | /** |
| 172 | * nfs_inode_reclaim_delegation - process a delegation reclaim request |
| 173 | * @inode: inode to process |
| 174 | * @cred: credential to use for request |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 175 | * @type: delegation type |
| 176 | * @stateid: delegation stateid |
| 177 | * @pagemod_limit: write delegation "space_limit" |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 178 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | */ |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 180 | void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 181 | fmode_t type, |
| 182 | const nfs4_stateid *stateid, |
| 183 | unsigned long pagemod_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Trond Myklebust | 8f649c3 | 2010-05-01 12:36:18 -0400 | [diff] [blame] | 185 | struct nfs_delegation *delegation; |
| 186 | struct rpc_cred *oldcred = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Trond Myklebust | 8f649c3 | 2010-05-01 12:36:18 -0400 | [diff] [blame] | 188 | rcu_read_lock(); |
| 189 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 190 | if (delegation != NULL) { |
| 191 | spin_lock(&delegation->lock); |
| 192 | if (delegation->inode != NULL) { |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 193 | nfs4_stateid_copy(&delegation->stateid, stateid); |
| 194 | delegation->type = type; |
| 195 | delegation->pagemod_limit = pagemod_limit; |
Trond Myklebust | 8f649c3 | 2010-05-01 12:36:18 -0400 | [diff] [blame] | 196 | oldcred = delegation->cred; |
| 197 | delegation->cred = get_rpccred(cred); |
| 198 | clear_bit(NFS_DELEGATION_NEED_RECLAIM, |
| 199 | &delegation->flags); |
Trond Myklebust | 8f649c3 | 2010-05-01 12:36:18 -0400 | [diff] [blame] | 200 | spin_unlock(&delegation->lock); |
Trond Myklebust | 8f649c3 | 2010-05-01 12:36:18 -0400 | [diff] [blame] | 201 | rcu_read_unlock(); |
Trond Myklebust | 7c0af9f | 2015-02-26 12:54:46 -0500 | [diff] [blame] | 202 | put_rpccred(oldcred); |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 203 | trace_nfs4_reclaim_delegation(inode, type); |
Trond Myklebust | b1a318d | 2016-09-22 13:39:12 -0400 | [diff] [blame] | 204 | return; |
Trond Myklebust | 8f649c3 | 2010-05-01 12:36:18 -0400 | [diff] [blame] | 205 | } |
Trond Myklebust | b1a318d | 2016-09-22 13:39:12 -0400 | [diff] [blame] | 206 | /* We appear to have raced with a delegation return. */ |
| 207 | spin_unlock(&delegation->lock); |
Trond Myklebust | 8f649c3 | 2010-05-01 12:36:18 -0400 | [diff] [blame] | 208 | } |
Trond Myklebust | b1a318d | 2016-09-22 13:39:12 -0400 | [diff] [blame] | 209 | rcu_read_unlock(); |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 210 | nfs_inode_set_delegation(inode, cred, type, stateid, pagemod_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 213 | static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync) |
| 214 | { |
| 215 | int res = 0; |
| 216 | |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 217 | if (!test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) |
| 218 | res = nfs4_proc_delegreturn(inode, |
| 219 | delegation->cred, |
| 220 | &delegation->stateid, |
| 221 | issync); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 222 | nfs_free_delegation(delegation); |
| 223 | return res; |
| 224 | } |
| 225 | |
Trond Myklebust | 86e8948 | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 226 | static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation) |
| 227 | { |
| 228 | struct inode *inode = NULL; |
| 229 | |
| 230 | spin_lock(&delegation->lock); |
| 231 | if (delegation->inode != NULL) |
| 232 | inode = igrab(delegation->inode); |
| 233 | spin_unlock(&delegation->lock); |
| 234 | return inode; |
| 235 | } |
| 236 | |
Chuck Lever | dda4b22 | 2010-12-24 01:32:54 +0000 | [diff] [blame] | 237 | static struct nfs_delegation * |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 238 | nfs_start_delegation_return_locked(struct nfs_inode *nfsi) |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 239 | { |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 240 | struct nfs_delegation *ret = NULL; |
| 241 | struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 242 | |
| 243 | if (delegation == NULL) |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 244 | goto out; |
| 245 | spin_lock(&delegation->lock); |
| 246 | if (!test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 247 | ret = delegation; |
| 248 | spin_unlock(&delegation->lock); |
| 249 | out: |
| 250 | return ret; |
| 251 | } |
| 252 | |
| 253 | static struct nfs_delegation * |
| 254 | nfs_start_delegation_return(struct nfs_inode *nfsi) |
| 255 | { |
| 256 | struct nfs_delegation *delegation; |
| 257 | |
| 258 | rcu_read_lock(); |
| 259 | delegation = nfs_start_delegation_return_locked(nfsi); |
| 260 | rcu_read_unlock(); |
| 261 | return delegation; |
| 262 | } |
| 263 | |
| 264 | static void |
| 265 | nfs_abort_delegation_return(struct nfs_delegation *delegation, |
| 266 | struct nfs_client *clp) |
| 267 | { |
Chuck Lever | dda4b22 | 2010-12-24 01:32:54 +0000 | [diff] [blame] | 268 | |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 269 | spin_lock(&delegation->lock); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 270 | clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags); |
| 271 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); |
| 272 | spin_unlock(&delegation->lock); |
| 273 | set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); |
| 274 | } |
| 275 | |
| 276 | static struct nfs_delegation * |
| 277 | nfs_detach_delegation_locked(struct nfs_inode *nfsi, |
| 278 | struct nfs_delegation *delegation, |
| 279 | struct nfs_client *clp) |
| 280 | { |
| 281 | struct nfs_delegation *deleg_cur = |
| 282 | rcu_dereference_protected(nfsi->delegation, |
| 283 | lockdep_is_held(&clp->cl_lock)); |
| 284 | |
| 285 | if (deleg_cur == NULL || delegation != deleg_cur) |
| 286 | return NULL; |
| 287 | |
| 288 | spin_lock(&delegation->lock); |
| 289 | set_bit(NFS_DELEGATION_RETURNING, &delegation->flags); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 290 | list_del_rcu(&delegation->super_list); |
Trond Myklebust | 86e8948 | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 291 | delegation->inode = NULL; |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 292 | rcu_assign_pointer(nfsi->delegation, NULL); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 293 | spin_unlock(&delegation->lock); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 294 | return delegation; |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 295 | } |
| 296 | |
Chuck Lever | dda4b22 | 2010-12-24 01:32:54 +0000 | [diff] [blame] | 297 | static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi, |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 298 | struct nfs_delegation *delegation, |
| 299 | struct nfs_server *server) |
Chuck Lever | dda4b22 | 2010-12-24 01:32:54 +0000 | [diff] [blame] | 300 | { |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 301 | struct nfs_client *clp = server->nfs_client; |
Chuck Lever | dda4b22 | 2010-12-24 01:32:54 +0000 | [diff] [blame] | 302 | |
| 303 | spin_lock(&clp->cl_lock); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 304 | delegation = nfs_detach_delegation_locked(nfsi, delegation, clp); |
Chuck Lever | dda4b22 | 2010-12-24 01:32:54 +0000 | [diff] [blame] | 305 | spin_unlock(&clp->cl_lock); |
| 306 | return delegation; |
| 307 | } |
| 308 | |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 309 | static struct nfs_delegation * |
| 310 | nfs_inode_detach_delegation(struct inode *inode) |
| 311 | { |
| 312 | struct nfs_inode *nfsi = NFS_I(inode); |
| 313 | struct nfs_server *server = NFS_SERVER(inode); |
| 314 | struct nfs_delegation *delegation; |
| 315 | |
| 316 | delegation = nfs_start_delegation_return(nfsi); |
| 317 | if (delegation == NULL) |
| 318 | return NULL; |
| 319 | return nfs_detach_delegation(nfsi, delegation, server); |
| 320 | } |
| 321 | |
Trond Myklebust | cf6726e | 2014-12-19 11:22:28 -0500 | [diff] [blame] | 322 | static void |
| 323 | nfs_update_inplace_delegation(struct nfs_delegation *delegation, |
| 324 | const struct nfs_delegation *update) |
| 325 | { |
| 326 | if (nfs4_stateid_is_newer(&update->stateid, &delegation->stateid)) { |
| 327 | delegation->stateid.seqid = update->stateid.seqid; |
| 328 | smp_wmb(); |
| 329 | delegation->type = update->type; |
| 330 | } |
| 331 | } |
| 332 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 333 | /** |
| 334 | * nfs_inode_set_delegation - set up a delegation on an inode |
| 335 | * @inode: inode to which delegation applies |
| 336 | * @cred: cred to use for subsequent delegation processing |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 337 | * @type: delegation type |
| 338 | * @stateid: delegation stateid |
| 339 | * @pagemod_limit: write delegation "space_limit" |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 340 | * |
| 341 | * Returns zero on success, or a negative errno value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | */ |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 343 | int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, |
| 344 | fmode_t type, |
| 345 | const nfs4_stateid *stateid, |
| 346 | unsigned long pagemod_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 348 | struct nfs_server *server = NFS_SERVER(inode); |
| 349 | struct nfs_client *clp = server->nfs_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | struct nfs_inode *nfsi = NFS_I(inode); |
David Howells | 17d2c0a | 2010-05-01 12:37:18 -0400 | [diff] [blame] | 351 | struct nfs_delegation *delegation, *old_delegation; |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 352 | struct nfs_delegation *freeme = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | int status = 0; |
| 354 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 355 | delegation = kmalloc(sizeof(*delegation), GFP_NOFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | if (delegation == NULL) |
| 357 | return -ENOMEM; |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 358 | nfs4_stateid_copy(&delegation->stateid, stateid); |
| 359 | delegation->type = type; |
| 360 | delegation->pagemod_limit = pagemod_limit; |
Jeff Layton | 1eb5d98 | 2018-01-09 08:21:17 -0500 | [diff] [blame] | 361 | delegation->change_attr = inode_peek_iversion_raw(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | delegation->cred = get_rpccred(cred); |
| 363 | delegation->inode = inode; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 364 | delegation->flags = 1<<NFS_DELEGATION_REFERENCED; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 365 | spin_lock_init(&delegation->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | spin_lock(&clp->cl_lock); |
David Howells | 17d2c0a | 2010-05-01 12:37:18 -0400 | [diff] [blame] | 368 | old_delegation = rcu_dereference_protected(nfsi->delegation, |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 369 | lockdep_is_held(&clp->cl_lock)); |
David Howells | 17d2c0a | 2010-05-01 12:37:18 -0400 | [diff] [blame] | 370 | if (old_delegation != NULL) { |
Trond Myklebust | cf6726e | 2014-12-19 11:22:28 -0500 | [diff] [blame] | 371 | /* Is this an update of the existing delegation? */ |
| 372 | if (nfs4_stateid_match_other(&old_delegation->stateid, |
| 373 | &delegation->stateid)) { |
| 374 | nfs_update_inplace_delegation(old_delegation, |
| 375 | delegation); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 376 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 378 | /* |
| 379 | * Deal with broken servers that hand out two |
| 380 | * delegations for the same file. |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 381 | * Allow for upgrades to a WRITE delegation, but |
| 382 | * nothing else. |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 383 | */ |
| 384 | dfprintk(FILE, "%s: server %s handed out " |
| 385 | "a duplicate delegation!\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 386 | __func__, clp->cl_hostname); |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 387 | if (delegation->type == old_delegation->type || |
| 388 | !(delegation->type & FMODE_WRITE)) { |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 389 | freeme = delegation; |
| 390 | delegation = NULL; |
| 391 | goto out; |
| 392 | } |
Trond Myklebust | ade0464 | 2015-02-27 14:25:50 -0500 | [diff] [blame] | 393 | if (test_and_set_bit(NFS_DELEGATION_RETURNING, |
| 394 | &old_delegation->flags)) |
| 395 | goto out; |
| 396 | freeme = nfs_detach_delegation_locked(nfsi, |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 397 | old_delegation, clp); |
| 398 | if (freeme == NULL) |
| 399 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
Trond Myklebust | 38942ba | 2015-03-04 15:59:05 -0500 | [diff] [blame] | 401 | list_add_tail_rcu(&delegation->super_list, &server->delegations); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 402 | rcu_assign_pointer(nfsi->delegation, delegation); |
| 403 | delegation = NULL; |
Trond Myklebust | 412c77c | 2007-07-03 16:10:55 -0400 | [diff] [blame] | 404 | |
Trond Myklebust | 35156bf | 2018-03-20 17:03:13 -0400 | [diff] [blame] | 405 | trace_nfs4_set_delegation(inode, type); |
Trond Myklebust | 412c77c | 2007-07-03 16:10:55 -0400 | [diff] [blame] | 406 | |
Trond Myklebust | 97c2c17 | 2018-04-07 18:43:17 -0400 | [diff] [blame] | 407 | spin_lock(&inode->i_lock); |
| 408 | if (NFS_I(inode)->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME)) |
| 409 | NFS_I(inode)->cache_validity |= NFS_INO_REVAL_FORCED; |
| 410 | spin_unlock(&inode->i_lock); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 411 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | spin_unlock(&clp->cl_lock); |
Trond Myklebust | 603c83d | 2007-10-18 19:59:20 -0400 | [diff] [blame] | 413 | if (delegation != NULL) |
| 414 | nfs_free_delegation(delegation); |
Trond Myklebust | 57bfa89 | 2008-01-25 16:38:18 -0500 | [diff] [blame] | 415 | if (freeme != NULL) |
| 416 | nfs_do_return_delegation(inode, freeme, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | return status; |
| 418 | } |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /* |
| 421 | * Basic procedure for returning a delegation to the server |
| 422 | */ |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 423 | static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation *delegation, int issync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 425 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | struct nfs_inode *nfsi = NFS_I(inode); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 427 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 429 | if (delegation == NULL) |
| 430 | return 0; |
| 431 | do { |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 432 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) |
| 433 | break; |
Trond Myklebust | 24311f8 | 2015-09-20 10:50:17 -0400 | [diff] [blame] | 434 | err = nfs_delegation_claim_opens(inode, &delegation->stateid, |
| 435 | delegation->type); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 436 | if (!issync || err != -EAGAIN) |
| 437 | break; |
| 438 | /* |
| 439 | * Guard against state recovery |
| 440 | */ |
| 441 | err = nfs4_wait_clnt_recover(clp); |
| 442 | } while (err == 0); |
| 443 | |
| 444 | if (err) { |
| 445 | nfs_abort_delegation_return(delegation, clp); |
| 446 | goto out; |
| 447 | } |
| 448 | if (!nfs_detach_delegation(nfsi, delegation, NFS_SERVER(inode))) |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 449 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 451 | err = nfs_do_return_delegation(inode, delegation, issync); |
| 452 | out: |
| 453 | return err; |
Trond Myklebust | 9016302 | 2007-07-05 14:55:18 -0400 | [diff] [blame] | 454 | } |
| 455 | |
Trond Myklebust | b757144 | 2013-04-03 14:33:49 -0400 | [diff] [blame] | 456 | static bool nfs_delegation_need_return(struct nfs_delegation *delegation) |
| 457 | { |
| 458 | bool ret = false; |
| 459 | |
Trond Myklebust | ec3ca4e5 | 2015-02-26 14:05:05 -0500 | [diff] [blame] | 460 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 461 | goto out; |
Trond Myklebust | b757144 | 2013-04-03 14:33:49 -0400 | [diff] [blame] | 462 | if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags)) |
| 463 | ret = true; |
| 464 | if (test_and_clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags) && !ret) { |
| 465 | struct inode *inode; |
| 466 | |
| 467 | spin_lock(&delegation->lock); |
| 468 | inode = delegation->inode; |
| 469 | if (inode && list_empty(&NFS_I(inode)->open_files)) |
| 470 | ret = true; |
| 471 | spin_unlock(&delegation->lock); |
| 472 | } |
Trond Myklebust | ec3ca4e5 | 2015-02-26 14:05:05 -0500 | [diff] [blame] | 473 | out: |
Trond Myklebust | b757144 | 2013-04-03 14:33:49 -0400 | [diff] [blame] | 474 | return ret; |
| 475 | } |
| 476 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 477 | /** |
| 478 | * nfs_client_return_marked_delegations - return previously marked delegations |
| 479 | * @clp: nfs_client to process |
| 480 | * |
Trond Myklebust | dc327ed | 2012-05-06 19:46:30 -0400 | [diff] [blame] | 481 | * Note that this function is designed to be called by the state |
| 482 | * manager thread. For this reason, it cannot flush the dirty data, |
| 483 | * since that could deadlock in case of a state recovery error. |
| 484 | * |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 485 | * Returns zero on success, or a negative errno value. |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 486 | */ |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 487 | int nfs_client_return_marked_delegations(struct nfs_client *clp) |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 488 | { |
| 489 | struct nfs_delegation *delegation; |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 490 | struct nfs_delegation *prev; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 491 | struct nfs_server *server; |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 492 | struct inode *inode; |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 493 | struct inode *place_holder = NULL; |
| 494 | struct nfs_delegation *place_holder_deleg = NULL; |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 495 | int err = 0; |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 496 | |
| 497 | restart: |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 498 | /* |
| 499 | * To avoid quadratic looping we hold a reference |
| 500 | * to an inode place_holder. Each time we restart, we |
| 501 | * list nfs_servers from the server of that inode, and |
| 502 | * delegation in the server from the delegations of that |
| 503 | * inode. |
| 504 | * prev is an RCU-protected pointer to a delegation which |
| 505 | * wasn't marked for return and might be a good choice for |
| 506 | * the next place_holder. |
| 507 | */ |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 508 | rcu_read_lock(); |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 509 | prev = NULL; |
| 510 | if (place_holder) |
| 511 | server = NFS_SERVER(place_holder); |
| 512 | else |
| 513 | server = list_entry_rcu(clp->cl_superblocks.next, |
| 514 | struct nfs_server, client_link); |
| 515 | list_for_each_entry_from_rcu(server, &clp->cl_superblocks, client_link) { |
| 516 | delegation = NULL; |
| 517 | if (place_holder && server == NFS_SERVER(place_holder)) |
| 518 | delegation = rcu_dereference(NFS_I(place_holder)->delegation); |
| 519 | if (!delegation || delegation != place_holder_deleg) |
| 520 | delegation = list_entry_rcu(server->delegations.next, |
| 521 | struct nfs_delegation, super_list); |
| 522 | list_for_each_entry_from_rcu(delegation, &server->delegations, super_list) { |
| 523 | struct inode *to_put = NULL; |
| 524 | |
| 525 | if (!nfs_delegation_need_return(delegation)) { |
| 526 | prev = delegation; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 527 | continue; |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 528 | } |
Trond Myklebust | 9f0f8e1 | 2015-02-26 09:57:34 -0500 | [diff] [blame] | 529 | if (!nfs_sb_active(server->super)) |
NeilBrown | f3893491 | 2018-05-31 15:23:22 +1000 | [diff] [blame] | 530 | break; /* continue in outer loop */ |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 531 | |
| 532 | if (prev) { |
| 533 | struct inode *tmp; |
| 534 | |
| 535 | tmp = nfs_delegation_grab_inode(prev); |
| 536 | if (tmp) { |
| 537 | to_put = place_holder; |
| 538 | place_holder = tmp; |
| 539 | place_holder_deleg = prev; |
| 540 | } |
| 541 | } |
| 542 | |
Trond Myklebust | 9f0f8e1 | 2015-02-26 09:57:34 -0500 | [diff] [blame] | 543 | inode = nfs_delegation_grab_inode(delegation); |
| 544 | if (inode == NULL) { |
| 545 | rcu_read_unlock(); |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 546 | if (to_put) |
| 547 | iput(to_put); |
Trond Myklebust | 9f0f8e1 | 2015-02-26 09:57:34 -0500 | [diff] [blame] | 548 | nfs_sb_deactive(server->super); |
| 549 | goto restart; |
| 550 | } |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 551 | delegation = nfs_start_delegation_return_locked(NFS_I(inode)); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 552 | rcu_read_unlock(); |
| 553 | |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 554 | if (to_put) |
| 555 | iput(to_put); |
| 556 | |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 557 | err = nfs_end_delegation_return(inode, delegation, 0); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 558 | iput(inode); |
Trond Myklebust | 9f0f8e1 | 2015-02-26 09:57:34 -0500 | [diff] [blame] | 559 | nfs_sb_deactive(server->super); |
NeilBrown | 3ca951b | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 560 | cond_resched(); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 561 | if (!err) |
| 562 | goto restart; |
| 563 | set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 564 | if (place_holder) |
| 565 | iput(place_holder); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 566 | return err; |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 567 | } |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 568 | } |
| 569 | rcu_read_unlock(); |
NeilBrown | e04bbf6 | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 570 | if (place_holder) |
| 571 | iput(place_holder); |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 572 | return 0; |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 573 | } |
| 574 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 575 | /** |
| 576 | * nfs_inode_return_delegation_noreclaim - return delegation, don't reclaim opens |
| 577 | * @inode: inode to process |
| 578 | * |
| 579 | * Does not protect against delegation reclaims, therefore really only safe |
| 580 | * to be called from nfs4_clear_inode(). |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 581 | */ |
| 582 | void nfs_inode_return_delegation_noreclaim(struct inode *inode) |
| 583 | { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 584 | struct nfs_delegation *delegation; |
| 585 | |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 586 | delegation = nfs_inode_detach_delegation(inode); |
| 587 | if (delegation != NULL) |
Trond Myklebust | 5fcdfac | 2015-03-25 13:19:42 -0400 | [diff] [blame] | 588 | nfs_do_return_delegation(inode, delegation, 1); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 589 | } |
| 590 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 591 | /** |
| 592 | * nfs_inode_return_delegation - synchronously return a delegation |
| 593 | * @inode: inode to process |
| 594 | * |
Trond Myklebust | c57d1bc | 2012-05-06 19:34:17 -0400 | [diff] [blame] | 595 | * This routine will always flush any dirty data to disk on the |
| 596 | * assumption that if we need to return the delegation, then |
| 597 | * we should stop caching. |
| 598 | * |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 599 | * Returns zero on success, or a negative errno value. |
| 600 | */ |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 601 | int nfs4_inode_return_delegation(struct inode *inode) |
Trond Myklebust | 9016302 | 2007-07-05 14:55:18 -0400 | [diff] [blame] | 602 | { |
Trond Myklebust | 9016302 | 2007-07-05 14:55:18 -0400 | [diff] [blame] | 603 | struct nfs_inode *nfsi = NFS_I(inode); |
| 604 | struct nfs_delegation *delegation; |
| 605 | int err = 0; |
| 606 | |
Trond Myklebust | c57d1bc | 2012-05-06 19:34:17 -0400 | [diff] [blame] | 607 | nfs_wb_all(inode); |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 608 | delegation = nfs_start_delegation_return(nfsi); |
| 609 | if (delegation != NULL) |
| 610 | err = nfs_end_delegation_return(inode, delegation, 1); |
Trond Myklebust | 9016302 | 2007-07-05 14:55:18 -0400 | [diff] [blame] | 611 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Trond Myklebust | c01d364 | 2018-03-20 16:43:20 -0400 | [diff] [blame] | 614 | /** |
| 615 | * nfs4_inode_make_writeable |
| 616 | * @inode: pointer to inode |
| 617 | * |
| 618 | * Make the inode writeable by returning the delegation if necessary |
| 619 | * |
| 620 | * Returns zero on success, or a negative errno value. |
| 621 | */ |
| 622 | int nfs4_inode_make_writeable(struct inode *inode) |
| 623 | { |
| 624 | if (!nfs4_has_session(NFS_SERVER(inode)->nfs_client) || |
| 625 | !nfs4_check_delegation(inode, FMODE_WRITE)) |
| 626 | return nfs4_inode_return_delegation(inode); |
| 627 | return 0; |
| 628 | } |
| 629 | |
Trond Myklebust | b757144 | 2013-04-03 14:33:49 -0400 | [diff] [blame] | 630 | static void nfs_mark_return_if_closed_delegation(struct nfs_server *server, |
| 631 | struct nfs_delegation *delegation) |
| 632 | { |
| 633 | set_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags); |
| 634 | set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); |
| 635 | } |
| 636 | |
Trond Myklebust | ed1e6211 | 2011-07-25 15:37:29 -0400 | [diff] [blame] | 637 | static void nfs_mark_return_delegation(struct nfs_server *server, |
| 638 | struct nfs_delegation *delegation) |
Trond Myklebust | 6411bd4 | 2008-12-23 15:21:51 -0500 | [diff] [blame] | 639 | { |
| 640 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); |
Trond Myklebust | ed1e6211 | 2011-07-25 15:37:29 -0400 | [diff] [blame] | 641 | set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state); |
Trond Myklebust | 6411bd4 | 2008-12-23 15:21:51 -0500 | [diff] [blame] | 642 | } |
| 643 | |
Trond Myklebust | 5c31e23 | 2013-04-03 19:04:58 -0400 | [diff] [blame] | 644 | static bool nfs_server_mark_return_all_delegations(struct nfs_server *server) |
| 645 | { |
| 646 | struct nfs_delegation *delegation; |
| 647 | bool ret = false; |
| 648 | |
| 649 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
| 650 | nfs_mark_return_delegation(server, delegation); |
| 651 | ret = true; |
| 652 | } |
| 653 | return ret; |
| 654 | } |
| 655 | |
Trond Myklebust | b02ba0b | 2013-04-03 19:23:58 -0400 | [diff] [blame] | 656 | static void nfs_client_mark_return_all_delegations(struct nfs_client *clp) |
| 657 | { |
| 658 | struct nfs_server *server; |
| 659 | |
| 660 | rcu_read_lock(); |
| 661 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) |
| 662 | nfs_server_mark_return_all_delegations(server); |
| 663 | rcu_read_unlock(); |
| 664 | } |
| 665 | |
| 666 | static void nfs_delegation_run_state_manager(struct nfs_client *clp) |
| 667 | { |
| 668 | if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) |
| 669 | nfs4_schedule_state_manager(clp); |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * nfs_expire_all_delegations |
| 674 | * @clp: client to process |
| 675 | * |
| 676 | */ |
| 677 | void nfs_expire_all_delegations(struct nfs_client *clp) |
| 678 | { |
| 679 | nfs_client_mark_return_all_delegations(clp); |
| 680 | nfs_delegation_run_state_manager(clp); |
| 681 | } |
| 682 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 683 | /** |
| 684 | * nfs_super_return_all_delegations - return delegations for one superblock |
| 685 | * @sb: sb to process |
| 686 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | */ |
Bryan Schumaker | eeebf91 | 2012-06-20 15:53:41 -0400 | [diff] [blame] | 688 | void nfs_server_return_all_delegations(struct nfs_server *server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 690 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 5c31e23 | 2013-04-03 19:04:58 -0400 | [diff] [blame] | 691 | bool need_wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | if (clp == NULL) |
| 694 | return; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 695 | |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 696 | rcu_read_lock(); |
Trond Myklebust | 5c31e23 | 2013-04-03 19:04:58 -0400 | [diff] [blame] | 697 | need_wait = nfs_server_mark_return_all_delegations(server); |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 698 | rcu_read_unlock(); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 699 | |
Trond Myklebust | 5c31e23 | 2013-04-03 19:04:58 -0400 | [diff] [blame] | 700 | if (need_wait) { |
Trond Myklebust | d18cc1f | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 701 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | 5c31e23 | 2013-04-03 19:04:58 -0400 | [diff] [blame] | 702 | nfs4_wait_clnt_recover(clp); |
| 703 | } |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 704 | } |
| 705 | |
Trond Myklebust | 826e001 | 2013-04-03 19:27:52 -0400 | [diff] [blame] | 706 | static void nfs_mark_return_unused_delegation_types(struct nfs_server *server, |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 707 | fmode_t flags) |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 708 | { |
| 709 | struct nfs_delegation *delegation; |
| 710 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 711 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
Alexandros Batsakis | c79571a | 2009-12-05 13:20:52 -0500 | [diff] [blame] | 712 | if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE)) |
| 713 | continue; |
| 714 | if (delegation->type & flags) |
Trond Myklebust | 826e001 | 2013-04-03 19:27:52 -0400 | [diff] [blame] | 715 | nfs_mark_return_if_closed_delegation(server, delegation); |
Trond Myklebust | 707fb4b | 2008-12-23 15:21:47 -0500 | [diff] [blame] | 716 | } |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Trond Myklebust | 826e001 | 2013-04-03 19:27:52 -0400 | [diff] [blame] | 719 | static void nfs_client_mark_return_unused_delegation_types(struct nfs_client *clp, |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 720 | fmode_t flags) |
| 721 | { |
| 722 | struct nfs_server *server; |
| 723 | |
| 724 | rcu_read_lock(); |
| 725 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) |
Trond Myklebust | 826e001 | 2013-04-03 19:27:52 -0400 | [diff] [blame] | 726 | nfs_mark_return_unused_delegation_types(server, flags); |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 727 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 730 | static void nfs_mark_delegation_revoked(struct nfs_server *server, |
| 731 | struct nfs_delegation *delegation) |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 732 | { |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 733 | set_bit(NFS_DELEGATION_REVOKED, &delegation->flags); |
Trond Myklebust | 059b43e | 2016-09-22 13:39:06 -0400 | [diff] [blame] | 734 | delegation->stateid.type = NFS4_INVALID_STATEID_TYPE; |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 735 | nfs_mark_return_delegation(server, delegation); |
Trond Myklebust | 869f9df | 2014-11-10 18:43:56 -0500 | [diff] [blame] | 736 | } |
| 737 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 738 | static bool nfs_revoke_delegation(struct inode *inode, |
| 739 | const nfs4_stateid *stateid) |
| 740 | { |
| 741 | struct nfs_delegation *delegation; |
Trond Myklebust | 7f04883 | 2016-09-22 13:39:14 -0400 | [diff] [blame] | 742 | nfs4_stateid tmp; |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 743 | bool ret = false; |
| 744 | |
| 745 | rcu_read_lock(); |
| 746 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 747 | if (delegation == NULL) |
| 748 | goto out; |
Trond Myklebust | 7f04883 | 2016-09-22 13:39:14 -0400 | [diff] [blame] | 749 | if (stateid == NULL) { |
| 750 | nfs4_stateid_copy(&tmp, &delegation->stateid); |
| 751 | stateid = &tmp; |
| 752 | } else if (!nfs4_stateid_match(stateid, &delegation->stateid)) |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 753 | goto out; |
| 754 | nfs_mark_delegation_revoked(NFS_SERVER(inode), delegation); |
| 755 | ret = true; |
| 756 | out: |
| 757 | rcu_read_unlock(); |
Trond Myklebust | 7f04883 | 2016-09-22 13:39:14 -0400 | [diff] [blame] | 758 | if (ret) |
| 759 | nfs_inode_find_state_and_recover(inode, stateid); |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 760 | return ret; |
| 761 | } |
| 762 | |
| 763 | void nfs_remove_bad_delegation(struct inode *inode, |
| 764 | const nfs4_stateid *stateid) |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 765 | { |
| 766 | struct nfs_delegation *delegation; |
| 767 | |
Trond Myklebust | 41020b6 | 2016-09-22 13:38:58 -0400 | [diff] [blame] | 768 | if (!nfs_revoke_delegation(inode, stateid)) |
| 769 | return; |
Trond Myklebust | d25be54 | 2013-02-05 11:43:28 -0500 | [diff] [blame] | 770 | delegation = nfs_inode_detach_delegation(inode); |
Trond Myklebust | 7f04883 | 2016-09-22 13:39:14 -0400 | [diff] [blame] | 771 | if (delegation) |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 772 | nfs_free_delegation(delegation); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 773 | } |
Andy Adamson | 9cb8196 | 2012-03-07 10:49:41 -0500 | [diff] [blame] | 774 | EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 775 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 776 | /** |
Trond Myklebust | 826e001 | 2013-04-03 19:27:52 -0400 | [diff] [blame] | 777 | * nfs_expire_unused_delegation_types |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 778 | * @clp: client to process |
| 779 | * @flags: delegation types to expire |
| 780 | * |
| 781 | */ |
Trond Myklebust | 826e001 | 2013-04-03 19:27:52 -0400 | [diff] [blame] | 782 | void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags) |
Alexandros Batsakis | c79571a | 2009-12-05 13:20:52 -0500 | [diff] [blame] | 783 | { |
Trond Myklebust | 826e001 | 2013-04-03 19:27:52 -0400 | [diff] [blame] | 784 | nfs_client_mark_return_unused_delegation_types(clp, flags); |
Alexandros Batsakis | c79571a | 2009-12-05 13:20:52 -0500 | [diff] [blame] | 785 | nfs_delegation_run_state_manager(clp); |
| 786 | } |
| 787 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 788 | static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server) |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 789 | { |
| 790 | struct nfs_delegation *delegation; |
| 791 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 792 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 793 | if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags)) |
| 794 | continue; |
Trond Myklebust | b757144 | 2013-04-03 14:33:49 -0400 | [diff] [blame] | 795 | nfs_mark_return_if_closed_delegation(server, delegation); |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 796 | } |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 797 | } |
| 798 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 799 | /** |
| 800 | * nfs_expire_unreferenced_delegations - Eliminate unused delegations |
| 801 | * @clp: nfs_client to process |
| 802 | * |
| 803 | */ |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 804 | void nfs_expire_unreferenced_delegations(struct nfs_client *clp) |
| 805 | { |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 806 | struct nfs_server *server; |
| 807 | |
| 808 | rcu_read_lock(); |
| 809 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) |
| 810 | nfs_mark_return_unreferenced_delegations(server); |
| 811 | rcu_read_unlock(); |
| 812 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 813 | nfs_delegation_run_state_manager(clp); |
| 814 | } |
| 815 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 816 | /** |
| 817 | * nfs_async_inode_return_delegation - asynchronously return a delegation |
| 818 | * @inode: inode to process |
Trond Myklebust | 8e663f0 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 819 | * @stateid: state ID information |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 820 | * |
| 821 | * Returns zero on success, or a negative errno value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | */ |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 823 | int nfs_async_inode_return_delegation(struct inode *inode, |
| 824 | const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | { |
Trond Myklebust | ed1e6211 | 2011-07-25 15:37:29 -0400 | [diff] [blame] | 826 | struct nfs_server *server = NFS_SERVER(inode); |
| 827 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 6411bd4 | 2008-12-23 15:21:51 -0500 | [diff] [blame] | 828 | struct nfs_delegation *delegation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Trond Myklebust | 6411bd4 | 2008-12-23 15:21:51 -0500 | [diff] [blame] | 830 | rcu_read_lock(); |
| 831 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | 755a48a | 2014-03-02 22:03:12 -0500 | [diff] [blame] | 832 | if (delegation == NULL) |
| 833 | goto out_enoent; |
Trond Myklebust | 4816fda | 2015-09-20 14:58:42 -0400 | [diff] [blame] | 834 | if (stateid != NULL && |
| 835 | !clp->cl_mvops->match_stateid(&delegation->stateid, stateid)) |
Trond Myklebust | 755a48a | 2014-03-02 22:03:12 -0500 | [diff] [blame] | 836 | goto out_enoent; |
Trond Myklebust | ed1e6211 | 2011-07-25 15:37:29 -0400 | [diff] [blame] | 837 | nfs_mark_return_delegation(server, delegation); |
Trond Myklebust | 6411bd4 | 2008-12-23 15:21:51 -0500 | [diff] [blame] | 838 | rcu_read_unlock(); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 839 | |
Trond Myklebust | 6411bd4 | 2008-12-23 15:21:51 -0500 | [diff] [blame] | 840 | nfs_delegation_run_state_manager(clp); |
| 841 | return 0; |
Trond Myklebust | 755a48a | 2014-03-02 22:03:12 -0500 | [diff] [blame] | 842 | out_enoent: |
| 843 | rcu_read_unlock(); |
| 844 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 847 | static struct inode * |
| 848 | nfs_delegation_find_inode_server(struct nfs_server *server, |
| 849 | const struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
| 851 | struct nfs_delegation *delegation; |
| 852 | struct inode *res = NULL; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 853 | |
| 854 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
Trond Myklebust | 86e8948 | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 855 | spin_lock(&delegation->lock); |
| 856 | if (delegation->inode != NULL && |
| 857 | nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | res = igrab(delegation->inode); |
Trond Myklebust | 6c34265 | 2018-06-07 14:22:00 -0400 | [diff] [blame] | 859 | spin_unlock(&delegation->lock); |
| 860 | if (res != NULL) |
| 861 | return res; |
| 862 | return ERR_PTR(-EAGAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
Trond Myklebust | 86e8948 | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 864 | spin_unlock(&delegation->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
Trond Myklebust | 6c34265 | 2018-06-07 14:22:00 -0400 | [diff] [blame] | 866 | return ERR_PTR(-ENOENT); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /** |
| 870 | * nfs_delegation_find_inode - retrieve the inode associated with a delegation |
| 871 | * @clp: client state handle |
| 872 | * @fhandle: filehandle from a delegation recall |
| 873 | * |
| 874 | * Returns pointer to inode matching "fhandle," or NULL if a matching inode |
| 875 | * cannot be found. |
| 876 | */ |
| 877 | struct inode *nfs_delegation_find_inode(struct nfs_client *clp, |
| 878 | const struct nfs_fh *fhandle) |
| 879 | { |
| 880 | struct nfs_server *server; |
Trond Myklebust | 6c34265 | 2018-06-07 14:22:00 -0400 | [diff] [blame] | 881 | struct inode *res; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 882 | |
| 883 | rcu_read_lock(); |
| 884 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
| 885 | res = nfs_delegation_find_inode_server(server, fhandle); |
Trond Myklebust | 6c34265 | 2018-06-07 14:22:00 -0400 | [diff] [blame] | 886 | if (res != ERR_PTR(-ENOENT)) |
| 887 | return res; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 888 | } |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 889 | rcu_read_unlock(); |
Trond Myklebust | 6c34265 | 2018-06-07 14:22:00 -0400 | [diff] [blame] | 890 | return ERR_PTR(-ENOENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 893 | static void nfs_delegation_mark_reclaim_server(struct nfs_server *server) |
| 894 | { |
| 895 | struct nfs_delegation *delegation; |
| 896 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 897 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
| 898 | /* |
| 899 | * If the delegation may have been admin revoked, then we |
| 900 | * cannot reclaim it. |
| 901 | */ |
| 902 | if (test_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) |
| 903 | continue; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 904 | set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 905 | } |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | /** |
| 909 | * nfs_delegation_mark_reclaim - mark all delegations as needing to be reclaimed |
| 910 | * @clp: nfs_client to process |
| 911 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | */ |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 913 | void nfs_delegation_mark_reclaim(struct nfs_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 915 | struct nfs_server *server; |
| 916 | |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 917 | rcu_read_lock(); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 918 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) |
| 919 | nfs_delegation_mark_reclaim_server(server); |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 920 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 923 | /** |
| 924 | * nfs_delegation_reap_unclaimed - reap unclaimed delegations after reboot recovery is done |
| 925 | * @clp: nfs_client to process |
| 926 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | */ |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 928 | void nfs_delegation_reap_unclaimed(struct nfs_client *clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 930 | struct nfs_delegation *delegation; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 931 | struct nfs_server *server; |
Trond Myklebust | 86e8948 | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 932 | struct inode *inode; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 933 | |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 934 | restart: |
| 935 | rcu_read_lock(); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 936 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
| 937 | list_for_each_entry_rcu(delegation, &server->delegations, |
| 938 | super_list) { |
Trond Myklebust | ec3ca4e5 | 2015-02-26 14:05:05 -0500 | [diff] [blame] | 939 | if (test_bit(NFS_DELEGATION_RETURNING, |
| 940 | &delegation->flags)) |
| 941 | continue; |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 942 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, |
| 943 | &delegation->flags) == 0) |
| 944 | continue; |
Trond Myklebust | 9f0f8e1 | 2015-02-26 09:57:34 -0500 | [diff] [blame] | 945 | if (!nfs_sb_active(server->super)) |
NeilBrown | f3893491 | 2018-05-31 15:23:22 +1000 | [diff] [blame] | 946 | break; /* continue in outer loop */ |
Trond Myklebust | 9f0f8e1 | 2015-02-26 09:57:34 -0500 | [diff] [blame] | 947 | inode = nfs_delegation_grab_inode(delegation); |
| 948 | if (inode == NULL) { |
| 949 | rcu_read_unlock(); |
| 950 | nfs_sb_deactive(server->super); |
| 951 | goto restart; |
| 952 | } |
Trond Myklebust | b04b22f | 2015-02-26 13:59:38 -0500 | [diff] [blame] | 953 | delegation = nfs_start_delegation_return_locked(NFS_I(inode)); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 954 | rcu_read_unlock(); |
Trond Myklebust | b04b22f | 2015-02-26 13:59:38 -0500 | [diff] [blame] | 955 | if (delegation != NULL) { |
| 956 | delegation = nfs_detach_delegation(NFS_I(inode), |
| 957 | delegation, server); |
| 958 | if (delegation != NULL) |
| 959 | nfs_free_delegation(delegation); |
| 960 | } |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 961 | iput(inode); |
Trond Myklebust | 9f0f8e1 | 2015-02-26 09:57:34 -0500 | [diff] [blame] | 962 | nfs_sb_deactive(server->super); |
NeilBrown | 3ca951b | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 963 | cond_resched(); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 964 | goto restart; |
| 965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | } |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 967 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 969 | |
Trond Myklebust | bb3d1a3 | 2016-09-22 13:39:00 -0400 | [diff] [blame] | 970 | static inline bool nfs4_server_rebooted(const struct nfs_client *clp) |
| 971 | { |
| 972 | return (clp->cl_state & (BIT(NFS4CLNT_CHECK_LEASE) | |
| 973 | BIT(NFS4CLNT_LEASE_EXPIRED) | |
| 974 | BIT(NFS4CLNT_SESSION_RESET))) != 0; |
| 975 | } |
| 976 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 977 | static void nfs_mark_test_expired_delegation(struct nfs_server *server, |
| 978 | struct nfs_delegation *delegation) |
| 979 | { |
Trond Myklebust | 059b43e | 2016-09-22 13:39:06 -0400 | [diff] [blame] | 980 | if (delegation->stateid.type == NFS4_INVALID_STATEID_TYPE) |
| 981 | return; |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 982 | clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); |
| 983 | set_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags); |
| 984 | set_bit(NFS4CLNT_DELEGATION_EXPIRED, &server->nfs_client->cl_state); |
| 985 | } |
| 986 | |
Trond Myklebust | bb3d1a3 | 2016-09-22 13:39:00 -0400 | [diff] [blame] | 987 | static void nfs_inode_mark_test_expired_delegation(struct nfs_server *server, |
| 988 | struct inode *inode) |
| 989 | { |
| 990 | struct nfs_delegation *delegation; |
| 991 | |
| 992 | rcu_read_lock(); |
| 993 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 994 | if (delegation) |
| 995 | nfs_mark_test_expired_delegation(server, delegation); |
| 996 | rcu_read_unlock(); |
| 997 | |
| 998 | } |
| 999 | |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 1000 | static void nfs_delegation_mark_test_expired_server(struct nfs_server *server) |
| 1001 | { |
| 1002 | struct nfs_delegation *delegation; |
| 1003 | |
| 1004 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) |
| 1005 | nfs_mark_test_expired_delegation(server, delegation); |
| 1006 | } |
| 1007 | |
| 1008 | /** |
| 1009 | * nfs_mark_test_expired_all_delegations - mark all delegations for testing |
| 1010 | * @clp: nfs_client to process |
| 1011 | * |
| 1012 | * Iterates through all the delegations associated with this server and |
| 1013 | * marks them as needing to be checked for validity. |
| 1014 | */ |
| 1015 | void nfs_mark_test_expired_all_delegations(struct nfs_client *clp) |
| 1016 | { |
| 1017 | struct nfs_server *server; |
| 1018 | |
| 1019 | rcu_read_lock(); |
| 1020 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) |
| 1021 | nfs_delegation_mark_test_expired_server(server); |
| 1022 | rcu_read_unlock(); |
| 1023 | } |
| 1024 | |
| 1025 | /** |
| 1026 | * nfs_reap_expired_delegations - reap expired delegations |
| 1027 | * @clp: nfs_client to process |
| 1028 | * |
| 1029 | * Iterates through all the delegations associated with this server and |
| 1030 | * checks if they have may have been revoked. This function is usually |
| 1031 | * expected to be called in cases where the server may have lost its |
| 1032 | * lease. |
| 1033 | */ |
| 1034 | void nfs_reap_expired_delegations(struct nfs_client *clp) |
| 1035 | { |
| 1036 | const struct nfs4_minor_version_ops *ops = clp->cl_mvops; |
| 1037 | struct nfs_delegation *delegation; |
| 1038 | struct nfs_server *server; |
| 1039 | struct inode *inode; |
| 1040 | struct rpc_cred *cred; |
| 1041 | nfs4_stateid stateid; |
| 1042 | |
| 1043 | restart: |
| 1044 | rcu_read_lock(); |
| 1045 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
| 1046 | list_for_each_entry_rcu(delegation, &server->delegations, |
| 1047 | super_list) { |
| 1048 | if (test_bit(NFS_DELEGATION_RETURNING, |
| 1049 | &delegation->flags)) |
| 1050 | continue; |
| 1051 | if (test_bit(NFS_DELEGATION_TEST_EXPIRED, |
| 1052 | &delegation->flags) == 0) |
| 1053 | continue; |
| 1054 | if (!nfs_sb_active(server->super)) |
NeilBrown | f3893491 | 2018-05-31 15:23:22 +1000 | [diff] [blame] | 1055 | break; /* continue in outer loop */ |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 1056 | inode = nfs_delegation_grab_inode(delegation); |
| 1057 | if (inode == NULL) { |
| 1058 | rcu_read_unlock(); |
| 1059 | nfs_sb_deactive(server->super); |
| 1060 | goto restart; |
| 1061 | } |
| 1062 | cred = get_rpccred_rcu(delegation->cred); |
| 1063 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 1064 | clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags); |
| 1065 | rcu_read_unlock(); |
| 1066 | if (cred != NULL && |
| 1067 | ops->test_and_free_expired(server, &stateid, cred) < 0) { |
| 1068 | nfs_revoke_delegation(inode, &stateid); |
| 1069 | nfs_inode_find_state_and_recover(inode, &stateid); |
| 1070 | } |
| 1071 | put_rpccred(cred); |
Trond Myklebust | bb3d1a3 | 2016-09-22 13:39:00 -0400 | [diff] [blame] | 1072 | if (nfs4_server_rebooted(clp)) { |
| 1073 | nfs_inode_mark_test_expired_delegation(server,inode); |
| 1074 | iput(inode); |
| 1075 | nfs_sb_deactive(server->super); |
| 1076 | return; |
| 1077 | } |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 1078 | iput(inode); |
| 1079 | nfs_sb_deactive(server->super); |
NeilBrown | 3ca951b | 2018-04-30 14:31:30 +1000 | [diff] [blame] | 1080 | cond_resched(); |
Trond Myklebust | 45870d6 | 2016-09-22 13:38:59 -0400 | [diff] [blame] | 1081 | goto restart; |
| 1082 | } |
| 1083 | } |
| 1084 | rcu_read_unlock(); |
| 1085 | } |
| 1086 | |
Trond Myklebust | 6c2d8f8 | 2016-09-22 13:39:07 -0400 | [diff] [blame] | 1087 | void nfs_inode_find_delegation_state_and_recover(struct inode *inode, |
| 1088 | const nfs4_stateid *stateid) |
| 1089 | { |
| 1090 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
| 1091 | struct nfs_delegation *delegation; |
| 1092 | bool found = false; |
| 1093 | |
| 1094 | rcu_read_lock(); |
| 1095 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1096 | if (delegation && |
| 1097 | nfs4_stateid_match_other(&delegation->stateid, stateid)) { |
| 1098 | nfs_mark_test_expired_delegation(NFS_SERVER(inode), delegation); |
| 1099 | found = true; |
| 1100 | } |
| 1101 | rcu_read_unlock(); |
| 1102 | if (found) |
| 1103 | nfs4_schedule_state_manager(clp); |
| 1104 | } |
| 1105 | |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1106 | /** |
| 1107 | * nfs_delegations_present - check for existence of delegations |
| 1108 | * @clp: client state handle |
| 1109 | * |
| 1110 | * Returns one if there are any nfs_delegation structures attached |
| 1111 | * to this nfs_client. |
| 1112 | */ |
| 1113 | int nfs_delegations_present(struct nfs_client *clp) |
| 1114 | { |
| 1115 | struct nfs_server *server; |
| 1116 | int ret = 0; |
| 1117 | |
| 1118 | rcu_read_lock(); |
| 1119 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) |
| 1120 | if (!list_empty(&server->delegations)) { |
| 1121 | ret = 1; |
| 1122 | break; |
| 1123 | } |
| 1124 | rcu_read_unlock(); |
| 1125 | return ret; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
Trond Myklebust | 12f275c | 2017-11-06 15:28:05 -0500 | [diff] [blame] | 1129 | * nfs4_refresh_delegation_stateid - Update delegation stateid seqid |
| 1130 | * @dst: stateid to refresh |
| 1131 | * @inode: inode to check |
| 1132 | * |
| 1133 | * Returns "true" and updates "dst->seqid" * if inode had a delegation |
| 1134 | * that matches our delegation stateid. Otherwise "false" is returned. |
| 1135 | */ |
| 1136 | bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode) |
| 1137 | { |
| 1138 | struct nfs_delegation *delegation; |
| 1139 | bool ret = false; |
| 1140 | if (!inode) |
| 1141 | goto out; |
| 1142 | |
| 1143 | rcu_read_lock(); |
| 1144 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1145 | if (delegation != NULL && |
| 1146 | nfs4_stateid_match_other(dst, &delegation->stateid)) { |
| 1147 | dst->seqid = delegation->stateid.seqid; |
| 1148 | return ret; |
| 1149 | } |
| 1150 | rcu_read_unlock(); |
| 1151 | out: |
| 1152 | return ret; |
| 1153 | } |
| 1154 | |
| 1155 | /** |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1156 | * nfs4_copy_delegation_stateid - Copy inode's state ID information |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1157 | * @inode: inode to check |
Trond Myklebust | 0032a7a | 2012-03-08 17:16:12 -0500 | [diff] [blame] | 1158 | * @flags: delegation type requirement |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 1159 | * @dst: stateid data structure to fill in |
| 1160 | * @cred: optional argument to retrieve credential |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1161 | * |
Trond Myklebust | 0032a7a | 2012-03-08 17:16:12 -0500 | [diff] [blame] | 1162 | * Returns "true" and fills in "dst->data" * if inode had a delegation, |
| 1163 | * otherwise "false" is returned. |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1164 | */ |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 1165 | bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, |
| 1166 | nfs4_stateid *dst, struct rpc_cred **cred) |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1167 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1168 | struct nfs_inode *nfsi = NFS_I(inode); |
| 1169 | struct nfs_delegation *delegation; |
Trond Myklebust | 0032a7a | 2012-03-08 17:16:12 -0500 | [diff] [blame] | 1170 | bool ret; |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1171 | |
Trond Myklebust | 0032a7a | 2012-03-08 17:16:12 -0500 | [diff] [blame] | 1172 | flags &= FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 1173 | rcu_read_lock(); |
| 1174 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | aa05c87 | 2016-09-22 13:38:54 -0400 | [diff] [blame] | 1175 | ret = nfs4_is_valid_delegation(delegation, flags); |
Trond Myklebust | 0032a7a | 2012-03-08 17:16:12 -0500 | [diff] [blame] | 1176 | if (ret) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1177 | nfs4_stateid_copy(dst, &delegation->stateid); |
Trond Myklebust | 0032a7a | 2012-03-08 17:16:12 -0500 | [diff] [blame] | 1178 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | abf4e13 | 2016-05-16 17:42:44 -0400 | [diff] [blame] | 1179 | if (cred) |
| 1180 | *cred = get_rpccred(delegation->cred); |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1181 | } |
Trond Myklebust | 8383e46 | 2007-07-06 15:12:04 -0400 | [diff] [blame] | 1182 | rcu_read_unlock(); |
| 1183 | return ret; |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1184 | } |
Trond Myklebust | 5445b1f | 2015-09-05 19:06:58 -0400 | [diff] [blame] | 1185 | |
| 1186 | /** |
| 1187 | * nfs4_delegation_flush_on_close - Check if we must flush file on close |
| 1188 | * @inode: inode to check |
| 1189 | * |
| 1190 | * This function checks the number of outstanding writes to the file |
| 1191 | * against the delegation 'space_limit' field to see if |
| 1192 | * the spec requires us to flush the file on close. |
| 1193 | */ |
| 1194 | bool nfs4_delegation_flush_on_close(const struct inode *inode) |
| 1195 | { |
| 1196 | struct nfs_inode *nfsi = NFS_I(inode); |
| 1197 | struct nfs_delegation *delegation; |
| 1198 | bool ret = true; |
| 1199 | |
| 1200 | rcu_read_lock(); |
| 1201 | delegation = rcu_dereference(nfsi->delegation); |
| 1202 | if (delegation == NULL || !(delegation->type & FMODE_WRITE)) |
| 1203 | goto out; |
Trond Myklebust | a6b6d5b | 2017-08-01 15:39:46 -0400 | [diff] [blame] | 1204 | if (atomic_long_read(&nfsi->nrequests) < delegation->pagemod_limit) |
Trond Myklebust | 5445b1f | 2015-09-05 19:06:58 -0400 | [diff] [blame] | 1205 | ret = false; |
| 1206 | out: |
| 1207 | rcu_read_unlock(); |
| 1208 | return ret; |
| 1209 | } |