blob: 56f4f6a99d4ef365b79b5a2a7e1450f1ce039d9c [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static void nfs_free_delegation(struct nfs_delegation *delegation)
24{
25 if (delegation->cred)
26 put_rpccred(delegation->cred);
27 kfree(delegation);
28}
29
Trond Myklebust8383e462007-07-06 15:12:04 -040030static void nfs_free_delegation_callback(struct rcu_head *head)
31{
32 struct nfs_delegation *delegation = container_of(head, struct nfs_delegation, rcu);
33
34 nfs_free_delegation(delegation);
35}
36
Trond Myklebust888e6942005-11-04 15:38:11 -050037static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_state *state)
38{
39 struct inode *inode = state->inode;
40 struct file_lock *fl;
41 int status;
42
43 for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) {
44 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
45 continue;
46 if ((struct nfs_open_context *)fl->fl_file->private_data != ctx)
47 continue;
48 status = nfs4_lock_delegation_recall(state, fl);
49 if (status >= 0)
50 continue;
51 switch (status) {
52 default:
53 printk(KERN_ERR "%s: unhandled error %d.\n",
54 __FUNCTION__, status);
55 case -NFS4ERR_EXPIRED:
56 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
57 case -NFS4ERR_STALE_CLIENTID:
David Howells7539bba2006-08-22 20:06:09 -040058 nfs4_schedule_state_recovery(NFS_SERVER(inode)->nfs_client);
Trond Myklebust888e6942005-11-04 15:38:11 -050059 goto out_err;
60 }
61 }
62 return 0;
63out_err:
64 return status;
65}
66
Trond Myklebust90163022007-07-05 14:55:18 -040067static void nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *stateid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 struct nfs_inode *nfsi = NFS_I(inode);
70 struct nfs_open_context *ctx;
71 struct nfs4_state *state;
Trond Myklebust888e6942005-11-04 15:38:11 -050072 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74again:
75 spin_lock(&inode->i_lock);
76 list_for_each_entry(ctx, &nfsi->open_files, list) {
77 state = ctx->state;
78 if (state == NULL)
79 continue;
80 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
81 continue;
Trond Myklebust90163022007-07-05 14:55:18 -040082 if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0)
83 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 get_nfs_open_context(ctx);
85 spin_unlock(&inode->i_lock);
Trond Myklebust13437e12007-07-06 15:10:43 -040086 err = nfs4_open_delegation_recall(ctx, state, stateid);
Trond Myklebust888e6942005-11-04 15:38:11 -050087 if (err >= 0)
88 err = nfs_delegation_claim_locks(ctx, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 put_nfs_open_context(ctx);
Trond Myklebust888e6942005-11-04 15:38:11 -050090 if (err != 0)
91 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 goto again;
93 }
94 spin_unlock(&inode->i_lock);
95}
96
97/*
98 * Set up a delegation on an inode
99 */
100void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
101{
102 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
103
104 if (delegation == NULL)
105 return;
106 memcpy(delegation->stateid.data, res->delegation.data,
107 sizeof(delegation->stateid.data));
108 delegation->type = res->delegation_type;
109 delegation->maxsize = res->maxsize;
110 put_rpccred(cred);
111 delegation->cred = get_rpccred(cred);
112 delegation->flags &= ~NFS_DELEGATION_NEED_RECLAIM;
113 NFS_I(inode)->delegation_state = delegation->type;
114 smp_wmb();
115}
116
117/*
118 * Set up a delegation on an inode
119 */
120int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
121{
David Howells7539bba2006-08-22 20:06:09 -0400122 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 struct nfs_inode *nfsi = NFS_I(inode);
124 struct nfs_delegation *delegation;
125 int status = 0;
126
Trond Myklebustb3c52da2005-10-17 06:02:00 -0400127 /* Ensure we first revalidate the attributes and page cache! */
128 if ((nfsi->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATTR)))
129 __nfs_revalidate_inode(NFS_SERVER(inode), inode);
130
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700131 delegation = kmalloc(sizeof(*delegation), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if (delegation == NULL)
133 return -ENOMEM;
134 memcpy(delegation->stateid.data, res->delegation.data,
135 sizeof(delegation->stateid.data));
136 delegation->type = res->delegation_type;
137 delegation->maxsize = res->maxsize;
Trond Myklebustbeb2a5e2006-01-03 09:55:37 +0100138 delegation->change_attr = nfsi->change_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 delegation->cred = get_rpccred(cred);
140 delegation->inode = inode;
141
142 spin_lock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400143 if (rcu_dereference(nfsi->delegation) == NULL) {
144 list_add_rcu(&delegation->super_list, &clp->cl_delegations);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 nfsi->delegation_state = delegation->type;
Trond Myklebust8383e462007-07-06 15:12:04 -0400146 rcu_assign_pointer(nfsi->delegation, delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 delegation = NULL;
148 } else {
149 if (memcmp(&delegation->stateid, &nfsi->delegation->stateid,
150 sizeof(delegation->stateid)) != 0 ||
151 delegation->type != nfsi->delegation->type) {
152 printk("%s: server %u.%u.%u.%u, handed out a duplicate delegation!\n",
David Howells24c8dbb2006-08-22 20:06:10 -0400153 __FUNCTION__, NIPQUAD(clp->cl_addr.sin_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 status = -EIO;
155 }
156 }
157 spin_unlock(&clp->cl_lock);
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800158 kfree(delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return status;
160}
161
162static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation)
163{
164 int res = 0;
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 res = nfs4_proc_delegreturn(inode, delegation->cred, &delegation->stateid);
Trond Myklebust8383e462007-07-06 15:12:04 -0400167 call_rcu(&delegation->rcu, nfs_free_delegation_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return res;
169}
170
171/* Sync all data to disk upon delegation return */
172static void nfs_msync_inode(struct inode *inode)
173{
174 filemap_fdatawrite(inode->i_mapping);
175 nfs_wb_all(inode);
176 filemap_fdatawait(inode->i_mapping);
177}
178
179/*
180 * Basic procedure for returning a delegation to the server
181 */
Trond Myklebust90163022007-07-05 14:55:18 -0400182static int __nfs_inode_return_delegation(struct inode *inode, struct nfs_delegation *delegation)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
David Howells7539bba2006-08-22 20:06:09 -0400184 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 struct nfs_inode *nfsi = NFS_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 nfs_msync_inode(inode);
188 down_read(&clp->cl_sem);
189 /* Guard against new delegated open calls */
190 down_write(&nfsi->rwsem);
Trond Myklebust90163022007-07-05 14:55:18 -0400191 nfs_delegation_claim_opens(inode, &delegation->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 up_write(&nfsi->rwsem);
193 up_read(&clp->cl_sem);
194 nfs_msync_inode(inode);
195
Trond Myklebust90163022007-07-05 14:55:18 -0400196 return nfs_do_return_delegation(inode, delegation);
197}
198
199static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi, const nfs4_stateid *stateid)
200{
Trond Myklebust8383e462007-07-06 15:12:04 -0400201 struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation);
Trond Myklebust90163022007-07-05 14:55:18 -0400202
203 if (delegation == NULL)
204 goto nomatch;
205 if (stateid != NULL && memcmp(delegation->stateid.data, stateid->data,
206 sizeof(delegation->stateid.data)) != 0)
207 goto nomatch;
Trond Myklebust8383e462007-07-06 15:12:04 -0400208 list_del_rcu(&delegation->super_list);
Trond Myklebust90163022007-07-05 14:55:18 -0400209 nfsi->delegation_state = 0;
Trond Myklebust8383e462007-07-06 15:12:04 -0400210 rcu_assign_pointer(nfsi->delegation, NULL);
Trond Myklebust90163022007-07-05 14:55:18 -0400211 return delegation;
212nomatch:
213 return NULL;
214}
215
216int nfs_inode_return_delegation(struct inode *inode)
217{
218 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
219 struct nfs_inode *nfsi = NFS_I(inode);
220 struct nfs_delegation *delegation;
221 int err = 0;
222
Trond Myklebust8383e462007-07-06 15:12:04 -0400223 if (rcu_dereference(nfsi->delegation) != NULL) {
Trond Myklebust90163022007-07-05 14:55:18 -0400224 spin_lock(&clp->cl_lock);
225 delegation = nfs_detach_delegation_locked(nfsi, NULL);
226 spin_unlock(&clp->cl_lock);
227 if (delegation != NULL)
228 err = __nfs_inode_return_delegation(inode, delegation);
229 }
230 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233/*
234 * Return all delegations associated to a super block
235 */
236void nfs_return_all_delegations(struct super_block *sb)
237{
David Howells7539bba2006-08-22 20:06:09 -0400238 struct nfs_client *clp = NFS_SB(sb)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 struct nfs_delegation *delegation;
240 struct inode *inode;
241
242 if (clp == NULL)
243 return;
244restart:
Trond Myklebust8383e462007-07-06 15:12:04 -0400245 rcu_read_lock();
246 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 if (delegation->inode->i_sb != sb)
248 continue;
249 inode = igrab(delegation->inode);
250 if (inode == NULL)
251 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400252 spin_lock(&clp->cl_lock);
253 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 spin_unlock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400255 rcu_read_unlock();
256 if (delegation != NULL)
257 __nfs_inode_return_delegation(inode, delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 iput(inode);
259 goto restart;
260 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400261 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Trond Myklebust10afec92007-05-14 17:16:04 -0400264static int nfs_do_expire_all_delegations(void *ptr)
Trond Myklebust58d97142006-01-03 09:55:24 +0100265{
David Howellsadfa6f92006-08-22 20:06:08 -0400266 struct nfs_client *clp = ptr;
Trond Myklebust58d97142006-01-03 09:55:24 +0100267 struct nfs_delegation *delegation;
268 struct inode *inode;
Trond Myklebust58d97142006-01-03 09:55:24 +0100269
270 allow_signal(SIGKILL);
271restart:
Trond Myklebust58d97142006-01-03 09:55:24 +0100272 if (test_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) != 0)
273 goto out;
274 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0)
275 goto out;
Trond Myklebust8383e462007-07-06 15:12:04 -0400276 rcu_read_lock();
277 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Trond Myklebust58d97142006-01-03 09:55:24 +0100278 inode = igrab(delegation->inode);
279 if (inode == NULL)
280 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400281 spin_lock(&clp->cl_lock);
282 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL);
Trond Myklebust58d97142006-01-03 09:55:24 +0100283 spin_unlock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400284 rcu_read_unlock();
285 if (delegation)
286 __nfs_inode_return_delegation(inode, delegation);
Trond Myklebust58d97142006-01-03 09:55:24 +0100287 iput(inode);
Trond Myklebust26c78e12006-01-03 09:55:58 +0100288 goto restart;
Trond Myklebust58d97142006-01-03 09:55:24 +0100289 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400290 rcu_read_unlock();
Trond Myklebust58d97142006-01-03 09:55:24 +0100291out:
David Howells24c8dbb2006-08-22 20:06:10 -0400292 nfs_put_client(clp);
Trond Myklebust58d97142006-01-03 09:55:24 +0100293 module_put_and_exit(0);
294}
295
David Howellsadfa6f92006-08-22 20:06:08 -0400296void nfs_expire_all_delegations(struct nfs_client *clp)
Trond Myklebust58d97142006-01-03 09:55:24 +0100297{
298 struct task_struct *task;
299
300 __module_get(THIS_MODULE);
301 atomic_inc(&clp->cl_count);
302 task = kthread_run(nfs_do_expire_all_delegations, clp,
303 "%u.%u.%u.%u-delegreturn",
David Howells24c8dbb2006-08-22 20:06:10 -0400304 NIPQUAD(clp->cl_addr.sin_addr));
Trond Myklebust58d97142006-01-03 09:55:24 +0100305 if (!IS_ERR(task))
306 return;
David Howells24c8dbb2006-08-22 20:06:10 -0400307 nfs_put_client(clp);
Trond Myklebust58d97142006-01-03 09:55:24 +0100308 module_put(THIS_MODULE);
309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/*
312 * Return all delegations following an NFS4ERR_CB_PATH_DOWN error.
313 */
David Howellsadfa6f92006-08-22 20:06:08 -0400314void nfs_handle_cb_pathdown(struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 struct nfs_delegation *delegation;
317 struct inode *inode;
318
319 if (clp == NULL)
320 return;
321restart:
Trond Myklebust8383e462007-07-06 15:12:04 -0400322 rcu_read_lock();
323 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 inode = igrab(delegation->inode);
325 if (inode == NULL)
326 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400327 spin_lock(&clp->cl_lock);
328 delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 spin_unlock(&clp->cl_lock);
Trond Myklebust8383e462007-07-06 15:12:04 -0400330 rcu_read_unlock();
331 if (delegation != NULL)
332 __nfs_inode_return_delegation(inode, delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 iput(inode);
334 goto restart;
335 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400336 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
339struct recall_threadargs {
340 struct inode *inode;
David Howellsadfa6f92006-08-22 20:06:08 -0400341 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 const nfs4_stateid *stateid;
343
344 struct completion started;
345 int result;
346};
347
348static int recall_thread(void *data)
349{
350 struct recall_threadargs *args = (struct recall_threadargs *)data;
351 struct inode *inode = igrab(args->inode);
David Howells7539bba2006-08-22 20:06:09 -0400352 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 struct nfs_inode *nfsi = NFS_I(inode);
354 struct nfs_delegation *delegation;
355
356 daemonize("nfsv4-delegreturn");
357
358 nfs_msync_inode(inode);
359 down_read(&clp->cl_sem);
360 down_write(&nfsi->rwsem);
361 spin_lock(&clp->cl_lock);
Trond Myklebust90163022007-07-05 14:55:18 -0400362 delegation = nfs_detach_delegation_locked(nfsi, args->stateid);
363 if (delegation != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 args->result = 0;
Trond Myklebust90163022007-07-05 14:55:18 -0400365 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 args->result = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 spin_unlock(&clp->cl_lock);
368 complete(&args->started);
Trond Myklebust90163022007-07-05 14:55:18 -0400369 nfs_delegation_claim_opens(inode, args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 up_write(&nfsi->rwsem);
371 up_read(&clp->cl_sem);
372 nfs_msync_inode(inode);
373
374 if (delegation != NULL)
375 nfs_do_return_delegation(inode, delegation);
376 iput(inode);
377 module_put_and_exit(0);
378}
379
380/*
381 * Asynchronous delegation recall!
382 */
383int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid)
384{
385 struct recall_threadargs data = {
386 .inode = inode,
387 .stateid = stateid,
388 };
389 int status;
390
391 init_completion(&data.started);
392 __module_get(THIS_MODULE);
393 status = kernel_thread(recall_thread, &data, CLONE_KERNEL);
394 if (status < 0)
395 goto out_module_put;
396 wait_for_completion(&data.started);
397 return data.result;
398out_module_put:
399 module_put(THIS_MODULE);
400 return status;
401}
402
403/*
404 * Retrieve the inode associated with a delegation
405 */
David Howellsadfa6f92006-08-22 20:06:08 -0400406struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
408 struct nfs_delegation *delegation;
409 struct inode *res = NULL;
Trond Myklebust8383e462007-07-06 15:12:04 -0400410 rcu_read_lock();
411 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 if (nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
413 res = igrab(delegation->inode);
414 break;
415 }
416 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400417 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return res;
419}
420
421/*
422 * Mark all delegations as needing to be reclaimed
423 */
David Howellsadfa6f92006-08-22 20:06:08 -0400424void nfs_delegation_mark_reclaim(struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
426 struct nfs_delegation *delegation;
Trond Myklebust8383e462007-07-06 15:12:04 -0400427 rcu_read_lock();
428 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 delegation->flags |= NFS_DELEGATION_NEED_RECLAIM;
Trond Myklebust8383e462007-07-06 15:12:04 -0400430 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
433/*
434 * Reap all unclaimed delegations after reboot recovery is done
435 */
David Howellsadfa6f92006-08-22 20:06:08 -0400436void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Trond Myklebust8383e462007-07-06 15:12:04 -0400438 struct nfs_delegation *delegation;
439restart:
440 rcu_read_lock();
441 list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if ((delegation->flags & NFS_DELEGATION_NEED_RECLAIM) == 0)
443 continue;
Trond Myklebust8383e462007-07-06 15:12:04 -0400444 spin_lock(&clp->cl_lock);
445 delegation = nfs_detach_delegation_locked(NFS_I(delegation->inode), NULL);
446 spin_unlock(&clp->cl_lock);
447 rcu_read_unlock();
448 if (delegation != NULL)
449 call_rcu(&delegation->rcu, nfs_free_delegation_callback);
450 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400452 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500454
455int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
456{
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500457 struct nfs_inode *nfsi = NFS_I(inode);
458 struct nfs_delegation *delegation;
Trond Myklebust8383e462007-07-06 15:12:04 -0400459 int ret = 0;
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500460
Trond Myklebust8383e462007-07-06 15:12:04 -0400461 rcu_read_lock();
462 delegation = rcu_dereference(nfsi->delegation);
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500463 if (delegation != NULL) {
464 memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
Trond Myklebust8383e462007-07-06 15:12:04 -0400465 ret = 1;
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500466 }
Trond Myklebust8383e462007-07-06 15:12:04 -0400467 rcu_read_unlock();
468 return ret;
Trond Myklebust3e4f6292006-03-20 13:44:46 -0500469}