delegation.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * linux/fs/nfs/delegation.c
  3. *
  4. * Copyright (C) 2004 Trond Myklebust
  5. *
  6. * NFS file delegation management
  7. *
  8. */
  9. #include <linux/completion.h>
  10. #include <linux/kthread.h>
  11. #include <linux/module.h>
  12. #include <linux/sched.h>
  13. #include <linux/slab.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/nfs4.h>
  16. #include <linux/nfs_fs.h>
  17. #include <linux/nfs_xdr.h>
  18. #include "nfs4_fs.h"
  19. #include "delegation.h"
  20. #include "internal.h"
  21. static void nfs_free_delegation(struct nfs_delegation *delegation)
  22. {
  23. if (delegation->cred) {
  24. put_rpccred(delegation->cred);
  25. delegation->cred = NULL;
  26. }
  27. kfree_rcu(delegation, rcu);
  28. }
  29. /**
  30. * nfs_mark_delegation_referenced - set delegation's REFERENCED flag
  31. * @delegation: delegation to process
  32. *
  33. */
  34. void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)
  35. {
  36. set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags);
  37. }
  38. /**
  39. * nfs_have_delegation - check if inode has a delegation
  40. * @inode: inode to check
  41. * @flags: delegation types to check for
  42. *
  43. * Returns one if inode has the indicated delegation, otherwise zero.
  44. */
  45. int nfs_have_delegation(struct inode *inode, fmode_t flags)
  46. {
  47. struct nfs_delegation *delegation;
  48. int ret = 0;
  49. flags &= FMODE_READ|FMODE_WRITE;
  50. rcu_read_lock();
  51. delegation = rcu_dereference(NFS_I(inode)->delegation);
  52. if (delegation != NULL && (delegation->type & flags) == flags) {
  53. nfs_mark_delegation_referenced(delegation);
  54. ret = 1;
  55. }
  56. rcu_read_unlock();
  57. return ret;
  58. }
  59. static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_state *state)
  60. {
  61. struct inode *inode = state->inode;
  62. struct file_lock *fl;
  63. int status = 0;
  64. if (inode->i_flock == NULL)
  65. goto out;
  66. /* Protect inode->i_flock using the file locks lock */
  67. lock_flocks();
  68. for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
  69. if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
  70. continue;
  71. if (nfs_file_open_context(fl->fl_file) != ctx)
  72. continue;
  73. unlock_flocks();
  74. status = nfs4_lock_delegation_recall(state, fl);
  75. if (status < 0)
  76. goto out;
  77. lock_flocks();
  78. }
  79. unlock_flocks();
  80. out:
  81. return status;
  82. }
  83. static int nfs_delegation_claim_opens(struct inode *inode, const nfs4_stateid *stateid)
  84. {
  85. struct nfs_inode *nfsi = NFS_I(inode);
  86. struct nfs_open_context *ctx;
  87. struct nfs4_state *state;
  88. int err;
  89. again:
  90. spin_lock(&inode->i_lock);
  91. list_for_each_entry(ctx, &nfsi->open_files, list) {
  92. state = ctx->state;
  93. if (state == NULL)
  94. continue;
  95. if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
  96. continue;
  97. if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0)
  98. continue;
  99. get_nfs_open_context(ctx);
  100. spin_unlock(&inode->i_lock);
  101. err = nfs4_open_delegation_recall(ctx, state, stateid);
  102. if (err >= 0)
  103. err = nfs_delegation_claim_locks(ctx, state);
  104. put_nfs_open_context(ctx);
  105. if (err != 0)
  106. return err;
  107. goto again;
  108. }
  109. spin_unlock(&inode->i_lock);
  110. return 0;
  111. }
  112. /**
  113. * nfs_inode_reclaim_delegation - process a delegation reclaim request
  114. * @inode: inode to process
  115. * @cred: credential to use for request
  116. * @res: new delegation state from server
  117. *
  118. */
  119. void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
  120. struct nfs_openres *res)
  121. {
  122. struct nfs_delegation *delegation;
  123. struct rpc_cred *oldcred = NULL;
  124. rcu_read_lock();
  125. delegation = rcu_dereference(NFS_I(inode)->delegation);
  126. if (delegation != NULL) {
  127. spin_lock(&delegation->lock);
  128. if (delegation->inode != NULL) {
  129. memcpy(delegation->stateid.data, res->delegation.data,
  130. sizeof(delegation->stateid.data));
  131. delegation->type = res->delegation_type;
  132. delegation->maxsize = res->maxsize;
  133. oldcred = delegation->cred;
  134. delegation->cred = get_rpccred(cred);
  135. clear_bit(NFS_DELEGATION_NEED_RECLAIM,
  136. &delegation->flags);
  137. NFS_I(inode)->delegation_state = delegation->type;
  138. spin_unlock(&delegation->lock);
  139. put_rpccred(oldcred);
  140. rcu_read_unlock();
  141. } else {
  142. /* We appear to have raced with a delegation return. */
  143. spin_unlock(&delegation->lock);
  144. rcu_read_unlock();
  145. nfs_inode_set_delegation(inode, cred, res);
  146. }
  147. } else {
  148. rcu_read_unlock();
  149. }
  150. }
  151. static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
  152. {
  153. int res = 0;
  154. res = nfs4_proc_delegreturn(inode, delegation->cred, &delegation->stateid, issync);
  155. nfs_free_delegation(delegation);
  156. return res;
  157. }
  158. static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation)
  159. {
  160. struct inode *inode = NULL;
  161. spin_lock(&delegation->lock);
  162. if (delegation->inode != NULL)
  163. inode = igrab(delegation->inode);
  164. spin_unlock(&delegation->lock);
  165. return inode;
  166. }
  167. static struct nfs_delegation *
  168. nfs_detach_delegation_locked(struct nfs_inode *nfsi,
  169. struct nfs_server *server)
  170. {
  171. struct nfs_delegation *delegation =
  172. rcu_dereference_protected(nfsi->delegation,
  173. lockdep_is_held(&server->nfs_client->cl_lock));
  174. if (delegation == NULL)
  175. goto nomatch;
  176. spin_lock(&delegation->lock);
  177. list_del_rcu(&delegation->super_list);
  178. delegation->inode = NULL;
  179. nfsi->delegation_state = 0;
  180. rcu_assign_pointer(nfsi->delegation, NULL);
  181. spin_unlock(&delegation->lock);
  182. return delegation;
  183. nomatch:
  184. return NULL;
  185. }
  186. static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi,
  187. struct nfs_server *server)
  188. {
  189. struct nfs_client *clp = server->nfs_client;
  190. struct nfs_delegation *delegation;
  191. spin_lock(&clp->cl_lock);
  192. delegation = nfs_detach_delegation_locked(nfsi, server);
  193. spin_unlock(&clp->cl_lock);
  194. return delegation;
  195. }
  196. /**
  197. * nfs_inode_set_delegation - set up a delegation on an inode
  198. * @inode: inode to which delegation applies
  199. * @cred: cred to use for subsequent delegation processing
  200. * @res: new delegation state from server
  201. *
  202. * Returns zero on success, or a negative errno value.
  203. */
  204. int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
  205. {
  206. struct nfs_server *server = NFS_SERVER(inode);
  207. struct nfs_client *clp = server->nfs_client;
  208. struct nfs_inode *nfsi = NFS_I(inode);
  209. struct nfs_delegation *delegation, *old_delegation;
  210. struct nfs_delegation *freeme = NULL;
  211. int status = 0;
  212. delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
  213. if (delegation == NULL)
  214. return -ENOMEM;
  215. memcpy(delegation->stateid.data, res->delegation.data,
  216. sizeof(delegation->stateid.data));
  217. delegation->type = res->delegation_type;
  218. delegation->maxsize = res->maxsize;
  219. delegation->change_attr = nfsi->change_attr;
  220. delegation->cred = get_rpccred(cred);
  221. delegation->inode = inode;
  222. delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
  223. spin_lock_init(&delegation->lock);
  224. spin_lock(&clp->cl_lock);
  225. old_delegation = rcu_dereference_protected(nfsi->delegation,
  226. lockdep_is_held(&clp->cl_lock));
  227. if (old_delegation != NULL) {
  228. if (memcmp(&delegation->stateid, &old_delegation->stateid,
  229. sizeof(old_delegation->stateid)) == 0 &&
  230. delegation->type == old_delegation->type) {
  231. goto out;
  232. }
  233. /*
  234. * Deal with broken servers that hand out two
  235. * delegations for the same file.
  236. */
  237. dfprintk(FILE, "%s: server %s handed out "
  238. "a duplicate delegation!\n",
  239. __func__, clp->cl_hostname);
  240. if (delegation->type <= old_delegation->type) {
  241. freeme = delegation;
  242. delegation = NULL;
  243. goto out;
  244. }
  245. freeme = nfs_detach_delegation_locked(nfsi, server);
  246. }
  247. list_add_rcu(&delegation->super_list, &server->delegations);
  248. nfsi->delegation_state = delegation->type;
  249. rcu_assign_pointer(nfsi->delegation, delegation);
  250. delegation = NULL;
  251. /* Ensure we revalidate the attributes and page cache! */
  252. spin_lock(&inode->i_lock);
  253. nfsi->cache_validity |= NFS_INO_REVAL_FORCED;
  254. spin_unlock(&inode->i_lock);
  255. out:
  256. spin_unlock(&clp->cl_lock);
  257. if (delegation != NULL)
  258. nfs_free_delegation(delegation);
  259. if (freeme != NULL)
  260. nfs_do_return_delegation(inode, freeme, 0);
  261. return status;
  262. }
  263. /*
  264. * Basic procedure for returning a delegation to the server
  265. */
  266. static int __nfs_inode_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
  267. {
  268. struct nfs_inode *nfsi = NFS_I(inode);
  269. int err;
  270. /*
  271. * Guard against new delegated open/lock/unlock calls and against
  272. * state recovery
  273. */
  274. down_write(&nfsi->rwsem);
  275. err = nfs_delegation_claim_opens(inode, &delegation->stateid);
  276. up_write(&nfsi->rwsem);
  277. if (err)
  278. goto out;
  279. err = nfs_do_return_delegation(inode, delegation, issync);
  280. out:
  281. return err;
  282. }
  283. /**
  284. * nfs_client_return_marked_delegations - return previously marked delegations
  285. * @clp: nfs_client to process
  286. *
  287. * Returns zero on success, or a negative errno value.
  288. */
  289. int nfs_client_return_marked_delegations(struct nfs_client *clp)
  290. {
  291. struct nfs_delegation *delegation;
  292. struct nfs_server *server;
  293. struct inode *inode;
  294. int err = 0;
  295. restart:
  296. rcu_read_lock();
  297. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  298. list_for_each_entry_rcu(delegation, &server->delegations,
  299. super_list) {
  300. if (!test_and_clear_bit(NFS_DELEGATION_RETURN,
  301. &delegation->flags))
  302. continue;
  303. inode = nfs_delegation_grab_inode(delegation);
  304. if (inode == NULL)
  305. continue;
  306. delegation = nfs_detach_delegation(NFS_I(inode),
  307. server);
  308. rcu_read_unlock();
  309. if (delegation != NULL) {
  310. filemap_flush(inode->i_mapping);
  311. err = __nfs_inode_return_delegation(inode,
  312. delegation, 0);
  313. }
  314. iput(inode);
  315. if (!err)
  316. goto restart;
  317. set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state);
  318. return err;
  319. }
  320. }
  321. rcu_read_unlock();
  322. return 0;
  323. }
  324. /**
  325. * nfs_inode_return_delegation_noreclaim - return delegation, don't reclaim opens
  326. * @inode: inode to process
  327. *
  328. * Does not protect against delegation reclaims, therefore really only safe
  329. * to be called from nfs4_clear_inode().
  330. */
  331. void nfs_inode_return_delegation_noreclaim(struct inode *inode)
  332. {
  333. struct nfs_server *server = NFS_SERVER(inode);
  334. struct nfs_inode *nfsi = NFS_I(inode);
  335. struct nfs_delegation *delegation;
  336. if (rcu_access_pointer(nfsi->delegation) != NULL) {
  337. delegation = nfs_detach_delegation(nfsi, server);
  338. if (delegation != NULL)
  339. nfs_do_return_delegation(inode, delegation, 0);
  340. }
  341. }
  342. /**
  343. * nfs_inode_return_delegation - synchronously return a delegation
  344. * @inode: inode to process
  345. *
  346. * Returns zero on success, or a negative errno value.
  347. */
  348. int nfs_inode_return_delegation(struct inode *inode)
  349. {
  350. struct nfs_server *server = NFS_SERVER(inode);
  351. struct nfs_inode *nfsi = NFS_I(inode);
  352. struct nfs_delegation *delegation;
  353. int err = 0;
  354. if (rcu_access_pointer(nfsi->delegation) != NULL) {
  355. delegation = nfs_detach_delegation(nfsi, server);
  356. if (delegation != NULL) {
  357. nfs_wb_all(inode);
  358. err = __nfs_inode_return_delegation(inode, delegation, 1);
  359. }
  360. }
  361. return err;
  362. }
  363. static void nfs_mark_return_delegation(struct nfs_server *server,
  364. struct nfs_delegation *delegation)
  365. {
  366. set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
  367. set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state);
  368. }
  369. /**
  370. * nfs_super_return_all_delegations - return delegations for one superblock
  371. * @sb: sb to process
  372. *
  373. */
  374. void nfs_super_return_all_delegations(struct super_block *sb)
  375. {
  376. struct nfs_server *server = NFS_SB(sb);
  377. struct nfs_client *clp = server->nfs_client;
  378. struct nfs_delegation *delegation;
  379. if (clp == NULL)
  380. return;
  381. rcu_read_lock();
  382. list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
  383. spin_lock(&delegation->lock);
  384. set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
  385. spin_unlock(&delegation->lock);
  386. }
  387. rcu_read_unlock();
  388. if (nfs_client_return_marked_delegations(clp) != 0)
  389. nfs4_schedule_state_manager(clp);
  390. }
  391. static void nfs_mark_return_all_delegation_types(struct nfs_server *server,
  392. fmode_t flags)
  393. {
  394. struct nfs_delegation *delegation;
  395. list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
  396. if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE))
  397. continue;
  398. if (delegation->type & flags)
  399. nfs_mark_return_delegation(server, delegation);
  400. }
  401. }
  402. static void nfs_client_mark_return_all_delegation_types(struct nfs_client *clp,
  403. fmode_t flags)
  404. {
  405. struct nfs_server *server;
  406. rcu_read_lock();
  407. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  408. nfs_mark_return_all_delegation_types(server, flags);
  409. rcu_read_unlock();
  410. }
  411. static void nfs_client_mark_return_all_delegations(struct nfs_client *clp)
  412. {
  413. nfs_client_mark_return_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
  414. }
  415. static void nfs_delegation_run_state_manager(struct nfs_client *clp)
  416. {
  417. if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state))
  418. nfs4_schedule_state_manager(clp);
  419. }
  420. void nfs_remove_bad_delegation(struct inode *inode)
  421. {
  422. struct nfs_delegation *delegation;
  423. delegation = nfs_detach_delegation(NFS_I(inode), NFS_SERVER(inode));
  424. if (delegation) {
  425. nfs_inode_find_state_and_recover(inode, &delegation->stateid);
  426. nfs_free_delegation(delegation);
  427. }
  428. }
  429. /**
  430. * nfs_expire_all_delegation_types
  431. * @clp: client to process
  432. * @flags: delegation types to expire
  433. *
  434. */
  435. void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags)
  436. {
  437. nfs_client_mark_return_all_delegation_types(clp, flags);
  438. nfs_delegation_run_state_manager(clp);
  439. }
  440. /**
  441. * nfs_expire_all_delegations
  442. * @clp: client to process
  443. *
  444. */
  445. void nfs_expire_all_delegations(struct nfs_client *clp)
  446. {
  447. nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
  448. }
  449. /**
  450. * nfs_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
  451. * @clp: client to process
  452. *
  453. */
  454. void nfs_handle_cb_pathdown(struct nfs_client *clp)
  455. {
  456. if (clp == NULL)
  457. return;
  458. nfs_client_mark_return_all_delegations(clp);
  459. }
  460. static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server)
  461. {
  462. struct nfs_delegation *delegation;
  463. list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
  464. if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags))
  465. continue;
  466. nfs_mark_return_delegation(server, delegation);
  467. }
  468. }
  469. /**
  470. * nfs_expire_unreferenced_delegations - Eliminate unused delegations
  471. * @clp: nfs_client to process
  472. *
  473. */
  474. void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
  475. {
  476. struct nfs_server *server;
  477. rcu_read_lock();
  478. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  479. nfs_mark_return_unreferenced_delegations(server);
  480. rcu_read_unlock();
  481. nfs_delegation_run_state_manager(clp);
  482. }
  483. /**
  484. * nfs_async_inode_return_delegation - asynchronously return a delegation
  485. * @inode: inode to process
  486. * @stateid: state ID information from CB_RECALL arguments
  487. *
  488. * Returns zero on success, or a negative errno value.
  489. */
  490. int nfs_async_inode_return_delegation(struct inode *inode,
  491. const nfs4_stateid *stateid)
  492. {
  493. struct nfs_server *server = NFS_SERVER(inode);
  494. struct nfs_client *clp = server->nfs_client;
  495. struct nfs_delegation *delegation;
  496. rcu_read_lock();
  497. delegation = rcu_dereference(NFS_I(inode)->delegation);
  498. if (!clp->cl_mvops->validate_stateid(delegation, stateid)) {
  499. rcu_read_unlock();
  500. return -ENOENT;
  501. }
  502. nfs_mark_return_delegation(server, delegation);
  503. rcu_read_unlock();
  504. nfs_delegation_run_state_manager(clp);
  505. return 0;
  506. }
  507. static struct inode *
  508. nfs_delegation_find_inode_server(struct nfs_server *server,
  509. const struct nfs_fh *fhandle)
  510. {
  511. struct nfs_delegation *delegation;
  512. struct inode *res = NULL;
  513. list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
  514. spin_lock(&delegation->lock);
  515. if (delegation->inode != NULL &&
  516. nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
  517. res = igrab(delegation->inode);
  518. }
  519. spin_unlock(&delegation->lock);
  520. if (res != NULL)
  521. break;
  522. }
  523. return res;
  524. }
  525. /**
  526. * nfs_delegation_find_inode - retrieve the inode associated with a delegation
  527. * @clp: client state handle
  528. * @fhandle: filehandle from a delegation recall
  529. *
  530. * Returns pointer to inode matching "fhandle," or NULL if a matching inode
  531. * cannot be found.
  532. */
  533. struct inode *nfs_delegation_find_inode(struct nfs_client *clp,
  534. const struct nfs_fh *fhandle)
  535. {
  536. struct nfs_server *server;
  537. struct inode *res = NULL;
  538. rcu_read_lock();
  539. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  540. res = nfs_delegation_find_inode_server(server, fhandle);
  541. if (res != NULL)
  542. break;
  543. }
  544. rcu_read_unlock();
  545. return res;
  546. }
  547. static void nfs_delegation_mark_reclaim_server(struct nfs_server *server)
  548. {
  549. struct nfs_delegation *delegation;
  550. list_for_each_entry_rcu(delegation, &server->delegations, super_list)
  551. set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
  552. }
  553. /**
  554. * nfs_delegation_mark_reclaim - mark all delegations as needing to be reclaimed
  555. * @clp: nfs_client to process
  556. *
  557. */
  558. void nfs_delegation_mark_reclaim(struct nfs_client *clp)
  559. {
  560. struct nfs_server *server;
  561. rcu_read_lock();
  562. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  563. nfs_delegation_mark_reclaim_server(server);
  564. rcu_read_unlock();
  565. }
  566. /**
  567. * nfs_delegation_reap_unclaimed - reap unclaimed delegations after reboot recovery is done
  568. * @clp: nfs_client to process
  569. *
  570. */
  571. void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
  572. {
  573. struct nfs_delegation *delegation;
  574. struct nfs_server *server;
  575. struct inode *inode;
  576. restart:
  577. rcu_read_lock();
  578. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  579. list_for_each_entry_rcu(delegation, &server->delegations,
  580. super_list) {
  581. if (test_bit(NFS_DELEGATION_NEED_RECLAIM,
  582. &delegation->flags) == 0)
  583. continue;
  584. inode = nfs_delegation_grab_inode(delegation);
  585. if (inode == NULL)
  586. continue;
  587. delegation = nfs_detach_delegation(NFS_I(inode),
  588. server);
  589. rcu_read_unlock();
  590. if (delegation != NULL)
  591. nfs_free_delegation(delegation);
  592. iput(inode);
  593. goto restart;
  594. }
  595. }
  596. rcu_read_unlock();
  597. }
  598. /**
  599. * nfs_delegations_present - check for existence of delegations
  600. * @clp: client state handle
  601. *
  602. * Returns one if there are any nfs_delegation structures attached
  603. * to this nfs_client.
  604. */
  605. int nfs_delegations_present(struct nfs_client *clp)
  606. {
  607. struct nfs_server *server;
  608. int ret = 0;
  609. rcu_read_lock();
  610. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  611. if (!list_empty(&server->delegations)) {
  612. ret = 1;
  613. break;
  614. }
  615. rcu_read_unlock();
  616. return ret;
  617. }
  618. /**
  619. * nfs4_copy_delegation_stateid - Copy inode's state ID information
  620. * @dst: stateid data structure to fill in
  621. * @inode: inode to check
  622. *
  623. * Returns one and fills in "dst->data" * if inode had a delegation,
  624. * otherwise zero is returned.
  625. */
  626. int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
  627. {
  628. struct nfs_inode *nfsi = NFS_I(inode);
  629. struct nfs_delegation *delegation;
  630. int ret = 0;
  631. rcu_read_lock();
  632. delegation = rcu_dereference(nfsi->delegation);
  633. if (delegation != NULL) {
  634. memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
  635. ret = 1;
  636. }
  637. rcu_read_unlock();
  638. return ret;
  639. }