callback_proc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/nfs/callback_proc.c
  4. *
  5. * Copyright (C) 2004 Trond Myklebust
  6. *
  7. * NFSv4 callback procedures
  8. */
  9. #include <linux/errno.h>
  10. #include <linux/math.h>
  11. #include <linux/nfs4.h>
  12. #include <linux/nfs_fs.h>
  13. #include <linux/slab.h>
  14. #include <linux/rcupdate.h>
  15. #include <linux/types.h>
  16. #include "nfs4_fs.h"
  17. #include "callback.h"
  18. #include "delegation.h"
  19. #include "internal.h"
  20. #include "pnfs.h"
  21. #include "nfs4session.h"
  22. #include "nfs4trace.h"
  23. #define NFSDBG_FACILITY NFSDBG_CALLBACK
  24. __be32 nfs4_callback_getattr(void *argp, void *resp,
  25. struct cb_process_state *cps)
  26. {
  27. struct cb_getattrargs *args = argp;
  28. struct cb_getattrres *res = resp;
  29. struct nfs_delegation *delegation;
  30. struct inode *inode;
  31. res->status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
  32. if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
  33. goto out;
  34. memset(res->bitmap, 0, sizeof(res->bitmap));
  35. res->status = htonl(NFS4ERR_BADHANDLE);
  36. dprintk_rcu("NFS: GETATTR callback request from %s\n",
  37. rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
  38. inode = nfs_delegation_find_inode(cps->clp, &args->fh);
  39. if (IS_ERR(inode)) {
  40. if (inode == ERR_PTR(-EAGAIN))
  41. res->status = htonl(NFS4ERR_DELAY);
  42. trace_nfs4_cb_getattr(cps->clp, &args->fh, NULL,
  43. -ntohl(res->status));
  44. goto out;
  45. }
  46. delegation = nfs4_get_valid_delegation(inode);
  47. if (!delegation)
  48. goto out_iput;
  49. if ((delegation->type & FMODE_WRITE) == 0) {
  50. nfs_put_delegation(delegation);
  51. goto out_iput;
  52. }
  53. res->change_attr = delegation->change_attr;
  54. nfs_put_delegation(delegation);
  55. res->size = i_size_read(inode);
  56. if (nfs_have_writebacks(inode))
  57. res->change_attr++;
  58. res->atime = inode_get_atime(inode);
  59. res->ctime = inode_get_ctime(inode);
  60. res->mtime = inode_get_mtime(inode);
  61. res->bitmap[0] = (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE) &
  62. args->bitmap[0];
  63. res->bitmap[1] = (FATTR4_WORD1_TIME_ACCESS |
  64. FATTR4_WORD1_TIME_METADATA |
  65. FATTR4_WORD1_TIME_MODIFY) & args->bitmap[1];
  66. res->bitmap[2] = (FATTR4_WORD2_TIME_DELEG_ACCESS |
  67. FATTR4_WORD2_TIME_DELEG_MODIFY) & args->bitmap[2];
  68. res->status = 0;
  69. out_iput:
  70. trace_nfs4_cb_getattr(cps->clp, &args->fh, inode, -ntohl(res->status));
  71. nfs_iput_and_deactive(inode);
  72. out:
  73. dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status));
  74. return res->status;
  75. }
  76. __be32 nfs4_callback_recall(void *argp, void *resp,
  77. struct cb_process_state *cps)
  78. {
  79. struct cb_recallargs *args = argp;
  80. struct inode *inode;
  81. __be32 res;
  82. res = htonl(NFS4ERR_OP_NOT_IN_SESSION);
  83. if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
  84. goto out;
  85. dprintk_rcu("NFS: RECALL callback request from %s\n",
  86. rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
  87. res = htonl(NFS4ERR_BADHANDLE);
  88. inode = nfs_delegation_find_inode(cps->clp, &args->fh);
  89. if (IS_ERR(inode)) {
  90. if (inode == ERR_PTR(-EAGAIN))
  91. res = htonl(NFS4ERR_DELAY);
  92. trace_nfs4_cb_recall(cps->clp, &args->fh, NULL,
  93. &args->stateid, -ntohl(res));
  94. goto out;
  95. }
  96. /* Set up a helper thread to actually return the delegation */
  97. switch (nfs_async_inode_return_delegation(inode, &args->stateid)) {
  98. case 0:
  99. res = 0;
  100. break;
  101. case -ENOENT:
  102. res = htonl(NFS4ERR_BAD_STATEID);
  103. break;
  104. default:
  105. res = htonl(NFS4ERR_RESOURCE);
  106. }
  107. trace_nfs4_cb_recall(cps->clp, &args->fh, inode,
  108. &args->stateid, -ntohl(res));
  109. nfs_iput_and_deactive(inode);
  110. out:
  111. dprintk("%s: exit with status = %d\n", __func__, ntohl(res));
  112. return res;
  113. }
  114. /*
  115. * Lookup a layout inode by stateid
  116. *
  117. * Note: returns a refcount on the inode and superblock
  118. */
  119. static struct inode *nfs_layout_find_inode_by_stateid(struct nfs_client *clp,
  120. const nfs4_stateid *stateid)
  121. __must_hold(RCU)
  122. {
  123. struct nfs_server *server;
  124. struct inode *inode;
  125. struct pnfs_layout_hdr *lo;
  126. rcu_read_lock();
  127. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  128. list_for_each_entry_rcu(lo, &server->layouts, plh_layouts) {
  129. if (!pnfs_layout_is_valid(lo))
  130. continue;
  131. if (!nfs4_stateid_match_other(stateid, &lo->plh_stateid))
  132. continue;
  133. if (nfs_sb_active(server->super))
  134. inode = igrab(lo->plh_inode);
  135. else
  136. inode = ERR_PTR(-EAGAIN);
  137. rcu_read_unlock();
  138. if (inode)
  139. return inode;
  140. nfs_sb_deactive(server->super);
  141. return ERR_PTR(-EAGAIN);
  142. }
  143. }
  144. rcu_read_unlock();
  145. return ERR_PTR(-ENOENT);
  146. }
  147. /*
  148. * Lookup a layout inode by filehandle.
  149. *
  150. * Note: returns a refcount on the inode and superblock
  151. *
  152. */
  153. static struct inode *nfs_layout_find_inode_by_fh(struct nfs_client *clp,
  154. const struct nfs_fh *fh)
  155. {
  156. struct nfs_server *server;
  157. struct nfs_inode *nfsi;
  158. struct inode *inode;
  159. struct pnfs_layout_hdr *lo;
  160. rcu_read_lock();
  161. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  162. list_for_each_entry_rcu(lo, &server->layouts, plh_layouts) {
  163. nfsi = NFS_I(lo->plh_inode);
  164. if (nfs_compare_fh(fh, &nfsi->fh))
  165. continue;
  166. if (nfsi->layout != lo)
  167. continue;
  168. if (nfs_sb_active(server->super))
  169. inode = igrab(lo->plh_inode);
  170. else
  171. inode = ERR_PTR(-EAGAIN);
  172. rcu_read_unlock();
  173. if (inode)
  174. return inode;
  175. nfs_sb_deactive(server->super);
  176. return ERR_PTR(-EAGAIN);
  177. }
  178. }
  179. rcu_read_unlock();
  180. return ERR_PTR(-ENOENT);
  181. }
  182. static struct inode *nfs_layout_find_inode(struct nfs_client *clp,
  183. const struct nfs_fh *fh,
  184. const nfs4_stateid *stateid)
  185. {
  186. struct inode *inode;
  187. inode = nfs_layout_find_inode_by_stateid(clp, stateid);
  188. if (inode == ERR_PTR(-ENOENT))
  189. inode = nfs_layout_find_inode_by_fh(clp, fh);
  190. return inode;
  191. }
  192. /*
  193. * Enforce RFC5661 section 12.5.5.2.1. (Layout Recall and Return Sequencing)
  194. */
  195. static u32 pnfs_check_callback_stateid(struct pnfs_layout_hdr *lo,
  196. const nfs4_stateid *new,
  197. struct cb_process_state *cps)
  198. {
  199. u32 oldseq, newseq;
  200. /* Is the stateid not initialised? */
  201. if (!pnfs_layout_is_valid(lo))
  202. return NFS4ERR_NOMATCHING_LAYOUT;
  203. /* Mismatched stateid? */
  204. if (!nfs4_stateid_match_other(&lo->plh_stateid, new))
  205. return NFS4ERR_BAD_STATEID;
  206. newseq = be32_to_cpu(new->seqid);
  207. /* Are we already in a layout recall situation? */
  208. if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags))
  209. return NFS4ERR_DELAY;
  210. /*
  211. * Check that the stateid matches what we think it should be.
  212. * Note that if the server sent us a list of referring calls,
  213. * and we know that those have completed, then we trust the
  214. * stateid argument is correct.
  215. */
  216. oldseq = be32_to_cpu(lo->plh_stateid.seqid);
  217. if (newseq > oldseq + 1 && !cps->referring_calls)
  218. return NFS4ERR_DELAY;
  219. /* Crazy server! */
  220. if (newseq <= oldseq)
  221. return NFS4ERR_OLD_STATEID;
  222. return NFS_OK;
  223. }
  224. static u32 initiate_file_draining(struct nfs_client *clp,
  225. struct cb_layoutrecallargs *args,
  226. struct cb_process_state *cps)
  227. {
  228. struct inode *ino;
  229. struct pnfs_layout_hdr *lo;
  230. u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
  231. LIST_HEAD(free_me_list);
  232. ino = nfs_layout_find_inode(clp, &args->cbl_fh, &args->cbl_stateid);
  233. if (IS_ERR(ino)) {
  234. if (ino == ERR_PTR(-EAGAIN))
  235. rv = NFS4ERR_DELAY;
  236. goto out_noput;
  237. }
  238. pnfs_layoutcommit_inode(ino, false);
  239. spin_lock(&ino->i_lock);
  240. lo = NFS_I(ino)->layout;
  241. if (!lo) {
  242. spin_unlock(&ino->i_lock);
  243. goto out;
  244. }
  245. pnfs_get_layout_hdr(lo);
  246. rv = pnfs_check_callback_stateid(lo, &args->cbl_stateid, cps);
  247. if (rv != NFS_OK)
  248. goto unlock;
  249. /*
  250. * Enforce RFC5661 Section 12.5.5.2.1.5 (Bulk Recall and Return)
  251. */
  252. if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
  253. rv = NFS4ERR_DELAY;
  254. goto unlock;
  255. }
  256. pnfs_set_layout_stateid(lo, &args->cbl_stateid, NULL, true);
  257. switch (pnfs_mark_matching_lsegs_return(lo, &free_me_list,
  258. &args->cbl_range,
  259. be32_to_cpu(args->cbl_stateid.seqid))) {
  260. case 0:
  261. case -EBUSY:
  262. /* There are layout segments that need to be returned */
  263. rv = NFS4_OK;
  264. break;
  265. case -ENOENT:
  266. set_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags);
  267. /* Embrace your forgetfulness! */
  268. rv = NFS4ERR_NOMATCHING_LAYOUT;
  269. if (NFS_SERVER(ino)->pnfs_curr_ld->return_range) {
  270. NFS_SERVER(ino)->pnfs_curr_ld->return_range(lo,
  271. &args->cbl_range);
  272. }
  273. }
  274. unlock:
  275. spin_unlock(&ino->i_lock);
  276. pnfs_free_lseg_list(&free_me_list);
  277. /* Free all lsegs that are attached to commit buckets */
  278. nfs_commit_inode(ino, 0);
  279. pnfs_put_layout_hdr(lo);
  280. out:
  281. nfs_iput_and_deactive(ino);
  282. out_noput:
  283. trace_nfs4_cb_layoutrecall_file(clp, &args->cbl_fh, ino,
  284. &args->cbl_stateid, -rv);
  285. return rv;
  286. }
  287. static u32 initiate_bulk_draining(struct nfs_client *clp,
  288. struct cb_layoutrecallargs *args)
  289. {
  290. int stat;
  291. if (args->cbl_recall_type == RETURN_FSID)
  292. stat = pnfs_layout_destroy_byfsid(clp, &args->cbl_fsid,
  293. PNFS_LAYOUT_BULK_RETURN);
  294. else
  295. stat = pnfs_layout_destroy_byclid(clp, PNFS_LAYOUT_BULK_RETURN);
  296. if (stat != 0)
  297. return NFS4ERR_DELAY;
  298. return NFS4ERR_NOMATCHING_LAYOUT;
  299. }
  300. static u32 do_callback_layoutrecall(struct nfs_client *clp,
  301. struct cb_layoutrecallargs *args,
  302. struct cb_process_state *cps)
  303. {
  304. if (args->cbl_recall_type == RETURN_FILE)
  305. return initiate_file_draining(clp, args, cps);
  306. return initiate_bulk_draining(clp, args);
  307. }
  308. __be32 nfs4_callback_layoutrecall(void *argp, void *resp,
  309. struct cb_process_state *cps)
  310. {
  311. struct cb_layoutrecallargs *args = argp;
  312. u32 res = NFS4ERR_OP_NOT_IN_SESSION;
  313. if (cps->clp)
  314. res = do_callback_layoutrecall(cps->clp, args, cps);
  315. return cpu_to_be32(res);
  316. }
  317. static void pnfs_recall_all_layouts(struct nfs_client *clp,
  318. struct cb_process_state *cps)
  319. {
  320. struct cb_layoutrecallargs args;
  321. /* Pretend we got a CB_LAYOUTRECALL(ALL) */
  322. memset(&args, 0, sizeof(args));
  323. args.cbl_recall_type = RETURN_ALL;
  324. /* FIXME we ignore errors, what should we do? */
  325. do_callback_layoutrecall(clp, &args, cps);
  326. }
  327. __be32 nfs4_callback_devicenotify(void *argp, void *resp,
  328. struct cb_process_state *cps)
  329. {
  330. struct cb_devicenotifyargs *args = argp;
  331. const struct pnfs_layoutdriver_type *ld = NULL;
  332. uint32_t i;
  333. __be32 res = 0;
  334. if (!cps->clp) {
  335. res = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION);
  336. goto out;
  337. }
  338. for (i = 0; i < args->ndevs; i++) {
  339. struct cb_devicenotifyitem *dev = &args->devs[i];
  340. if (!ld || ld->id != dev->cbd_layout_type) {
  341. pnfs_put_layoutdriver(ld);
  342. ld = pnfs_find_layoutdriver(dev->cbd_layout_type);
  343. if (!ld)
  344. continue;
  345. }
  346. nfs4_delete_deviceid(ld, cps->clp, &dev->cbd_dev_id);
  347. }
  348. pnfs_put_layoutdriver(ld);
  349. out:
  350. kfree(args->devs);
  351. return res;
  352. }
  353. /*
  354. * Validate the sequenceID sent by the server.
  355. * Return success if the sequenceID is one more than what we last saw on
  356. * this slot, accounting for wraparound. Increments the slot's sequence.
  357. *
  358. * We don't yet implement a duplicate request cache, instead we set the
  359. * back channel ca_maxresponsesize_cached to zero. This is OK for now
  360. * since we only currently implement idempotent callbacks anyway.
  361. *
  362. * We have a single slot backchannel at this time, so we don't bother
  363. * checking the used_slots bit array on the table. The lower layer guarantees
  364. * a single outstanding callback request at a time.
  365. */
  366. static __be32
  367. validate_seqid(const struct nfs4_slot_table *tbl, const struct nfs4_slot *slot,
  368. const struct cb_sequenceargs * args)
  369. {
  370. __be32 ret;
  371. ret = cpu_to_be32(NFS4ERR_BADSLOT);
  372. if (args->csa_slotid > tbl->server_highest_slotid)
  373. goto out_err;
  374. /* Replay */
  375. if (args->csa_sequenceid == slot->seq_nr) {
  376. ret = cpu_to_be32(NFS4ERR_DELAY);
  377. if (nfs4_test_locked_slot(tbl, slot->slot_nr))
  378. goto out_err;
  379. /* Signal process_op to set this error on next op */
  380. ret = cpu_to_be32(NFS4ERR_RETRY_UNCACHED_REP);
  381. if (args->csa_cachethis == 0)
  382. goto out_err;
  383. /* Liar! We never allowed you to set csa_cachethis != 0 */
  384. ret = cpu_to_be32(NFS4ERR_SEQ_FALSE_RETRY);
  385. goto out_err;
  386. }
  387. /* Note: wraparound relies on seq_nr being of type u32 */
  388. /* Misordered request */
  389. ret = cpu_to_be32(NFS4ERR_SEQ_MISORDERED);
  390. if (args->csa_sequenceid != slot->seq_nr + 1)
  391. goto out_err;
  392. return cpu_to_be32(NFS4_OK);
  393. out_err:
  394. trace_nfs4_cb_seqid_err(args, ret);
  395. return ret;
  396. }
  397. /*
  398. * For each referring call triple, check the session's slot table for
  399. * a match. If the slot is in use and the sequence numbers match, the
  400. * client is still waiting for a response to the original request.
  401. */
  402. static int referring_call_exists(struct nfs_client *clp,
  403. uint32_t nrclists,
  404. struct referring_call_list *rclists,
  405. spinlock_t *lock)
  406. __releases(lock)
  407. __acquires(lock)
  408. {
  409. int status = 0;
  410. int found = 0;
  411. int i, j;
  412. struct nfs4_session *session;
  413. struct nfs4_slot_table *tbl;
  414. struct referring_call_list *rclist;
  415. struct referring_call *ref;
  416. /*
  417. * XXX When client trunking is implemented, this becomes
  418. * a session lookup from within the loop
  419. */
  420. session = clp->cl_session;
  421. tbl = &session->fc_slot_table;
  422. for (i = 0; i < nrclists; i++) {
  423. rclist = &rclists[i];
  424. if (memcmp(session->sess_id.data,
  425. rclist->rcl_sessionid.data,
  426. NFS4_MAX_SESSIONID_LEN) != 0)
  427. continue;
  428. for (j = 0; j < rclist->rcl_nrefcalls; j++) {
  429. ref = &rclist->rcl_refcalls[j];
  430. spin_unlock(lock);
  431. status = nfs4_slot_wait_on_seqid(tbl, ref->rc_slotid,
  432. ref->rc_sequenceid, HZ >> 1) < 0;
  433. spin_lock(lock);
  434. if (status)
  435. goto out;
  436. found++;
  437. }
  438. }
  439. out:
  440. return status < 0 ? status : found;
  441. }
  442. __be32 nfs4_callback_sequence(void *argp, void *resp,
  443. struct cb_process_state *cps)
  444. {
  445. struct cb_sequenceargs *args = argp;
  446. struct cb_sequenceres *res = resp;
  447. struct nfs4_slot_table *tbl;
  448. struct nfs4_slot *slot;
  449. struct nfs_client *clp;
  450. int ret;
  451. int i;
  452. __be32 status = htonl(NFS4ERR_BADSESSION);
  453. clp = nfs4_find_client_sessionid(cps->net, args->csa_addr,
  454. &args->csa_sessionid, cps->minorversion);
  455. if (clp == NULL)
  456. goto out;
  457. if (!(clp->cl_session->flags & SESSION4_BACK_CHAN))
  458. goto out;
  459. tbl = &clp->cl_session->bc_slot_table;
  460. /* Set up res before grabbing the spinlock */
  461. memcpy(&res->csr_sessionid, &args->csa_sessionid,
  462. sizeof(res->csr_sessionid));
  463. res->csr_sequenceid = args->csa_sequenceid;
  464. res->csr_slotid = args->csa_slotid;
  465. spin_lock(&tbl->slot_tbl_lock);
  466. /* state manager is resetting the session */
  467. if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state)) {
  468. status = htonl(NFS4ERR_DELAY);
  469. /* Return NFS4ERR_BADSESSION if we're draining the session
  470. * in order to reset it.
  471. */
  472. if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
  473. status = htonl(NFS4ERR_BADSESSION);
  474. goto out_unlock;
  475. }
  476. status = htonl(NFS4ERR_BADSLOT);
  477. slot = nfs4_lookup_slot(tbl, args->csa_slotid);
  478. if (IS_ERR(slot))
  479. goto out_unlock;
  480. res->csr_highestslotid = tbl->server_highest_slotid;
  481. res->csr_target_highestslotid = tbl->target_highest_slotid;
  482. status = validate_seqid(tbl, slot, args);
  483. if (status)
  484. goto out_unlock;
  485. if (!nfs4_try_to_lock_slot(tbl, slot)) {
  486. status = htonl(NFS4ERR_DELAY);
  487. goto out_unlock;
  488. }
  489. cps->slot = slot;
  490. /* The ca_maxresponsesize_cached is 0 with no DRC */
  491. if (args->csa_cachethis != 0) {
  492. status = htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE);
  493. goto out_unlock;
  494. }
  495. /*
  496. * Check for pending referring calls. If a match is found, a
  497. * related callback was received before the response to the original
  498. * call.
  499. */
  500. ret = referring_call_exists(clp, args->csa_nrclists, args->csa_rclists,
  501. &tbl->slot_tbl_lock);
  502. if (ret < 0) {
  503. status = htonl(NFS4ERR_DELAY);
  504. goto out_unlock;
  505. }
  506. cps->referring_calls = ret;
  507. /*
  508. * RFC5661 20.9.3
  509. * If CB_SEQUENCE returns an error, then the state of the slot
  510. * (sequence ID, cached reply) MUST NOT change.
  511. */
  512. slot->seq_nr = args->csa_sequenceid;
  513. out_unlock:
  514. spin_unlock(&tbl->slot_tbl_lock);
  515. out:
  516. cps->clp = clp; /* put in nfs4_callback_compound */
  517. for (i = 0; i < args->csa_nrclists; i++)
  518. kfree(args->csa_rclists[i].rcl_refcalls);
  519. kfree(args->csa_rclists);
  520. if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) {
  521. cps->drc_status = status;
  522. status = 0;
  523. } else
  524. res->csr_status = status;
  525. trace_nfs4_cb_sequence(args, res, status);
  526. return status;
  527. }
  528. static bool
  529. validate_bitmap_values(unsigned int mask)
  530. {
  531. return (mask & ~RCA4_TYPE_MASK_ALL) == 0;
  532. }
  533. __be32 nfs4_callback_recallany(void *argp, void *resp,
  534. struct cb_process_state *cps)
  535. {
  536. struct cb_recallanyargs *args = argp;
  537. __be32 status;
  538. fmode_t flags = 0;
  539. bool schedule_manager = false;
  540. status = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION);
  541. if (!cps->clp) /* set in cb_sequence */
  542. goto out;
  543. dprintk_rcu("NFS: RECALL_ANY callback request from %s\n",
  544. rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
  545. status = cpu_to_be32(NFS4ERR_INVAL);
  546. if (!validate_bitmap_values(args->craa_type_mask))
  547. goto out;
  548. status = cpu_to_be32(NFS4_OK);
  549. if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_RDATA_DLG))
  550. flags = FMODE_READ;
  551. if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_WDATA_DLG))
  552. flags |= FMODE_WRITE;
  553. if (flags)
  554. nfs_expire_unused_delegation_types(cps->clp, flags);
  555. if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_FILE_LAYOUT))
  556. pnfs_recall_all_layouts(cps->clp, cps);
  557. if (args->craa_type_mask & BIT(PNFS_FF_RCA4_TYPE_MASK_READ)) {
  558. set_bit(NFS4CLNT_RECALL_ANY_LAYOUT_READ, &cps->clp->cl_state);
  559. schedule_manager = true;
  560. }
  561. if (args->craa_type_mask & BIT(PNFS_FF_RCA4_TYPE_MASK_RW)) {
  562. set_bit(NFS4CLNT_RECALL_ANY_LAYOUT_RW, &cps->clp->cl_state);
  563. schedule_manager = true;
  564. }
  565. if (schedule_manager)
  566. nfs4_schedule_state_manager(cps->clp);
  567. out:
  568. dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
  569. return status;
  570. }
  571. /* Reduce the fore channel's max_slots to the target value */
  572. __be32 nfs4_callback_recallslot(void *argp, void *resp,
  573. struct cb_process_state *cps)
  574. {
  575. struct cb_recallslotargs *args = argp;
  576. struct nfs4_slot_table *fc_tbl;
  577. __be32 status;
  578. status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
  579. if (!cps->clp) /* set in cb_sequence */
  580. goto out;
  581. dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target highest slotid %u\n",
  582. rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR),
  583. args->crsa_target_highest_slotid);
  584. fc_tbl = &cps->clp->cl_session->fc_slot_table;
  585. status = htonl(NFS4_OK);
  586. nfs41_set_target_slotid(fc_tbl, args->crsa_target_highest_slotid);
  587. nfs41_notify_server(cps->clp);
  588. out:
  589. dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
  590. return status;
  591. }
  592. __be32 nfs4_callback_notify_lock(void *argp, void *resp,
  593. struct cb_process_state *cps)
  594. {
  595. struct cb_notify_lock_args *args = argp;
  596. if (!cps->clp) /* set in cb_sequence */
  597. return htonl(NFS4ERR_OP_NOT_IN_SESSION);
  598. dprintk_rcu("NFS: CB_NOTIFY_LOCK request from %s\n",
  599. rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
  600. /* Don't wake anybody if the string looked bogus */
  601. if (args->cbnl_valid)
  602. __wake_up(&cps->clp->cl_lock_waitq, TASK_NORMAL, 0, args);
  603. return htonl(NFS4_OK);
  604. }
  605. #ifdef CONFIG_NFS_V4_2
  606. static void nfs4_copy_cb_args(struct nfs4_copy_state *cp_state,
  607. struct cb_offloadargs *args)
  608. {
  609. cp_state->count = args->wr_count;
  610. cp_state->error = args->error;
  611. if (!args->error) {
  612. cp_state->verf.committed = args->wr_writeverf.committed;
  613. memcpy(&cp_state->verf.verifier.data[0],
  614. &args->wr_writeverf.verifier.data[0],
  615. NFS4_VERIFIER_SIZE);
  616. }
  617. }
  618. __be32 nfs4_callback_offload(void *data, void *dummy,
  619. struct cb_process_state *cps)
  620. {
  621. struct cb_offloadargs *args = data;
  622. struct nfs_server *server;
  623. struct nfs4_copy_state *copy, *tmp_copy;
  624. bool found = false;
  625. copy = kzalloc_obj(struct nfs4_copy_state);
  626. if (!copy)
  627. return cpu_to_be32(NFS4ERR_DELAY);
  628. spin_lock(&cps->clp->cl_lock);
  629. rcu_read_lock();
  630. list_for_each_entry_rcu(server, &cps->clp->cl_superblocks,
  631. client_link) {
  632. list_for_each_entry(tmp_copy, &server->ss_copies, copies) {
  633. if (memcmp(args->coa_stateid.other,
  634. tmp_copy->stateid.other,
  635. sizeof(args->coa_stateid.other)))
  636. continue;
  637. nfs4_copy_cb_args(tmp_copy, args);
  638. complete(&tmp_copy->completion);
  639. found = true;
  640. goto out;
  641. }
  642. }
  643. out:
  644. rcu_read_unlock();
  645. if (!found) {
  646. memcpy(&copy->stateid, &args->coa_stateid, NFS4_STATEID_SIZE);
  647. nfs4_copy_cb_args(copy, args);
  648. list_add_tail(&copy->copies, &cps->clp->pending_cb_stateids);
  649. } else
  650. kfree(copy);
  651. spin_unlock(&cps->clp->cl_lock);
  652. trace_nfs4_cb_offload(&args->coa_fh, &args->coa_stateid,
  653. args->wr_count, args->error,
  654. args->wr_writeverf.committed);
  655. return 0;
  656. }
  657. #endif /* CONFIG_NFS_V4_2 */