callback_proc.c 19 KB

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