Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/nfs/delegation.c | |
3 | * | |
4 | * Copyright (C) 2004 Trond Myklebust | |
5 | * | |
6 | * NFS file delegation management | |
7 | * | |
8 | */ | |
1da177e4 | 9 | #include <linux/completion.h> |
58d9714a | 10 | #include <linux/kthread.h> |
1da177e4 LT |
11 | #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 | ||
4ce79717 | 19 | #include "nfs4_fs.h" |
1da177e4 | 20 | #include "delegation.h" |
24c8dbbb | 21 | #include "internal.h" |
1da177e4 | 22 | |
905f8d16 | 23 | static void nfs_do_free_delegation(struct nfs_delegation *delegation) |
1da177e4 | 24 | { |
1da177e4 LT |
25 | kfree(delegation); |
26 | } | |
27 | ||
8383e460 TM |
28 | static void nfs_free_delegation_callback(struct rcu_head *head) |
29 | { | |
30 | struct nfs_delegation *delegation = container_of(head, struct nfs_delegation, rcu); | |
31 | ||
905f8d16 TM |
32 | nfs_do_free_delegation(delegation); |
33 | } | |
34 | ||
35 | static 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); | |
8383e460 TM |
44 | } |
45 | ||
888e694c TM |
46 | static 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 | ||
90dc7d27 | 52 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
888e694c TM |
53 | if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) |
54 | continue; | |
cd3758e3 | 55 | if (nfs_file_open_context(fl->fl_file) != ctx) |
888e694c TM |
56 | 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", | |
3110ff80 | 63 | __func__, status); |
888e694c TM |
64 | case -NFS4ERR_EXPIRED: |
65 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ | |
66 | case -NFS4ERR_STALE_CLIENTID: | |
7539bbab | 67 | nfs4_schedule_state_recovery(NFS_SERVER(inode)->nfs_client); |
888e694c TM |
68 | goto out_err; |
69 | } | |
70 | } | |
71 | return 0; | |
72 | out_err: | |
73 | return status; | |
74 | } | |
75 | ||
90163027 | 76 | static void nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *stateid) |
1da177e4 LT |
77 | { |
78 | struct nfs_inode *nfsi = NFS_I(inode); | |
79 | struct nfs_open_context *ctx; | |
80 | struct nfs4_state *state; | |
888e694c | 81 | int err; |
1da177e4 LT |
82 | |
83 | again: | |
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; | |
90163027 TM |
91 | if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0) |
92 | continue; | |
1da177e4 LT |
93 | get_nfs_open_context(ctx); |
94 | spin_unlock(&inode->i_lock); | |
13437e12 | 95 | err = nfs4_open_delegation_recall(ctx, state, stateid); |
888e694c TM |
96 | if (err >= 0) |
97 | err = nfs_delegation_claim_locks(ctx, state); | |
1da177e4 | 98 | put_nfs_open_context(ctx); |
888e694c TM |
99 | if (err != 0) |
100 | return; | |
1da177e4 LT |
101 | goto again; |
102 | } | |
103 | spin_unlock(&inode->i_lock); | |
104 | } | |
105 | ||
106 | /* | |
107 | * Set up a delegation on an inode | |
108 | */ | |
109 | void 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; | |
05c88bab | 112 | struct rpc_cred *oldcred; |
1da177e4 LT |
113 | |
114 | if (delegation == NULL) | |
115 | return; | |
116 | memcpy(delegation->stateid.data, res->delegation.data, | |
117 | sizeof(delegation->stateid.data)); | |
118 | delegation->type = res->delegation_type; | |
119 | delegation->maxsize = res->maxsize; | |
05c88bab | 120 | oldcred = delegation->cred; |
1da177e4 | 121 | delegation->cred = get_rpccred(cred); |
15c831bf | 122 | clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); |
1da177e4 LT |
123 | NFS_I(inode)->delegation_state = delegation->type; |
124 | smp_wmb(); | |
05c88bab | 125 | put_rpccred(oldcred); |
1da177e4 LT |
126 | } |
127 | ||
57bfa891 TM |
128 | static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync) |
129 | { | |
130 | int res = 0; | |
131 | ||
132 | res = nfs4_proc_delegreturn(inode, delegation->cred, &delegation->stateid, issync); | |
133 | nfs_free_delegation(delegation); | |
134 | return res; | |
135 | } | |
136 | ||
86e89489 TM |
137 | static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation) |
138 | { | |
139 | struct inode *inode = NULL; | |
140 | ||
141 | spin_lock(&delegation->lock); | |
142 | if (delegation->inode != NULL) | |
143 | inode = igrab(delegation->inode); | |
144 | spin_unlock(&delegation->lock); | |
145 | return inode; | |
146 | } | |
147 | ||
57bfa891 TM |
148 | static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi, const nfs4_stateid *stateid) |
149 | { | |
150 | struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation); | |
151 | ||
152 | if (delegation == NULL) | |
153 | goto nomatch; | |
34310430 | 154 | spin_lock(&delegation->lock); |
57bfa891 TM |
155 | if (stateid != NULL && memcmp(delegation->stateid.data, stateid->data, |
156 | sizeof(delegation->stateid.data)) != 0) | |
34310430 | 157 | goto nomatch_unlock; |
57bfa891 | 158 | list_del_rcu(&delegation->super_list); |
86e89489 | 159 | delegation->inode = NULL; |
57bfa891 TM |
160 | nfsi->delegation_state = 0; |
161 | rcu_assign_pointer(nfsi->delegation, NULL); | |
34310430 | 162 | spin_unlock(&delegation->lock); |
57bfa891 | 163 | return delegation; |
34310430 TM |
164 | nomatch_unlock: |
165 | spin_unlock(&delegation->lock); | |
57bfa891 TM |
166 | nomatch: |
167 | return NULL; | |
168 | } | |
169 | ||
1da177e4 LT |
170 | /* |
171 | * Set up a delegation on an inode | |
172 | */ | |
173 | int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res) | |
174 | { | |
7539bbab | 175 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
1da177e4 LT |
176 | struct nfs_inode *nfsi = NFS_I(inode); |
177 | struct nfs_delegation *delegation; | |
57bfa891 | 178 | struct nfs_delegation *freeme = NULL; |
1da177e4 LT |
179 | int status = 0; |
180 | ||
f52720ca | 181 | delegation = kmalloc(sizeof(*delegation), GFP_KERNEL); |
1da177e4 LT |
182 | if (delegation == NULL) |
183 | return -ENOMEM; | |
184 | memcpy(delegation->stateid.data, res->delegation.data, | |
185 | sizeof(delegation->stateid.data)); | |
186 | delegation->type = res->delegation_type; | |
187 | delegation->maxsize = res->maxsize; | |
beb2a5ec | 188 | delegation->change_attr = nfsi->change_attr; |
1da177e4 LT |
189 | delegation->cred = get_rpccred(cred); |
190 | delegation->inode = inode; | |
34310430 | 191 | spin_lock_init(&delegation->lock); |
1da177e4 LT |
192 | |
193 | spin_lock(&clp->cl_lock); | |
57bfa891 | 194 | if (rcu_dereference(nfsi->delegation) != NULL) { |
1da177e4 | 195 | if (memcmp(&delegation->stateid, &nfsi->delegation->stateid, |
57bfa891 TM |
196 | sizeof(delegation->stateid)) == 0 && |
197 | delegation->type == nfsi->delegation->type) { | |
198 | goto out; | |
1da177e4 | 199 | } |
57bfa891 TM |
200 | /* |
201 | * Deal with broken servers that hand out two | |
202 | * delegations for the same file. | |
203 | */ | |
204 | dfprintk(FILE, "%s: server %s handed out " | |
205 | "a duplicate delegation!\n", | |
3110ff80 | 206 | __func__, clp->cl_hostname); |
57bfa891 TM |
207 | if (delegation->type <= nfsi->delegation->type) { |
208 | freeme = delegation; | |
209 | delegation = NULL; | |
210 | goto out; | |
211 | } | |
212 | freeme = nfs_detach_delegation_locked(nfsi, NULL); | |
1da177e4 | 213 | } |
57bfa891 TM |
214 | list_add_rcu(&delegation->super_list, &clp->cl_delegations); |
215 | nfsi->delegation_state = delegation->type; | |
216 | rcu_assign_pointer(nfsi->delegation, delegation); | |
217 | delegation = NULL; | |
412c77ce TM |
218 | |
219 | /* Ensure we revalidate the attributes and page cache! */ | |
220 | spin_lock(&inode->i_lock); | |
221 | nfsi->cache_validity |= NFS_INO_REVAL_FORCED; | |
222 | spin_unlock(&inode->i_lock); | |
223 | ||
57bfa891 | 224 | out: |
1da177e4 | 225 | spin_unlock(&clp->cl_lock); |
603c83da TM |
226 | if (delegation != NULL) |
227 | nfs_free_delegation(delegation); | |
57bfa891 TM |
228 | if (freeme != NULL) |
229 | nfs_do_return_delegation(inode, freeme, 0); | |
1da177e4 LT |
230 | return status; |
231 | } | |
232 | ||
1da177e4 LT |
233 | /* Sync all data to disk upon delegation return */ |
234 | static void nfs_msync_inode(struct inode *inode) | |
235 | { | |
236 | filemap_fdatawrite(inode->i_mapping); | |
237 | nfs_wb_all(inode); | |
238 | filemap_fdatawait(inode->i_mapping); | |
239 | } | |
240 | ||
241 | /* | |
242 | * Basic procedure for returning a delegation to the server | |
243 | */ | |
90163027 | 244 | static int __nfs_inode_return_delegation(struct inode *inode, struct nfs_delegation *delegation) |
1da177e4 | 245 | { |
1da177e4 | 246 | struct nfs_inode *nfsi = NFS_I(inode); |
1da177e4 LT |
247 | |
248 | nfs_msync_inode(inode); | |
1da177e4 LT |
249 | /* Guard against new delegated open calls */ |
250 | down_write(&nfsi->rwsem); | |
90163027 | 251 | nfs_delegation_claim_opens(inode, &delegation->stateid); |
1da177e4 | 252 | up_write(&nfsi->rwsem); |
1da177e4 LT |
253 | nfs_msync_inode(inode); |
254 | ||
e6f81075 | 255 | return nfs_do_return_delegation(inode, delegation, 1); |
90163027 TM |
256 | } |
257 | ||
515d8611 TM |
258 | /* |
259 | * Return all delegations that have been marked for return | |
260 | */ | |
707fb4b3 | 261 | void nfs_client_return_marked_delegations(struct nfs_client *clp) |
515d8611 TM |
262 | { |
263 | struct nfs_delegation *delegation; | |
264 | struct inode *inode; | |
265 | ||
266 | restart: | |
267 | rcu_read_lock(); | |
268 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | |
269 | if (!test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags)) | |
270 | continue; | |
271 | inode = nfs_delegation_grab_inode(delegation); | |
272 | if (inode == NULL) | |
273 | continue; | |
274 | spin_lock(&clp->cl_lock); | |
275 | delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL); | |
276 | spin_unlock(&clp->cl_lock); | |
277 | rcu_read_unlock(); | |
278 | if (delegation != NULL) | |
279 | __nfs_inode_return_delegation(inode, delegation); | |
280 | iput(inode); | |
281 | goto restart; | |
282 | } | |
283 | rcu_read_unlock(); | |
284 | } | |
285 | ||
e6f81075 TM |
286 | /* |
287 | * This function returns the delegation without reclaiming opens | |
288 | * or protecting against delegation reclaims. | |
289 | * It is therefore really only safe to be called from | |
290 | * nfs4_clear_inode() | |
291 | */ | |
292 | void nfs_inode_return_delegation_noreclaim(struct inode *inode) | |
293 | { | |
294 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; | |
295 | struct nfs_inode *nfsi = NFS_I(inode); | |
296 | struct nfs_delegation *delegation; | |
297 | ||
298 | if (rcu_dereference(nfsi->delegation) != NULL) { | |
299 | spin_lock(&clp->cl_lock); | |
300 | delegation = nfs_detach_delegation_locked(nfsi, NULL); | |
301 | spin_unlock(&clp->cl_lock); | |
302 | if (delegation != NULL) | |
303 | nfs_do_return_delegation(inode, delegation, 0); | |
304 | } | |
305 | } | |
306 | ||
90163027 TM |
307 | int nfs_inode_return_delegation(struct inode *inode) |
308 | { | |
309 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; | |
310 | struct nfs_inode *nfsi = NFS_I(inode); | |
311 | struct nfs_delegation *delegation; | |
312 | int err = 0; | |
313 | ||
8383e460 | 314 | if (rcu_dereference(nfsi->delegation) != NULL) { |
90163027 TM |
315 | spin_lock(&clp->cl_lock); |
316 | delegation = nfs_detach_delegation_locked(nfsi, NULL); | |
317 | spin_unlock(&clp->cl_lock); | |
318 | if (delegation != NULL) | |
319 | err = __nfs_inode_return_delegation(inode, delegation); | |
320 | } | |
321 | return err; | |
1da177e4 LT |
322 | } |
323 | ||
324 | /* | |
325 | * Return all delegations associated to a super block | |
326 | */ | |
515d8611 | 327 | void nfs_super_return_all_delegations(struct super_block *sb) |
1da177e4 | 328 | { |
7539bbab | 329 | struct nfs_client *clp = NFS_SB(sb)->nfs_client; |
1da177e4 | 330 | struct nfs_delegation *delegation; |
1da177e4 LT |
331 | |
332 | if (clp == NULL) | |
333 | return; | |
8383e460 TM |
334 | rcu_read_lock(); |
335 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | |
86e89489 TM |
336 | spin_lock(&delegation->lock); |
337 | if (delegation->inode != NULL && delegation->inode->i_sb == sb) | |
515d8611 | 338 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); |
86e89489 | 339 | spin_unlock(&delegation->lock); |
1da177e4 | 340 | } |
8383e460 | 341 | rcu_read_unlock(); |
515d8611 TM |
342 | nfs_client_return_marked_delegations(clp); |
343 | } | |
344 | ||
707fb4b3 | 345 | static void nfs_client_mark_return_all_delegations(struct nfs_client *clp) |
515d8611 TM |
346 | { |
347 | struct nfs_delegation *delegation; | |
348 | ||
349 | rcu_read_lock(); | |
707fb4b3 | 350 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { |
515d8611 | 351 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); |
707fb4b3 TM |
352 | set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); |
353 | } | |
515d8611 | 354 | rcu_read_unlock(); |
1da177e4 LT |
355 | } |
356 | ||
10afec90 | 357 | static int nfs_do_expire_all_delegations(void *ptr) |
58d9714a | 358 | { |
adfa6f98 | 359 | struct nfs_client *clp = ptr; |
58d9714a TM |
360 | |
361 | allow_signal(SIGKILL); | |
515d8611 | 362 | |
e005e804 | 363 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0) |
58d9714a TM |
364 | goto out; |
365 | if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) | |
366 | goto out; | |
707fb4b3 TM |
367 | nfs_client_mark_return_all_delegations(clp); |
368 | nfs_client_return_marked_delegations(clp); | |
58d9714a | 369 | out: |
24c8dbbb | 370 | nfs_put_client(clp); |
58d9714a TM |
371 | module_put_and_exit(0); |
372 | } | |
373 | ||
adfa6f98 | 374 | void nfs_expire_all_delegations(struct nfs_client *clp) |
58d9714a TM |
375 | { |
376 | struct task_struct *task; | |
377 | ||
378 | __module_get(THIS_MODULE); | |
379 | atomic_inc(&clp->cl_count); | |
380 | task = kthread_run(nfs_do_expire_all_delegations, clp, | |
5d8515ca CL |
381 | "%s-delegreturn", |
382 | rpc_peeraddr2str(clp->cl_rpcclient, | |
383 | RPC_DISPLAY_ADDR)); | |
58d9714a TM |
384 | if (!IS_ERR(task)) |
385 | return; | |
24c8dbbb | 386 | nfs_put_client(clp); |
58d9714a TM |
387 | module_put(THIS_MODULE); |
388 | } | |
389 | ||
1da177e4 LT |
390 | /* |
391 | * Return all delegations following an NFS4ERR_CB_PATH_DOWN error. | |
392 | */ | |
adfa6f98 | 393 | void nfs_handle_cb_pathdown(struct nfs_client *clp) |
1da177e4 | 394 | { |
1da177e4 LT |
395 | if (clp == NULL) |
396 | return; | |
707fb4b3 | 397 | nfs_client_mark_return_all_delegations(clp); |
1da177e4 LT |
398 | } |
399 | ||
400 | struct recall_threadargs { | |
401 | struct inode *inode; | |
adfa6f98 | 402 | struct nfs_client *clp; |
1da177e4 LT |
403 | const nfs4_stateid *stateid; |
404 | ||
405 | struct completion started; | |
406 | int result; | |
407 | }; | |
408 | ||
409 | static int recall_thread(void *data) | |
410 | { | |
411 | struct recall_threadargs *args = (struct recall_threadargs *)data; | |
412 | struct inode *inode = igrab(args->inode); | |
7539bbab | 413 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
1da177e4 LT |
414 | struct nfs_inode *nfsi = NFS_I(inode); |
415 | struct nfs_delegation *delegation; | |
416 | ||
417 | daemonize("nfsv4-delegreturn"); | |
418 | ||
419 | nfs_msync_inode(inode); | |
1da177e4 LT |
420 | down_write(&nfsi->rwsem); |
421 | spin_lock(&clp->cl_lock); | |
90163027 TM |
422 | delegation = nfs_detach_delegation_locked(nfsi, args->stateid); |
423 | if (delegation != NULL) | |
1da177e4 | 424 | args->result = 0; |
90163027 | 425 | else |
1da177e4 | 426 | args->result = -ENOENT; |
1da177e4 LT |
427 | spin_unlock(&clp->cl_lock); |
428 | complete(&args->started); | |
90163027 | 429 | nfs_delegation_claim_opens(inode, args->stateid); |
1da177e4 | 430 | up_write(&nfsi->rwsem); |
1da177e4 LT |
431 | nfs_msync_inode(inode); |
432 | ||
433 | if (delegation != NULL) | |
e6f81075 | 434 | nfs_do_return_delegation(inode, delegation, 1); |
1da177e4 LT |
435 | iput(inode); |
436 | module_put_and_exit(0); | |
437 | } | |
438 | ||
439 | /* | |
440 | * Asynchronous delegation recall! | |
441 | */ | |
442 | int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid) | |
443 | { | |
444 | struct recall_threadargs data = { | |
445 | .inode = inode, | |
446 | .stateid = stateid, | |
447 | }; | |
448 | int status; | |
449 | ||
450 | init_completion(&data.started); | |
451 | __module_get(THIS_MODULE); | |
452 | status = kernel_thread(recall_thread, &data, CLONE_KERNEL); | |
453 | if (status < 0) | |
454 | goto out_module_put; | |
455 | wait_for_completion(&data.started); | |
456 | return data.result; | |
457 | out_module_put: | |
458 | module_put(THIS_MODULE); | |
459 | return status; | |
460 | } | |
461 | ||
462 | /* | |
463 | * Retrieve the inode associated with a delegation | |
464 | */ | |
adfa6f98 | 465 | struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle) |
1da177e4 LT |
466 | { |
467 | struct nfs_delegation *delegation; | |
468 | struct inode *res = NULL; | |
8383e460 TM |
469 | rcu_read_lock(); |
470 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | |
86e89489 TM |
471 | spin_lock(&delegation->lock); |
472 | if (delegation->inode != NULL && | |
473 | nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) { | |
1da177e4 | 474 | res = igrab(delegation->inode); |
1da177e4 | 475 | } |
86e89489 TM |
476 | spin_unlock(&delegation->lock); |
477 | if (res != NULL) | |
478 | break; | |
1da177e4 | 479 | } |
8383e460 | 480 | rcu_read_unlock(); |
1da177e4 LT |
481 | return res; |
482 | } | |
483 | ||
484 | /* | |
485 | * Mark all delegations as needing to be reclaimed | |
486 | */ | |
adfa6f98 | 487 | void nfs_delegation_mark_reclaim(struct nfs_client *clp) |
1da177e4 LT |
488 | { |
489 | struct nfs_delegation *delegation; | |
8383e460 TM |
490 | rcu_read_lock(); |
491 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) | |
15c831bf | 492 | set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); |
8383e460 | 493 | rcu_read_unlock(); |
1da177e4 LT |
494 | } |
495 | ||
496 | /* | |
497 | * Reap all unclaimed delegations after reboot recovery is done | |
498 | */ | |
adfa6f98 | 499 | void nfs_delegation_reap_unclaimed(struct nfs_client *clp) |
1da177e4 | 500 | { |
8383e460 | 501 | struct nfs_delegation *delegation; |
86e89489 | 502 | struct inode *inode; |
8383e460 TM |
503 | restart: |
504 | rcu_read_lock(); | |
505 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | |
15c831bf | 506 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) |
1da177e4 | 507 | continue; |
86e89489 TM |
508 | inode = nfs_delegation_grab_inode(delegation); |
509 | if (inode == NULL) | |
510 | continue; | |
8383e460 | 511 | spin_lock(&clp->cl_lock); |
86e89489 | 512 | delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL); |
8383e460 TM |
513 | spin_unlock(&clp->cl_lock); |
514 | rcu_read_unlock(); | |
515 | if (delegation != NULL) | |
905f8d16 | 516 | nfs_free_delegation(delegation); |
86e89489 | 517 | iput(inode); |
8383e460 | 518 | goto restart; |
1da177e4 | 519 | } |
8383e460 | 520 | rcu_read_unlock(); |
1da177e4 | 521 | } |
3e4f6290 TM |
522 | |
523 | int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode) | |
524 | { | |
3e4f6290 TM |
525 | struct nfs_inode *nfsi = NFS_I(inode); |
526 | struct nfs_delegation *delegation; | |
8383e460 | 527 | int ret = 0; |
3e4f6290 | 528 | |
8383e460 TM |
529 | rcu_read_lock(); |
530 | delegation = rcu_dereference(nfsi->delegation); | |
3e4f6290 TM |
531 | if (delegation != NULL) { |
532 | memcpy(dst->data, delegation->stateid.data, sizeof(dst->data)); | |
8383e460 | 533 | ret = 1; |
3e4f6290 | 534 | } |
8383e460 TM |
535 | rcu_read_unlock(); |
536 | return ret; | |
3e4f6290 | 537 | } |