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