blob: 7a1b6e869f9cbb179ed014eb45fa0b4288e7b442 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfs/delegation.c
3 *
4 * Copyright (C) 2004 Trond Myklebust
5 *
6 * NFS file delegation management
7 *
8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/completion.h>
Trond Myklebust58d97142006-01-03 09:55:24 +010010#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
12#include <linux/sched.h>
13#include <linux/spinlock.h>
14
15#include <linux/nfs4.h>
16#include <linux/nfs_fs.h>
17#include <linux/nfs_xdr.h>
18
Trond Myklebust4ce79712005-06-22 17:16:21 +000019#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "delegation.h"
David Howells24c8dbb2006-08-22 20:06:10 -040021#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Trond Myklebust905f8d12007-08-06 12:18:34 -040023static void nfs_do_free_delegation(struct nfs_delegation *delegation)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 kfree(delegation);
26}
27
Trond Myklebust8383e462007-07-06 15:12:04 -040028static void nfs_free_delegation_callback(struct rcu_head *head)
29{
30 struct nfs_delegation *delegation = container_of(head, struct nfs_delegation, rcu);
31
Trond Myklebust905f8d12007-08-06 12:18:34 -040032 nfs_do_free_delegation(delegation);
33}
34
35static void nfs_free_delegation(struct nfs_delegation *delegation)
36{
37 struct rpc_cred *cred;
38
39 cred = rcu_dereference(delegation->cred);
40 rcu_assign_pointer(delegation->cred, NULL);
41 call_rcu(&delegation->rcu, nfs_free_delegation_callback);
42 if (cred)
43 put_rpccred(cred);
Trond Myklebust8383e462007-07-06 15:12:04 -040044}
45
Trond Myklebust888e6942005-11-04 15:38:11 -050046static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_state *state)
47{
48 struct inode *inode = state->inode;
49 struct file_lock *fl;
50 int status;
51
52 for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) {
53 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
54 continue;
Trond Myklebustcd3758e2007-08-10 17:44:32 -040055 if (nfs_file_open_context(fl->fl_file) != ctx)
Trond Myklebust888e6942005-11-04 15:38:11 -050056 continue;
57 status = nfs4_lock_delegation_recall(state, fl);
58 if (status >= 0)
59 continue;
60 switch (status) {
61 default:
62 printk(KERN_ERR "%s: unhandled error %d.\n",
63 __FUNCTION__, status);
64 case -NFS4ERR_EXPIRED:
65 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
66 case -NFS4ERR_STALE_CLIENTID:
David Howells7539bba2006-08-22 20:06:09 -040067 nfs4_schedule_state_recovery(NFS_SERVER(inode)->nfs_client);
Trond Myklebust888e6942005-11-04 15:38:11 -050068 goto out_err;
69 }
70 }
71 return 0;
72out_err:
73 return status;
74}
75
Trond Myklebust90163022007-07-05 14:55:18 -040076static void nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *stateid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 struct nfs_inode *nfsi = NFS_I(inode);
79 struct nfs_open_context *ctx;
80 struct nfs4_state *state;
Trond Myklebust888e6942005-11-04 15:38:11 -050081 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83again:
84 spin_lock(&inode->i_lock);
85 list_for_each_entry(ctx, &nfsi->open_files, list) {
86 state = ctx->state;
87 if (state == NULL)
88 continue;
89 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
90 continue;
Trond Myklebust90163022007-07-05 14:55:18 -040091 if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0)
92 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 get_nfs_open_context(ctx);
94 spin_unlock(&inode->i_lock);
Trond Myklebust13437e12007-07-06 15:10:43 -040095 err = nfs4_open_delegation_recall(ctx, state, stateid);
Trond Myklebust888e6942005-11-04 15:38:11 -050096 if (err >= 0)
97 err = nfs_delegation_claim_locks(ctx, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 put_nfs_open_context(ctx);
Trond Myklebust888e6942005-11-04 15:38:11 -050099 if (err != 0)
100 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 goto again;
102 }
103 spin_unlock(&inode->i_lock);
104}
105
106/*
107 * Set up a delegation on an inode
108 */
109void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
110{
111 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
112
113 if (delegation == NULL)
114 return;
115 memcpy(delegation->stateid.data, res->delegation.data,
116 sizeof(delegation->stateid.data));
117 delegation->type = res->delegation_type;
118 delegation->maxsize = res->maxsize;
119 put_rpccred(cred);
120 delegation->cred = get_rpccred(cred);
121 delegation->flags &= ~NFS_DELEGATION_NEED_RECLAIM;
122 NFS_I(inode)->delegation_state = delegation->type;
123 smp_wmb();
124}
125
126/*
127 * Set up a delegation on an inode
128 */
129int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
130{
David Howells7539bba2006-08-22 20:06:09 -0400131 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 struct nfs_inode *nfsi = NFS_I(inode);
133 struct nfs_delegation *delegation;
134 int status = 0;
135
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700136 delegation = kmalloc(sizeof(*delegation), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 if (delegation == NULL)
138 return -ENOMEM;
139 memcpy(delegation->stateid.data, res->delegation.data,
140 sizeof(delegation->stateid.data));
141 delegation->type = res->delegation_type;
142 delegation->maxsize = res->maxsize;
Trond Myklebustbeb2a5e2006-01-03 09:55:37 +0100143 delegation->change_attr = nfsi->change_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 delegation->cred = get_rpccred(cred);
145 delegation->inode = inode;
146
147 spin_lock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400148 if (rcu_dereference(nfsi->delegation) == NULL) {
149 list_add_rcu(&delegation->super_list, &clp->cl_delegations);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 nfsi->delegation_state = delegation->type;
Trond Myklebust8383e462007-07-06 15:12:04 -0400151 rcu_assign_pointer(nfsi->delegation, delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 delegation = NULL;
153 } else {
154 if (memcmp(&delegation->stateid, &nfsi->delegation->stateid,
155 sizeof(delegation->stateid)) != 0 ||
156 delegation->type != nfsi->delegation->type) {
157 printk("%s: server %u.%u.%u.%u, handed out a duplicate delegation!\n",
David Howells24c8dbb2006-08-22 20:06:10 -0400158 __FUNCTION__, NIPQUAD(clp->cl_addr.sin_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 status = -EIO;
160 }
161 }
Trond Myklebust412c77c2007-07-03 16:10:55 -0400162
163 /* Ensure we revalidate the attributes and page cache! */
164 spin_lock(&inode->i_lock);
165 nfsi->cache_validity |= NFS_INO_REVAL_FORCED;
166 spin_unlock(&inode->i_lock);
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 spin_unlock(&clp->cl_lock);
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800169 kfree(delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return status;
171}
172
173static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation)
174{
175 int res = 0;
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 res = nfs4_proc_delegreturn(inode, delegation->cred, &delegation->stateid);
Trond Myklebust905f8d12007-08-06 12:18:34 -0400178 nfs_free_delegation(delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return res;
180}
181
182/* Sync all data to disk upon delegation return */
183static void nfs_msync_inode(struct inode *inode)
184{
185 filemap_fdatawrite(inode->i_mapping);
186 nfs_wb_all(inode);
187 filemap_fdatawait(inode->i_mapping);
188}
189
190/*
191 * Basic procedure for returning a delegation to the server
192 */
Trond Myklebust90163022007-07-05 14:55:18 -0400193static int __nfs_inode_return_delegation(struct inode *inode, struct nfs_delegation *delegation)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
David Howells7539bba2006-08-22 20:06:09 -0400195 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 struct nfs_inode *nfsi = NFS_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 nfs_msync_inode(inode);
199 down_read(&clp->cl_sem);
200 /* Guard against new delegated open calls */
201 down_write(&nfsi->rwsem);
Trond Myklebust90163022007-07-05 14:55:18 -0400202 nfs_delegation_claim_opens(inode, &delegation->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 up_write(&nfsi->rwsem);
204 up_read(&clp->cl_sem);
205 nfs_msync_inode(inode);
206
Trond Myklebust90163022007-07-05 14:55:18 -0400207 return nfs_do_return_delegation(inode, delegation);
208}
209
210static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi, const nfs4_stateid *stateid)
211{
Trond Myklebust8383e462007-07-06 15:12:04 -0400212 struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation);
Trond Myklebust90163022007-07-05 14:55:18 -0400213
214 if (delegation == NULL)
215 goto nomatch;
216 if (stateid != NULL && memcmp(delegation->stateid.data, stateid->data,
217 sizeof(delegation->stateid.data)) != 0)
218 goto nomatch;
Trond Myklebust8383e462007-07-06 15:12:04 -0400219 list_del_rcu(&delegation->super_list);
Trond Myklebust90163022007-07-05 14:55:18 -0400220 nfsi->delegation_state = 0;
Trond Myklebust8383e462007-07-06 15:12:04 -0400221 rcu_assign_pointer(nfsi->delegation, NULL);
Trond Myklebust90163022007-07-05 14:55:18 -0400222 return delegation;
223nomatch:
224 return NULL;
225}
226
227int nfs_inode_return_delegation(struct inode *inode)
228{
229 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
230 struct nfs_inode *nfsi = NFS_I(inode);
231 struct nfs_delegation *delegation;
232 int err = 0;
233
Trond Myklebust8383e462007-07-06 15:12:04 -0400234 if (rcu_dereference(nfsi->delegation) != NULL) {
Trond Myklebust90163022007-07-05 14:55:18 -0400235 spin_lock(&clp->cl_lock);
236 delegation = nfs_detach_delegation_locked(nfsi, NULL);
237 spin_unlock(&clp->cl_lock);
238 if (delegation != NULL)
239 err = __nfs_inode_return_delegation(inode, delegation);
240 }
241 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
244/*
245 * Return all delegations associated to a super block
246 */
247void nfs_return_all_delegations(struct super_block *sb)
248{
David Howells7539bba2006-08-22 20:06:09 -0400249 struct nfs_client *clp = NFS_SB(sb)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 struct nfs_delegation *delegation;
251 struct inode *inode;
252
253 if (clp == NULL)
254 return;
255restart:
Trond Myklebust8383e462007-07-06 15:12:04 -0400256 rcu_read_lock();
257 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (delegation->inode->i_sb != sb)
259 continue;
260 inode = igrab(delegation->inode);
261 if (inode == NULL)
262 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400263 spin_lock(&clp->cl_lock);
264 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 spin_unlock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400266 rcu_read_unlock();
267 if (delegation != NULL)
268 __nfs_inode_return_delegation(inode, delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 iput(inode);
270 goto restart;
271 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400272 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
Trond Myklebust10afec902007-05-14 17:16:04 -0400275static int nfs_do_expire_all_delegations(void *ptr)
Trond Myklebust58d97142006-01-03 09:55:24 +0100276{
David Howellsadfa6f92006-08-22 20:06:08 -0400277 struct nfs_client *clp = ptr;
Trond Myklebust58d97142006-01-03 09:55:24 +0100278 struct nfs_delegation *delegation;
279 struct inode *inode;
Trond Myklebust58d97142006-01-03 09:55:24 +0100280
281 allow_signal(SIGKILL);
282restart:
Trond Myklebust58d97142006-01-03 09:55:24 +0100283 if (test_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) != 0)
284 goto out;
285 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0)
286 goto out;
Trond Myklebust8383e462007-07-06 15:12:04 -0400287 rcu_read_lock();
288 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Trond Myklebust58d97142006-01-03 09:55:24 +0100289 inode = igrab(delegation->inode);
290 if (inode == NULL)
291 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400292 spin_lock(&clp->cl_lock);
293 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL);
Trond Myklebust58d97142006-01-03 09:55:24 +0100294 spin_unlock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400295 rcu_read_unlock();
296 if (delegation)
297 __nfs_inode_return_delegation(inode, delegation);
Trond Myklebust58d97142006-01-03 09:55:24 +0100298 iput(inode);
Trond Myklebust26c78e12006-01-03 09:55:58 +0100299 goto restart;
Trond Myklebust58d97142006-01-03 09:55:24 +0100300 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400301 rcu_read_unlock();
Trond Myklebust58d97142006-01-03 09:55:24 +0100302out:
David Howells24c8dbb2006-08-22 20:06:10 -0400303 nfs_put_client(clp);
Trond Myklebust58d97142006-01-03 09:55:24 +0100304 module_put_and_exit(0);
305}
306
David Howellsadfa6f92006-08-22 20:06:08 -0400307void nfs_expire_all_delegations(struct nfs_client *clp)
Trond Myklebust58d97142006-01-03 09:55:24 +0100308{
309 struct task_struct *task;
310
311 __module_get(THIS_MODULE);
312 atomic_inc(&clp->cl_count);
313 task = kthread_run(nfs_do_expire_all_delegations, clp,
314 "%u.%u.%u.%u-delegreturn",
David Howells24c8dbb2006-08-22 20:06:10 -0400315 NIPQUAD(clp->cl_addr.sin_addr));
Trond Myklebust58d97142006-01-03 09:55:24 +0100316 if (!IS_ERR(task))
317 return;
David Howells24c8dbb2006-08-22 20:06:10 -0400318 nfs_put_client(clp);
Trond Myklebust58d97142006-01-03 09:55:24 +0100319 module_put(THIS_MODULE);
320}
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/*
323 * Return all delegations following an NFS4ERR_CB_PATH_DOWN error.
324 */
David Howellsadfa6f92006-08-22 20:06:08 -0400325void nfs_handle_cb_pathdown(struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 struct nfs_delegation *delegation;
328 struct inode *inode;
329
330 if (clp == NULL)
331 return;
332restart:
Trond Myklebust8383e462007-07-06 15:12:04 -0400333 rcu_read_lock();
334 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 inode = igrab(delegation->inode);
336 if (inode == NULL)
337 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400338 spin_lock(&clp->cl_lock);
339 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 spin_unlock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400341 rcu_read_unlock();
342 if (delegation != NULL)
343 __nfs_inode_return_delegation(inode, delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 iput(inode);
345 goto restart;
346 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400347 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350struct recall_threadargs {
351 struct inode *inode;
David Howellsadfa6f92006-08-22 20:06:08 -0400352 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 const nfs4_stateid *stateid;
354
355 struct completion started;
356 int result;
357};
358
359static int recall_thread(void *data)
360{
361 struct recall_threadargs *args = (struct recall_threadargs *)data;
362 struct inode *inode = igrab(args->inode);
David Howells7539bba2006-08-22 20:06:09 -0400363 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 struct nfs_inode *nfsi = NFS_I(inode);
365 struct nfs_delegation *delegation;
366
367 daemonize("nfsv4-delegreturn");
368
369 nfs_msync_inode(inode);
370 down_read(&clp->cl_sem);
371 down_write(&nfsi->rwsem);
372 spin_lock(&clp->cl_lock);
Trond Myklebust90163022007-07-05 14:55:18 -0400373 delegation = nfs_detach_delegation_locked(nfsi, args->stateid);
374 if (delegation != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 args->result = 0;
Trond Myklebust90163022007-07-05 14:55:18 -0400376 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 args->result = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 spin_unlock(&clp->cl_lock);
379 complete(&args->started);
Trond Myklebust90163022007-07-05 14:55:18 -0400380 nfs_delegation_claim_opens(inode, args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 up_write(&nfsi->rwsem);
382 up_read(&clp->cl_sem);
383 nfs_msync_inode(inode);
384
385 if (delegation != NULL)
386 nfs_do_return_delegation(inode, delegation);
387 iput(inode);
388 module_put_and_exit(0);
389}
390
391/*
392 * Asynchronous delegation recall!
393 */
394int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid)
395{
396 struct recall_threadargs data = {
397 .inode = inode,
398 .stateid = stateid,
399 };
400 int status;
401
402 init_completion(&data.started);
403 __module_get(THIS_MODULE);
404 status = kernel_thread(recall_thread, &data, CLONE_KERNEL);
405 if (status < 0)
406 goto out_module_put;
407 wait_for_completion(&data.started);
408 return data.result;
409out_module_put:
410 module_put(THIS_MODULE);
411 return status;
412}
413
414/*
415 * Retrieve the inode associated with a delegation
416 */
David Howellsadfa6f92006-08-22 20:06:08 -0400417struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
419 struct nfs_delegation *delegation;
420 struct inode *res = NULL;
Trond Myklebust8383e462007-07-06 15:12:04 -0400421 rcu_read_lock();
422 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 if (nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
424 res = igrab(delegation->inode);
425 break;
426 }
427 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400428 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return res;
430}
431
432/*
433 * Mark all delegations as needing to be reclaimed
434 */
David Howellsadfa6f92006-08-22 20:06:08 -0400435void nfs_delegation_mark_reclaim(struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
437 struct nfs_delegation *delegation;
Trond Myklebust8383e462007-07-06 15:12:04 -0400438 rcu_read_lock();
439 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 delegation->flags |= NFS_DELEGATION_NEED_RECLAIM;
Trond Myklebust8383e462007-07-06 15:12:04 -0400441 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
443
444/*
445 * Reap all unclaimed delegations after reboot recovery is done
446 */
David Howellsadfa6f92006-08-22 20:06:08 -0400447void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Trond Myklebust8383e462007-07-06 15:12:04 -0400449 struct nfs_delegation *delegation;
450restart:
451 rcu_read_lock();
452 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if ((delegation->flags & NFS_DELEGATION_NEED_RECLAIM) == 0)
454 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400455 spin_lock(&clp->cl_lock);
456 delegation = nfs_detach_delegation_locked(NFS_I(delegation->inode), NULL);
457 spin_unlock(&clp->cl_lock);
458 rcu_read_unlock();
459 if (delegation != NULL)
Trond Myklebust905f8d12007-08-06 12:18:34 -0400460 nfs_free_delegation(delegation);
Trond Myklebust8383e462007-07-06 15:12:04 -0400461 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400463 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500465
466int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
467{
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500468 struct nfs_inode *nfsi = NFS_I(inode);
469 struct nfs_delegation *delegation;
Trond Myklebust8383e462007-07-06 15:12:04 -0400470 int ret = 0;
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500471
Trond Myklebust8383e462007-07-06 15:12:04 -0400472 rcu_read_lock();
473 delegation = rcu_dereference(nfsi->delegation);
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500474 if (delegation != NULL) {
475 memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
Trond Myklebust8383e462007-07-06 15:12:04 -0400476 ret = 1;
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500477 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400478 rcu_read_unlock();
479 return ret;
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500480}