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