callback_proc.c 19 KB

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