callback_proc.c 18 KB

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