1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _NFS4_H 27 #define _NFS4_H 28 29 #include <sys/types.h> 30 #include <sys/vnode.h> 31 #include <sys/fem.h> 32 #include <rpc/rpc.h> 33 #include <nfs/nfs.h> 34 35 #ifdef _KERNEL 36 #include <nfs/nfs4_kprot.h> 37 #include <sys/nvpair.h> 38 #else 39 #include <rpcsvc/nfs4_prot.h> 40 #endif 41 #include <nfs/nfs4_attr.h> 42 #include <sys/acl.h> 43 #include <sys/list.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 #define NFS4_MAX_UTF8STRING 65536 50 #define NFS4_MAX_PATHNAME4 65536 51 #define NFS4_MAX_SECOID4 65536 52 53 #ifdef _KERNEL 54 55 typedef struct nfs4_fhandle { 56 int fh_len; 57 char fh_buf[NFS4_FHSIZE]; 58 } nfs4_fhandle_t; 59 60 #define NFS4_MINORVERSION 0 61 #define CB4_MINORVERSION 0 62 63 /* 64 * Set the fattr4_change variable using a time struct. Note that change 65 * is 64 bits, but timestruc_t is 128 bits in a 64-bit kernel. 66 */ 67 #define NFS4_SET_FATTR4_CHANGE(change, ts) \ 68 { \ 69 change = (ts).tv_sec; \ 70 change <<= 32; \ 71 change |= (uint32_t)((ts).tv_nsec); \ 72 } 73 74 /* 75 * Server lease period. Value is in seconds; Also used for grace period 76 */ 77 extern time_t rfs4_lease_time; 78 79 /* 80 * This set of typedefs and interfaces represent the core or base set 81 * of functionality that backs the NFSv4 server's state related data 82 * structures. Since the NFSv4 server needs inter-RPC state to be 83 * available that is unrelated to the filesystem (in other words, 84 * soft-state), this functionality is needed to maintain that and is 85 * written to be somewhat flexible to adapt to the various types of 86 * data structures contained within the server. 87 * 88 * The basic structure at this level is that the server maintains a 89 * global "database" which consists of a set of tables. Each table 90 * contains a set of like data structures. Each table is indexed by 91 * at least one hash function and in most cases two hashes. Each 92 * table's characteristics is set when it is created at run-time via 93 * rfs4_table_create(). All table creation and related functions are 94 * located in nfs4_state.c. The generic database functionality is 95 * located in nfs4_db.c. 96 */ 97 98 typedef struct rfs4_dbe rfs4_dbe_t; /* basic opaque db entry */ 99 typedef struct rfs4_table rfs4_table_t; /* basic table type */ 100 typedef struct rfs4_index rfs4_index_t; /* index */ 101 typedef struct rfs4_database rfs4_database_t; /* and database */ 102 103 typedef struct { /* opaque entry type for later use */ 104 rfs4_dbe_t *dbe; 105 } *rfs4_entry_t; 106 107 extern rfs4_table_t *rfs4_client_tab; 108 109 /* database, table, index creation entry points */ 110 extern rfs4_database_t *rfs4_database_create(uint32_t); 111 extern void rfs4_database_shutdown(rfs4_database_t *); 112 extern void rfs4_database_destroy(rfs4_database_t *); 113 114 extern void rfs4_database_destroy(rfs4_database_t *); 115 116 extern rfs4_table_t *rfs4_table_create(rfs4_database_t *, char *, 117 time_t, uint32_t, 118 bool_t (*create)(rfs4_entry_t, void *), 119 void (*destroy)(rfs4_entry_t), 120 bool_t (*expiry)(rfs4_entry_t), 121 uint32_t, uint32_t, uint32_t, id_t); 122 extern void rfs4_table_destroy(rfs4_database_t *, rfs4_table_t *); 123 extern rfs4_index_t *rfs4_index_create(rfs4_table_t *, char *, 124 uint32_t (*hash)(void *), 125 bool_t (compare)(rfs4_entry_t, void *), 126 void *(*mkkey)(rfs4_entry_t), bool_t); 127 extern void rfs4_index_destroy(rfs4_index_t *); 128 129 /* Type used to direct rfs4_dbsearch() in what types of records to inspect */ 130 typedef enum {RFS4_DBS_VALID, RFS4_DBS_INVALID} rfs4_dbsearch_type_t; 131 /* search and db entry manipulation entry points */ 132 extern rfs4_entry_t rfs4_dbsearch(rfs4_index_t *, void *, 133 bool_t *, void *, rfs4_dbsearch_type_t); 134 extern void rfs4_dbe_lock(rfs4_dbe_t *); 135 extern void rfs4_dbe_unlock(rfs4_dbe_t *); 136 extern clock_t rfs4_dbe_twait(rfs4_dbe_t *, clock_t); 137 extern void rfs4_dbe_cv_broadcast(rfs4_dbe_t *); 138 extern void rfs4_dbe_hold(rfs4_dbe_t *); 139 extern void rfs4_dbe_hold_nolock(rfs4_dbe_t *); 140 extern void rfs4_dbe_rele_nolock(rfs4_dbe_t *); 141 extern void rfs4_dbe_rele(rfs4_dbe_t *); 142 extern uint32_t rfs4_dbe_refcnt(rfs4_dbe_t *); 143 extern id_t rfs4_dbe_getid(rfs4_dbe_t *); 144 extern void rfs4_dbe_invalidate(rfs4_dbe_t *); 145 extern bool_t rfs4_dbe_is_invalid(rfs4_dbe_t *); 146 extern time_t rfs4_dbe_get_timerele(rfs4_dbe_t *); 147 extern void rfs4_dbe_hide(rfs4_dbe_t *); 148 extern void rfs4_dbe_unhide(rfs4_dbe_t *); 149 #ifdef DEBUG 150 extern bool_t rfs4_dbe_islocked(rfs4_dbe_t *); 151 #endif 152 extern void rfs4_dbe_walk(rfs4_table_t *, 153 void (*callout)(rfs4_entry_t, void *), void *); 154 155 /* 156 * Minimal server stable storage. 157 * 158 * Currently the NFSv4 server will only save the client 159 * ID (the long version) so that it will be able to 160 * grant possible reclaim requests during the infamous 161 * grace_period. 162 */ 163 164 #define RFS4_SS_DIRSIZE 64 * 1024 165 #define NFS4_SS_VERSION 1 166 167 /* handy pathname structure */ 168 typedef struct ss_pn { 169 char *leaf; 170 char pn[MAXPATHLEN]; 171 } rfs4_ss_pn_t; 172 173 /* 174 * The server will build this link list on startup. It represents the 175 * clients that have had valid state on the server in a prior instance. 176 * 177 */ 178 typedef struct rfs4_oldstate { 179 struct rfs4_oldstate *next; 180 struct rfs4_oldstate *prev; 181 rfs4_ss_pn_t *ss_pn; 182 nfs_client_id4 cl_id4; 183 } rfs4_oldstate_t; 184 185 /* 186 * This union is used to overlay the server's internal treatment of 187 * the protocols stateid4 datatype. Therefore, "bits" must not exceed 188 * the size of stateid4 and more importantly should match the size of 189 * stateid4. The chgseq field must the first entry since it overlays 190 * stateid4.seqid. 191 */ 192 typedef union { 193 stateid4 stateid; 194 struct { 195 uint32_t chgseq; /* State changes / protocol's seqid */ 196 uint32_t boottime; /* boot time */ 197 uint32_t type:2; /* stateid_type_t as define below */ 198 uint32_t clnodeid:8; /* cluster server nodeid */ 199 uint32_t ident:22; /* 2^22-1 openowner x fhs */ 200 pid_t pid; /* pid of corresponding lock owner */ 201 } bits; 202 } stateid_t; 203 /* 204 * Note that the way the type field above is defined, this enum must 205 * not have more than 4 members. 206 */ 207 typedef enum {OPENID, LOCKID, DELEGID} stateid_type_t; 208 209 210 /* 211 * Set of RPC credentials used for a particular operation. 212 * Used for operations like SETCLIENTID_CONFIRM where the 213 * credentials needs to match those used at SETCLIENTID. 214 */ 215 typedef void *cred_set_t; /* For now XXX */ 216 217 /* 218 * "wait" struct for use in the open open and lock owner state 219 * structures to provide serialization between server threads that are 220 * handling requests for the same open owner or lock stateid. This 221 * way only one thread will be updating things like sequence ids, 222 * replay cache and stateid at a time. 223 */ 224 typedef struct rfs4_state_wait { 225 uint32_t sw_active; 226 uint32_t sw_wait_count; 227 kmutex_t sw_cv_lock[1]; 228 kcondvar_t sw_cv[1]; 229 } rfs4_state_wait_t; 230 231 extern void rfs4_sw_enter(rfs4_state_wait_t *); 232 extern void rfs4_sw_exit(rfs4_state_wait_t *); 233 234 /* 235 * This enum and the following rfs4_cbinfo_t struct are used to 236 * maintain information about the callback path used from the server 237 * to client for operations like CB_GETATTR and CB_RECALL. The 238 * rfs4_cbinfo_t struct is meant to be encompassed in the client 239 * struct and managed within that structure's locking scheme. 240 * 241 * The various states of the callback path are used by the server to 242 * determine if delegations should initially be provided to a client 243 * and then later on if connectivity has been lost and delegations 244 * should be revoked. 245 */ 246 247 /* 248 * CB_NOCHANGE - Special value used for interfaces within the delegation 249 * code to signify that "no change" has occurred to the 250 * callback path 251 * CB_UNINIT - No callback info provided by the client 252 * CB_NONE - Callback info provided but CB_NULL call 253 * has yet to be attempted 254 * CB_OK - Callback path tested with CB_NULL with success 255 * CB_INPROG - Callback path currently being tested with CB_NULL 256 * CB_FAILED - Callback path was == CB_OK but has failed 257 * with timeout/rpc error 258 * CB_BAD - Callback info provided but CB_NULL failed 259 */ 260 typedef enum { 261 CB_NOCHANGE = 0, 262 CB_UNINIT = 1, 263 CB_NONE = 2, 264 CB_OK = 3, 265 CB_INPROG = 4, 266 CB_FAILED = 5, 267 CB_BAD = 6 268 } rfs4_cbstate_t; 269 270 #define RFS4_CBCH_MAX 10 /* size callback client handle cache */ 271 /* 272 * Callback info for a client. 273 * Client only provides: cb_client4 and cb_ident 274 * The rest of the information is used to track callback path status 275 * and usage. 276 * 277 * cb_state - used as comments for the rfs4_cbstate_t enum indicate 278 * cb_notified_of_cb_path_down - if the callback path was once CB_OK and 279 * has hence CB_FAILED, the client needs to be notified via RENEW. 280 * cb_timefailed - current time when cb_state transitioned from 281 * CB_OK -> CB_FAILED. Meant for observability. When did that happen? 282 * cb_chc_free/cb_chc - cache of client handles for the callback path 283 * cb_ident - SETCLIENTID provided callback_ident value 284 * callback - SETCLIENTID provided cb_client4 value 285 * cb_refcnt - current number of users of this structure's content 286 * protected by cb_lock 287 * cb_badbehavior - how many times did a client do something we didn't like? 288 * cb_lock - lock for contents of cbinfo 289 * cb_cv - used to allow threads to wait on CB_NULL completion 290 * cb_nullcaller - is there a thread currently taking care of 291 * new callback information? 292 * cb_cv_nullcaller - used by the thread doing CB_NULL to wait on 293 * threads that may be using client handles of the current 294 * client handle cache. 295 * newer - new callback info provided by a client and awaiting 296 * CB_NULL testing and move to regular cbinfo. 297 */ 298 typedef struct { 299 rfs4_cbstate_t cb_state; 300 unsigned cb_notified_of_cb_path_down:1; 301 time_t cb_timefailed; 302 int cb_chc_free; 303 CLIENT *cb_chc[RFS4_CBCH_MAX]; 304 uint32_t cb_ident; 305 cb_client4 cb_callback; 306 uint32_t cb_refcnt; 307 uint32_t cb_badbehavior; 308 kmutex_t cb_lock[1]; 309 kcondvar_t cb_cv[1]; 310 bool_t cb_nullcaller; 311 kcondvar_t cb_cv_nullcaller[1]; 312 struct { 313 bool_t cb_new; 314 bool_t cb_confirmed; 315 uint32_t cb_ident; 316 cb_client4 cb_callback; 317 } cb_newer; 318 } rfs4_cbinfo_t; 319 320 /* 321 * A server instance. We can associate sets of clients - via a pointer in 322 * rfs4_client_t - with a given server instance, allowing us to treat clients 323 * in the set differently to clients in other sets. 324 * 325 * Currently used only for Sun Cluster HA-NFS support, to group clients 326 * on NFS resource failover so each set of clients gets its own dedicated 327 * grace period and distributed stable storage data. 328 */ 329 typedef struct rfs4_servinst { 330 int dss_npaths; 331 krwlock_t rwlock; 332 krwlock_t oldstate_lock; 333 time_t start_time; 334 time_t grace_period; 335 rfs4_oldstate_t *oldstate; 336 struct rfs4_dss_path **dss_paths; 337 struct rfs4_servinst *next; 338 struct rfs4_servinst *prev; 339 } rfs4_servinst_t; 340 341 /* 342 * DSS: distributed stable storage 343 */ 344 345 typedef struct rfs4_dss_path { 346 struct rfs4_dss_path *next; /* for insque/remque */ 347 struct rfs4_dss_path *prev; /* for insque/remque */ 348 char *path; 349 struct rfs4_servinst *sip; 350 unsigned index; /* offset in servinst's array */ 351 } rfs4_dss_path_t; 352 353 /* array of paths passed-in from nfsd command-line; stored in nvlist */ 354 char **rfs4_dss_newpaths; 355 uint_t rfs4_dss_numnewpaths; 356 357 /* 358 * Circular doubly-linked list of paths for currently-served RGs. 359 * No locking required: only changed on warmstart. Managed with insque/remque. 360 */ 361 rfs4_dss_path_t *rfs4_dss_pathlist; 362 363 /* nvlists of all DSS paths: current, and before last warmstart */ 364 nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths; 365 366 /* 367 * The server maintains a set of state on a per client basis that 368 * matches that of the protocol requirements. A client's state is 369 * rooted with the rfs4_client_t struct of which there is one per 370 * client and is created when SETCLIENTID/SETCLIENTID_CONFIRM are 371 * received. From there, the server then creates rfs4_openowner_t 372 * structs for each new open owner from that client and are initiated 373 * at OPEN/OPEN_CONFIRM (when the open owner is new to the server). 374 * At OPEN, at least two other structures are created, and potentially a 375 * third. rfs4_state_t is created to track the association between an 376 * open owner and a particular file. An rfs4_file_t struct may be 377 * created (if the file is not already open) at OPEN as well. The 378 * rfs4_file_t struct is the only one that is per server and not per 379 * client. The rfs4_deleg_state_t struct is created in the 380 * instance that the server is going to provide a delegation for the 381 * file being OPENed. Finally, the rfs4_lockowner_t is created at the 382 * first use of a lock owner at the server and is a result of the LOCK 383 * operation. The rfs4_lo_state_t struct is then created to represent 384 * the relation between the lock owner and the file. 385 * 386 */ 387 /* 388 * The following ascii art represents each of these data structs and 389 * their references to each other. Note: "<-(x)->" represents the 390 * doubly link lists defined above. 391 * 392 * ____________________ 393 * | | 394 * | rfs4_client_t | 395 * ->| (1),(2) |<- 396 * / |____________________| \ 397 * / ^ \ 398 * / | \ 399 * ____________________ ____________________ ____________________ 400 * | | | | | | 401 * | rfs4_lockowner_t | | rfs4_openowner_t | | rfs4_deleg_state_t | 402 * | | | (3) <-(1)-> | | <-(2)-> | 403 * |____________________| |____________________| |____________________| 404 * ^ ^ | 405 * | | V 406 * ____________________ ____________________ ____________________ 407 * | | | | | | 408 * | rfs4_lo_state_t |->| rfs4_state_t |->| rfs4_file_t | 409 * | <-(4)-> | | (4) <-(3)-> | | | 410 * |____________________| |____________________| |____________________| 411 */ 412 /* 413 * Each of these data types are kept in a separate rfs4_table_t and is 414 * actually encapsulated within a rfs4_dbe_t struct. The various 415 * tables and their construction is done in nfs4_state.c but 416 * documented here to completeness. 417 * 418 * Table Data struct stored Indexed by 419 * ----- ------------------ ---------- 420 * rfs4_client_tab rfs4_client_t nfs_client_id4 421 * clientid4 422 * 423 * rfs4_openowner_tab rfs4_openowner_t open_owner4 424 * 425 * rfs4_state_tab rfs4_state_t open_owner4 | file 426 * stateid 427 * 428 * rfs4_lo_state_tab rfs4_lo_state_t lockowner | stateid 429 * lock_stateid 430 * 431 * rfs4_lockowner_tab rfs4_lockowner_t lockowner 432 * pid 433 * 434 * rfs4_file_tab rfs4_file_t filehandle 435 * 436 * rfs4_deleg_state_tab rfs4_deleg_state_t clientid4 | file 437 * deleg_stateid 438 */ 439 440 /* 441 * The client struct, it is the root of all state for a particular 442 * client. The client is identified by the nfs_client_id4 via 443 * SETCLIENTID and the server returns the clientid4 as short hand reference 444 */ 445 /* 446 * Client struct - as mentioned above it is the root of all state for 447 * a single client as identified by the client supplied nfs_client_id4 448 * 449 * dbe - encapsulation struct 450 * clientid - server assigned short hand reference to client 451 * nfs_client - client supplied identifier for itself 452 * confirm_verf - the value provided to the client for SETCLIENTID_CONFIRM 453 * need_confirm - does this client need to be SETCLIENTID_CONFIRMed? 454 * 455 * unlksys_completed - has an F_UNLKSYS been done for this client which 456 * says that the use of cleanlocks() on individual files 457 * is not required? 458 * can_reclaim - indicates if client is allowed to reclaim after server 459 * start-up (client had previous state at server) 460 * ss_remove - indicates that the rfs4_client_destroy function should 461 * clean up stable storage file. 462 * forced_expire - set if the sysadmin has used clear_locks for this client. 463 * no_referrals - set if the client is Solaris and pre-dates referrals 464 * deleg_revoked - how many delegations have been revoked for this client? 465 * 466 * cp_confirmed - this refers to a confirmed client struct that has 467 * the same nfs_client_id4 as this client struct. When/if this client 468 * struct is confirmed via SETCLINETID_CONFIRM, the previously 469 * confirmed client struct will be "closed" and hence this reference. 470 * 471 * last_access - used to determine if the client has let its lease expire 472 * cbinfo - struct containing all callback related information 473 * cr_set - credentials used for the SETCLIENTID/SETCLIENTID_CONFIRM pair 474 * sysid - the lock manager sysid allocated for this client's file locks 475 * openownerlist - root of openowners list associated with this client 476 * ss_pn - Pathname to the stable storage file. 477 * cl_addr - Clients network address. 478 * server_instance - pointer to the currently associated server instance 479 */ 480 typedef struct rfs4_client { 481 rfs4_dbe_t *rc_dbe; 482 clientid4 rc_clientid; 483 nfs_client_id4 rc_nfs_client; 484 verifier4 rc_confirm_verf; 485 unsigned rc_need_confirm:1; 486 unsigned rc_unlksys_completed:1; 487 unsigned rc_can_reclaim:1; 488 unsigned rc_ss_remove:1; 489 unsigned rc_forced_expire:1; 490 uint_t rc_deleg_revoked; 491 struct rfs4_client *rc_cp_confirmed; 492 time_t rc_last_access; 493 rfs4_cbinfo_t rc_cbinfo; 494 cred_set_t rc_cr_set; 495 sysid_t rc_sysidt; 496 list_t rc_openownerlist; 497 rfs4_ss_pn_t *rc_ss_pn; 498 struct sockaddr_storage rc_addr; 499 rfs4_servinst_t *rc_server_instance; 500 } rfs4_client_t; 501 502 /* 503 * ClntIP struct - holds the diagnosis about whether the client 504 * cannot support referrals. Set to true for old Solaris clients. 505 */ 506 507 typedef struct rfs4_clntip { 508 rfs4_dbe_t *ri_dbe; 509 struct sockaddr_storage ri_addr; 510 unsigned ri_no_referrals:1; 511 } rfs4_clntip_t; 512 513 /* 514 * The openowner contains the client supplied open_owner4 as well as 515 * the matching sequence id and is used to track the client's usage of 516 * the open_owner4. Note that a reply is saved here as well for 517 * processing of retransmissions. 518 * 519 * dbe - encapsulation struct 520 * client - reference to rfs4_client_t for this openowner 521 * owner - actual client supplied open_owner4 522 * need_confirm - does this openowner need to be OPEN_CONFIRMed 523 * postpone_confirm - set if error received on first use of open_owner 524 * state2confirm - what stateid4 should be used on the OPEN_CONFIRM 525 * open_seqid - what is the next open_seqid expected for this openowner 526 * oo_sw - used to serialize access to the open seqid/reply handling 527 * cr_set - credential used for the OPEN 528 * statelist - root of state struct list associated with this openowner 529 * node - node for client struct list of openowners 530 * reply_fh - open replay processing needs the filehandle so that it is 531 * able to reset the current filehandle for appropriate compound 532 * processing and reply. 533 * reply - last reply sent in relation to this openowner 534 */ 535 typedef struct rfs4_openowner { 536 rfs4_dbe_t *ro_dbe; 537 rfs4_client_t *ro_client; 538 open_owner4 ro_owner; 539 unsigned ro_need_confirm:1; 540 unsigned ro_postpone_confirm:1; 541 seqid4 ro_open_seqid; 542 rfs4_state_wait_t ro_sw; 543 cred_set_t ro_cr_set; 544 list_t ro_statelist; 545 list_node_t ro_node; 546 nfs_fh4 ro_reply_fh; 547 nfs_resop4 ro_reply; 548 } rfs4_openowner_t; 549 550 /* 551 * This state struct represents the association between an openowner 552 * and a file that has been OPENed by that openowner. 553 * 554 * dbe - encapsulation struct 555 * stateid - server provided stateid 556 * owner - reference back to the openowner for this state 557 * finfo - reference to the open file for this state 558 * open_access - how did the openowner OPEN the file (access) 559 * open_deny - how did the openowner OPEN the file (deny) 560 * share_access - what share reservation is on the file (access) 561 * share_deny - what share reservation is on the file (deny) 562 * closed - has this file been closed? 563 * lostatelist - root of list of lo_state associated with this state/file 564 * node - node for state struct list of states 565 */ 566 typedef struct rfs4_state { 567 rfs4_dbe_t *rs_dbe; 568 stateid_t rs_stateid; 569 rfs4_openowner_t *rs_owner; 570 struct rfs4_file *rs_finfo; 571 uint32_t rs_open_access; 572 uint32_t rs_open_deny; 573 uint32_t rs_share_access; 574 uint32_t rs_share_deny; 575 unsigned rs_closed:1; 576 list_t rs_lostatelist; 577 list_node_t rs_node; 578 } rfs4_state_t; 579 580 /* 581 * Lockowner - track the lockowner and its related info 582 * 583 * dbe - encapsulation struct 584 * client - reference to the client 585 * owner - lockowner supplied by the client 586 * pid - local identifier used for file locking 587 */ 588 typedef struct rfs4_lockowner { 589 rfs4_dbe_t *rl_dbe; 590 rfs4_client_t *rl_client; 591 lock_owner4 rl_owner; 592 pid_t rl_pid; 593 } rfs4_lockowner_t; 594 595 /* 596 * Lockowner_state associated with a state struct and lockowner 597 * 598 * dbe - encapsulation struct 599 * state - reference back to state struct for open file 600 * lockid - stateid for this lockowner/state 601 * locker - reference to lockowner 602 * seqid - sequence id for this lockowner/state 603 * skip_seqid_check - used on initialization of struct 604 * locks_cleaned - have all locks been released for this lockowner/file? 605 * lock_completed - successful LOCK with lockowner/file? 606 * ls_sw - used to serialize update seqid/reply/stateid handling 607 * node - node for state struct list of lo_states 608 * reply - last reply sent in relation to this lockowner/state 609 */ 610 typedef struct rfs4_lo_state { 611 rfs4_dbe_t *rls_dbe; 612 rfs4_state_t *rls_state; 613 stateid_t rls_lockid; 614 rfs4_lockowner_t *rls_locker; 615 seqid4 rls_seqid; 616 unsigned rls_skip_seqid_check:1; 617 unsigned rls_locks_cleaned:1; 618 unsigned rls_lock_completed:1; 619 rfs4_state_wait_t rls_sw; 620 list_node_t rls_node; 621 nfs_resop4 rls_reply; 622 } rfs4_lo_state_t; 623 624 /* 625 * Delegation state - per client 626 * 627 * dbe - encapsulation struct 628 * dtype - type of delegation (NONE, READ, WRITE) 629 * delegid - stateid for this delegation 630 * time_granted - time this delegation was assigned to client 631 * time_recalled - time when the server started recall process 632 * time_revoked - if revoked, time that the revoke occurred 633 * finfo - reference to the file associated with this delegation 634 * client - reference to client for which this delegation is associated 635 * node - list of delegations for the file (WRITE == 1, READ == ) 636 */ 637 typedef struct rfs4_deleg_state { 638 rfs4_dbe_t *rds_dbe; 639 open_delegation_type4 rds_dtype; 640 stateid_t rds_delegid; 641 time_t rds_time_granted; 642 time_t rds_time_recalled; 643 time_t rds_time_revoked; 644 struct rfs4_file *rds_finfo; 645 rfs4_client_t *rds_client; 646 list_node_t rds_node; 647 } rfs4_deleg_state_t; 648 649 /* 650 * Delegation info associated with the file 651 * 652 * dtype - type of delegation for file (NONE, READ, WRITE) 653 * time_returned - time that last delegation was returned for file 654 * time_recalled - time that recall sequence started 655 * time_lastgrant - time that last delegation was provided to a client 656 * time_lastwrite - time of last write to use the delegation stateid 657 * time_rm_delayed - time of last remove/rename which was DELAYed 658 * rdgrants - how many read delegations have been provided for this file 659 * wrgrants - how many write delegations provided (can only be one) 660 * recall_count - how many recall threads are outstanding 661 * recall_lock - lock to protect contents of this struct 662 * recall_cv - condition var for the "parent" thread to wait upon 663 * deleg_change_grant - value for change attribute at time of write grant 664 * deleg_change - most recent value of change obtained from client 665 * deleg_change_ts - time of last deleg_change update 666 * ever_recalled - has this particular delegation ever been recalled? 667 * dont_grant - file deletion is impending, don't grant a delegation 668 * conflicted_client - clientid of the client that caused a CB_RECALL 669 * to occur. This is used for delegation policy (should a delegation 670 * be granted shortly after it has been returned?) 671 */ 672 typedef struct rfs4_dinfo { 673 open_delegation_type4 rd_dtype; 674 time_t rd_time_returned; 675 time_t rd_time_recalled; 676 time_t rd_time_lastgrant; 677 time_t rd_time_lastwrite; 678 time_t rd_time_rm_delayed; 679 uint32_t rd_rdgrants; 680 uint32_t rd_wrgrants; 681 int32_t rd_recall_count; 682 kmutex_t rd_recall_lock[1]; 683 kcondvar_t rd_recall_cv[1]; 684 bool_t rd_ever_recalled; 685 uint32_t rd_hold_grant; 686 clientid4 rd_conflicted_client; 687 } rfs4_dinfo_t; 688 689 /* 690 * File 691 * 692 * dbe - encapsulation struct 693 * vp - vnode for the file that is open or has a delegation 694 * filehandle - the filehandle generated by the server for this file 695 * delegstatelist - root of delegation list for this file 696 * dinfo - see struct definition above 697 * share_deny - union of all deny modes on file 698 * share_access - union of all access modes on file 699 * access_read - count of read access 700 * access_write - count of write access 701 * deny_read - count of deny reads 702 * deny_write - count of deny writes 703 * file_rwlock - lock for serializing the removal of a file while 704 * the state structures are active within the server 705 * 706 * The only requirement for locking file_rwlock is that the 707 * caller have a reference to the containing rfs4_file. The dbe 708 * lock may or may not be held for lock/unlock of file_rwlock. 709 * As mentioned above, the file_rwlock is used for serialization 710 * of file removal and more specifically reference to the held 711 * vnode (e.g. vp). 712 */ 713 typedef struct rfs4_file { 714 rfs4_dbe_t *rf_dbe; 715 vnode_t *rf_vp; 716 nfs_fh4 rf_filehandle; 717 list_t rf_delegstatelist; 718 rfs4_dinfo_t rf_dinfo; 719 uint32_t rf_share_deny; 720 uint32_t rf_share_access; 721 uint32_t rf_access_read; 722 uint32_t rf_access_write; 723 uint32_t rf_deny_read; 724 uint32_t rf_deny_write; 725 krwlock_t rf_file_rwlock; 726 } rfs4_file_t; 727 728 extern int rfs4_seen_first_compound; /* set first time we see one */ 729 730 extern rfs4_servinst_t *rfs4_cur_servinst; /* current server instance */ 731 extern kmutex_t rfs4_servinst_lock; /* protects linked list */ 732 extern void rfs4_servinst_create(int, int, char **); 733 extern void rfs4_servinst_destroy_all(void); 734 extern void rfs4_servinst_assign(rfs4_client_t *, 735 rfs4_servinst_t *); 736 extern rfs4_servinst_t *rfs4_servinst(rfs4_client_t *); 737 extern int rfs4_clnt_in_grace(rfs4_client_t *); 738 extern int rfs4_servinst_in_grace(rfs4_servinst_t *); 739 extern int rfs4_servinst_grace_new(rfs4_servinst_t *); 740 extern void rfs4_grace_start(rfs4_servinst_t *); 741 extern void rfs4_grace_start_new(void); 742 extern void rfs4_grace_reset_all(void); 743 extern void rfs4_ss_oldstate(rfs4_oldstate_t *, char *, char *); 744 extern void rfs4_dss_readstate(int, char **); 745 746 /* 747 * rfs4_deleg_policy is used to signify the server's global delegation 748 * policy. The default is to NEVER delegate files and the 749 * administrator must configure the server to enable delegations. 750 * 751 * The disable/enable delegation functions are used to eliminate a 752 * race with exclusive creates. 753 */ 754 typedef enum { 755 SRV_NEVER_DELEGATE = 0, 756 SRV_NORMAL_DELEGATE = 1 757 } srv_deleg_policy_t; 758 759 extern srv_deleg_policy_t rfs4_deleg_policy; 760 extern kmutex_t rfs4_deleg_lock; 761 extern void rfs4_disable_delegation(void), rfs4_enable_delegation(void); 762 763 /* 764 * Request types for delegation. These correspond with 765 * open_delegation_type4 with the addition of a new value, DELEG_ANY, 766 * to reqequest any delegation. 767 */ 768 typedef enum { 769 DELEG_NONE = 0, /* Corresponds to OPEN_DELEG_NONE */ 770 DELEG_READ = 1, /* Corresponds to OPEN_DELEG_READ */ 771 DELEG_WRITE = 2, /* Corresponds to OPEN_DELEG_WRITE */ 772 DELEG_ANY = -1 /* New value to request any delegation type */ 773 } delegreq_t; 774 775 #define NFS4_DELEG4TYPE2REQTYPE(x) (delegreq_t)(x) 776 777 /* 778 * Various interfaces to manipulate the state structures introduced 779 * above 780 */ 781 extern kmutex_t rfs4_state_lock; 782 extern void rfs4_clean_state_exi(struct exportinfo *exi); 783 extern void rfs4_free_reply(nfs_resop4 *); 784 extern void rfs4_copy_reply(nfs_resop4 *, nfs_resop4 *); 785 786 /* rfs4_client_t handling */ 787 extern rfs4_client_t *rfs4_findclient(nfs_client_id4 *, 788 bool_t *, rfs4_client_t *); 789 extern rfs4_client_t *rfs4_findclient_by_id(clientid4, bool_t); 790 extern rfs4_client_t *rfs4_findclient_by_addr(struct sockaddr *); 791 extern void rfs4_client_rele(rfs4_client_t *); 792 extern void rfs4_client_close(rfs4_client_t *); 793 extern void rfs4_client_state_remove(rfs4_client_t *); 794 extern void rfs4_client_scv_next(rfs4_client_t *); 795 extern void rfs4_update_lease(rfs4_client_t *); 796 extern bool_t rfs4_lease_expired(rfs4_client_t *); 797 extern nfsstat4 rfs4_check_clientid(clientid4 *, int); 798 799 /* rfs4_clntip_t handling */ 800 extern rfs4_clntip_t *rfs4_find_clntip(struct sockaddr *, bool_t *); 801 extern void rfs4_invalidate_clntip(struct sockaddr *); 802 803 /* rfs4_openowner_t handling */ 804 extern rfs4_openowner_t *rfs4_findopenowner(open_owner4 *, bool_t *, seqid4); 805 extern void rfs4_update_open_sequence(rfs4_openowner_t *); 806 extern void rfs4_update_open_resp(rfs4_openowner_t *, 807 nfs_resop4 *, nfs_fh4 *); 808 extern void rfs4_openowner_rele(rfs4_openowner_t *); 809 extern void rfs4_free_opens(rfs4_openowner_t *, bool_t, bool_t); 810 811 /* rfs4_lockowner_t handling */ 812 extern rfs4_lockowner_t *rfs4_findlockowner(lock_owner4 *, bool_t *); 813 extern rfs4_lockowner_t *rfs4_findlockowner_by_pid(pid_t); 814 extern void rfs4_lockowner_rele(rfs4_lockowner_t *); 815 816 /* rfs4_state_t handling */ 817 extern rfs4_state_t *rfs4_findstate_by_owner_file(rfs4_openowner_t *, 818 rfs4_file_t *, bool_t *); 819 extern void rfs4_state_rele(rfs4_state_t *); 820 extern void rfs4_state_close(rfs4_state_t *, bool_t, 821 bool_t, cred_t *); 822 extern void rfs4_release_share_lock_state(rfs4_state_t *, 823 cred_t *, bool_t); 824 extern void rfs4_close_all_state(rfs4_file_t *); 825 826 /* rfs4_lo_state_t handling */ 827 extern rfs4_lo_state_t *rfs4_findlo_state_by_owner(rfs4_lockowner_t *, 828 rfs4_state_t *, bool_t *); 829 extern void rfs4_lo_state_rele(rfs4_lo_state_t *, bool_t); 830 extern void rfs4_update_lock_sequence(rfs4_lo_state_t *); 831 extern void rfs4_update_lock_resp(rfs4_lo_state_t *, 832 nfs_resop4 *); 833 834 /* rfs4_file_t handling */ 835 extern rfs4_file_t *rfs4_findfile(vnode_t *, nfs_fh4 *, bool_t *); 836 extern rfs4_file_t *rfs4_findfile_withlock(vnode_t *, nfs_fh4 *, 837 bool_t *); 838 extern void rfs4_file_rele(rfs4_file_t *); 839 840 /* General collection of "get state" functions */ 841 extern nfsstat4 rfs4_get_state(stateid4 *, rfs4_state_t **, 842 rfs4_dbsearch_type_t); 843 extern nfsstat4 rfs4_get_deleg_state(stateid4 *, 844 rfs4_deleg_state_t **); 845 extern nfsstat4 rfs4_get_lo_state(stateid4 *, rfs4_lo_state_t **, 846 bool_t); 847 extern nfsstat4 rfs4_check_stateid(int, vnode_t *, stateid4 *, 848 bool_t, bool_t *, bool_t, 849 caller_context_t *); 850 extern int rfs4_check_stateid_seqid(rfs4_state_t *, stateid4 *); 851 extern int rfs4_check_lo_stateid_seqid(rfs4_lo_state_t *, 852 stateid4 *); 853 854 /* return values for rfs4_check_stateid_seqid() */ 855 #define NFS4_CHECK_STATEID_OKAY 1 856 #define NFS4_CHECK_STATEID_OLD 2 857 #define NFS4_CHECK_STATEID_BAD 3 858 #define NFS4_CHECK_STATEID_EXPIRED 4 859 #define NFS4_CHECK_STATEID_REPLAY 5 860 #define NFS4_CHECK_STATEID_CLOSED 6 861 #define NFS4_CHECK_STATEID_UNCONFIRMED 7 862 863 /* delay() time that server is willing to briefly wait for a delegreturn */ 864 #define NFS4_DELEGATION_CONFLICT_DELAY (hz/10) 865 866 /* 867 * Interfaces for handling of callback's client handle cache and 868 * callback interfaces themselves. 869 */ 870 extern void rfs4_cbinfo_free(rfs4_cbinfo_t *); 871 extern void rfs4_client_setcb(rfs4_client_t *, cb_client4 *, 872 uint32_t); 873 extern void rfs4_deleg_cb_check(rfs4_client_t *); 874 extern nfsstat4 rfs4_vop_getattr(vnode_t *, vattr_t *, int, cred_t *); 875 876 /* rfs4_deleg_state_t handling and other delegation interfaces */ 877 extern rfs4_deleg_state_t *rfs4_finddeleg(rfs4_state_t *, bool_t *); 878 extern rfs4_deleg_state_t *rfs4_finddelegstate(stateid_t *); 879 extern bool_t rfs4_check_recall(rfs4_state_t *, uint32_t); 880 extern void rfs4_recall_deleg(rfs4_file_t *, 881 bool_t, rfs4_client_t *); 882 extern int rfs4_get_deleg(rfs4_state_t *, open_delegation_type4, 883 open_delegation_type4 (*policy)(rfs4_state_t *, 884 open_delegation_type4 dtype)); 885 extern rfs4_deleg_state_t *rfs4_grant_delegation(delegreq_t, rfs4_state_t *, 886 int *); 887 extern void rfs4_set_deleg_response(rfs4_deleg_state_t *, 888 open_delegation4 *, nfsace4 *, int); 889 extern void rfs4_return_deleg(rfs4_deleg_state_t *, bool_t); 890 extern bool_t rfs4_is_deleg(rfs4_state_t *); 891 extern void rfs4_deleg_state_rele(rfs4_deleg_state_t *); 892 extern bool_t rfs4_check_delegated_byfp(int, rfs4_file_t *, 893 bool_t, bool_t, bool_t, clientid4 *); 894 extern void rfs4_clear_dont_grant(rfs4_file_t *); 895 896 /* 897 * nfs4 monitored operations. 898 */ 899 extern int deleg_rd_open(femarg_t *, int, cred_t *, caller_context_t *); 900 extern int deleg_wr_open(femarg_t *, int, cred_t *, caller_context_t *); 901 extern int deleg_wr_read(femarg_t *, uio_t *, int, cred_t *, 902 caller_context_t *); 903 extern int deleg_rd_write(femarg_t *, uio_t *, int, cred_t *, 904 caller_context_t *); 905 extern int deleg_wr_write(femarg_t *, uio_t *, int, cred_t *, 906 caller_context_t *); 907 extern int deleg_rd_setattr(femarg_t *, vattr_t *, int, cred_t *, 908 caller_context_t *); 909 extern int deleg_wr_setattr(femarg_t *, vattr_t *, int, cred_t *, 910 caller_context_t *); 911 extern int deleg_rd_rwlock(femarg_t *, int, caller_context_t *); 912 extern int deleg_wr_rwlock(femarg_t *, int, caller_context_t *); 913 extern int deleg_rd_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *, 914 caller_context_t *); 915 extern int deleg_wr_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *, 916 caller_context_t *); 917 extern int deleg_rd_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *, 918 caller_context_t *); 919 extern int deleg_wr_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *, 920 caller_context_t *); 921 extern int deleg_rd_vnevent(femarg_t *, vnevent_t, vnode_t *, char *, 922 caller_context_t *); 923 extern int deleg_wr_vnevent(femarg_t *, vnevent_t, vnode_t *, char *, 924 caller_context_t *); 925 926 extern void rfs4_mon_hold(void *); 927 extern void rfs4_mon_rele(void *); 928 929 extern fem_t *deleg_rdops; 930 extern fem_t *deleg_wrops; 931 932 extern int rfs4_share(rfs4_state_t *, uint32_t, uint32_t); 933 extern int rfs4_unshare(rfs4_state_t *); 934 extern void rfs4_set_deleg_policy(srv_deleg_policy_t); 935 #ifdef DEBUG 936 #define NFS4_DEBUG(var, args) if (var) cmn_err args 937 938 extern int rfs4_debug; 939 extern int nfs4_client_attr_debug; 940 extern int nfs4_client_state_debug; 941 extern int nfs4_client_shadow_debug; 942 extern int nfs4_client_lock_debug; 943 extern int nfs4_client_lease_debug; 944 extern int nfs4_seqid_sync; 945 extern int nfs4_client_map_debug; 946 extern int nfs4_client_inactive_debug; 947 extern int nfs4_client_recov_debug; 948 extern int nfs4_client_failover_debug; 949 extern int nfs4_client_call_debug; 950 extern int nfs4_client_foo_debug; 951 extern int nfs4_client_zone_debug; 952 extern int nfs4_lost_rqst_debug; 953 extern int nfs4_open_stream_debug; 954 extern int nfs4_client_open_dg; 955 extern int nfs4_srvmnt_debug; 956 extern int nfs4_utf8_debug; 957 958 void rfs4_dbe_debug(rfs4_dbe_t *e); 959 960 #ifdef NFS4_DEBUG_MUTEX 961 void nfs4_debug_mutex_enter(kmutex_t *, char *, int); 962 void nfs4_debug_mutex_exit(kmutex_t *, char *, int); 963 964 #define mutex_enter(m) nfs4_debug_mutex_enter((m), __FILE__, __LINE__) 965 #define mutex_exit(m) nfs4_debug_mutex_exit((m), __FILE__, __LINE__) 966 #endif /* NFS4_DEBUG_MUTEX */ 967 968 #else /* ! DEBUG */ 969 #define NFS4_DEBUG(var, args) 970 #endif /* DEBUG */ 971 972 /* 973 * XXX - temporary for testing of volatile fh 974 */ 975 976 #ifdef VOLATILE_FH_TEST 977 978 struct nfs_fh4_fmt { 979 fhandle4_t fh4_i; 980 uint32_t fh4_flag; 981 uint32_t fh4_volatile_id; 982 }; 983 984 #else /* VOLATILE_FH_TEST */ 985 986 struct nfs_fh4_fmt { 987 fhandle4_t fh4_i; 988 uint32_t fh4_flag; 989 }; 990 991 #endif /* VOLATILE_FH_TEST */ 992 993 #define FH4_NAMEDATTR 1 994 #define FH4_ATTRDIR 2 995 996 #define fh4_fsid fh4_i.fhx_fsid 997 #define fh4_len fh4_i.fhx_len /* fid length */ 998 #define fh4_data fh4_i.fhx_data /* fid bytes */ 999 #define fh4_xlen fh4_i.fhx_xlen 1000 #define fh4_xdata fh4_i.fhx_xdata 1001 typedef struct nfs_fh4_fmt nfs_fh4_fmt_t; 1002 1003 #define fh4_to_fmt4(fh4p) ((nfs_fh4_fmt_t *)(fh4p)->nfs_fh4_val) 1004 #define get_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) & (flag)) 1005 #define set_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) |= (flag)) 1006 #define clr_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) &= ~(flag)) 1007 1008 #define NFS_FH4_LEN sizeof (nfs_fh4_fmt_t) 1009 1010 /* 1011 * Copy fields from external (fhandle_t) to in-memory (nfs_fh4_fmt_t) 1012 * format to support export info checking. It does not copy over 1013 * the complete filehandle, just the fsid, xlen and xdata. It may 1014 * need to be changed to be used in other places. 1015 * 1016 * NOTE: The macro expects the space to be pre-allocated for 1017 * the contents of nfs_fh4_fmt_t. 1018 */ 1019 #define FH_TO_FMT4(exifh, nfs_fmt) { \ 1020 bzero((nfs_fmt), NFS_FH4_LEN); \ 1021 (nfs_fmt)->fh4_fsid = (exifh)->fh_fsid; \ 1022 (nfs_fmt)->fh4_xlen = (exifh)->fh_xlen; \ 1023 bcopy((exifh)->fh_xdata, (nfs_fmt)->fh4_xdata, \ 1024 (exifh)->fh_xlen); \ 1025 } 1026 1027 /* 1028 * A few definitions of repeatedly used constructs for nfsv4 1029 */ 1030 #define UTF8STRING_FREE(str) \ 1031 kmem_free((str).utf8string_val, (str).utf8string_len); \ 1032 (str).utf8string_val = NULL; \ 1033 (str).utf8string_len = 0; 1034 1035 /* 1036 * NFS4_VOLATILE_FH yields non-zero if the filesystem uses non-persistent 1037 * filehandles. 1038 */ 1039 #define NFS4_VOLATILE_FH(mi) \ 1040 ((mi)->mi_fh_expire_type & \ 1041 (FH4_VOLATILE_ANY | FH4_VOL_MIGRATION | FH4_VOL_RENAME)) 1042 1043 /* 1044 * NFS_IS_DOTNAME checks if the name given represents a dot or dotdot entry 1045 */ 1046 #define NFS_IS_DOTNAME(name) \ 1047 (((name)[0] == '.') && \ 1048 (((name)[1] == '\0') || (((name)[1] == '.') && ((name)[2] == '\0')))) 1049 1050 /* 1051 * Define the number of bits in a bitmap word (uint32) 1052 */ 1053 #define NFS4_BITMAP4_BITSPERWORD (sizeof (uint32_t) * 8) 1054 1055 /* 1056 * Define the value for the access field of the compound_state structure 1057 * based on the result of nfsauth access checking. 1058 */ 1059 #define CS_ACCESS_OK 0x1 1060 #define CS_ACCESS_DENIED 0x2 1061 #define CS_ACCESS_LIMITED 0x4 1062 1063 /* 1064 * compound state in nfsv4 server 1065 */ 1066 struct compound_state { 1067 struct exportinfo *exi; 1068 struct exportinfo *saved_exi; /* export struct for saved_vp */ 1069 cred_t *basecr; /* UNIX cred: only RPC request */ 1070 caddr_t principal; 1071 int nfsflavor; 1072 cred_t *cr; /* UNIX cred: RPC request and */ 1073 /* target export */ 1074 bool_t cont; 1075 uint_t access; /* access perm on vp per request */ 1076 bool_t deleg; /* TRUE if current fh has */ 1077 /* write delegated */ 1078 vnode_t *vp; /* modified by PUTFH, and by ops that */ 1079 /* input to GETFH */ 1080 bool_t mandlock; /* Is mandatory locking in effect */ 1081 /* for vp */ 1082 vnode_t *saved_vp; /* modified by SAVEFH, copied to */ 1083 /* vp by RESTOREFH */ 1084 nfsstat4 *statusp; 1085 nfs_fh4 fh; /* ditto. valid only if vp != NULL */ 1086 nfs_fh4 saved_fh; /* ditto. valid only if */ 1087 /* saved_vp != NULL */ 1088 struct svc_req *req; 1089 char fhbuf[NFS4_FHSIZE]; 1090 }; 1091 1092 /* 1093 * Conversion commands for nfsv4 server attr checking 1094 */ 1095 enum nfs4_attr_cmd { 1096 NFS4ATTR_SUPPORTED = 0, /* check which attrs supported */ 1097 NFS4ATTR_GETIT = 1, /* getattr - sys to fattr4 (r) */ 1098 NFS4ATTR_SETIT = 2, /* setattr - fattr4 to sys (w) */ 1099 NFS4ATTR_VERIT = 3, /* verify - fattr4 to sys (r) */ 1100 NFS4ATTR_FREEIT = 4 /* free any alloc'd space for attr */ 1101 }; 1102 1103 typedef enum nfs4_attr_cmd nfs4_attr_cmd_t; 1104 1105 struct nfs4_svgetit_arg { 1106 nfs4_attr_cmd_t op; /* getit or setit */ 1107 struct compound_state *cs; 1108 struct statvfs64 *sbp; 1109 uint_t flag; /* VOP_GETATTR/VOP_SETATTR flag */ 1110 uint_t xattr; /* object is xattr */ 1111 bool_t rdattr_error_req; /* if readdir & client wants */ 1112 /* rdattr_error */ 1113 nfsstat4 rdattr_error; /* used for per-entry status */ 1114 /* (if rdattr_err) */ 1115 bool_t is_referral; /* because sometimes we tell lies */ 1116 bool_t mntdfid_set; 1117 fattr4_mounted_on_fileid 1118 mounted_on_fileid; 1119 /* readdir op can always return */ 1120 /* d_ino from server fs dirent */ 1121 /* for mounted_on_fileid attr. */ 1122 /* This field holds d_ino so */ 1123 /* srv attr conv code can avoid */ 1124 /* doing an untraverse. */ 1125 vattr_t vap[1]; 1126 }; 1127 1128 struct nfs4_ntov_map { 1129 bitmap4 fbit; /* FATTR4_XXX_MASKY */ 1130 uint_t vbit; /* AT_XXX */ 1131 bool_t vfsstat; 1132 bool_t mandatory; /* attribute mandatory to implement? */ 1133 uint_t nval; 1134 int xdr_size; /* Size of XDR'd attr */ 1135 xdrproc_t xfunc; 1136 int (*sv_getit)(nfs4_attr_cmd_t, struct nfs4_svgetit_arg *, 1137 union nfs4_attr_u *); /* subroutine for getting attr. */ 1138 char *prtstr; /* string attr for printing */ 1139 }; 1140 1141 struct nfs4attr_to_vattr { 1142 vnode_t *vp; 1143 vattr_t *vap; 1144 nfs_fh4 *fhp; 1145 nfsstat4 rdattr_error; 1146 uint32_t flag; 1147 fattr4_change change; 1148 fattr4_fsid srv_fsid; 1149 fattr4_mounted_on_fileid mntd_fid; 1150 }; 1151 1152 typedef struct nfs4attr_to_vattr ntov4_t; 1153 1154 /* 1155 * nfs4attr_to_vattr flags 1156 */ 1157 #define NTOV_FHP_VALID 0x01 1158 #define NTOV_RDATTR_ERROR_VALID 0x02 1159 #define NTOV_CHANGE_VALID 0x04 1160 #define NTOV_SUPP_VALID 0x08 1161 #define NTOV_SRV_FSID_VALID 0x10 1162 #define NTOV_MOUNTED_ON_FILEID_VALID 0x20 1163 1164 1165 #define FATTR4_MANDATTR_MASK ( \ 1166 FATTR4_SUPPORTED_ATTRS_MASK | \ 1167 FATTR4_TYPE_MASK | \ 1168 FATTR4_FH_EXPIRE_TYPE_MASK | \ 1169 FATTR4_CHANGE_MASK | \ 1170 FATTR4_SIZE_MASK | \ 1171 FATTR4_LINK_SUPPORT_MASK | \ 1172 FATTR4_SYMLINK_SUPPORT_MASK | \ 1173 FATTR4_NAMED_ATTR_MASK | \ 1174 FATTR4_FSID_MASK | \ 1175 FATTR4_UNIQUE_HANDLES_MASK | \ 1176 FATTR4_LEASE_TIME_MASK | \ 1177 FATTR4_RDATTR_ERROR_MASK | \ 1178 FATTR4_FILEHANDLE_MASK) 1179 1180 1181 struct nfs4attr_to_osattr { 1182 void *attrconv_arg; 1183 uint_t mask; 1184 }; 1185 1186 struct mntinfo4; 1187 1188 /* 1189 * lkp4_attr_setup lists the different options for attributes when calling 1190 * nfs4lookup_setup - either no attributes (just lookups - e.g., secinfo), 1191 * one component only (normal component lookup), get attributes for the 1192 * last component (e.g., mount), attributes for each component (e.g., 1193 * failovers later), just the filehandle for the last component (e.g., 1194 * volatile filehandle recovery), or stuff that needs OPENATTR (e.g. 1195 * looking up a named attribute or it's hidden directory). 1196 */ 1197 enum lkp4_attr_setup { 1198 LKP4_NO_ATTRIBUTES = 0, /* no attrs or filehandles */ 1199 LKP4_ALL_ATTRIBUTES = 3, /* multi-comp: attrs for all comps */ 1200 LKP4_LAST_NAMED_ATTR = 5, /* multi-comp: named attr & attrdir */ 1201 LKP4_LAST_ATTRDIR = 6, /* multi-comp: just attrdir */ 1202 LKP4_ALL_ATTR_SECINFO = 7 /* multi-comp: attrs for all comp and */ 1203 /* secinfo for last comp */ 1204 }; 1205 1206 /* 1207 * lookup4_param a set of parameters to nfs4lookup_setup - 1208 * used to setup a path lookup compound request. 1209 */ 1210 typedef struct lookup4_param { 1211 enum lkp4_attr_setup l4_getattrs; /* (in) get attrs in the lookup? */ 1212 int header_len; /* (in) num ops before first lookup */ 1213 int trailer_len; /* (in) num ops after last */ 1214 /* Lookup/Getattr */ 1215 bitmap4 ga_bits; /* (in) Which attributes for Getattr */ 1216 COMPOUND4args_clnt *argsp; /* (in/out) args for compound struct */ 1217 COMPOUND4res_clnt *resp; /* (in/out) res for compound struct */ 1218 int arglen; /* (out) argop buffer alloc'd length */ 1219 struct mntinfo4 *mi; 1220 } lookup4_param_t; 1221 1222 1223 #define NFS4_FATTR4_FINISH -1 /* fattr4 index indicating finish */ 1224 1225 typedef int (*nfs4attr_to_os_t)(int, union nfs4_attr_u *, 1226 struct nfs4attr_to_osattr *); 1227 1228 /* 1229 * The nfs4_error_t is the basic structure to return error values 1230 * from rfs4call. It encapsulates the unix errno 1231 * value, the nfsstat4 value and the rpc status value into a single 1232 * structure. 1233 * 1234 * If error is set, then stat is ignored and rpc_status may be 1235 * set if the error occurred as the result of a CLNT_CALL. If 1236 * stat is set, then rpc request succeeded, error and 1237 * rpc_status are set to 0 and stat contains the result of 1238 * operation, NFS4_OK or one of the NFS4ERR_* values. 1239 * 1240 * Functions which want to generate errors independently from 1241 * rfs4call should set error to the desired errno value and 1242 * set stat and rpc_status to 0. nfs4_error_init() is a 1243 * convenient function to do this. 1244 */ 1245 typedef struct { 1246 int error; 1247 nfsstat4 stat; 1248 enum clnt_stat rpc_status; 1249 } nfs4_error_t; 1250 1251 /* 1252 * Shared functions 1253 */ 1254 extern void rfs4_op_readdir(nfs_argop4 *, nfs_resop4 *, 1255 struct svc_req *, struct compound_state *); 1256 extern void nfs_fh4_copy(nfs_fh4 *, nfs_fh4 *); 1257 1258 extern void nfs4_fattr4_free(fattr4 *); 1259 1260 extern int nfs4lookup_setup(char *, lookup4_param_t *, int); 1261 extern void nfs4_getattr_otw_norecovery(vnode_t *, 1262 nfs4_ga_res_t *, nfs4_error_t *, cred_t *, int); 1263 extern int nfs4_getattr_otw(vnode_t *, nfs4_ga_res_t *, cred_t *, int); 1264 extern int nfs4cmpfh(const nfs_fh4 *, const nfs_fh4 *); 1265 extern int nfs4cmpfhandle(nfs4_fhandle_t *, nfs4_fhandle_t *); 1266 extern int nfs4getattr(vnode_t *, struct vattr *, cred_t *); 1267 extern int nfs4_waitfor_purge_complete(vnode_t *); 1268 extern int nfs4_validate_caches(vnode_t *, cred_t *); 1269 extern int nfs4init(int, char *); 1270 extern void nfs4fini(void); 1271 extern int nfs4_vfsinit(void); 1272 extern void nfs4_vfsfini(void); 1273 1274 extern void nfs4_vnops_init(void); 1275 extern void nfs4_vnops_fini(void); 1276 extern void nfs_idmap_init(void); 1277 extern void nfs_idmap_flush(int); 1278 extern void nfs_idmap_fini(void); 1279 extern int nfs4_rnode_init(void); 1280 extern int nfs4_rnode_fini(void); 1281 extern int nfs4_shadow_init(void); 1282 extern int nfs4_shadow_fini(void); 1283 extern int nfs4_acache_init(void); 1284 extern int nfs4_acache_fini(void); 1285 extern int nfs4_subr_init(void); 1286 extern int nfs4_subr_fini(void); 1287 extern void nfs4_acl_init(void); 1288 extern void nfs4_acl_free_cache(vsecattr_t *); 1289 1290 extern int geterrno4(nfsstat4); 1291 extern nfsstat4 puterrno4(int); 1292 extern int nfs4_need_to_bump_seqid(COMPOUND4res_clnt *); 1293 extern int nfs4tsize(void); 1294 extern int checkauth4(struct compound_state *, struct svc_req *); 1295 extern nfsstat4 call_checkauth4(struct compound_state *, struct svc_req *); 1296 extern int is_exported_sec(int, struct exportinfo *); 1297 extern void nfs4_vmask_to_nmask(uint_t, bitmap4 *); 1298 extern void nfs4_vmask_to_nmask_set(uint_t, bitmap4 *); 1299 extern int nfs_idmap_str_uid(utf8string *u8s, uid_t *, bool_t); 1300 extern int nfs_idmap_str_gid(utf8string *u8s, gid_t *, bool_t); 1301 extern int nfs_idmap_uid_str(uid_t, utf8string *u8s, bool_t); 1302 extern int nfs_idmap_gid_str(gid_t gid, utf8string *u8s, bool_t); 1303 extern int nfs4_time_ntov(nfstime4 *, timestruc_t *); 1304 extern int nfs4_time_vton(timestruc_t *, nfstime4 *); 1305 extern char *utf8_to_str(utf8string *, uint_t *, char *); 1306 extern char *utf8_to_fn(utf8string *, uint_t *, char *); 1307 extern utf8string *str_to_utf8(char *, utf8string *); 1308 extern utf8string *utf8_copy(utf8string *, utf8string *); 1309 extern int utf8_compare(const utf8string *, const utf8string *); 1310 extern int utf8_dir_verify(utf8string *); 1311 extern char *utf8_strchr(utf8string *, const char); 1312 extern int ln_ace4_cmp(nfsace4 *, nfsace4 *, int); 1313 extern int vs_aent_to_ace4(vsecattr_t *, vsecattr_t *, int, int); 1314 extern int vs_ace4_to_aent(vsecattr_t *, vsecattr_t *, uid_t, gid_t, 1315 int, int, int); 1316 extern int vs_ace4_to_acet(vsecattr_t *, vsecattr_t *, uid_t, gid_t, 1317 int, int); 1318 extern int vs_acet_to_ace4(vsecattr_t *, vsecattr_t *, int); 1319 extern void vs_acet_destroy(vsecattr_t *); 1320 extern void vs_ace4_destroy(vsecattr_t *); 1321 extern void vs_aent_destroy(vsecattr_t *); 1322 1323 extern int vn_find_nfs_record(vnode_t *, nvlist_t **, char **, char **); 1324 extern int vn_is_nfs_reparse(vnode_t *, cred_t *); 1325 extern fs_locations4 *fetch_referral(vnode_t *, cred_t *); 1326 extern char *build_symlink(vnode_t *, cred_t *, size_t *); 1327 1328 extern int stateid4_cmp(stateid4 *, stateid4 *); 1329 1330 extern vtype_t nf4_to_vt[]; 1331 1332 extern struct nfs4_ntov_map nfs4_ntov_map[]; 1333 extern uint_t nfs4_ntov_map_size; 1334 1335 extern kstat_named_t *rfsproccnt_v4_ptr; 1336 extern struct vfsops *nfs4_vfsops; 1337 extern struct vnodeops *nfs4_vnodeops; 1338 extern const struct fs_operation_def nfs4_vnodeops_template[]; 1339 extern vnodeops_t *nfs4_trigger_vnodeops; 1340 extern const struct fs_operation_def nfs4_trigger_vnodeops_template[]; 1341 1342 extern uint_t nfs4_tsize(struct knetconfig *); 1343 extern uint_t rfs4_tsize(struct svc_req *); 1344 1345 extern bool_t xdr_inline_decode_nfs_fh4(uint32_t *, nfs_fh4_fmt_t *, 1346 uint32_t); 1347 extern bool_t xdr_inline_encode_nfs_fh4(uint32_t **, uint32_t *, 1348 nfs_fh4_fmt_t *); 1349 1350 #ifdef DEBUG 1351 extern int rfs4_do_pre_op_attr; 1352 extern int rfs4_do_post_op_attr; 1353 #endif 1354 1355 extern stateid4 clnt_special0; 1356 extern stateid4 clnt_special1; 1357 #define CLNT_ISSPECIAL(id) (stateid4_cmp(id, &clnt_special0) || \ 1358 stateid4_cmp(id, &clnt_special1)) 1359 1360 /* 1361 * The NFS Version 4 service procedures. 1362 */ 1363 1364 extern void rfs4_compound(COMPOUND4args *, COMPOUND4res *, 1365 struct exportinfo *, struct svc_req *, cred_t *, int *); 1366 extern void rfs4_compound_free(COMPOUND4res *); 1367 extern void rfs4_compound_flagproc(COMPOUND4args *, int *); 1368 1369 extern int rfs4_srvrinit(void); 1370 extern void rfs4_srvrfini(void); 1371 extern void rfs4_state_init(void); 1372 extern void rfs4_state_fini(void); 1373 1374 #endif 1375 #ifdef __cplusplus 1376 } 1377 #endif 1378 1379 #endif /* _NFS4_H */ 1380