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 case 0: 296 case -EBUSY: 297 /* There are layout segments that need to be returned */ 298 rv = NFS4_OK; 299 break; 300 case -ENOENT: 301 set_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags); 302 /* Embrace your forgetfulness! */ 303 rv = NFS4ERR_NOMATCHING_LAYOUT; 304 305 return_range = true; 306 } 307 unlock: 308 spin_unlock(&ino->i_lock); 309 if (return_range && NFS_SERVER(ino)->pnfs_curr_ld->return_range) 310 NFS_SERVER(ino)->pnfs_curr_ld->return_range(lo, 311 &args->cbl_range); 312 pnfs_free_lseg_list(&free_me_list); 313 /* Free all lsegs that are attached to commit buckets */ 314 nfs_commit_inode(ino, 0); 315 pnfs_put_layout_hdr(lo); 316 out: 317 nfs_iput_and_deactive(ino); 318 out_noput: 319 trace_nfs4_cb_layoutrecall_file(clp, &args->cbl_fh, ino, 320 &args->cbl_stateid, -rv); 321 return rv; 322 } 323 324 static u32 initiate_bulk_draining(struct nfs_client *clp, 325 struct cb_layoutrecallargs *args) 326 { 327 int stat; 328 329 if (args->cbl_recall_type == RETURN_FSID) 330 stat = pnfs_layout_destroy_byfsid(clp, &args->cbl_fsid, 331 PNFS_LAYOUT_BULK_RETURN); 332 else 333 stat = pnfs_layout_destroy_byclid(clp, PNFS_LAYOUT_BULK_RETURN); 334 if (stat != 0) 335 return NFS4ERR_DELAY; 336 return NFS4ERR_NOMATCHING_LAYOUT; 337 } 338 339 static u32 do_callback_layoutrecall(struct nfs_client *clp, 340 struct cb_layoutrecallargs *args, 341 struct cb_process_state *cps) 342 { 343 if (args->cbl_recall_type == RETURN_FILE) 344 return initiate_file_draining(clp, args, cps); 345 return initiate_bulk_draining(clp, args); 346 } 347 348 __be32 nfs4_callback_layoutrecall(void *argp, void *resp, 349 struct cb_process_state *cps) 350 { 351 struct cb_layoutrecallargs *args = argp; 352 u32 res = NFS4ERR_OP_NOT_IN_SESSION; 353 354 if (cps->clp) 355 res = do_callback_layoutrecall(cps->clp, args, cps); 356 return cpu_to_be32(res); 357 } 358 359 static void pnfs_recall_all_layouts(struct nfs_client *clp, 360 struct cb_process_state *cps) 361 { 362 struct cb_layoutrecallargs args; 363 364 /* Pretend we got a CB_LAYOUTRECALL(ALL) */ 365 memset(&args, 0, sizeof(args)); 366 args.cbl_recall_type = RETURN_ALL; 367 /* FIXME we ignore errors, what should we do? */ 368 do_callback_layoutrecall(clp, &args, cps); 369 } 370 371 __be32 nfs4_callback_devicenotify(void *argp, void *resp, 372 struct cb_process_state *cps) 373 { 374 struct cb_devicenotifyargs *args = argp; 375 const struct pnfs_layoutdriver_type *ld = NULL; 376 uint32_t i; 377 __be32 res = 0; 378 379 if (!cps->clp) { 380 res = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION); 381 goto out; 382 } 383 384 for (i = 0; i < args->ndevs; i++) { 385 struct cb_devicenotifyitem *dev = &args->devs[i]; 386 387 if (!ld || ld->id != dev->cbd_layout_type) { 388 pnfs_put_layoutdriver(ld); 389 ld = pnfs_find_layoutdriver(dev->cbd_layout_type); 390 if (!ld) 391 continue; 392 } 393 nfs4_delete_deviceid(ld, cps->clp, &dev->cbd_dev_id); 394 } 395 pnfs_put_layoutdriver(ld); 396 out: 397 kfree(args->devs); 398 return res; 399 } 400 401 /* 402 * Validate the sequenceID sent by the server. 403 * Return success if the sequenceID is one more than what we last saw on 404 * this slot, accounting for wraparound. Increments the slot's sequence. 405 * 406 * We don't yet implement a duplicate request cache, instead we set the 407 * back channel ca_maxresponsesize_cached to zero. This is OK for now 408 * since we only currently implement idempotent callbacks anyway. 409 * 410 * We have a single slot backchannel at this time, so we don't bother 411 * checking the used_slots bit array on the table. The lower layer guarantees 412 * a single outstanding callback request at a time. 413 */ 414 static __be32 415 validate_seqid(const struct nfs4_slot_table *tbl, const struct nfs4_slot *slot, 416 const struct cb_sequenceargs * args) 417 { 418 __be32 ret; 419 420 ret = cpu_to_be32(NFS4ERR_BADSLOT); 421 if (args->csa_slotid > tbl->server_highest_slotid) 422 goto out_err; 423 424 /* Replay */ 425 if (args->csa_sequenceid == slot->seq_nr) { 426 ret = cpu_to_be32(NFS4ERR_DELAY); 427 if (nfs4_test_locked_slot(tbl, slot->slot_nr)) 428 goto out_err; 429 430 /* Signal process_op to set this error on next op */ 431 ret = cpu_to_be32(NFS4ERR_RETRY_UNCACHED_REP); 432 if (args->csa_cachethis == 0) 433 goto out_err; 434 435 /* Liar! We never allowed you to set csa_cachethis != 0 */ 436 ret = cpu_to_be32(NFS4ERR_SEQ_FALSE_RETRY); 437 goto out_err; 438 } 439 440 /* Note: wraparound relies on seq_nr being of type u32 */ 441 /* Misordered request */ 442 ret = cpu_to_be32(NFS4ERR_SEQ_MISORDERED); 443 if (args->csa_sequenceid != slot->seq_nr + 1) 444 goto out_err; 445 446 return cpu_to_be32(NFS4_OK); 447 448 out_err: 449 trace_nfs4_cb_seqid_err(args, ret); 450 return ret; 451 } 452 453 /* 454 * For each referring call triple, check the session's slot table for 455 * a match. If the slot is in use and the sequence numbers match, the 456 * client is still waiting for a response to the original request. 457 */ 458 static int referring_call_exists(struct nfs_client *clp, 459 uint32_t nrclists, 460 struct referring_call_list *rclists, 461 spinlock_t *lock) 462 __releases(lock) 463 __acquires(lock) 464 { 465 int status = 0; 466 int found = 0; 467 int i, j; 468 struct nfs4_session *session; 469 struct nfs4_slot_table *tbl; 470 struct referring_call_list *rclist; 471 struct referring_call *ref; 472 473 /* 474 * XXX When client trunking is implemented, this becomes 475 * a session lookup from within the loop 476 */ 477 session = clp->cl_session; 478 tbl = &session->fc_slot_table; 479 480 for (i = 0; i < nrclists; i++) { 481 rclist = &rclists[i]; 482 if (memcmp(session->sess_id.data, 483 rclist->rcl_sessionid.data, 484 NFS4_MAX_SESSIONID_LEN) != 0) 485 continue; 486 487 for (j = 0; j < rclist->rcl_nrefcalls; j++) { 488 ref = &rclist->rcl_refcalls[j]; 489 spin_unlock(lock); 490 status = nfs4_slot_wait_on_seqid(tbl, ref->rc_slotid, 491 ref->rc_sequenceid, HZ >> 1) < 0; 492 spin_lock(lock); 493 if (status) 494 goto out; 495 found++; 496 } 497 } 498 499 out: 500 return status < 0 ? status : found; 501 } 502 503 __be32 nfs4_callback_sequence(void *argp, void *resp, 504 struct cb_process_state *cps) 505 { 506 struct cb_sequenceargs *args = argp; 507 struct cb_sequenceres *res = resp; 508 struct nfs4_slot_table *tbl; 509 struct nfs4_slot *slot; 510 struct nfs_client *clp; 511 int ret; 512 int i; 513 __be32 status = htonl(NFS4ERR_BADSESSION); 514 515 clp = nfs4_find_client_sessionid(cps->net, args->csa_addr, 516 &args->csa_sessionid, cps->minorversion); 517 if (clp == NULL) 518 goto out; 519 520 if (!(clp->cl_session->flags & SESSION4_BACK_CHAN)) 521 goto out; 522 523 tbl = &clp->cl_session->bc_slot_table; 524 525 /* Set up res before grabbing the spinlock */ 526 memcpy(&res->csr_sessionid, &args->csa_sessionid, 527 sizeof(res->csr_sessionid)); 528 res->csr_sequenceid = args->csa_sequenceid; 529 res->csr_slotid = args->csa_slotid; 530 531 spin_lock(&tbl->slot_tbl_lock); 532 /* state manager is resetting the session */ 533 if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state)) { 534 status = htonl(NFS4ERR_DELAY); 535 /* Return NFS4ERR_BADSESSION if we're draining the session 536 * in order to reset it. 537 */ 538 if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)) 539 status = htonl(NFS4ERR_BADSESSION); 540 goto out_unlock; 541 } 542 543 status = htonl(NFS4ERR_BADSLOT); 544 slot = nfs4_lookup_slot(tbl, args->csa_slotid); 545 if (IS_ERR(slot)) 546 goto out_unlock; 547 548 res->csr_highestslotid = tbl->server_highest_slotid; 549 res->csr_target_highestslotid = tbl->target_highest_slotid; 550 551 status = validate_seqid(tbl, slot, args); 552 if (status) 553 goto out_unlock; 554 if (!nfs4_try_to_lock_slot(tbl, slot)) { 555 status = htonl(NFS4ERR_DELAY); 556 goto out_unlock; 557 } 558 cps->slot = slot; 559 560 /* The ca_maxresponsesize_cached is 0 with no DRC */ 561 if (args->csa_cachethis != 0) { 562 status = htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE); 563 goto out_unlock; 564 } 565 566 /* 567 * Check for pending referring calls. If a match is found, a 568 * related callback was received before the response to the original 569 * call. 570 */ 571 ret = referring_call_exists(clp, args->csa_nrclists, args->csa_rclists, 572 &tbl->slot_tbl_lock); 573 if (ret < 0) { 574 status = htonl(NFS4ERR_DELAY); 575 goto out_unlock; 576 } 577 cps->referring_calls = ret; 578 579 /* 580 * RFC5661 20.9.3 581 * If CB_SEQUENCE returns an error, then the state of the slot 582 * (sequence ID, cached reply) MUST NOT change. 583 */ 584 slot->seq_nr = args->csa_sequenceid; 585 out_unlock: 586 spin_unlock(&tbl->slot_tbl_lock); 587 588 out: 589 cps->clp = clp; /* put in nfs4_callback_compound */ 590 for (i = 0; i < args->csa_nrclists; i++) 591 kfree(args->csa_rclists[i].rcl_refcalls); 592 kfree(args->csa_rclists); 593 594 if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) { 595 cps->drc_status = status; 596 status = 0; 597 } else 598 res->csr_status = status; 599 600 trace_nfs4_cb_sequence(args, res, status); 601 return status; 602 } 603 604 static bool 605 validate_bitmap_values(unsigned int mask) 606 { 607 return (mask & ~RCA4_TYPE_MASK_ALL) == 0; 608 } 609 610 __be32 nfs4_callback_recallany(void *argp, void *resp, 611 struct cb_process_state *cps) 612 { 613 struct cb_recallanyargs *args = argp; 614 __be32 status; 615 fmode_t flags = 0; 616 bool schedule_manager = false; 617 618 status = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION); 619 if (!cps->clp) /* set in cb_sequence */ 620 goto out; 621 622 dprintk_rcu("NFS: RECALL_ANY callback request from %s\n", 623 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 624 625 status = cpu_to_be32(NFS4ERR_INVAL); 626 if (!validate_bitmap_values(args->craa_type_mask)) 627 goto out; 628 629 status = cpu_to_be32(NFS4_OK); 630 if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_RDATA_DLG)) 631 flags = FMODE_READ; 632 if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_WDATA_DLG)) 633 flags |= FMODE_WRITE; 634 if (flags) 635 nfs_expire_unused_delegation_types(cps->clp, flags); 636 637 if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_FILE_LAYOUT)) 638 pnfs_recall_all_layouts(cps->clp, cps); 639 640 if (args->craa_type_mask & BIT(PNFS_FF_RCA4_TYPE_MASK_READ)) { 641 set_bit(NFS4CLNT_RECALL_ANY_LAYOUT_READ, &cps->clp->cl_state); 642 schedule_manager = true; 643 } 644 if (args->craa_type_mask & BIT(PNFS_FF_RCA4_TYPE_MASK_RW)) { 645 set_bit(NFS4CLNT_RECALL_ANY_LAYOUT_RW, &cps->clp->cl_state); 646 schedule_manager = true; 647 } 648 if (schedule_manager) 649 nfs4_schedule_state_manager(cps->clp); 650 651 out: 652 dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); 653 return status; 654 } 655 656 /* Reduce the fore channel's max_slots to the target value */ 657 __be32 nfs4_callback_recallslot(void *argp, void *resp, 658 struct cb_process_state *cps) 659 { 660 struct cb_recallslotargs *args = argp; 661 struct nfs4_slot_table *fc_tbl; 662 __be32 status; 663 664 status = htonl(NFS4ERR_OP_NOT_IN_SESSION); 665 if (!cps->clp) /* set in cb_sequence */ 666 goto out; 667 668 dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target highest slotid %u\n", 669 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR), 670 args->crsa_target_highest_slotid); 671 672 fc_tbl = &cps->clp->cl_session->fc_slot_table; 673 674 status = htonl(NFS4_OK); 675 676 nfs41_set_target_slotid(fc_tbl, args->crsa_target_highest_slotid); 677 nfs41_notify_server(cps->clp); 678 out: 679 dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); 680 return status; 681 } 682 683 __be32 nfs4_callback_notify_lock(void *argp, void *resp, 684 struct cb_process_state *cps) 685 { 686 struct cb_notify_lock_args *args = argp; 687 688 if (!cps->clp) /* set in cb_sequence */ 689 return htonl(NFS4ERR_OP_NOT_IN_SESSION); 690 691 dprintk_rcu("NFS: CB_NOTIFY_LOCK request from %s\n", 692 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 693 694 /* Don't wake anybody if the string looked bogus */ 695 if (args->cbnl_valid) 696 __wake_up(&cps->clp->cl_lock_waitq, TASK_NORMAL, 0, args); 697 698 return htonl(NFS4_OK); 699 } 700 #ifdef CONFIG_NFS_V4_2 701 static void nfs4_copy_cb_args(struct nfs4_copy_state *cp_state, 702 struct cb_offloadargs *args) 703 { 704 cp_state->count = args->wr_count; 705 cp_state->error = args->error; 706 if (!args->error) { 707 cp_state->verf.committed = args->wr_writeverf.committed; 708 memcpy(&cp_state->verf.verifier.data[0], 709 &args->wr_writeverf.verifier.data[0], 710 NFS4_VERIFIER_SIZE); 711 } 712 } 713 714 __be32 nfs4_callback_offload(void *data, void *dummy, 715 struct cb_process_state *cps) 716 { 717 struct cb_offloadargs *args = data; 718 struct nfs_server *server; 719 struct nfs4_copy_state *copy, *tmp_copy; 720 bool found = false; 721 722 copy = kzalloc_obj(struct nfs4_copy_state); 723 if (!copy) 724 return cpu_to_be32(NFS4ERR_DELAY); 725 726 spin_lock(&cps->clp->cl_lock); 727 rcu_read_lock(); 728 list_for_each_entry_rcu(server, &cps->clp->cl_superblocks, 729 client_link) { 730 list_for_each_entry(tmp_copy, &server->ss_copies, copies) { 731 if (memcmp(args->coa_stateid.other, 732 tmp_copy->stateid.other, 733 sizeof(args->coa_stateid.other))) 734 continue; 735 nfs4_copy_cb_args(tmp_copy, args); 736 complete(&tmp_copy->completion); 737 found = true; 738 goto out; 739 } 740 } 741 out: 742 rcu_read_unlock(); 743 if (!found) { 744 memcpy(©->stateid, &args->coa_stateid, NFS4_STATEID_SIZE); 745 nfs4_copy_cb_args(copy, args); 746 list_add_tail(©->copies, &cps->clp->pending_cb_stateids); 747 } else 748 kfree(copy); 749 spin_unlock(&cps->clp->cl_lock); 750 751 trace_nfs4_cb_offload(&args->coa_fh, &args->coa_stateid, 752 args->wr_count, args->error, 753 args->wr_writeverf.committed); 754 return 0; 755 } 756 #endif /* CONFIG_NFS_V4_2 */ 757