callback_proc.c 19 KB

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