delegation.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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. /**
  421. * nfs_expire_all_delegation_types
  422. * @clp: client to process
  423. * @flags: delegation types to expire
  424. *
  425. */
  426. void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags)
  427. {
  428. nfs_client_mark_return_all_delegation_types(clp, flags);
  429. nfs_delegation_run_state_manager(clp);
  430. }
  431. /**
  432. * nfs_expire_all_delegations
  433. * @clp: client to process
  434. *
  435. */
  436. void nfs_expire_all_delegations(struct nfs_client *clp)
  437. {
  438. nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
  439. }
  440. /**
  441. * nfs_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
  442. * @clp: client to process
  443. *
  444. */
  445. void nfs_handle_cb_pathdown(struct nfs_client *clp)
  446. {
  447. if (clp == NULL)
  448. return;
  449. nfs_client_mark_return_all_delegations(clp);
  450. }
  451. static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server)
  452. {
  453. struct nfs_delegation *delegation;
  454. list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
  455. if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags))
  456. continue;
  457. nfs_mark_return_delegation(server, delegation);
  458. }
  459. }
  460. /**
  461. * nfs_expire_unreferenced_delegations - Eliminate unused delegations
  462. * @clp: nfs_client to process
  463. *
  464. */
  465. void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
  466. {
  467. struct nfs_server *server;
  468. rcu_read_lock();
  469. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  470. nfs_mark_return_unreferenced_delegations(server);
  471. rcu_read_unlock();
  472. nfs_delegation_run_state_manager(clp);
  473. }
  474. /**
  475. * nfs_async_inode_return_delegation - asynchronously return a delegation
  476. * @inode: inode to process
  477. * @stateid: state ID information from CB_RECALL arguments
  478. *
  479. * Returns zero on success, or a negative errno value.
  480. */
  481. int nfs_async_inode_return_delegation(struct inode *inode,
  482. const nfs4_stateid *stateid)
  483. {
  484. struct nfs_server *server = NFS_SERVER(inode);
  485. struct nfs_client *clp = server->nfs_client;
  486. struct nfs_delegation *delegation;
  487. rcu_read_lock();
  488. delegation = rcu_dereference(NFS_I(inode)->delegation);
  489. if (!clp->cl_mvops->validate_stateid(delegation, stateid)) {
  490. rcu_read_unlock();
  491. return -ENOENT;
  492. }
  493. nfs_mark_return_delegation(server, delegation);
  494. rcu_read_unlock();
  495. nfs_delegation_run_state_manager(clp);
  496. return 0;
  497. }
  498. static struct inode *
  499. nfs_delegation_find_inode_server(struct nfs_server *server,
  500. const struct nfs_fh *fhandle)
  501. {
  502. struct nfs_delegation *delegation;
  503. struct inode *res = NULL;
  504. list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
  505. spin_lock(&delegation->lock);
  506. if (delegation->inode != NULL &&
  507. nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
  508. res = igrab(delegation->inode);
  509. }
  510. spin_unlock(&delegation->lock);
  511. if (res != NULL)
  512. break;
  513. }
  514. return res;
  515. }
  516. /**
  517. * nfs_delegation_find_inode - retrieve the inode associated with a delegation
  518. * @clp: client state handle
  519. * @fhandle: filehandle from a delegation recall
  520. *
  521. * Returns pointer to inode matching "fhandle," or NULL if a matching inode
  522. * cannot be found.
  523. */
  524. struct inode *nfs_delegation_find_inode(struct nfs_client *clp,
  525. const struct nfs_fh *fhandle)
  526. {
  527. struct nfs_server *server;
  528. struct inode *res = NULL;
  529. rcu_read_lock();
  530. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  531. res = nfs_delegation_find_inode_server(server, fhandle);
  532. if (res != NULL)
  533. break;
  534. }
  535. rcu_read_unlock();
  536. return res;
  537. }
  538. static void nfs_delegation_mark_reclaim_server(struct nfs_server *server)
  539. {
  540. struct nfs_delegation *delegation;
  541. list_for_each_entry_rcu(delegation, &server->delegations, super_list)
  542. set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
  543. }
  544. /**
  545. * nfs_delegation_mark_reclaim - mark all delegations as needing to be reclaimed
  546. * @clp: nfs_client to process
  547. *
  548. */
  549. void nfs_delegation_mark_reclaim(struct nfs_client *clp)
  550. {
  551. struct nfs_server *server;
  552. rcu_read_lock();
  553. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  554. nfs_delegation_mark_reclaim_server(server);
  555. rcu_read_unlock();
  556. }
  557. /**
  558. * nfs_delegation_reap_unclaimed - reap unclaimed delegations after reboot recovery is done
  559. * @clp: nfs_client to process
  560. *
  561. */
  562. void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
  563. {
  564. struct nfs_delegation *delegation;
  565. struct nfs_server *server;
  566. struct inode *inode;
  567. restart:
  568. rcu_read_lock();
  569. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  570. list_for_each_entry_rcu(delegation, &server->delegations,
  571. super_list) {
  572. if (test_bit(NFS_DELEGATION_NEED_RECLAIM,
  573. &delegation->flags) == 0)
  574. continue;
  575. inode = nfs_delegation_grab_inode(delegation);
  576. if (inode == NULL)
  577. continue;
  578. delegation = nfs_detach_delegation(NFS_I(inode),
  579. server);
  580. rcu_read_unlock();
  581. if (delegation != NULL)
  582. nfs_free_delegation(delegation);
  583. iput(inode);
  584. goto restart;
  585. }
  586. }
  587. rcu_read_unlock();
  588. }
  589. /**
  590. * nfs_delegations_present - check for existence of delegations
  591. * @clp: client state handle
  592. *
  593. * Returns one if there are any nfs_delegation structures attached
  594. * to this nfs_client.
  595. */
  596. int nfs_delegations_present(struct nfs_client *clp)
  597. {
  598. struct nfs_server *server;
  599. int ret = 0;
  600. rcu_read_lock();
  601. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  602. if (!list_empty(&server->delegations)) {
  603. ret = 1;
  604. break;
  605. }
  606. rcu_read_unlock();
  607. return ret;
  608. }
  609. /**
  610. * nfs4_copy_delegation_stateid - Copy inode's state ID information
  611. * @dst: stateid data structure to fill in
  612. * @inode: inode to check
  613. *
  614. * Returns one and fills in "dst->data" * if inode had a delegation,
  615. * otherwise zero is returned.
  616. */
  617. int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
  618. {
  619. struct nfs_inode *nfsi = NFS_I(inode);
  620. struct nfs_delegation *delegation;
  621. int ret = 0;
  622. rcu_read_lock();
  623. delegation = rcu_dereference(nfsi->delegation);
  624. if (delegation != NULL) {
  625. memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
  626. ret = 1;
  627. }
  628. rcu_read_unlock();
  629. return ret;
  630. }