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