1 /* 2 * Server-side types for NFSv4. 3 * 4 * Copyright (c) 2002 The Regents of the University of Michigan. 5 * All rights reserved. 6 * 7 * Kendrick Smith <kmsmith@umich.edu> 8 * Andy Adamson <andros@umich.edu> 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its 20 * contributors may be used to endorse or promote products derived 21 * from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 */ 36 37 #ifndef _LINUX_NFSD_XDR4_H 38 #define _LINUX_NFSD_XDR4_H 39 40 #include <linux/nfs_fh.h> 41 42 #include "state.h" 43 #include "vfs.h" 44 45 #define NFSD4_MAX_TAGLEN 128 46 #define XDR_LEN(n) (((n) + 3) & ~3) 47 48 #define CURRENT_STATE_ID_FLAG (1<<0) 49 #define SAVED_STATE_ID_FLAG (1<<1) 50 51 #define SET_CSTATE_FLAG(c, f) ((c)->sid_flags |= (f)) 52 #define HAS_CSTATE_FLAG(c, f) ((c)->sid_flags & (f)) 53 #define CLEAR_CSTATE_FLAG(c, f) ((c)->sid_flags &= ~(f)) 54 55 struct nfsd4_compound_state { 56 struct svc_fh current_fh; 57 struct svc_fh save_fh; 58 struct nfs4_stateowner *replay_owner; 59 struct nfs4_client *clp; 60 /* For sessions DRC */ 61 struct nfsd4_session *session; 62 struct nfsd4_slot *slot; 63 int data_offset; 64 bool spo_must_allowed; 65 bool slot_owned; 66 size_t iovlen; 67 u32 minorversion; 68 __be32 status; 69 stateid_t current_stateid; 70 stateid_t save_stateid; 71 /* to indicate current and saved state id presents */ 72 u32 sid_flags; 73 }; 74 75 static inline bool nfsd4_has_session(struct nfsd4_compound_state *cs) 76 { 77 return cs->slot != NULL; 78 } 79 80 struct nfsd4_change_info { 81 u32 atomic; 82 u64 before_change; 83 u64 after_change; 84 }; 85 86 struct nfsd4_access { 87 u32 ac_req_access; /* request */ 88 u32 ac_supported; /* response */ 89 u32 ac_resp_access; /* response */ 90 }; 91 92 struct nfsd4_close { 93 u32 cl_seqid; /* request */ 94 stateid_t cl_stateid; /* request+response */ 95 }; 96 97 struct nfsd4_commit { 98 u64 co_offset; /* request */ 99 u32 co_count; /* request */ 100 nfs4_verifier co_verf; /* response */ 101 }; 102 103 struct nfsd4_create { 104 u32 cr_namelen; /* request */ 105 char * cr_name; /* request */ 106 u32 cr_type; /* request */ 107 union { /* request */ 108 struct { 109 u32 datalen; 110 char *data; 111 struct kvec first; 112 } link; /* NF4LNK */ 113 struct { 114 u32 specdata1; 115 u32 specdata2; 116 } dev; /* NF4BLK, NF4CHR */ 117 } u; 118 u32 cr_bmval[3]; /* request */ 119 struct iattr cr_iattr; /* request */ 120 int cr_umask; /* request */ 121 struct nfsd4_change_info cr_cinfo; /* response */ 122 struct nfs4_acl *cr_acl; 123 struct posix_acl *cr_dpacl; 124 struct posix_acl *cr_pacl; 125 struct xdr_netobj cr_label; 126 }; 127 #define cr_datalen u.link.datalen 128 #define cr_data u.link.data 129 #define cr_first u.link.first 130 #define cr_specdata1 u.dev.specdata1 131 #define cr_specdata2 u.dev.specdata2 132 133 struct nfsd4_delegreturn { 134 stateid_t dr_stateid; 135 }; 136 137 struct nfsd4_getattr { 138 u32 ga_bmval[3]; /* request */ 139 struct svc_fh *ga_fhp; /* response */ 140 }; 141 142 struct nfsd4_link { 143 u32 li_namelen; /* request */ 144 char * li_name; /* request */ 145 struct nfsd4_change_info li_cinfo; /* response */ 146 }; 147 148 struct nfsd4_lock_denied { 149 clientid_t ld_clientid; 150 struct xdr_netobj ld_owner; 151 u64 ld_start; 152 u64 ld_length; 153 u32 ld_type; 154 }; 155 156 struct nfsd4_lock { 157 /* request */ 158 u32 lk_type; 159 u32 lk_reclaim; /* boolean */ 160 u64 lk_offset; 161 u64 lk_length; 162 u32 lk_is_new; 163 union { 164 struct { 165 u32 open_seqid; 166 stateid_t open_stateid; 167 u32 lock_seqid; 168 clientid_t clientid; 169 struct xdr_netobj owner; 170 } new; 171 struct { 172 stateid_t lock_stateid; 173 u32 lock_seqid; 174 } old; 175 } v; 176 177 /* response */ 178 stateid_t lk_resp_stateid; 179 struct nfsd4_lock_denied lk_denied; 180 }; 181 #define lk_new_open_seqid v.new.open_seqid 182 #define lk_new_open_stateid v.new.open_stateid 183 #define lk_new_lock_seqid v.new.lock_seqid 184 #define lk_new_clientid v.new.clientid 185 #define lk_new_owner v.new.owner 186 #define lk_old_lock_stateid v.old.lock_stateid 187 #define lk_old_lock_seqid v.old.lock_seqid 188 189 struct nfsd4_lockt { 190 u32 lt_type; 191 clientid_t lt_clientid; 192 struct xdr_netobj lt_owner; 193 u64 lt_offset; 194 u64 lt_length; 195 struct nfsd4_lock_denied lt_denied; 196 }; 197 198 struct nfsd4_locku { 199 u32 lu_type; 200 u32 lu_seqid; 201 stateid_t lu_stateid; 202 u64 lu_offset; 203 u64 lu_length; 204 }; 205 206 207 struct nfsd4_lookup { 208 u32 lo_len; /* request */ 209 char * lo_name; /* request */ 210 }; 211 212 struct nfsd4_putfh { 213 u32 pf_fhlen; /* request */ 214 char *pf_fhval; /* request */ 215 bool no_verify; /* represents foreigh fh */ 216 }; 217 218 struct nfsd4_getxattr { 219 char *getxa_name; /* request */ 220 u32 getxa_len; /* request */ 221 void *getxa_buf; 222 }; 223 224 struct nfsd4_setxattr { 225 u32 setxa_flags; /* request */ 226 char *setxa_name; /* request */ 227 char *setxa_buf; /* request */ 228 u32 setxa_len; /* request */ 229 struct nfsd4_change_info setxa_cinfo; /* response */ 230 }; 231 232 struct nfsd4_removexattr { 233 char *rmxa_name; /* request */ 234 struct nfsd4_change_info rmxa_cinfo; /* response */ 235 }; 236 237 struct nfsd4_listxattrs { 238 u64 lsxa_cookie; /* request */ 239 u32 lsxa_maxcount; /* request */ 240 char *lsxa_buf; /* unfiltered buffer (reply) */ 241 u32 lsxa_len; /* unfiltered len (reply) */ 242 }; 243 244 struct nfsd4_open { 245 u32 op_claim_type; /* request */ 246 u32 op_fnamelen; 247 char * op_fname; /* request - everything but CLAIM_PREV */ 248 u32 op_delegate_type; /* request - CLAIM_PREV only */ 249 stateid_t op_delegate_stateid; /* request - response */ 250 u32 op_why_no_deleg; /* response - DELEG_NONE_EXT only */ 251 u32 op_create; /* request */ 252 u32 op_createmode; /* request */ 253 int op_umask; /* request */ 254 u32 op_bmval[3]; /* request */ 255 struct iattr op_iattr; /* UNCHECKED4, GUARDED4, EXCLUSIVE4_1 */ 256 nfs4_verifier op_verf __attribute__((aligned(32))); 257 /* EXCLUSIVE4 */ 258 clientid_t op_clientid; /* request */ 259 struct xdr_netobj op_owner; /* request */ 260 u32 op_seqid; /* request */ 261 u32 op_share_access; /* request */ 262 u32 op_share_deny; /* request */ 263 u32 op_deleg_want; /* request */ 264 stateid_t op_stateid; /* response */ 265 __be32 op_xdr_error; /* see nfsd4_open_omfg() */ 266 struct nfsd4_change_info op_cinfo; /* response */ 267 u32 op_rflags; /* response */ 268 bool op_recall; /* response */ 269 bool op_truncate; /* used during processing */ 270 bool op_created; /* used during processing */ 271 struct nfs4_openowner *op_openowner; /* used during processing */ 272 struct file *op_filp; /* used during processing */ 273 struct nfs4_file *op_file; /* used during processing */ 274 struct nfs4_ol_stateid *op_stp; /* used during processing */ 275 struct nfs4_clnt_odstate *op_odstate; /* used during processing */ 276 struct nfs4_acl *op_acl; 277 struct posix_acl *op_dpacl; 278 struct posix_acl *op_pacl; 279 struct xdr_netobj op_label; 280 struct svc_rqst *op_rqstp; 281 }; 282 283 struct nfsd4_open_confirm { 284 stateid_t oc_req_stateid /* request */; 285 u32 oc_seqid /* request */; 286 stateid_t oc_resp_stateid /* response */; 287 }; 288 289 struct nfsd4_open_downgrade { 290 stateid_t od_stateid; 291 u32 od_seqid; 292 u32 od_share_access; /* request */ 293 u32 od_deleg_want; /* request */ 294 u32 od_share_deny; /* request */ 295 }; 296 297 298 struct nfsd4_read { 299 stateid_t rd_stateid; /* request */ 300 u64 rd_offset; /* request */ 301 u32 rd_length; /* request */ 302 int rd_vlen; 303 struct nfsd_file *rd_nf; 304 305 struct svc_rqst *rd_rqstp; /* response */ 306 struct svc_fh *rd_fhp; /* response */ 307 u32 rd_eof; /* response */ 308 }; 309 310 /* 311 * Cache the case-folding properties of @dir so a batched encoder 312 * (e.g., READDIR) does not re-probe per child. @dir is the 313 * directory being read, held by the request, so it is stable 314 * against rename for the duration of the cache's lifetime. 315 */ 316 struct nfsd_case_attrs_cache { 317 struct dentry *dir; 318 bool valid; 319 bool insensitive; 320 bool preserving; 321 }; 322 323 struct nfsd4_readdir { 324 u64 rd_cookie; /* request */ 325 nfs4_verifier rd_verf; /* request */ 326 u32 rd_dircount; /* request */ 327 u32 rd_maxcount; /* request */ 328 u32 rd_bmval[3]; /* request */ 329 struct svc_rqst *rd_rqstp; /* response */ 330 struct svc_fh * rd_fhp; /* response */ 331 332 struct readdir_cd common; 333 struct xdr_stream *xdr; 334 int cookie_offset; 335 struct nfsd_case_attrs_cache rd_case_cache; 336 }; 337 338 struct nfsd4_release_lockowner { 339 clientid_t rl_clientid; 340 struct xdr_netobj rl_owner; 341 }; 342 struct nfsd4_readlink { 343 struct svc_rqst *rl_rqstp; /* request */ 344 struct svc_fh * rl_fhp; /* request */ 345 }; 346 347 struct nfsd4_remove { 348 u32 rm_namelen; /* request */ 349 char * rm_name; /* request */ 350 struct nfsd4_change_info rm_cinfo; /* response */ 351 }; 352 353 struct nfsd4_rename { 354 u32 rn_snamelen; /* request */ 355 char * rn_sname; /* request */ 356 u32 rn_tnamelen; /* request */ 357 char * rn_tname; /* request */ 358 struct nfsd4_change_info rn_sinfo; /* response */ 359 struct nfsd4_change_info rn_tinfo; /* response */ 360 }; 361 362 struct nfsd4_secinfo { 363 u32 si_namelen; /* request */ 364 char *si_name; /* request */ 365 struct svc_export *si_exp; /* response */ 366 }; 367 368 struct nfsd4_secinfo_no_name { 369 u32 sin_style; /* request */ 370 struct svc_export *sin_exp; /* response */ 371 }; 372 373 struct nfsd4_setattr { 374 stateid_t sa_stateid; /* request */ 375 u32 sa_bmval[3]; /* request */ 376 struct iattr sa_iattr; /* request */ 377 struct nfs4_acl *sa_acl; 378 struct xdr_netobj sa_label; 379 struct posix_acl *sa_dpacl; 380 struct posix_acl *sa_pacl; 381 }; 382 383 struct nfsd4_setclientid { 384 nfs4_verifier se_verf; /* request */ 385 struct xdr_netobj se_name; 386 u32 se_callback_prog; /* request */ 387 u32 se_callback_netid_len; /* request */ 388 char * se_callback_netid_val; /* request */ 389 u32 se_callback_addr_len; /* request */ 390 char * se_callback_addr_val; /* request */ 391 u32 se_callback_ident; /* request */ 392 clientid_t se_clientid; /* response */ 393 nfs4_verifier se_confirm; /* response */ 394 }; 395 396 struct nfsd4_setclientid_confirm { 397 clientid_t sc_clientid; 398 nfs4_verifier sc_confirm; 399 }; 400 401 struct nfsd4_test_stateid_id { 402 __be32 ts_id_status; 403 stateid_t ts_id_stateid; 404 struct list_head ts_id_list; 405 }; 406 407 struct nfsd4_test_stateid { 408 u32 ts_num_ids; 409 struct list_head ts_stateid_list; 410 }; 411 412 struct nfsd4_free_stateid { 413 stateid_t fr_stateid; /* request */ 414 }; 415 416 struct nfsd4_get_dir_delegation { 417 /* request */ 418 u32 gdda_signal_deleg_avail; 419 u32 gdda_notification_types[1]; 420 struct timespec64 gdda_child_attr_delay; 421 struct timespec64 gdda_dir_attr_delay; 422 u32 gdda_child_attributes[3]; 423 u32 gdda_dir_attributes[3]; 424 /* response */ 425 u32 gddrnf_status; 426 nfs4_verifier gddr_cookieverf; 427 stateid_t gddr_stateid; 428 u32 gddr_notification[1]; 429 u32 gddr_child_attributes[3]; 430 u32 gddr_dir_attributes[3]; 431 bool gddrnf_will_signal_deleg_avail; 432 }; 433 434 /* also used for NVERIFY */ 435 struct nfsd4_verify { 436 u32 ve_bmval[3]; /* request */ 437 u32 ve_attrlen; /* request */ 438 char * ve_attrval; /* request */ 439 }; 440 441 struct nfsd4_write { 442 stateid_t wr_stateid; /* request */ 443 u64 wr_offset; /* request */ 444 u32 wr_stable_how; /* request */ 445 u32 wr_buflen; /* request */ 446 struct xdr_buf wr_payload; /* request */ 447 448 u32 wr_bytes_written; /* response */ 449 u32 wr_how_written; /* response */ 450 nfs4_verifier wr_verifier; /* response */ 451 }; 452 453 struct nfsd4_exchange_id { 454 nfs4_verifier verifier; 455 struct xdr_netobj clname; 456 u32 flags; 457 clientid_t clientid; 458 u32 seqid; 459 u32 spa_how; 460 u32 spo_must_enforce[3]; 461 u32 spo_must_allow[3]; 462 struct xdr_netobj nii_domain; 463 struct xdr_netobj nii_name; 464 struct timespec64 nii_time; 465 char *server_impl_name; 466 }; 467 468 struct nfsd4_sequence { 469 struct nfs4_sessionid sessionid; /* request/response */ 470 u32 seqid; /* request/response */ 471 u32 slotid; /* request/response */ 472 u32 maxslots; /* request */ 473 u32 cachethis; /* request */ 474 u32 maxslots_response; /* response */ 475 u32 target_maxslots; /* response */ 476 u32 status_flags; /* response */ 477 }; 478 479 struct nfsd4_destroy_session { 480 struct nfs4_sessionid sessionid; 481 }; 482 483 struct nfsd4_destroy_clientid { 484 clientid_t clientid; 485 }; 486 487 struct nfsd4_reclaim_complete { 488 u32 rca_one_fs; 489 }; 490 491 struct nfsd4_deviceid { 492 u64 fsid_idx; 493 u32 generation; 494 }; 495 496 static inline __be32 * 497 svcxdr_encode_deviceid4(__be32 *p, const struct nfsd4_deviceid *devid) 498 { 499 __be64 *q = (__be64 *)p; 500 501 *q = (__force __be64)devid->fsid_idx; 502 p += 2; 503 *p++ = (__force __be32)devid->generation; 504 *p++ = xdr_zero; 505 return p; 506 } 507 508 static inline __be32 * 509 svcxdr_decode_deviceid4(__be32 *p, struct nfsd4_deviceid *devid) 510 { 511 __be64 *q = (__be64 *)p; 512 513 devid->fsid_idx = (__force u64)(*q); 514 p += 2; 515 devid->generation = (__force u32)(*p++); 516 p++; /* NFSD does not use the remaining octets */ 517 return p; 518 } 519 520 struct nfsd4_layout_seg { 521 u32 iomode; 522 u64 offset; 523 u64 length; 524 }; 525 526 struct nfsd4_getdeviceinfo { 527 struct nfsd4_deviceid gd_devid; /* request */ 528 u32 gd_layout_type; /* request */ 529 u32 gd_maxcount; /* request */ 530 u32 gd_notify_types;/* request - response */ 531 void *gd_device; /* response */ 532 }; 533 534 struct nfsd4_layoutget { 535 u64 lg_minlength; /* request */ 536 u32 lg_signal; /* request */ 537 u32 lg_layout_type; /* request */ 538 u32 lg_maxcount; /* request */ 539 stateid_t lg_sid; /* request/response */ 540 struct nfsd4_layout_seg lg_seg; /* request/response */ 541 void *lg_content; /* response */ 542 }; 543 544 struct nfsd4_layoutcommit { 545 stateid_t lc_sid; /* request */ 546 struct nfsd4_layout_seg lc_seg; /* request */ 547 u32 lc_reclaim; /* request */ 548 u32 lc_newoffset; /* request */ 549 u64 lc_last_wr; /* request */ 550 struct timespec64 lc_mtime; /* request */ 551 u32 lc_layout_type; /* request */ 552 struct xdr_buf lc_up_layout; /* decoded by callback */ 553 bool lc_size_chg; /* response */ 554 u64 lc_newsize; /* response */ 555 }; 556 557 struct nfsd4_layoutreturn { 558 u32 lr_return_type; /* request */ 559 u32 lr_layout_type; /* request */ 560 struct nfsd4_layout_seg lr_seg; /* request */ 561 u32 lr_reclaim; /* request */ 562 u32 lrf_body_len; /* request */ 563 void *lrf_body; /* request */ 564 stateid_t lr_sid; /* request/response */ 565 bool lrs_present; /* response */ 566 }; 567 568 struct nfsd4_fallocate { 569 /* request */ 570 stateid_t falloc_stateid; 571 loff_t falloc_offset; 572 u64 falloc_length; 573 }; 574 575 struct nfsd4_clone { 576 /* request */ 577 stateid_t cl_src_stateid; 578 stateid_t cl_dst_stateid; 579 u64 cl_src_pos; 580 u64 cl_dst_pos; 581 u64 cl_count; 582 }; 583 584 struct nfsd42_write_res { 585 u64 wr_bytes_written; 586 u32 wr_stable_how; 587 nfs4_verifier wr_verifier; 588 stateid_t cb_stateid; 589 }; 590 591 struct nfsd4_cb_offload { 592 struct nfsd4_callback co_cb; 593 struct nfsd42_write_res co_res; 594 __be32 co_nfserr; 595 unsigned int co_retries; 596 struct knfsd_fh co_fh; 597 598 struct nfs4_sessionid co_referring_sessionid; 599 u32 co_referring_slotid; 600 u32 co_referring_seqno; 601 }; 602 603 struct nfsd4_ssc_umount_item { 604 struct list_head nsui_list; 605 bool nsui_busy; 606 /* 607 * nsui_refcnt inited to 2, 1 on list and 1 for consumer. Entry 608 * is removed when refcnt drops to 1 and nsui_expire expires. 609 */ 610 refcount_t nsui_refcnt; 611 unsigned long nsui_expire; 612 struct vfsmount *nsui_vfsmount; 613 char nsui_ipaddr[RPC_MAX_ADDRBUFLEN + 1]; 614 }; 615 616 struct nfsd4_copy { 617 /* request */ 618 stateid_t cp_src_stateid; 619 stateid_t cp_dst_stateid; 620 u64 cp_src_pos; 621 u64 cp_dst_pos; 622 u64 cp_count; 623 struct nl4_server *cp_src; 624 625 unsigned long cp_flags; 626 #define NFSD4_COPY_F_STOPPED (0) 627 #define NFSD4_COPY_F_INTRA (1) 628 #define NFSD4_COPY_F_SYNCHRONOUS (2) 629 #define NFSD4_COPY_F_COMMITTED (3) 630 #define NFSD4_COPY_F_COMPLETED (4) 631 #define NFSD4_COPY_F_OFFLOAD_DONE (5) 632 #define NFSD4_COPY_F_CB_ERROR (6) 633 634 /* response */ 635 __be32 nfserr; 636 struct nfsd42_write_res cp_res; 637 struct knfsd_fh fh; 638 639 struct nfs4_client *cp_clp; 640 641 struct nfsd_file *nf_src; 642 struct nfsd_file *nf_dst; 643 bool attr_update; 644 645 struct nfsd4_ssc_umount_item *ss_nsui; 646 struct nfs_fh c_fh; 647 nfs4_stateid stateid; 648 struct nfsd_net *cp_nn; 649 }; 650 651 /* 652 * Durable state for an async (background) server-side COPY. 653 * 654 * struct nfsd4_copy is transient: it lives in the COMPOUND argument buffer 655 * and is reused once the op returns. An async COPY outlives the COMPOUND 656 * (worker kthread, reaper linkage, CB_OFFLOAD), so its params and result are 657 * snapshotted into the embedded cp_copy and it never points into the request 658 * buffer. 659 */ 660 struct nfsd4_async_copy { 661 struct nfs4_stid cp_stid; /* SC_TYPE_COPY, in cl_stateids */ 662 struct nfsd4_copy cp_copy; /* operation params + result */ 663 664 struct list_head copies; /* nfs4_client.async_copies */ 665 struct task_struct *copy_task; 666 refcount_t refcount; 667 unsigned int cp_ttl; 668 struct nfsd4_cb_offload cp_cb_offload; 669 }; 670 671 static inline void nfsd4_copy_set_sync(struct nfsd4_copy *copy, bool sync) 672 { 673 if (sync) 674 set_bit(NFSD4_COPY_F_SYNCHRONOUS, ©->cp_flags); 675 else 676 clear_bit(NFSD4_COPY_F_SYNCHRONOUS, ©->cp_flags); 677 } 678 679 static inline bool nfsd4_copy_is_sync(const struct nfsd4_copy *copy) 680 { 681 return test_bit(NFSD4_COPY_F_SYNCHRONOUS, ©->cp_flags); 682 } 683 684 static inline bool nfsd4_copy_is_async(const struct nfsd4_copy *copy) 685 { 686 return !test_bit(NFSD4_COPY_F_SYNCHRONOUS, ©->cp_flags); 687 } 688 689 static inline bool nfsd4_ssc_is_inter(const struct nfsd4_copy *copy) 690 { 691 return !test_bit(NFSD4_COPY_F_INTRA, ©->cp_flags); 692 } 693 694 struct nfsd4_seek { 695 /* request */ 696 stateid_t seek_stateid; 697 loff_t seek_offset; 698 u32 seek_whence; 699 700 /* response */ 701 u32 seek_eof; 702 loff_t seek_pos; 703 }; 704 705 struct nfsd4_offload_status { 706 /* request */ 707 stateid_t stateid; 708 709 /* response */ 710 u64 count; 711 __be32 status; 712 bool completed; 713 }; 714 715 struct nfsd4_copy_notify { 716 /* request */ 717 stateid_t cpn_src_stateid; 718 struct nl4_server *cpn_dst; 719 720 /* response */ 721 stateid_t cpn_cnr_stateid; 722 struct timespec64 cpn_lease_time; 723 struct nl4_server *cpn_src; 724 }; 725 726 struct nfsd4_op { 727 u32 opnum; 728 __be32 status; 729 const struct nfsd4_operation *opdesc; 730 struct nfs4_replay *replay; 731 union nfsd4_op_u { 732 struct nfsd4_access access; 733 struct nfsd4_close close; 734 struct nfsd4_commit commit; 735 struct nfsd4_create create; 736 struct nfsd4_delegreturn delegreturn; 737 struct nfsd4_getattr getattr; 738 struct svc_fh * getfh; 739 struct nfsd4_link link; 740 struct nfsd4_lock lock; 741 struct nfsd4_lockt lockt; 742 struct nfsd4_locku locku; 743 struct nfsd4_lookup lookup; 744 struct nfsd4_verify nverify; 745 struct nfsd4_open open; 746 struct nfsd4_open_confirm open_confirm; 747 struct nfsd4_open_downgrade open_downgrade; 748 struct nfsd4_putfh putfh; 749 struct nfsd4_read read; 750 struct nfsd4_readdir readdir; 751 struct nfsd4_readlink readlink; 752 struct nfsd4_remove remove; 753 struct nfsd4_rename rename; 754 clientid_t renew; 755 struct nfsd4_secinfo secinfo; 756 struct nfsd4_setattr setattr; 757 struct nfsd4_setclientid setclientid; 758 struct nfsd4_setclientid_confirm setclientid_confirm; 759 struct nfsd4_verify verify; 760 struct nfsd4_write write; 761 struct nfsd4_release_lockowner release_lockowner; 762 763 /* NFSv4.1 */ 764 struct nfsd4_exchange_id exchange_id; 765 struct nfsd4_backchannel_ctl backchannel_ctl; 766 struct nfsd4_bind_conn_to_session bind_conn_to_session; 767 struct nfsd4_create_session create_session; 768 struct nfsd4_destroy_session destroy_session; 769 struct nfsd4_destroy_clientid destroy_clientid; 770 struct nfsd4_sequence sequence; 771 struct nfsd4_reclaim_complete reclaim_complete; 772 struct nfsd4_test_stateid test_stateid; 773 struct nfsd4_free_stateid free_stateid; 774 struct nfsd4_get_dir_delegation get_dir_delegation; 775 struct nfsd4_getdeviceinfo getdeviceinfo; 776 struct nfsd4_layoutget layoutget; 777 struct nfsd4_layoutcommit layoutcommit; 778 struct nfsd4_layoutreturn layoutreturn; 779 struct nfsd4_secinfo_no_name secinfo_no_name; 780 781 /* NFSv4.2 */ 782 struct nfsd4_fallocate allocate; 783 struct nfsd4_fallocate deallocate; 784 struct nfsd4_clone clone; 785 struct nfsd4_copy copy; 786 struct nfsd4_offload_status offload_status; 787 struct nfsd4_copy_notify copy_notify; 788 struct nfsd4_seek seek; 789 790 struct nfsd4_getxattr getxattr; 791 struct nfsd4_setxattr setxattr; 792 struct nfsd4_listxattrs listxattrs; 793 struct nfsd4_removexattr removexattr; 794 } u; 795 }; 796 797 bool nfsd4_cache_this_op(struct nfsd4_op *); 798 799 /* 800 * Memory needed just for the duration of processing one compound: 801 */ 802 struct svcxdr_tmpbuf { 803 struct svcxdr_tmpbuf *next; 804 void (*release)(void *buf); 805 char buf[]; 806 }; 807 808 struct nfsd4_compoundargs { 809 /* scratch variables for XDR decode */ 810 struct xdr_stream *xdr; 811 struct svcxdr_tmpbuf *to_free; 812 struct svc_rqst *rqstp; 813 814 char * tag; 815 u32 taglen; 816 u32 minorversion; 817 u32 client_opcnt; 818 u32 opcnt; 819 bool splice_ok; 820 struct nfsd4_op *ops; 821 struct nfsd4_op iops[8]; 822 }; 823 824 struct nfsd4_compoundres { 825 /* scratch variables for XDR encode */ 826 struct xdr_stream *xdr; 827 struct svc_rqst * rqstp; 828 829 __be32 *statusp; 830 char * tag; 831 u32 taglen; 832 u32 opcnt; 833 834 struct nfsd4_compound_state cstate; 835 }; 836 837 static inline bool nfsd4_last_compound_op(struct svc_rqst *rqstp) 838 { 839 struct nfsd4_compoundres *resp = rqstp->rq_resp; 840 struct nfsd4_compoundargs *argp = rqstp->rq_argp; 841 842 return argp->opcnt == resp->opcnt; 843 } 844 845 const struct nfsd4_operation *OPDESC(struct nfsd4_op *op); 846 int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op); 847 void warn_on_nonidempotent_op(struct nfsd4_op *op); 848 849 #define NFS4_SVC_XDRSIZE sizeof(struct nfsd4_compoundargs) 850 851 bool nfsd4_mach_creds_match(struct nfs4_client *cl, struct svc_rqst *rqstp); 852 bool nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, struct xdr_stream *xdr); 853 bool nfs4svc_encode_compoundres(struct svc_rqst *rqstp, struct xdr_stream *xdr); 854 __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *, u32); 855 void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *); 856 void nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op); 857 __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, 858 struct svc_fh *fhp, struct svc_export *exp, 859 struct dentry *dentry, 860 u32 *bmval, struct svc_rqst *, int ignore_crossmnt); 861 u8 *nfsd4_encode_notify_event(struct xdr_stream *xdr, struct nfsd_notify_event *nne, 862 struct nfs4_delegation *dd, struct nfsd_file *nf, 863 u32 *notify_mask); 864 u8 *nfsd4_encode_dir_attr_change(struct xdr_stream *xdr, struct nfs4_delegation *dp, 865 struct nfsd_file *nf); 866 extern __be32 nfsd4_setclientid(struct svc_rqst *rqstp, 867 struct nfsd4_compound_state *, union nfsd4_op_u *u); 868 extern __be32 nfsd4_setclientid_confirm(struct svc_rqst *rqstp, 869 struct nfsd4_compound_state *, union nfsd4_op_u *u); 870 void nfsd4_exchange_id_release(union nfsd4_op_u *u); 871 extern __be32 nfsd4_exchange_id(struct svc_rqst *rqstp, 872 struct nfsd4_compound_state *, union nfsd4_op_u *u); 873 extern __be32 nfsd4_backchannel_ctl(struct svc_rqst *, 874 struct nfsd4_compound_state *, union nfsd4_op_u *u); 875 extern __be32 nfsd4_bind_conn_to_session(struct svc_rqst *, 876 struct nfsd4_compound_state *, union nfsd4_op_u *u); 877 extern __be32 nfsd4_create_session(struct svc_rqst *, 878 struct nfsd4_compound_state *, union nfsd4_op_u *u); 879 extern __be32 nfsd4_sequence(struct svc_rqst *, 880 struct nfsd4_compound_state *, union nfsd4_op_u *u); 881 extern void nfsd4_sequence_done(struct nfsd4_compoundres *resp); 882 extern __be32 nfsd4_destroy_session(struct svc_rqst *, 883 struct nfsd4_compound_state *, union nfsd4_op_u *u); 884 extern __be32 nfsd4_destroy_clientid(struct svc_rqst *, struct nfsd4_compound_state *, 885 union nfsd4_op_u *u); 886 __be32 nfsd4_reclaim_complete(struct svc_rqst *, struct nfsd4_compound_state *, 887 union nfsd4_op_u *u); 888 extern __be32 nfsd4_process_open1(struct nfsd4_compound_state *, 889 struct nfsd4_open *open, struct nfsd_net *nn); 890 extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp, 891 struct svc_fh *current_fh, struct nfsd4_open *open); 892 extern void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate); 893 extern void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate, 894 struct nfsd4_open *open); 895 extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp, 896 struct nfsd4_compound_state *, union nfsd4_op_u *u); 897 extern __be32 nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *, 898 union nfsd4_op_u *u); 899 extern __be32 nfsd4_open_downgrade(struct svc_rqst *rqstp, 900 struct nfsd4_compound_state *, union nfsd4_op_u *u); 901 extern __be32 nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *, 902 union nfsd4_op_u *u); 903 extern void nfsd4_lock_release(union nfsd4_op_u *u); 904 extern __be32 nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *, 905 union nfsd4_op_u *u); 906 extern void nfsd4_lockt_release(union nfsd4_op_u *u); 907 extern __be32 nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *, 908 union nfsd4_op_u *u); 909 extern __be32 910 nfsd4_release_lockowner(struct svc_rqst *rqstp, 911 struct nfsd4_compound_state *, union nfsd4_op_u *u); 912 extern void nfsd4_release_compoundargs(struct svc_rqst *rqstp); 913 extern __be32 nfsd4_delegreturn(struct svc_rqst *rqstp, 914 struct nfsd4_compound_state *, union nfsd4_op_u *u); 915 extern __be32 nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *, 916 union nfsd4_op_u *u); 917 extern __be32 nfsd4_test_stateid(struct svc_rqst *rqstp, 918 struct nfsd4_compound_state *, union nfsd4_op_u *); 919 extern __be32 nfsd4_free_stateid(struct svc_rqst *rqstp, 920 struct nfsd4_compound_state *, union nfsd4_op_u *); 921 extern void nfsd4_bump_seqid(struct nfsd4_compound_state *, __be32 nfserr); 922 923 enum nfsd4_op_flags { 924 ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 925 ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ 926 ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ 927 /* For rfc 5661 section 2.6.3.1.1: */ 928 OP_HANDLES_WRONGSEC = 1 << 3, 929 OP_IS_PUTFH_LIKE = 1 << 4, 930 /* 931 * These are the ops whose result size we estimate before 932 * encoding, to avoid performing an op then not being able to 933 * respond or cache a response. This includes writes and setattrs 934 * as well as the operations usually called "nonidempotent": 935 */ 936 OP_MODIFIES_SOMETHING = 1 << 5, 937 /* 938 * Cache compounds containing these ops in the xid-based drc: 939 * We use the DRC for compounds containing non-idempotent 940 * operations, *except* those that are 4.1-specific (since 941 * sessions provide their own EOS), and except for stateful 942 * operations other than setclientid and setclientid_confirm 943 * (since sequence numbers provide EOS for open, lock, etc in 944 * the v4.0 case). 945 */ 946 OP_CACHEME = 1 << 6, 947 /* 948 * These are ops which clear current state id. 949 */ 950 OP_CLEAR_STATEID = 1 << 7, 951 /* Most ops return only an error on failure; some may do more: */ 952 OP_NONTRIVIAL_ERROR_ENCODE = 1 << 8, 953 }; 954 955 struct nfsd4_operation { 956 __be32 (*op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 957 union nfsd4_op_u *); 958 void (*op_release)(union nfsd4_op_u *); 959 u32 op_flags; 960 char *op_name; 961 /* Try to get response size before operation */ 962 u32 (*op_rsize_bop)(const struct svc_rqst *rqstp, 963 const struct nfsd4_op *op); 964 void (*op_get_currentstateid)(struct nfsd4_compound_state *, 965 union nfsd4_op_u *); 966 void (*op_set_currentstateid)(struct nfsd4_compound_state *, 967 union nfsd4_op_u *); 968 }; 969 970 struct nfsd4_cb_recall_any { 971 struct nfsd4_callback ra_cb; 972 u32 ra_keep; 973 u32 ra_bmval[1]; 974 }; 975 976 #endif 977