17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 527242a7cSthurlow * Common Development and Distribution License (the "License"). 627242a7cSthurlow * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*2e9d26a4Srmesta * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _NFS4_H 277c478bd9Sstevel@tonic-gate #define _NFS4_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 337c478bd9Sstevel@tonic-gate #include <sys/fem.h> 347c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 357c478bd9Sstevel@tonic-gate #include <nfs/nfs.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef _KERNEL 387c478bd9Sstevel@tonic-gate #include <nfs/nfs4_kprot.h> 39cee86682Scalum #include <sys/nvpair.h> 407c478bd9Sstevel@tonic-gate #else 417c478bd9Sstevel@tonic-gate #include <rpcsvc/nfs4_prot.h> 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate #include <nfs/nfs4_attr.h> 447c478bd9Sstevel@tonic-gate #include <sys/acl.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #ifdef __cplusplus 477c478bd9Sstevel@tonic-gate extern "C" { 487c478bd9Sstevel@tonic-gate #endif 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #define NFS4_MAX_UTF8STRING 65536 517c478bd9Sstevel@tonic-gate #define NFS4_MAX_PATHNAME4 65536 527c478bd9Sstevel@tonic-gate #define NFS4_MAX_SECOID4 65536 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #ifdef _KERNEL 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate typedef struct nfs4_fhandle { 577c478bd9Sstevel@tonic-gate int fh_len; 587c478bd9Sstevel@tonic-gate char fh_buf[NFS4_FHSIZE]; 597c478bd9Sstevel@tonic-gate } nfs4_fhandle_t; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate #define NFS4_MINORVERSION 0 627c478bd9Sstevel@tonic-gate #define CB4_MINORVERSION 0 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * Set the fattr4_change variable using a time struct. Note that change 667c478bd9Sstevel@tonic-gate * is 64 bits, but timestruc_t is 128 bits in a 64-bit kernel. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate #define NFS4_SET_FATTR4_CHANGE(change, ts) \ 697c478bd9Sstevel@tonic-gate { \ 707c478bd9Sstevel@tonic-gate change = (ts).tv_sec; \ 717c478bd9Sstevel@tonic-gate change <<= 32; \ 727c478bd9Sstevel@tonic-gate change |= (uint32_t)((ts).tv_nsec); \ 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* 767c478bd9Sstevel@tonic-gate * Server lease period. Value is in seconds; Also used for grace period 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate extern time_t rfs4_lease_time; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * This set of typedefs and interfaces represent the core or base set 827c478bd9Sstevel@tonic-gate * of functionality that backs the NFSv4 server's state related data 837c478bd9Sstevel@tonic-gate * structures. Since the NFSv4 server needs inter-RPC state to be 847c478bd9Sstevel@tonic-gate * available that is unrelated to the filesystem (in other words, 857c478bd9Sstevel@tonic-gate * soft-state), this functionality is needed to maintain that and is 867c478bd9Sstevel@tonic-gate * written to be somewhat flexible to adapt to the various types of 877c478bd9Sstevel@tonic-gate * data structures contained within the server. 887c478bd9Sstevel@tonic-gate * 897c478bd9Sstevel@tonic-gate * The basic structure at this level is that the server maintains a 907c478bd9Sstevel@tonic-gate * global "database" which consists of a set of tables. Each table 917c478bd9Sstevel@tonic-gate * contains a set of like data structures. Each table is indexed by 927c478bd9Sstevel@tonic-gate * at least one hash function and in most cases two hashes. Each 937c478bd9Sstevel@tonic-gate * table's characteristics is set when it is created at run-time via 947c478bd9Sstevel@tonic-gate * rfs4_table_create(). All table creation and related functions are 957c478bd9Sstevel@tonic-gate * located in nfs4_state.c. The generic database functionality is 967c478bd9Sstevel@tonic-gate * located in nfs4_db.c. 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate typedef struct rfs4_dbe rfs4_dbe_t; /* basic opaque db entry */ 1007c478bd9Sstevel@tonic-gate typedef struct rfs4_table rfs4_table_t; /* basic table type */ 1017c478bd9Sstevel@tonic-gate typedef struct rfs4_index rfs4_index_t; /* index */ 1027c478bd9Sstevel@tonic-gate typedef struct rfs4_database rfs4_database_t; /* and database */ 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate typedef struct { /* opaque entry type for later use */ 1057c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 1067c478bd9Sstevel@tonic-gate } *rfs4_entry_t; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate extern rfs4_table_t *rfs4_client_tab; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* database, table, index creation entry points */ 1117c478bd9Sstevel@tonic-gate extern rfs4_database_t *rfs4_database_create(uint32_t); 1127c478bd9Sstevel@tonic-gate extern void rfs4_database_shutdown(rfs4_database_t *); 1137c478bd9Sstevel@tonic-gate extern void rfs4_database_destroy(rfs4_database_t *); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate extern void rfs4_database_destroy(rfs4_database_t *); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate extern rfs4_table_t *rfs4_table_create(rfs4_database_t *, char *, 1187c478bd9Sstevel@tonic-gate time_t, uint32_t, 1197c478bd9Sstevel@tonic-gate bool_t (*create)(rfs4_entry_t, void *), 1207c478bd9Sstevel@tonic-gate void (*destroy)(rfs4_entry_t), 1217c478bd9Sstevel@tonic-gate bool_t (*expiry)(rfs4_entry_t), 1227c478bd9Sstevel@tonic-gate uint32_t, uint32_t, uint32_t, id_t); 1237c478bd9Sstevel@tonic-gate extern void rfs4_table_destroy(rfs4_database_t *, rfs4_table_t *); 1247c478bd9Sstevel@tonic-gate extern rfs4_index_t *rfs4_index_create(rfs4_table_t *, char *, 1257c478bd9Sstevel@tonic-gate uint32_t (*hash)(void *), 1267c478bd9Sstevel@tonic-gate bool_t (compare)(rfs4_entry_t, void *), 1277c478bd9Sstevel@tonic-gate void *(*mkkey)(rfs4_entry_t), bool_t); 1287c478bd9Sstevel@tonic-gate extern void rfs4_index_destroy(rfs4_index_t *); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* Type used to direct rfs4_dbsearch() in what types of records to inspect */ 1317c478bd9Sstevel@tonic-gate typedef enum {RFS4_DBS_VALID, RFS4_DBS_INVALID} rfs4_dbsearch_type_t; 1327c478bd9Sstevel@tonic-gate /* search and db entry manipulation entry points */ 1337c478bd9Sstevel@tonic-gate extern rfs4_entry_t rfs4_dbsearch(rfs4_index_t *, void *, 1347c478bd9Sstevel@tonic-gate bool_t *, void *, rfs4_dbsearch_type_t); 1357c478bd9Sstevel@tonic-gate extern void rfs4_dbe_lock(rfs4_dbe_t *); 1367c478bd9Sstevel@tonic-gate extern void rfs4_dbe_unlock(rfs4_dbe_t *); 1377c478bd9Sstevel@tonic-gate extern clock_t rfs4_dbe_twait(rfs4_dbe_t *, clock_t); 1387c478bd9Sstevel@tonic-gate extern void rfs4_dbe_cv_broadcast(rfs4_dbe_t *); 1397c478bd9Sstevel@tonic-gate extern void rfs4_dbe_hold(rfs4_dbe_t *); 1407c478bd9Sstevel@tonic-gate extern void rfs4_dbe_hold_nolock(rfs4_dbe_t *); 1417c478bd9Sstevel@tonic-gate extern void rfs4_dbe_rele_nolock(rfs4_dbe_t *); 1427c478bd9Sstevel@tonic-gate extern void rfs4_dbe_rele(rfs4_dbe_t *); 1437c478bd9Sstevel@tonic-gate extern uint32_t rfs4_dbe_refcnt(rfs4_dbe_t *); 1447c478bd9Sstevel@tonic-gate extern id_t rfs4_dbe_getid(rfs4_dbe_t *); 1457c478bd9Sstevel@tonic-gate extern void rfs4_dbe_invalidate(rfs4_dbe_t *); 1467c478bd9Sstevel@tonic-gate extern bool_t rfs4_dbe_is_invalid(rfs4_dbe_t *); 1477c478bd9Sstevel@tonic-gate extern time_t rfs4_dbe_get_timerele(rfs4_dbe_t *); 1487c478bd9Sstevel@tonic-gate extern void rfs4_dbe_hide(rfs4_dbe_t *); 1497c478bd9Sstevel@tonic-gate extern void rfs4_dbe_unhide(rfs4_dbe_t *); 1507c478bd9Sstevel@tonic-gate #ifdef DEBUG 1517c478bd9Sstevel@tonic-gate extern bool_t rfs4_dbe_islocked(rfs4_dbe_t *); 1527c478bd9Sstevel@tonic-gate #endif 1537c478bd9Sstevel@tonic-gate extern void rfs4_dbe_walk(rfs4_table_t *, 1547c478bd9Sstevel@tonic-gate void (*callout)(rfs4_entry_t, void *), void *); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * Minimal server stable storage. 1587c478bd9Sstevel@tonic-gate * 1597c478bd9Sstevel@tonic-gate * Currently the NFSv4 server will only save the client 1607c478bd9Sstevel@tonic-gate * ID (the long version) so that it will be able to 1617c478bd9Sstevel@tonic-gate * grant possible reclaim requests during the infamous 1627c478bd9Sstevel@tonic-gate * grace_period. 1637c478bd9Sstevel@tonic-gate */ 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate #define RFS4_SS_DIRSIZE 64 * 1024 1667c478bd9Sstevel@tonic-gate #define NFS4_SS_VERSION 1 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* handy pathname structure */ 1697c478bd9Sstevel@tonic-gate typedef struct ss_pn { 1707c478bd9Sstevel@tonic-gate char *leaf; 1717c478bd9Sstevel@tonic-gate char pn[MAXPATHLEN]; 1727c478bd9Sstevel@tonic-gate } rfs4_ss_pn_t; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * The server will build this link list on startup. It represents the 1767c478bd9Sstevel@tonic-gate * clients that have had valid state on the server in a prior instance. 1777c478bd9Sstevel@tonic-gate * 1787c478bd9Sstevel@tonic-gate */ 1797c478bd9Sstevel@tonic-gate typedef struct rfs4_oldstate { 1807c478bd9Sstevel@tonic-gate struct rfs4_oldstate *next; 1817c478bd9Sstevel@tonic-gate struct rfs4_oldstate *prev; 1827c478bd9Sstevel@tonic-gate rfs4_ss_pn_t *ss_pn; 1837c478bd9Sstevel@tonic-gate nfs_client_id4 cl_id4; 1847c478bd9Sstevel@tonic-gate } rfs4_oldstate_t; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * This union is used to overlay the server's internal treatment of 1887c478bd9Sstevel@tonic-gate * the protocols stateid4 datatype. Therefore, "bits" must not exceed 1897c478bd9Sstevel@tonic-gate * the size of stateid4 and more importantly should match the size of 1907c478bd9Sstevel@tonic-gate * stateid4. The chgseq field must the first entry since it overlays 1917c478bd9Sstevel@tonic-gate * stateid4.seqid. 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate typedef union { 1947c478bd9Sstevel@tonic-gate stateid4 stateid; 1957c478bd9Sstevel@tonic-gate struct { 1967c478bd9Sstevel@tonic-gate uint32_t chgseq; /* State changes / protocol's seqid */ 1977c478bd9Sstevel@tonic-gate uint32_t boottime; /* boot time */ 1987c478bd9Sstevel@tonic-gate uint32_t type:2; /* stateid_type_t as define below */ 1997c478bd9Sstevel@tonic-gate uint32_t clnodeid:8; /* cluster server nodeid */ 2007c478bd9Sstevel@tonic-gate uint32_t ident:22; /* 2^22-1 openowner x fhs */ 2017c478bd9Sstevel@tonic-gate pid_t pid; /* pid of corresponding lock owner */ 2027c478bd9Sstevel@tonic-gate } bits; 2037c478bd9Sstevel@tonic-gate } stateid_t; 2047c478bd9Sstevel@tonic-gate /* 2057c478bd9Sstevel@tonic-gate * Note that the way the type field above is defined, this enum must 2067c478bd9Sstevel@tonic-gate * not have more than 4 members. 2077c478bd9Sstevel@tonic-gate */ 2087c478bd9Sstevel@tonic-gate typedef enum {OPENID, LOCKID, DELEGID} stateid_type_t; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * Set of RPC credentials used for a particular operation. 2137c478bd9Sstevel@tonic-gate * Used for operations like SETCLIENTID_CONFIRM where the 2147c478bd9Sstevel@tonic-gate * credentials needs to match those used at SETCLIENTID. 2157c478bd9Sstevel@tonic-gate */ 2167c478bd9Sstevel@tonic-gate typedef void *cred_set_t; /* For now XXX */ 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate /* 2197c478bd9Sstevel@tonic-gate * "wait" struct for use in the open open and lock owner state 2207c478bd9Sstevel@tonic-gate * structures to provide serialization between server threads that are 2217c478bd9Sstevel@tonic-gate * handling requests for the same open owner or lock stateid. This 2227c478bd9Sstevel@tonic-gate * way only one thread will be updating things like sequence ids, 2237c478bd9Sstevel@tonic-gate * replay cache and stateid at a time. 2247c478bd9Sstevel@tonic-gate */ 2257c478bd9Sstevel@tonic-gate typedef struct rfs4_state_wait { 2267c478bd9Sstevel@tonic-gate uint32_t sw_active; 2277c478bd9Sstevel@tonic-gate uint32_t sw_wait_count; 2287c478bd9Sstevel@tonic-gate kmutex_t sw_cv_lock[1]; 2297c478bd9Sstevel@tonic-gate kcondvar_t sw_cv[1]; 2307c478bd9Sstevel@tonic-gate } rfs4_state_wait_t; 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate extern void rfs4_sw_enter(rfs4_state_wait_t *); 2337c478bd9Sstevel@tonic-gate extern void rfs4_sw_exit(rfs4_state_wait_t *); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * This enum and the following rfs4_cbinfo_t struct are used to 2377c478bd9Sstevel@tonic-gate * maintain information about the callback path used from the server 2387c478bd9Sstevel@tonic-gate * to client for operations like CB_GETATTR and CB_RECALL. The 2397c478bd9Sstevel@tonic-gate * rfs4_cbinfo_t struct is meant to be encompassed in the client 2407c478bd9Sstevel@tonic-gate * struct and managed within that structure's locking scheme. 2417c478bd9Sstevel@tonic-gate * 2427c478bd9Sstevel@tonic-gate * The various states of the callback path are used by the server to 2437c478bd9Sstevel@tonic-gate * determine if delegations should initially be provided to a client 2447c478bd9Sstevel@tonic-gate * and then later on if connectivity has been lost and delegations 2457c478bd9Sstevel@tonic-gate * should be revoked. 2467c478bd9Sstevel@tonic-gate */ 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* 2497c478bd9Sstevel@tonic-gate * CB_NOCHANGE - Special value used for interfaces within the delegation 2507c478bd9Sstevel@tonic-gate * code to signify that "no change" has occurred to the 2517c478bd9Sstevel@tonic-gate * callback path 2527c478bd9Sstevel@tonic-gate * CB_UNINIT - No callback info provided by the client 2537c478bd9Sstevel@tonic-gate * CB_NONE - Callback info provided but CB_NULL call 2547c478bd9Sstevel@tonic-gate * has yet to be attempted 2557c478bd9Sstevel@tonic-gate * CB_OK - Callback path tested with CB_NULL with success 2567c478bd9Sstevel@tonic-gate * CB_INPROG - Callback path currently being tested with CB_NULL 2577c478bd9Sstevel@tonic-gate * CB_FAILED - Callback path was == CB_OK but has failed 2587c478bd9Sstevel@tonic-gate * with timeout/rpc error 2597c478bd9Sstevel@tonic-gate * CB_BAD - Callback info provided but CB_NULL failed 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate typedef enum { 2627c478bd9Sstevel@tonic-gate CB_NOCHANGE = 0, 2637c478bd9Sstevel@tonic-gate CB_UNINIT = 1, 2647c478bd9Sstevel@tonic-gate CB_NONE = 2, 2657c478bd9Sstevel@tonic-gate CB_OK = 3, 2667c478bd9Sstevel@tonic-gate CB_INPROG = 4, 2677c478bd9Sstevel@tonic-gate CB_FAILED = 5, 2687c478bd9Sstevel@tonic-gate CB_BAD = 6 2697c478bd9Sstevel@tonic-gate } rfs4_cbstate_t; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate #define RFS4_CBCH_MAX 10 /* size callback client handle cache */ 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * Callback info for a client. 2747c478bd9Sstevel@tonic-gate * Client only provides: cb_client4 and cb_ident 2757c478bd9Sstevel@tonic-gate * The rest of the information is used to track callback path status 2767c478bd9Sstevel@tonic-gate * and usage. 2777c478bd9Sstevel@tonic-gate * 2787c478bd9Sstevel@tonic-gate * cb_state - used as comments for the rfs4_cbstate_t enum indicate 2797c478bd9Sstevel@tonic-gate * cb_notified_of_cb_path_down - if the callback path was once CB_OK and 2807c478bd9Sstevel@tonic-gate * has hence CB_FAILED, the client needs to be notified via RENEW. 2817c478bd9Sstevel@tonic-gate * cb_timefailed - current time when cb_state transitioned from 2827c478bd9Sstevel@tonic-gate * CB_OK -> CB_FAILED. Meant for observability. When did that happen? 2837c478bd9Sstevel@tonic-gate * cb_chc_free/cb_chc - cache of client handles for the callback path 2847c478bd9Sstevel@tonic-gate * cb_ident - SETCLIENTID provided callback_ident value 2857c478bd9Sstevel@tonic-gate * callback - SETCLIENTID provided cb_client4 value 2867c478bd9Sstevel@tonic-gate * cb_refcnt - current number of users of this structure's content 2877c478bd9Sstevel@tonic-gate * protected by cb_lock 2887c478bd9Sstevel@tonic-gate * cb_badbehavior - how many times did a client do something we didn't like? 2897c478bd9Sstevel@tonic-gate * cb_lock - lock for contents of cbinfo 2907c478bd9Sstevel@tonic-gate * cb_cv - used to allow threads to wait on CB_NULL completion 2917c478bd9Sstevel@tonic-gate * cb_nullcaller - is there a thread currently taking care of 2927c478bd9Sstevel@tonic-gate * new callback information? 2937c478bd9Sstevel@tonic-gate * cb_cv_nullcaller - used by the thread doing CB_NULL to wait on 2947c478bd9Sstevel@tonic-gate * threads that may be using client handles of the current 2957c478bd9Sstevel@tonic-gate * client handle cache. 2967c478bd9Sstevel@tonic-gate * newer - new callback info provided by a client and awaiting 2977c478bd9Sstevel@tonic-gate * CB_NULL testing and move to regular cbinfo. 2987c478bd9Sstevel@tonic-gate */ 2997c478bd9Sstevel@tonic-gate typedef struct { 3007c478bd9Sstevel@tonic-gate rfs4_cbstate_t cb_state; 3017c478bd9Sstevel@tonic-gate unsigned cb_notified_of_cb_path_down:1; 3027c478bd9Sstevel@tonic-gate time_t cb_timefailed; 3037c478bd9Sstevel@tonic-gate int cb_chc_free; 3047c478bd9Sstevel@tonic-gate CLIENT *cb_chc[RFS4_CBCH_MAX]; 3057c478bd9Sstevel@tonic-gate uint32_t cb_ident; 3067c478bd9Sstevel@tonic-gate cb_client4 cb_callback; 3077c478bd9Sstevel@tonic-gate uint32_t cb_refcnt; 3087c478bd9Sstevel@tonic-gate uint32_t cb_badbehavior; 3097c478bd9Sstevel@tonic-gate kmutex_t cb_lock[1]; 3107c478bd9Sstevel@tonic-gate kcondvar_t cb_cv[1]; 3117c478bd9Sstevel@tonic-gate bool_t cb_nullcaller; 3127c478bd9Sstevel@tonic-gate kcondvar_t cb_cv_nullcaller[1]; 3137c478bd9Sstevel@tonic-gate struct { 3147c478bd9Sstevel@tonic-gate bool_t cb_new; 3157c478bd9Sstevel@tonic-gate bool_t cb_confirmed; 3167c478bd9Sstevel@tonic-gate uint32_t cb_ident; 3177c478bd9Sstevel@tonic-gate cb_client4 cb_callback; 3187c478bd9Sstevel@tonic-gate } cb_newer; 3197c478bd9Sstevel@tonic-gate } rfs4_cbinfo_t; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate /* 3227c478bd9Sstevel@tonic-gate * A server instance. We can associate sets of clients - via a pointer in 3237c478bd9Sstevel@tonic-gate * rfs4_client_t - with a given server instance, allowing us to treat clients 3247c478bd9Sstevel@tonic-gate * in the set differently to clients in other sets. 3257c478bd9Sstevel@tonic-gate * 3267c478bd9Sstevel@tonic-gate * Currently used only for Sun Cluster HA-NFS support, to group clients 3277c478bd9Sstevel@tonic-gate * on NFS resource failover so each set of clients gets its own dedicated 328cee86682Scalum * grace period and distributed stable storage data. 3297c478bd9Sstevel@tonic-gate */ 3307c478bd9Sstevel@tonic-gate typedef struct rfs4_servinst { 331cee86682Scalum int dss_npaths; 3327c478bd9Sstevel@tonic-gate krwlock_t rwlock; 333cee86682Scalum krwlock_t oldstate_lock; 3347c478bd9Sstevel@tonic-gate time_t start_time; 3357c478bd9Sstevel@tonic-gate time_t grace_period; 336cee86682Scalum rfs4_oldstate_t *oldstate; 337cee86682Scalum struct rfs4_dss_path **dss_paths; 3387c478bd9Sstevel@tonic-gate struct rfs4_servinst *next; 3397c478bd9Sstevel@tonic-gate struct rfs4_servinst *prev; 3407c478bd9Sstevel@tonic-gate } rfs4_servinst_t; 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate /* 343cee86682Scalum * DSS: distributed stable storage 344cee86682Scalum */ 345cee86682Scalum 346cee86682Scalum typedef struct rfs4_dss_path { 347cee86682Scalum struct rfs4_dss_path *next; /* for insque/remque */ 348cee86682Scalum struct rfs4_dss_path *prev; /* for insque/remque */ 349cee86682Scalum char *path; 350cee86682Scalum struct rfs4_servinst *sip; 351cee86682Scalum unsigned index; /* offset in servinst's array */ 352cee86682Scalum } rfs4_dss_path_t; 353cee86682Scalum 354cee86682Scalum /* array of paths passed-in from nfsd command-line; stored in nvlist */ 355cee86682Scalum char **rfs4_dss_newpaths; 356cee86682Scalum uint_t rfs4_dss_numnewpaths; 357cee86682Scalum 358cee86682Scalum /* 359cee86682Scalum * Circular doubly-linked list of paths for currently-served RGs. 360cee86682Scalum * No locking required: only changed on warmstart. Managed with insque/remque. 361cee86682Scalum */ 362cee86682Scalum rfs4_dss_path_t *rfs4_dss_pathlist; 363cee86682Scalum 364cee86682Scalum /* nvlists of all DSS paths: current, and before last warmstart */ 365cee86682Scalum nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths; 366cee86682Scalum 367cee86682Scalum /* 3687c478bd9Sstevel@tonic-gate * List declarations (suitable for insque/remque) used to link the 3697c478bd9Sstevel@tonic-gate * various datastructs listed below. 3707c478bd9Sstevel@tonic-gate */ 3717c478bd9Sstevel@tonic-gate typedef struct rfs4_state_list { 3727c478bd9Sstevel@tonic-gate struct rfs4_state_list *next; 3737c478bd9Sstevel@tonic-gate struct rfs4_state_list *prev; 3747c478bd9Sstevel@tonic-gate struct rfs4_state *sp; 3757c478bd9Sstevel@tonic-gate } rfs4_state_list_t; 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate typedef struct rfs4_lo_state_list { 3787c478bd9Sstevel@tonic-gate struct rfs4_lo_state_list *next; 3797c478bd9Sstevel@tonic-gate struct rfs4_lo_state_list *prev; 3807c478bd9Sstevel@tonic-gate struct rfs4_lo_state *lsp; 3817c478bd9Sstevel@tonic-gate } rfs4_lo_state_list_t; 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate typedef struct rfs4_openowner_list { 3847c478bd9Sstevel@tonic-gate struct rfs4_openowner_list *next; 3857c478bd9Sstevel@tonic-gate struct rfs4_openowner_list *prev; 3867c478bd9Sstevel@tonic-gate struct rfs4_openowner *oop; 3877c478bd9Sstevel@tonic-gate } rfs4_openowner_list_t; 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate typedef struct rfs4_deleg_list { 3907c478bd9Sstevel@tonic-gate struct rfs4_deleg_list *next; 3917c478bd9Sstevel@tonic-gate struct rfs4_deleg_list *prev; 3927c478bd9Sstevel@tonic-gate struct rfs4_deleg_state *dsp; 3937c478bd9Sstevel@tonic-gate } rfs4_deleg_list_t; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* 3967c478bd9Sstevel@tonic-gate * The server maintains a set of state on a per client basis that 3977c478bd9Sstevel@tonic-gate * matches that of the protocol requirements. A client's state is 3987c478bd9Sstevel@tonic-gate * rooted with the rfs4_client_t struct of which there is one per 3997c478bd9Sstevel@tonic-gate * client and is created when SETCLIENTID/SETCLIENTID_CONFIRM are 4007c478bd9Sstevel@tonic-gate * received. From there, the server then creates rfs4_openowner_t 4017c478bd9Sstevel@tonic-gate * structs for each new open owner from that client and are initiated 4027c478bd9Sstevel@tonic-gate * at OPEN/OPEN_CONFIRM (when the open owner is new to the server). 4037c478bd9Sstevel@tonic-gate * At OPEN, at least two other structures are created, and potentially a 4047c478bd9Sstevel@tonic-gate * third. rfs4_state_t is created to track the association between an 4057c478bd9Sstevel@tonic-gate * open owner and a particular file. An rfs4_file_t struct may be 4067c478bd9Sstevel@tonic-gate * created (if the file is not already open) at OPEN as well. The 4077c478bd9Sstevel@tonic-gate * rfs4_file_t struct is the only one that is per server and not per 4087c478bd9Sstevel@tonic-gate * client. The rfs4_deleg_state_t struct is created in the 4097c478bd9Sstevel@tonic-gate * instance that the server is going to provide a delegation for the 4107c478bd9Sstevel@tonic-gate * file being OPENed. Finally, the rfs4_lockowner_t is created at the 4117c478bd9Sstevel@tonic-gate * first use of a lock owner at the server and is a result of the LOCK 4127c478bd9Sstevel@tonic-gate * operation. The rfs4_lo_state_t struct is then created to represent 4137c478bd9Sstevel@tonic-gate * the relation between the lock owner and the file. 4147c478bd9Sstevel@tonic-gate * 4157c478bd9Sstevel@tonic-gate */ 4167c478bd9Sstevel@tonic-gate /* 4177c478bd9Sstevel@tonic-gate * The following ascii art represents each of these data structs and 4187c478bd9Sstevel@tonic-gate * their references to each other. Note: "<-(x)->" represents the 4197c478bd9Sstevel@tonic-gate * doubly link lists defined above. 4207c478bd9Sstevel@tonic-gate * 4217c478bd9Sstevel@tonic-gate * ____________________ 4227c478bd9Sstevel@tonic-gate * | | 4237c478bd9Sstevel@tonic-gate * | rfs4_client_t | 4247c478bd9Sstevel@tonic-gate * ->| (1),(2) |<- 4257c478bd9Sstevel@tonic-gate * / |____________________| \ 4267c478bd9Sstevel@tonic-gate * / ^ \ 4277c478bd9Sstevel@tonic-gate * / | \ 4287c478bd9Sstevel@tonic-gate * ____________________ ____________________ ____________________ 4297c478bd9Sstevel@tonic-gate * | | | | | | 4307c478bd9Sstevel@tonic-gate * | rfs4_lockowner_t | | rfs4_openowner_t | | rfs4_deleg_state_t | 4317c478bd9Sstevel@tonic-gate * | | | (3) <-(1)-> | | <-(2)-> | 4327c478bd9Sstevel@tonic-gate * |____________________| |____________________| |____________________| 4337c478bd9Sstevel@tonic-gate * ^ ^ | 4347c478bd9Sstevel@tonic-gate * | | V 4357c478bd9Sstevel@tonic-gate * ____________________ ____________________ ____________________ 4367c478bd9Sstevel@tonic-gate * | | | | | | 4377c478bd9Sstevel@tonic-gate * | rfs4_lo_state_t |->| rfs4_state_t |->| rfs4_file_t | 4387c478bd9Sstevel@tonic-gate * | <-(4)-> | | (4) <-(3)-> | | | 4397c478bd9Sstevel@tonic-gate * |____________________| |____________________| |____________________| 4407c478bd9Sstevel@tonic-gate */ 4417c478bd9Sstevel@tonic-gate /* 4427c478bd9Sstevel@tonic-gate * Each of these data types are kept in a separate rfs4_table_t and is 4437c478bd9Sstevel@tonic-gate * actually encapsulated within a rfs4_dbe_t struct. The various 4447c478bd9Sstevel@tonic-gate * tables and their construction is done in nfs4_state.c but 4457c478bd9Sstevel@tonic-gate * documented here to completeness. 4467c478bd9Sstevel@tonic-gate * 4477c478bd9Sstevel@tonic-gate * Table Data struct stored Indexed by 4487c478bd9Sstevel@tonic-gate * ----- ------------------ ---------- 4497c478bd9Sstevel@tonic-gate * rfs4_client_tab rfs4_client_t nfs_client_id4 4507c478bd9Sstevel@tonic-gate * clientid4 4517c478bd9Sstevel@tonic-gate * 4527c478bd9Sstevel@tonic-gate * rfs4_openowner_tab rfs4_openowner_t open_owner4 4537c478bd9Sstevel@tonic-gate * 4547c478bd9Sstevel@tonic-gate * rfs4_state_tab rfs4_state_t open_owner4 | file 4557c478bd9Sstevel@tonic-gate * stateid 4567c478bd9Sstevel@tonic-gate * 4577c478bd9Sstevel@tonic-gate * rfs4_lo_state_tab rfs4_lo_state_t lockowner | stateid 4587c478bd9Sstevel@tonic-gate * lock_stateid 4597c478bd9Sstevel@tonic-gate * 4607c478bd9Sstevel@tonic-gate * rfs4_lockowner_tab rfs4_lockowner_t lockowner 4617c478bd9Sstevel@tonic-gate * pid 4627c478bd9Sstevel@tonic-gate * 4637c478bd9Sstevel@tonic-gate * rfs4_file_tab rfs4_file_t filehandle 4647c478bd9Sstevel@tonic-gate * 4657c478bd9Sstevel@tonic-gate * rfs4_deleg_state_tab rfs4_deleg_state_t clientid4 | file 4667c478bd9Sstevel@tonic-gate * deleg_stateid 4677c478bd9Sstevel@tonic-gate */ 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate /* 4707c478bd9Sstevel@tonic-gate * The client struct, it is the root of all state for a particular 4717c478bd9Sstevel@tonic-gate * client. The client is identified by the nfs_client_id4 via 4727c478bd9Sstevel@tonic-gate * SETCLIENTID and the server returns the clientid4 as short hand reference 4737c478bd9Sstevel@tonic-gate */ 4747c478bd9Sstevel@tonic-gate /* 4757c478bd9Sstevel@tonic-gate * Client struct - as mentioned above it is the root of all state for 4767c478bd9Sstevel@tonic-gate * a single client as identified by the client supplied nfs_client_id4 4777c478bd9Sstevel@tonic-gate * 4787c478bd9Sstevel@tonic-gate * dbe - encapsulation struct 4797c478bd9Sstevel@tonic-gate * clientid - server assigned short hand reference to client 4807c478bd9Sstevel@tonic-gate * nfs_client - client supplied identifier for itself 4817c478bd9Sstevel@tonic-gate * confirm_verf - the value provided to the client for SETCLIENTID_CONFIRM 4827c478bd9Sstevel@tonic-gate * need_confirm - does this client need to be SETCLIENTID_CONFIRMed? 4837c478bd9Sstevel@tonic-gate * 4847c478bd9Sstevel@tonic-gate * unlksys_completed - has an F_UNLKSYS been done for this client which 4857c478bd9Sstevel@tonic-gate * says that the use of cleanlocks() on individual files 4867c478bd9Sstevel@tonic-gate * is not required? 4877c478bd9Sstevel@tonic-gate * can_reclaim - indicates if client is allowed to reclaim after server 4887c478bd9Sstevel@tonic-gate * start-up (client had previous state at server) 4897c478bd9Sstevel@tonic-gate * ss_remove - indicates that the rfs4_client_destroy function should 4907c478bd9Sstevel@tonic-gate * clean up stable storage file. 4917c478bd9Sstevel@tonic-gate * forced_expire - set if the sysadmin has used clear_locks for this client. 4927c478bd9Sstevel@tonic-gate * deleg_revoked - how many delegations have been revoked for this client? 4937c478bd9Sstevel@tonic-gate * 4947c478bd9Sstevel@tonic-gate * cp_confirmed - this refers to a confirmed client struct that has 4957c478bd9Sstevel@tonic-gate * the same nfs_client_id4 as this client struct. When/if this client 4967c478bd9Sstevel@tonic-gate * struct is confirmed via SETCLINETID_CONFIRM, the previously 4977c478bd9Sstevel@tonic-gate * confirmed client struct will be "closed" and hence this reference. 4987c478bd9Sstevel@tonic-gate * 4997c478bd9Sstevel@tonic-gate * last_access - used to determine if the client has let its lease expire 5007c478bd9Sstevel@tonic-gate * cbinfo - struct containing all callback related information 5017c478bd9Sstevel@tonic-gate * cr_set - credentials used for the SETCLIENTID/SETCLIENTID_CONFIRM pair 5027c478bd9Sstevel@tonic-gate * sysid - the lock manager sysid allocated for this client's file locks 5037c478bd9Sstevel@tonic-gate * openownerlist - root of openowners list associated with this client 5047c478bd9Sstevel@tonic-gate * clientdeleglist - root of delegations list provided to this client 5057c478bd9Sstevel@tonic-gate * ss_pn - Pathname to the stable storage file. 5067c478bd9Sstevel@tonic-gate * cl_addr - Clients network address. 5077c478bd9Sstevel@tonic-gate * server_instance - pointer to the currently associated server instance 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate typedef struct rfs4_client { 5107c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 5117c478bd9Sstevel@tonic-gate clientid4 clientid; 5127c478bd9Sstevel@tonic-gate nfs_client_id4 nfs_client; 5137c478bd9Sstevel@tonic-gate verifier4 confirm_verf; 5147c478bd9Sstevel@tonic-gate unsigned need_confirm:1; 5157c478bd9Sstevel@tonic-gate unsigned unlksys_completed:1; 5167c478bd9Sstevel@tonic-gate unsigned can_reclaim:1; 5177c478bd9Sstevel@tonic-gate unsigned ss_remove:1; 5187c478bd9Sstevel@tonic-gate unsigned forced_expire:1; 5197c478bd9Sstevel@tonic-gate uint_t deleg_revoked; 5207c478bd9Sstevel@tonic-gate struct rfs4_client *cp_confirmed; 5217c478bd9Sstevel@tonic-gate time_t last_access; 5227c478bd9Sstevel@tonic-gate rfs4_cbinfo_t cbinfo; 5237c478bd9Sstevel@tonic-gate cred_set_t cr_set; 5247c478bd9Sstevel@tonic-gate sysid_t sysidt; 5257c478bd9Sstevel@tonic-gate rfs4_openowner_list_t openownerlist; 5267c478bd9Sstevel@tonic-gate rfs4_deleg_list_t clientdeleglist; 5277c478bd9Sstevel@tonic-gate rfs4_ss_pn_t *ss_pn; 5287c478bd9Sstevel@tonic-gate struct sockaddr_storage cl_addr; 5297c478bd9Sstevel@tonic-gate rfs4_servinst_t *server_instance; 5307c478bd9Sstevel@tonic-gate } rfs4_client_t; 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate /* 5337c478bd9Sstevel@tonic-gate * The openowner contains the client supplied open_owner4 as well as 5347c478bd9Sstevel@tonic-gate * the matching sequence id and is used to track the client's usage of 5357c478bd9Sstevel@tonic-gate * the open_owner4. Note that a reply is saved here as well for 5367c478bd9Sstevel@tonic-gate * processing of retransmissions. 5377c478bd9Sstevel@tonic-gate * 5387c478bd9Sstevel@tonic-gate * dbe - encapsulation struct 5397c478bd9Sstevel@tonic-gate * client - reference to rfs4_client_t for this openowner 5407c478bd9Sstevel@tonic-gate * owner - actual client supplied open_owner4 5417c478bd9Sstevel@tonic-gate * need_confirm - does this openowner need to be OPEN_CONFIRMed 5427c478bd9Sstevel@tonic-gate * postpone_confirm - set if error received on first use of open_owner 5437c478bd9Sstevel@tonic-gate * state2confirm - what stateid4 should be used on the OPEN_CONFIRM 5447c478bd9Sstevel@tonic-gate * open_seqid - what is the next open_seqid expected for this openowner 5457c478bd9Sstevel@tonic-gate * oo_sw - used to serialize access to the open seqid/reply handling 5467c478bd9Sstevel@tonic-gate * cr_set - credential used for the OPEN 5477c478bd9Sstevel@tonic-gate * ownerstateids - root of state struct list associated with this openowner 5487c478bd9Sstevel@tonic-gate * openownerlist - list of openowners for a client struct 5497c478bd9Sstevel@tonic-gate * reply_fh - open replay processing needs the filehandle so that it is 5507c478bd9Sstevel@tonic-gate * able to reset the current filehandle for appropriate compound 5517c478bd9Sstevel@tonic-gate * processing and reply. 5527c478bd9Sstevel@tonic-gate * reply - last reply sent in relation to this openowner 5537c478bd9Sstevel@tonic-gate */ 5547c478bd9Sstevel@tonic-gate typedef struct rfs4_openowner { 5557c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 5567c478bd9Sstevel@tonic-gate rfs4_client_t *client; 5577c478bd9Sstevel@tonic-gate open_owner4 owner; 5587c478bd9Sstevel@tonic-gate unsigned need_confirm:1; 5597c478bd9Sstevel@tonic-gate unsigned postpone_confirm:1; 5607c478bd9Sstevel@tonic-gate seqid4 open_seqid; 5617c478bd9Sstevel@tonic-gate rfs4_state_wait_t oo_sw; 5627c478bd9Sstevel@tonic-gate cred_set_t cr_set; 5637c478bd9Sstevel@tonic-gate rfs4_state_list_t ownerstateids; 5647c478bd9Sstevel@tonic-gate rfs4_openowner_list_t openownerlist; 5657c478bd9Sstevel@tonic-gate nfs_fh4 reply_fh; 5667c478bd9Sstevel@tonic-gate nfs_resop4 reply[1]; 5677c478bd9Sstevel@tonic-gate } rfs4_openowner_t; 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate /* 5707c478bd9Sstevel@tonic-gate * This state struct represents the association between an openowner 5717c478bd9Sstevel@tonic-gate * and a file that has been OPENed by that openowner. 5727c478bd9Sstevel@tonic-gate * 5737c478bd9Sstevel@tonic-gate * dbe - encapsulation struct 5747c478bd9Sstevel@tonic-gate * stateid - server provided stateid 5757c478bd9Sstevel@tonic-gate * owner - reference back to the openowner for this state 5767c478bd9Sstevel@tonic-gate * finfo - reference to the open file for this state 5777c478bd9Sstevel@tonic-gate * share_access - how did the openowner OPEN the file (access) 5787c478bd9Sstevel@tonic-gate * share_deny - how did the openowner OPEN the file (deny) 5797c478bd9Sstevel@tonic-gate * closed - has this file been closed? 5807c478bd9Sstevel@tonic-gate * lockownerlist - root of list of lockowners associated with this state/file 5817c478bd9Sstevel@tonic-gate * ownerstateids - list of state structs for an openowner 5827c478bd9Sstevel@tonic-gate */ 5837c478bd9Sstevel@tonic-gate typedef struct rfs4_state { 5847c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 5857c478bd9Sstevel@tonic-gate stateid_t stateid; 5867c478bd9Sstevel@tonic-gate rfs4_openowner_t *owner; 5877c478bd9Sstevel@tonic-gate struct rfs4_file *finfo; 5887c478bd9Sstevel@tonic-gate uint32_t share_access; 5897c478bd9Sstevel@tonic-gate uint32_t share_deny; 5907c478bd9Sstevel@tonic-gate unsigned closed:1; 5917c478bd9Sstevel@tonic-gate rfs4_lo_state_list_t lockownerlist; 5927c478bd9Sstevel@tonic-gate rfs4_state_list_t ownerstateids; 5937c478bd9Sstevel@tonic-gate } rfs4_state_t; 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate /* 5967c478bd9Sstevel@tonic-gate * Lockowner - track the lockowner and its related info 5977c478bd9Sstevel@tonic-gate * 5987c478bd9Sstevel@tonic-gate * dbe - encapsulation struct 5997c478bd9Sstevel@tonic-gate * client - reference to the client 6007c478bd9Sstevel@tonic-gate * owner - lockowner supplied by the client 6017c478bd9Sstevel@tonic-gate * pid - local identifier used for file locking 6027c478bd9Sstevel@tonic-gate */ 6037c478bd9Sstevel@tonic-gate typedef struct rfs4_lockowner { 6047c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 6057c478bd9Sstevel@tonic-gate rfs4_client_t *client; 6067c478bd9Sstevel@tonic-gate lock_owner4 owner; 6077c478bd9Sstevel@tonic-gate pid_t pid; 6087c478bd9Sstevel@tonic-gate } rfs4_lockowner_t; 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * Lockowner_state associated with a state struct and lockowner 6127c478bd9Sstevel@tonic-gate * 6137c478bd9Sstevel@tonic-gate * dbe - encapsulation struct 6147c478bd9Sstevel@tonic-gate * state - reference back to state struct for open file 6157c478bd9Sstevel@tonic-gate * lockid - stateid for this lockowner/state 6167c478bd9Sstevel@tonic-gate * locker - reference to lockowner 6177c478bd9Sstevel@tonic-gate * seqid - sequence id for this lockowner/state 6187c478bd9Sstevel@tonic-gate * skip_seqid_check - used on initialization of struct 6197c478bd9Sstevel@tonic-gate * locks_cleaned - have all locks been released for this lockowner/file? 6207c478bd9Sstevel@tonic-gate * lock_completed - successful LOCK with lockowner/file? 6217c478bd9Sstevel@tonic-gate * ls_sw - used to serialize update seqid/reply/stateid handling 6227c478bd9Sstevel@tonic-gate * lockownerlist - list of lockowners for a state struct 6237c478bd9Sstevel@tonic-gate * reply - last reply sent in relation to this lockowner/state 6247c478bd9Sstevel@tonic-gate */ 6257c478bd9Sstevel@tonic-gate typedef struct rfs4_lo_state { 6267c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 6277c478bd9Sstevel@tonic-gate rfs4_state_t *state; 6287c478bd9Sstevel@tonic-gate stateid_t lockid; 6297c478bd9Sstevel@tonic-gate rfs4_lockowner_t *locker; 6307c478bd9Sstevel@tonic-gate seqid4 seqid; 6317c478bd9Sstevel@tonic-gate unsigned skip_seqid_check:1; 6327c478bd9Sstevel@tonic-gate unsigned locks_cleaned:1; 6337c478bd9Sstevel@tonic-gate unsigned lock_completed:1; 6347c478bd9Sstevel@tonic-gate rfs4_state_wait_t ls_sw; 6357c478bd9Sstevel@tonic-gate rfs4_lo_state_list_t lockownerlist; 6367c478bd9Sstevel@tonic-gate nfs_resop4 reply[1]; 6377c478bd9Sstevel@tonic-gate } rfs4_lo_state_t; 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate /* 6407c478bd9Sstevel@tonic-gate * Delegation state - per client 6417c478bd9Sstevel@tonic-gate * 6427c478bd9Sstevel@tonic-gate * dbe - encapsulation struct 6437c478bd9Sstevel@tonic-gate * dtype - type of delegation (NONE, READ, WRITE) 6447c478bd9Sstevel@tonic-gate * delegid - stateid for this delegation 6457c478bd9Sstevel@tonic-gate * time_granted - time this delegation was assigned to client 6467c478bd9Sstevel@tonic-gate * time_recalled - time when the server started recall process 6477c478bd9Sstevel@tonic-gate * time_revoked - if revoked, time that the revoke occurred 6487c478bd9Sstevel@tonic-gate * finfo - reference to the file associated with this delegation 6497c478bd9Sstevel@tonic-gate * client - reference to client for which this delegation is associated 6507c478bd9Sstevel@tonic-gate * delegationlist - list of delegations for the file (WRITE == 1, READ == ) 6517c478bd9Sstevel@tonic-gate * clientdeleglist - list of delegations for the client 6527c478bd9Sstevel@tonic-gate */ 6537c478bd9Sstevel@tonic-gate typedef struct rfs4_deleg_state { 6547c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 6557c478bd9Sstevel@tonic-gate open_delegation_type4 dtype; 6567c478bd9Sstevel@tonic-gate stateid_t delegid; 6577c478bd9Sstevel@tonic-gate time_t time_granted; 6587c478bd9Sstevel@tonic-gate time_t time_recalled; 6597c478bd9Sstevel@tonic-gate time_t time_revoked; 6607c478bd9Sstevel@tonic-gate struct rfs4_file *finfo; 6617c478bd9Sstevel@tonic-gate rfs4_client_t *client; 6627c478bd9Sstevel@tonic-gate rfs4_deleg_list_t delegationlist; 6637c478bd9Sstevel@tonic-gate rfs4_deleg_list_t clientdeleglist; 6647c478bd9Sstevel@tonic-gate } rfs4_deleg_state_t; 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate /* 6677c478bd9Sstevel@tonic-gate * Delegation info associated with the file 6687c478bd9Sstevel@tonic-gate * 6697c478bd9Sstevel@tonic-gate * dtype - type of delegation for file (NONE, READ, WRITE) 6707c478bd9Sstevel@tonic-gate * time_returned - time that last delegation was returned for file 6717c478bd9Sstevel@tonic-gate * time_recalled - time that recall sequence started 6727c478bd9Sstevel@tonic-gate * time_lastgrant - time that last delegation was provided to a client 6737c478bd9Sstevel@tonic-gate * time_lastwrite - time of last write to use the delegation stateid 6747c478bd9Sstevel@tonic-gate * time_rm_delayed - time of last remove/rename which was DELAYed 6757c478bd9Sstevel@tonic-gate * rdgrants - how many read delegations have been provided for this file 6767c478bd9Sstevel@tonic-gate * wrgrants - how many write delegations provided (can only be one) 6777c478bd9Sstevel@tonic-gate * recall_count - how many recall threads are outstanding 6787c478bd9Sstevel@tonic-gate * recall_lock - lock to protect contents of this struct 6797c478bd9Sstevel@tonic-gate * recall_cv - condition var for the "parent" thread to wait upon 6807c478bd9Sstevel@tonic-gate * deleg_change_grant - value for change attribute at time of write grant 6817c478bd9Sstevel@tonic-gate * deleg_change - most recent value of change obtained from client 6827c478bd9Sstevel@tonic-gate * deleg_change_ts - time of last deleg_change update 6837c478bd9Sstevel@tonic-gate * ever_recalled - has this particular delegation ever been recalled? 6847c478bd9Sstevel@tonic-gate * dont_grant - file deletion is impending, don't grant a delegation 6857c478bd9Sstevel@tonic-gate * conflicted_client - clientid of the client that caused a CB_RECALL 6867c478bd9Sstevel@tonic-gate * to occur. This is used for delegation policy (should a delegation 6877c478bd9Sstevel@tonic-gate * be granted shortly after it has been returned?) 6887c478bd9Sstevel@tonic-gate */ 6897c478bd9Sstevel@tonic-gate typedef struct rfs4_dinfo { 6907c478bd9Sstevel@tonic-gate open_delegation_type4 dtype; 6917c478bd9Sstevel@tonic-gate time_t time_returned; 6927c478bd9Sstevel@tonic-gate time_t time_recalled; 6937c478bd9Sstevel@tonic-gate time_t time_lastgrant; 6947c478bd9Sstevel@tonic-gate time_t time_lastwrite; 6957c478bd9Sstevel@tonic-gate time_t time_rm_delayed; 6967c478bd9Sstevel@tonic-gate uint32_t rdgrants; 6977c478bd9Sstevel@tonic-gate uint32_t wrgrants; 6987c478bd9Sstevel@tonic-gate int32_t recall_count; 6997c478bd9Sstevel@tonic-gate kmutex_t recall_lock[1]; 7007c478bd9Sstevel@tonic-gate kcondvar_t recall_cv[1]; 7017c478bd9Sstevel@tonic-gate bool_t ever_recalled; 7027c478bd9Sstevel@tonic-gate uint32_t hold_grant; 7037c478bd9Sstevel@tonic-gate clientid4 conflicted_client; 7047c478bd9Sstevel@tonic-gate } rfs4_dinfo_t; 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * File 7087c478bd9Sstevel@tonic-gate * 7097c478bd9Sstevel@tonic-gate * dbe - encapsulation struct 7107c478bd9Sstevel@tonic-gate * vp - vnode for the file that is open or has a delegation 7117c478bd9Sstevel@tonic-gate * filehandle - the filehandle generated by the server for this file 7127c478bd9Sstevel@tonic-gate * delegationlist - root of delegation list for this file 7137c478bd9Sstevel@tonic-gate * dinfo - see struct definition above 7147c478bd9Sstevel@tonic-gate * share_deny - union of all deny modes on file 7157c478bd9Sstevel@tonic-gate * share_access - union of all access modes on file 7167c478bd9Sstevel@tonic-gate * access_read - count of read access 7177c478bd9Sstevel@tonic-gate * access_write - count of write access 7187c478bd9Sstevel@tonic-gate * deny_read - count of deny reads 7197c478bd9Sstevel@tonic-gate * deny_write - count of deny writes 7207c478bd9Sstevel@tonic-gate * file_rwlock - lock for serializing the removal of a file while 7217c478bd9Sstevel@tonic-gate * the state structures are active within the server 7227c478bd9Sstevel@tonic-gate * 7237c478bd9Sstevel@tonic-gate * The only requirement for locking file_rwlock is that the 7247c478bd9Sstevel@tonic-gate * caller have a reference to the containing rfs4_file. The dbe 7257c478bd9Sstevel@tonic-gate * lock may or may not be held for lock/unlock of file_rwlock. 7267c478bd9Sstevel@tonic-gate * As mentioned above, the file_rwlock is used for serialization 7277c478bd9Sstevel@tonic-gate * of file removal and more specifically reference to the held 7287c478bd9Sstevel@tonic-gate * vnode (e.g. vp). 7297c478bd9Sstevel@tonic-gate */ 7307c478bd9Sstevel@tonic-gate typedef struct rfs4_file { 7317c478bd9Sstevel@tonic-gate rfs4_dbe_t *dbe; 7327c478bd9Sstevel@tonic-gate vnode_t *vp; 7337c478bd9Sstevel@tonic-gate nfs_fh4 filehandle; 7347c478bd9Sstevel@tonic-gate rfs4_deleg_list_t delegationlist; 7357c478bd9Sstevel@tonic-gate rfs4_dinfo_t dinfo[1]; 7367c478bd9Sstevel@tonic-gate uint32_t share_deny; 7377c478bd9Sstevel@tonic-gate uint32_t share_access; 7387c478bd9Sstevel@tonic-gate uint32_t access_read; 7397c478bd9Sstevel@tonic-gate uint32_t access_write; 7407c478bd9Sstevel@tonic-gate uint32_t deny_read; 7417c478bd9Sstevel@tonic-gate uint32_t deny_write; 7427c478bd9Sstevel@tonic-gate krwlock_t file_rwlock; 7437c478bd9Sstevel@tonic-gate } rfs4_file_t; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate extern int rfs4_seen_first_compound; /* set first time we see one */ 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate extern rfs4_servinst_t *rfs4_cur_servinst; /* current server instance */ 7487c478bd9Sstevel@tonic-gate extern kmutex_t rfs4_servinst_lock; /* protects linked list */ 749cee86682Scalum extern void rfs4_servinst_create(int, int, char **); 7507c478bd9Sstevel@tonic-gate extern void rfs4_servinst_destroy_all(void); 7517c478bd9Sstevel@tonic-gate extern void rfs4_servinst_assign(rfs4_client_t *, 7527c478bd9Sstevel@tonic-gate rfs4_servinst_t *); 7537c478bd9Sstevel@tonic-gate extern rfs4_servinst_t *rfs4_servinst(rfs4_client_t *); 7547c478bd9Sstevel@tonic-gate extern int rfs4_clnt_in_grace(rfs4_client_t *); 7557c478bd9Sstevel@tonic-gate extern int rfs4_servinst_in_grace(rfs4_servinst_t *); 7567c478bd9Sstevel@tonic-gate extern int rfs4_servinst_grace_new(rfs4_servinst_t *); 7577c478bd9Sstevel@tonic-gate extern void rfs4_grace_start(rfs4_servinst_t *); 7587c478bd9Sstevel@tonic-gate extern void rfs4_grace_start_new(void); 7597c478bd9Sstevel@tonic-gate extern void rfs4_grace_reset_all(void); 760cee86682Scalum extern void rfs4_ss_oldstate(rfs4_oldstate_t *, char *, char *); 761cee86682Scalum extern void rfs4_dss_readstate(int, char **); 7627c478bd9Sstevel@tonic-gate 7637c478bd9Sstevel@tonic-gate /* 7647c478bd9Sstevel@tonic-gate * rfs4_deleg_policy is used to signify the server's global delegation 7657c478bd9Sstevel@tonic-gate * policy. The default is to NEVER delegate files and the 7667c478bd9Sstevel@tonic-gate * administrator must configure the server to enable delegations. 7677c478bd9Sstevel@tonic-gate * 7687c478bd9Sstevel@tonic-gate * The disable/enable delegation functions are used to eliminate a 7697c478bd9Sstevel@tonic-gate * race with exclusive creates. 7707c478bd9Sstevel@tonic-gate */ 7717c478bd9Sstevel@tonic-gate typedef enum { 7727c478bd9Sstevel@tonic-gate SRV_NEVER_DELEGATE = 0, 7737c478bd9Sstevel@tonic-gate SRV_NORMAL_DELEGATE = 1 7747c478bd9Sstevel@tonic-gate } srv_deleg_policy_t; 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate extern srv_deleg_policy_t rfs4_deleg_policy; 7777c478bd9Sstevel@tonic-gate extern kmutex_t rfs4_deleg_lock; 7787c478bd9Sstevel@tonic-gate extern void rfs4_disable_delegation(void), rfs4_enable_delegation(void); 7797c478bd9Sstevel@tonic-gate 7807c478bd9Sstevel@tonic-gate /* 7817c478bd9Sstevel@tonic-gate * Request types for delegation. These correspond with 7827c478bd9Sstevel@tonic-gate * open_delegation_type4 with the addition of a new value, DELEG_ANY, 7837c478bd9Sstevel@tonic-gate * to reqequest any delegation. 7847c478bd9Sstevel@tonic-gate */ 7857c478bd9Sstevel@tonic-gate typedef enum { 7867c478bd9Sstevel@tonic-gate DELEG_NONE = 0, /* Corresponds to OPEN_DELEG_NONE */ 7877c478bd9Sstevel@tonic-gate DELEG_READ = 1, /* Corresponds to OPEN_DELEG_READ */ 7887c478bd9Sstevel@tonic-gate DELEG_WRITE = 2, /* Corresponds to OPEN_DELEG_WRITE */ 7897c478bd9Sstevel@tonic-gate DELEG_ANY = -1 /* New value to request any delegation type */ 7907c478bd9Sstevel@tonic-gate } delegreq_t; 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate #define NFS4_DELEG4TYPE2REQTYPE(x) (delegreq_t)(x) 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate /* 7957c478bd9Sstevel@tonic-gate * Various interfaces to manipulate the state structures introduced 7967c478bd9Sstevel@tonic-gate * above 7977c478bd9Sstevel@tonic-gate */ 7987c478bd9Sstevel@tonic-gate extern kmutex_t rfs4_state_lock; 7997c478bd9Sstevel@tonic-gate extern void rfs4_clean_state_exi(struct exportinfo *exi); 8007c478bd9Sstevel@tonic-gate extern void rfs4_free_reply(nfs_resop4 *); 8017c478bd9Sstevel@tonic-gate extern void rfs4_copy_reply(nfs_resop4 *, nfs_resop4 *); 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /* rfs4_client_t handling */ 8047c478bd9Sstevel@tonic-gate extern rfs4_client_t *rfs4_findclient(nfs_client_id4 *, 8057c478bd9Sstevel@tonic-gate bool_t *, rfs4_client_t *); 8067c478bd9Sstevel@tonic-gate extern rfs4_client_t *rfs4_findclient_by_id(clientid4, bool_t); 8077c478bd9Sstevel@tonic-gate extern void rfs4_client_rele(rfs4_client_t *); 8087c478bd9Sstevel@tonic-gate extern void rfs4_client_close(rfs4_client_t *); 8097c478bd9Sstevel@tonic-gate extern void rfs4_client_state_remove(rfs4_client_t *); 8107c478bd9Sstevel@tonic-gate extern void rfs4_client_scv_next(rfs4_client_t *); 8117c478bd9Sstevel@tonic-gate extern void rfs4_update_lease(rfs4_client_t *); 8127c478bd9Sstevel@tonic-gate extern bool_t rfs4_lease_expired(rfs4_client_t *); 8137c478bd9Sstevel@tonic-gate extern nfsstat4 rfs4_check_clientid(clientid4 *, int); 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate /* rfs4_openowner_t handling */ 8167c478bd9Sstevel@tonic-gate extern rfs4_openowner_t *rfs4_findopenowner(open_owner4 *, bool_t *, seqid4); 8177c478bd9Sstevel@tonic-gate extern void rfs4_update_open_sequence(rfs4_openowner_t *); 8187c478bd9Sstevel@tonic-gate extern void rfs4_update_open_resp(rfs4_openowner_t *, 8197c478bd9Sstevel@tonic-gate nfs_resop4 *, nfs_fh4 *); 8207c478bd9Sstevel@tonic-gate extern void rfs4_openowner_rele(rfs4_openowner_t *); 8217c478bd9Sstevel@tonic-gate extern void rfs4_free_opens(rfs4_openowner_t *, bool_t, bool_t); 8227c478bd9Sstevel@tonic-gate 8237c478bd9Sstevel@tonic-gate /* rfs4_lockowner_t handling */ 8247c478bd9Sstevel@tonic-gate extern rfs4_lockowner_t *rfs4_findlockowner(lock_owner4 *, bool_t *); 8257c478bd9Sstevel@tonic-gate extern rfs4_lockowner_t *rfs4_findlockowner_by_pid(pid_t); 8267c478bd9Sstevel@tonic-gate extern void rfs4_lockowner_rele(rfs4_lockowner_t *); 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate /* rfs4_state_t handling */ 8297c478bd9Sstevel@tonic-gate extern rfs4_state_t *rfs4_findstate_by_owner_file(rfs4_openowner_t *, 8307c478bd9Sstevel@tonic-gate rfs4_file_t *, bool_t *); 8317c478bd9Sstevel@tonic-gate extern void rfs4_state_rele(rfs4_state_t *); 8327c478bd9Sstevel@tonic-gate extern void rfs4_state_close(rfs4_state_t *, bool_t, 8337c478bd9Sstevel@tonic-gate bool_t, cred_t *); 8347c478bd9Sstevel@tonic-gate extern void rfs4_release_share_lock_state(rfs4_state_t *, 8357c478bd9Sstevel@tonic-gate cred_t *, bool_t); 8367c478bd9Sstevel@tonic-gate extern void rfs4_close_all_state(rfs4_file_t *); 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate /* rfs4_lo_state_t handling */ 8397c478bd9Sstevel@tonic-gate extern rfs4_lo_state_t *rfs4_findlo_state_by_owner(rfs4_lockowner_t *, 8407c478bd9Sstevel@tonic-gate rfs4_state_t *, bool_t *); 8417c478bd9Sstevel@tonic-gate extern void rfs4_lo_state_rele(rfs4_lo_state_t *, bool_t); 8427c478bd9Sstevel@tonic-gate extern void rfs4_update_lock_sequence(rfs4_lo_state_t *); 8437c478bd9Sstevel@tonic-gate extern void rfs4_update_lock_resp(rfs4_lo_state_t *, 8447c478bd9Sstevel@tonic-gate nfs_resop4 *); 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate /* rfs4_file_t handling */ 8477c478bd9Sstevel@tonic-gate extern rfs4_file_t *rfs4_findfile(vnode_t *, nfs_fh4 *, bool_t *); 8487c478bd9Sstevel@tonic-gate extern rfs4_file_t *rfs4_findfile_withlock(vnode_t *, nfs_fh4 *, 8497c478bd9Sstevel@tonic-gate bool_t *); 8507c478bd9Sstevel@tonic-gate extern void rfs4_file_rele(rfs4_file_t *); 8517c478bd9Sstevel@tonic-gate extern void rfs4_file_rele_withunlock(rfs4_file_t *); 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate /* General collection of "get state" functions */ 8547c478bd9Sstevel@tonic-gate extern nfsstat4 rfs4_get_state(stateid4 *, rfs4_state_t **, 8557c478bd9Sstevel@tonic-gate rfs4_dbsearch_type_t); 8567c478bd9Sstevel@tonic-gate extern nfsstat4 rfs4_get_deleg_state(stateid4 *, 8577c478bd9Sstevel@tonic-gate rfs4_deleg_state_t **); 8587c478bd9Sstevel@tonic-gate extern nfsstat4 rfs4_get_lo_state(stateid4 *, rfs4_lo_state_t **, 8597c478bd9Sstevel@tonic-gate bool_t); 8607c478bd9Sstevel@tonic-gate extern nfsstat4 rfs4_check_stateid(int, vnode_t *, stateid4 *, 861da6c28aaSamw bool_t, bool_t *, bool_t, 862da6c28aaSamw caller_context_t *); 8637c478bd9Sstevel@tonic-gate extern int rfs4_check_stateid_seqid(rfs4_state_t *, stateid4 *); 8647c478bd9Sstevel@tonic-gate extern int rfs4_check_lo_stateid_seqid(rfs4_lo_state_t *, 8657c478bd9Sstevel@tonic-gate stateid4 *); 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate /* return values for rfs4_check_stateid_seqid() */ 8687c478bd9Sstevel@tonic-gate #define NFS4_CHECK_STATEID_OKAY 1 8697c478bd9Sstevel@tonic-gate #define NFS4_CHECK_STATEID_OLD 2 8707c478bd9Sstevel@tonic-gate #define NFS4_CHECK_STATEID_BAD 3 8717c478bd9Sstevel@tonic-gate #define NFS4_CHECK_STATEID_EXPIRED 4 8727c478bd9Sstevel@tonic-gate #define NFS4_CHECK_STATEID_REPLAY 5 8737c478bd9Sstevel@tonic-gate #define NFS4_CHECK_STATEID_CLOSED 6 8747c478bd9Sstevel@tonic-gate #define NFS4_CHECK_STATEID_UNCONFIRMED 7 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /* delay() time that server is willing to briefly wait for a delegreturn */ 8777c478bd9Sstevel@tonic-gate #define NFS4_DELEGATION_CONFLICT_DELAY (hz/10) 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate /* 8807c478bd9Sstevel@tonic-gate * Interfaces for handling of callback's client handle cache and 8817c478bd9Sstevel@tonic-gate * callback interfaces themselves. 8827c478bd9Sstevel@tonic-gate */ 8837c478bd9Sstevel@tonic-gate extern void rfs4_cbinfo_free(rfs4_cbinfo_t *); 8847c478bd9Sstevel@tonic-gate extern void rfs4_client_setcb(rfs4_client_t *, cb_client4 *, 8857c478bd9Sstevel@tonic-gate uint32_t); 8867c478bd9Sstevel@tonic-gate extern void rfs4_deleg_cb_check(rfs4_client_t *); 8877c478bd9Sstevel@tonic-gate extern nfsstat4 rfs4_vop_getattr(vnode_t *, vattr_t *, int, cred_t *); 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate /* rfs4_deleg_state_t handling and other delegation interfaces */ 8907c478bd9Sstevel@tonic-gate extern rfs4_deleg_state_t *rfs4_finddeleg(rfs4_state_t *, bool_t *); 8917c478bd9Sstevel@tonic-gate extern rfs4_deleg_state_t *rfs4_finddelegstate(stateid_t *); 8927c478bd9Sstevel@tonic-gate extern bool_t rfs4_check_recall(rfs4_state_t *, uint32_t); 8937c478bd9Sstevel@tonic-gate extern void rfs4_recall_deleg(rfs4_file_t *, 8947c478bd9Sstevel@tonic-gate bool_t, rfs4_client_t *); 8957c478bd9Sstevel@tonic-gate extern int rfs4_get_deleg(rfs4_state_t *, open_delegation_type4, 8967c478bd9Sstevel@tonic-gate open_delegation_type4 (*policy)(rfs4_state_t *, 8977c478bd9Sstevel@tonic-gate open_delegation_type4 dtype)); 8987c478bd9Sstevel@tonic-gate extern rfs4_deleg_state_t *rfs4_grant_delegation(delegreq_t, rfs4_state_t *, 8997c478bd9Sstevel@tonic-gate int *); 9007c478bd9Sstevel@tonic-gate extern void rfs4_set_deleg_response(rfs4_deleg_state_t *, 9017c478bd9Sstevel@tonic-gate open_delegation4 *, nfsace4 *, int); 9027c478bd9Sstevel@tonic-gate extern void rfs4_return_deleg(rfs4_deleg_state_t *, bool_t); 9037c478bd9Sstevel@tonic-gate extern bool_t rfs4_is_deleg(rfs4_state_t *); 9047c478bd9Sstevel@tonic-gate extern void rfs4_deleg_state_rele(rfs4_deleg_state_t *); 9057c478bd9Sstevel@tonic-gate extern bool_t rfs4_check_delegated_byfp(int, rfs4_file_t *, 9067c478bd9Sstevel@tonic-gate bool_t, bool_t, bool_t, clientid4 *); 9077c478bd9Sstevel@tonic-gate extern void rfs4_clear_dont_grant(rfs4_file_t *); 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate /* 9107c478bd9Sstevel@tonic-gate * nfs4 monitored operations. 9117c478bd9Sstevel@tonic-gate */ 912cfae96c2Sjwahlig extern int deleg_rd_open(femarg_t *, int, cred_t *, caller_context_t *); 913cfae96c2Sjwahlig extern int deleg_wr_open(femarg_t *, int, cred_t *, caller_context_t *); 914cfae96c2Sjwahlig extern int deleg_wr_read(femarg_t *, uio_t *, int, cred_t *, 915cfae96c2Sjwahlig caller_context_t *); 916cfae96c2Sjwahlig extern int deleg_rd_write(femarg_t *, uio_t *, int, cred_t *, 917cfae96c2Sjwahlig caller_context_t *); 918cfae96c2Sjwahlig extern int deleg_wr_write(femarg_t *, uio_t *, int, cred_t *, 919cfae96c2Sjwahlig caller_context_t *); 920cfae96c2Sjwahlig extern int deleg_rd_setattr(femarg_t *, vattr_t *, int, cred_t *, 921cfae96c2Sjwahlig caller_context_t *); 922cfae96c2Sjwahlig extern int deleg_wr_setattr(femarg_t *, vattr_t *, int, cred_t *, 923cfae96c2Sjwahlig caller_context_t *); 9247c478bd9Sstevel@tonic-gate extern int deleg_rd_rwlock(femarg_t *, int, caller_context_t *); 9257c478bd9Sstevel@tonic-gate extern int deleg_wr_rwlock(femarg_t *, int, caller_context_t *); 926cfae96c2Sjwahlig extern int deleg_rd_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *, 9277c478bd9Sstevel@tonic-gate caller_context_t *); 928cfae96c2Sjwahlig extern int deleg_wr_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *, 9297c478bd9Sstevel@tonic-gate caller_context_t *); 930cfae96c2Sjwahlig extern int deleg_rd_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *, 931da6c28aaSamw caller_context_t *); 932cfae96c2Sjwahlig extern int deleg_wr_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *, 933cfae96c2Sjwahlig caller_context_t *); 934cfae96c2Sjwahlig extern int deleg_rd_vnevent(femarg_t *, vnevent_t, vnode_t *, char *, 935cfae96c2Sjwahlig caller_context_t *); 936cfae96c2Sjwahlig extern int deleg_wr_vnevent(femarg_t *, vnevent_t, vnode_t *, char *, 937da6c28aaSamw caller_context_t *); 9387c478bd9Sstevel@tonic-gate 9397c478bd9Sstevel@tonic-gate extern void rfs4_mon_hold(void *); 9407c478bd9Sstevel@tonic-gate extern void rfs4_mon_rele(void *); 9417c478bd9Sstevel@tonic-gate 9427c478bd9Sstevel@tonic-gate extern fem_t *deleg_rdops; 9437c478bd9Sstevel@tonic-gate extern fem_t *deleg_wrops; 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate extern void rfs4_unshare(rfs4_state_t *); 9467c478bd9Sstevel@tonic-gate extern void rfs4_set_deleg_policy(srv_deleg_policy_t); 9477c478bd9Sstevel@tonic-gate #ifdef DEBUG 9487c478bd9Sstevel@tonic-gate #define NFS4_DEBUG(var, args) if (var) cmn_err args 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate extern int rfs4_debug; 9517c478bd9Sstevel@tonic-gate extern int nfs4_client_attr_debug; 9527c478bd9Sstevel@tonic-gate extern int nfs4_client_state_debug; 9537c478bd9Sstevel@tonic-gate extern int nfs4_client_shadow_debug; 9547c478bd9Sstevel@tonic-gate extern int nfs4_client_lock_debug; 9557c478bd9Sstevel@tonic-gate extern int nfs4_client_lease_debug; 9567c478bd9Sstevel@tonic-gate extern int nfs4_seqid_sync; 9577c478bd9Sstevel@tonic-gate extern int nfs4_client_map_debug; 9587c478bd9Sstevel@tonic-gate extern int nfs4_client_inactive_debug; 9597c478bd9Sstevel@tonic-gate extern int nfs4_client_recov_debug; 9607c478bd9Sstevel@tonic-gate extern int nfs4_client_failover_debug; 9617c478bd9Sstevel@tonic-gate extern int nfs4_client_call_debug; 9627c478bd9Sstevel@tonic-gate extern int nfs4_client_foo_debug; 9637c478bd9Sstevel@tonic-gate extern int nfs4_client_zone_debug; 9647c478bd9Sstevel@tonic-gate extern int nfs4_lost_rqst_debug; 9657c478bd9Sstevel@tonic-gate extern int nfs4_open_stream_debug; 9667c478bd9Sstevel@tonic-gate extern int nfs4_client_open_dg; 9677c478bd9Sstevel@tonic-gate extern int nfs4_srvmnt_debug; 9687c478bd9Sstevel@tonic-gate extern int nfs4_utf8_debug; 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate void rfs4_dbe_debug(rfs4_dbe_t *e); 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate #ifdef NFS4_DEBUG_MUTEX 9737c478bd9Sstevel@tonic-gate void nfs4_debug_mutex_enter(kmutex_t *, char *, int); 9747c478bd9Sstevel@tonic-gate void nfs4_debug_mutex_exit(kmutex_t *, char *, int); 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate #define mutex_enter(m) nfs4_debug_mutex_enter((m), __FILE__, __LINE__) 9777c478bd9Sstevel@tonic-gate #define mutex_exit(m) nfs4_debug_mutex_exit((m), __FILE__, __LINE__) 9787c478bd9Sstevel@tonic-gate #endif /* NFS4_DEBUG_MUTEX */ 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate #else /* ! DEBUG */ 9817c478bd9Sstevel@tonic-gate #define NFS4_DEBUG(var, args) 9827c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 9837c478bd9Sstevel@tonic-gate 9847c478bd9Sstevel@tonic-gate /* 9857c478bd9Sstevel@tonic-gate * XXX - temporary for testing of volatile fh 9867c478bd9Sstevel@tonic-gate */ 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate #ifdef VOLATILE_FH_TEST 9897c478bd9Sstevel@tonic-gate 9907c478bd9Sstevel@tonic-gate struct nfs_fh4_fmt { 99127242a7cSthurlow fhandle4_t fh4_i; 9927c478bd9Sstevel@tonic-gate uint32_t fh4_flag; 9937c478bd9Sstevel@tonic-gate uint32_t fh4_volatile_id; 9947c478bd9Sstevel@tonic-gate }; 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate #else /* VOLATILE_FH_TEST */ 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate struct nfs_fh4_fmt { 99927242a7cSthurlow fhandle4_t fh4_i; 10007c478bd9Sstevel@tonic-gate uint32_t fh4_flag; 10017c478bd9Sstevel@tonic-gate }; 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate #endif /* VOLATILE_FH_TEST */ 10047c478bd9Sstevel@tonic-gate 10057c478bd9Sstevel@tonic-gate #define FH4_NAMEDATTR 1 10067c478bd9Sstevel@tonic-gate #define FH4_ATTRDIR 2 10077c478bd9Sstevel@tonic-gate 10087c46fb7fSek110237 #define fh4_fsid fh4_i.fhx_fsid 10097c46fb7fSek110237 #define fh4_len fh4_i.fhx_len /* fid length */ 10107c46fb7fSek110237 #define fh4_data fh4_i.fhx_data /* fid bytes */ 10117c46fb7fSek110237 #define fh4_xlen fh4_i.fhx_xlen 10127c46fb7fSek110237 #define fh4_xdata fh4_i.fhx_xdata 10137c478bd9Sstevel@tonic-gate typedef struct nfs_fh4_fmt nfs_fh4_fmt_t; 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate #define fh4_to_fmt4(fh4p) ((nfs_fh4_fmt_t *)(fh4p)->nfs_fh4_val) 10167c478bd9Sstevel@tonic-gate #define get_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) & (flag)) 10177c478bd9Sstevel@tonic-gate #define set_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) |= (flag)) 10187c478bd9Sstevel@tonic-gate #define clr_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) &= ~(flag)) 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate #define NFS_FH4_LEN sizeof (nfs_fh4_fmt_t) 10217c478bd9Sstevel@tonic-gate 1022b096b66cSnr123932 /* 1023b096b66cSnr123932 * Copy fields from external (fhandle_t) to in-memory (nfs_fh4_fmt_t) 1024b096b66cSnr123932 * format to support export info checking. It does not copy over 1025b096b66cSnr123932 * the complete filehandle, just the fsid, xlen and xdata. It may 1026b096b66cSnr123932 * need to be changed to be used in other places. 1027b096b66cSnr123932 * 1028b096b66cSnr123932 * NOTE: The macro expects the space to be pre-allocated for 1029b096b66cSnr123932 * the contents of nfs_fh4_fmt_t. 1030b096b66cSnr123932 */ 1031b096b66cSnr123932 #define FH_TO_FMT4(exifh, nfs_fmt) { \ 1032b096b66cSnr123932 bzero((nfs_fmt), NFS_FH4_LEN); \ 1033b096b66cSnr123932 (nfs_fmt)->fh4_fsid = (exifh)->fh_fsid; \ 1034b096b66cSnr123932 (nfs_fmt)->fh4_xlen = (exifh)->fh_xlen; \ 1035b096b66cSnr123932 bcopy((exifh)->fh_xdata, (nfs_fmt)->fh4_xdata, \ 1036b096b66cSnr123932 (exifh)->fh_xlen); \ 1037b096b66cSnr123932 } 10387c478bd9Sstevel@tonic-gate 10397c478bd9Sstevel@tonic-gate /* 10407c478bd9Sstevel@tonic-gate * A few definitions of repeatedly used constructs for nfsv4 10417c478bd9Sstevel@tonic-gate */ 10427c478bd9Sstevel@tonic-gate #define UTF8STRING_FREE(str) \ 10437c478bd9Sstevel@tonic-gate kmem_free((str).utf8string_val, (str).utf8string_len); \ 10447c478bd9Sstevel@tonic-gate (str).utf8string_val = NULL; \ 10457c478bd9Sstevel@tonic-gate (str).utf8string_len = 0; 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate /* 10487c478bd9Sstevel@tonic-gate * NFS4_VOLATILE_FH yields non-zero if the filesystem uses non-persistent 10497c478bd9Sstevel@tonic-gate * filehandles. 10507c478bd9Sstevel@tonic-gate */ 10517c478bd9Sstevel@tonic-gate #define NFS4_VOLATILE_FH(mi) \ 10527c478bd9Sstevel@tonic-gate ((mi)->mi_fh_expire_type & \ 10537c478bd9Sstevel@tonic-gate (FH4_VOLATILE_ANY | FH4_VOL_MIGRATION | FH4_VOL_RENAME)) 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate /* 10567c478bd9Sstevel@tonic-gate * NFS_IS_DOTNAME checks if the name given represents a dot or dotdot entry 10577c478bd9Sstevel@tonic-gate */ 10587c478bd9Sstevel@tonic-gate #define NFS_IS_DOTNAME(name) \ 10597c478bd9Sstevel@tonic-gate (((name)[0] == '.') && \ 10607c478bd9Sstevel@tonic-gate (((name)[1] == '\0') || (((name)[1] == '.') && ((name)[2] == '\0')))) 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate /* 10637c478bd9Sstevel@tonic-gate * Define the number of bits in a bitmap word (uint32) 10647c478bd9Sstevel@tonic-gate */ 10657c478bd9Sstevel@tonic-gate #define NFS4_BITMAP4_BITSPERWORD (sizeof (uint32_t) * 8) 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate /* 10687c478bd9Sstevel@tonic-gate * Define the value for the access field of the compound_state structure 10697c478bd9Sstevel@tonic-gate * based on the result of nfsauth access checking. 10707c478bd9Sstevel@tonic-gate */ 10717c478bd9Sstevel@tonic-gate #define CS_ACCESS_OK 0x1 10727c478bd9Sstevel@tonic-gate #define CS_ACCESS_DENIED 0x2 10737c478bd9Sstevel@tonic-gate #define CS_ACCESS_LIMITED 0x4 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate /* 10767c478bd9Sstevel@tonic-gate * compound state in nfsv4 server 10777c478bd9Sstevel@tonic-gate */ 10787c478bd9Sstevel@tonic-gate struct compound_state { 10797c478bd9Sstevel@tonic-gate struct exportinfo *exi; 10807c478bd9Sstevel@tonic-gate struct exportinfo *saved_exi; /* export struct for saved_vp */ 10817c478bd9Sstevel@tonic-gate cred_t *basecr; /* UNIX cred: only RPC request */ 10827c478bd9Sstevel@tonic-gate caddr_t principal; 10837c478bd9Sstevel@tonic-gate int nfsflavor; 10847c478bd9Sstevel@tonic-gate cred_t *cr; /* UNIX cred: RPC request and */ 10857c478bd9Sstevel@tonic-gate /* target export */ 10867c478bd9Sstevel@tonic-gate bool_t cont; 10877c478bd9Sstevel@tonic-gate uint_t access; /* access perm on vp per request */ 10887c478bd9Sstevel@tonic-gate bool_t deleg; /* TRUE if current fh has */ 10897c478bd9Sstevel@tonic-gate /* write delegated */ 10907c478bd9Sstevel@tonic-gate vnode_t *vp; /* modified by PUTFH, and by ops that */ 10917c478bd9Sstevel@tonic-gate /* input to GETFH */ 10927c478bd9Sstevel@tonic-gate bool_t mandlock; /* Is mandatory locking in effect */ 10937c478bd9Sstevel@tonic-gate /* for vp */ 10947c478bd9Sstevel@tonic-gate vnode_t *saved_vp; /* modified by SAVEFH, copied to */ 10957c478bd9Sstevel@tonic-gate /* vp by RESTOREFH */ 10967c478bd9Sstevel@tonic-gate nfsstat4 *statusp; 10977c478bd9Sstevel@tonic-gate nfs_fh4 fh; /* ditto. valid only if vp != NULL */ 10987c478bd9Sstevel@tonic-gate nfs_fh4 saved_fh; /* ditto. valid only if */ 10997c478bd9Sstevel@tonic-gate /* saved_vp != NULL */ 11007c478bd9Sstevel@tonic-gate struct svc_req *req; 11017c478bd9Sstevel@tonic-gate char fhbuf[NFS4_FHSIZE]; 11027c478bd9Sstevel@tonic-gate }; 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate /* 11057c478bd9Sstevel@tonic-gate * Conversion commands for nfsv4 server attr checking 11067c478bd9Sstevel@tonic-gate */ 11077c478bd9Sstevel@tonic-gate enum nfs4_attr_cmd { 11087c478bd9Sstevel@tonic-gate NFS4ATTR_SUPPORTED = 0, /* check which attrs supported */ 11097c478bd9Sstevel@tonic-gate NFS4ATTR_GETIT = 1, /* getattr - sys to fattr4 (r) */ 11107c478bd9Sstevel@tonic-gate NFS4ATTR_SETIT = 2, /* setattr - fattr4 to sys (w) */ 11117c478bd9Sstevel@tonic-gate NFS4ATTR_VERIT = 3, /* verify - fattr4 to sys (r) */ 11127c478bd9Sstevel@tonic-gate NFS4ATTR_FREEIT = 4 /* free any alloc'd space for attr */ 11137c478bd9Sstevel@tonic-gate }; 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate typedef enum nfs4_attr_cmd nfs4_attr_cmd_t; 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate struct nfs4_svgetit_arg { 11187c478bd9Sstevel@tonic-gate nfs4_attr_cmd_t op; /* getit or setit */ 11197c478bd9Sstevel@tonic-gate struct compound_state *cs; 11207c478bd9Sstevel@tonic-gate struct statvfs64 *sbp; 11217c478bd9Sstevel@tonic-gate uint_t flag; /* VOP_GETATTR/VOP_SETATTR flag */ 11227c478bd9Sstevel@tonic-gate uint_t xattr; /* object is xattr */ 11237c478bd9Sstevel@tonic-gate bool_t rdattr_error_req; /* if readdir & client wants */ 11247c478bd9Sstevel@tonic-gate /* rdattr_error */ 11257c478bd9Sstevel@tonic-gate nfsstat4 rdattr_error; /* used for per-entry status */ 11267c478bd9Sstevel@tonic-gate /* (if rdattr_err) */ 11277c478bd9Sstevel@tonic-gate bool_t mntdfid_set; 11287c478bd9Sstevel@tonic-gate fattr4_mounted_on_fileid 11297c478bd9Sstevel@tonic-gate mounted_on_fileid; 11307c478bd9Sstevel@tonic-gate /* readdir op can always return */ 11317c478bd9Sstevel@tonic-gate /* d_ino from server fs dirent */ 11327c478bd9Sstevel@tonic-gate /* for mounted_on_fileid attr. */ 11337c478bd9Sstevel@tonic-gate /* This field holds d_ino so */ 11347c478bd9Sstevel@tonic-gate /* srv attr conv code can avoid */ 11357c478bd9Sstevel@tonic-gate /* doing an untraverse. */ 11367c478bd9Sstevel@tonic-gate vattr_t vap[1]; 11377c478bd9Sstevel@tonic-gate }; 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate struct nfs4_ntov_map { 11407c478bd9Sstevel@tonic-gate bitmap4 fbit; /* FATTR4_XXX_MASKY */ 11417c478bd9Sstevel@tonic-gate uint_t vbit; /* AT_XXX */ 11427c478bd9Sstevel@tonic-gate bool_t vfsstat; 11437c478bd9Sstevel@tonic-gate bool_t mandatory; /* attribute mandatory to implement? */ 11447c478bd9Sstevel@tonic-gate uint_t nval; 11457c478bd9Sstevel@tonic-gate int xdr_size; /* Size of XDR'd attr */ 11467c478bd9Sstevel@tonic-gate xdrproc_t xfunc; 11477c478bd9Sstevel@tonic-gate int (*sv_getit)(nfs4_attr_cmd_t, struct nfs4_svgetit_arg *, 11487c478bd9Sstevel@tonic-gate union nfs4_attr_u *); /* subroutine for getting attr. */ 11497c478bd9Sstevel@tonic-gate char *prtstr; /* string attr for printing */ 11507c478bd9Sstevel@tonic-gate }; 11517c478bd9Sstevel@tonic-gate 11527c478bd9Sstevel@tonic-gate struct nfs4attr_to_vattr { 11537c478bd9Sstevel@tonic-gate vnode_t *vp; 11547c478bd9Sstevel@tonic-gate vattr_t *vap; 11557c478bd9Sstevel@tonic-gate nfs_fh4 *fhp; 11567c478bd9Sstevel@tonic-gate nfsstat4 rdattr_error; 11577c478bd9Sstevel@tonic-gate uint32_t flag; 11587c478bd9Sstevel@tonic-gate fattr4_change change; 11597c478bd9Sstevel@tonic-gate fattr4_fsid srv_fsid; 11607c478bd9Sstevel@tonic-gate fattr4_mounted_on_fileid mntd_fid; 11617c478bd9Sstevel@tonic-gate }; 11627c478bd9Sstevel@tonic-gate 11637c478bd9Sstevel@tonic-gate typedef struct nfs4attr_to_vattr ntov4_t; 11647c478bd9Sstevel@tonic-gate 11657c478bd9Sstevel@tonic-gate /* 11667c478bd9Sstevel@tonic-gate * nfs4attr_to_vattr flags 11677c478bd9Sstevel@tonic-gate */ 11687c478bd9Sstevel@tonic-gate #define NTOV_FHP_VALID 0x01 11697c478bd9Sstevel@tonic-gate #define NTOV_RDATTR_ERROR_VALID 0x02 11707c478bd9Sstevel@tonic-gate #define NTOV_CHANGE_VALID 0x04 11717c478bd9Sstevel@tonic-gate #define NTOV_SUPP_VALID 0x08 11727c478bd9Sstevel@tonic-gate #define NTOV_SRV_FSID_VALID 0x10 11737c478bd9Sstevel@tonic-gate #define NTOV_MOUNTED_ON_FILEID_VALID 0x20 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate #define FATTR4_MANDATTR_MASK ( \ 11777c478bd9Sstevel@tonic-gate FATTR4_SUPPORTED_ATTRS_MASK | \ 11787c478bd9Sstevel@tonic-gate FATTR4_TYPE_MASK | \ 11797c478bd9Sstevel@tonic-gate FATTR4_FH_EXPIRE_TYPE_MASK | \ 11807c478bd9Sstevel@tonic-gate FATTR4_CHANGE_MASK | \ 11817c478bd9Sstevel@tonic-gate FATTR4_SIZE_MASK | \ 11827c478bd9Sstevel@tonic-gate FATTR4_LINK_SUPPORT_MASK | \ 11837c478bd9Sstevel@tonic-gate FATTR4_SYMLINK_SUPPORT_MASK | \ 11847c478bd9Sstevel@tonic-gate FATTR4_NAMED_ATTR_MASK | \ 11857c478bd9Sstevel@tonic-gate FATTR4_FSID_MASK | \ 11867c478bd9Sstevel@tonic-gate FATTR4_UNIQUE_HANDLES_MASK | \ 11877c478bd9Sstevel@tonic-gate FATTR4_LEASE_TIME_MASK | \ 11887c478bd9Sstevel@tonic-gate FATTR4_RDATTR_ERROR_MASK | \ 11897c478bd9Sstevel@tonic-gate FATTR4_FILEHANDLE_MASK) 11907c478bd9Sstevel@tonic-gate 11917c478bd9Sstevel@tonic-gate 11927c478bd9Sstevel@tonic-gate struct nfs4attr_to_osattr { 11937c478bd9Sstevel@tonic-gate void *attrconv_arg; 11947c478bd9Sstevel@tonic-gate uint_t mask; 11957c478bd9Sstevel@tonic-gate }; 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate struct mntinfo4; 11987c478bd9Sstevel@tonic-gate 11997c478bd9Sstevel@tonic-gate /* 12007c478bd9Sstevel@tonic-gate * lkp4_attr_setup lists the different options for attributes when calling 12017c478bd9Sstevel@tonic-gate * nfs4lookup_setup - either no attributes (just lookups - e.g., secinfo), 12027c478bd9Sstevel@tonic-gate * one component only (normal component lookup), get attributes for the 12037c478bd9Sstevel@tonic-gate * last component (e.g., mount), attributes for each component (e.g., 12047c478bd9Sstevel@tonic-gate * failovers later), just the filehandle for the last component (e.g., 12057c478bd9Sstevel@tonic-gate * volatile filehandle recovery), or stuff that needs OPENATTR (e.g. 12067c478bd9Sstevel@tonic-gate * looking up a named attribute or it's hidden directory). 12077c478bd9Sstevel@tonic-gate */ 12087c478bd9Sstevel@tonic-gate enum lkp4_attr_setup { 12097c478bd9Sstevel@tonic-gate LKP4_NO_ATTRIBUTES = 0, /* no attrs or filehandles */ 12107c478bd9Sstevel@tonic-gate LKP4_ALL_ATTRIBUTES = 3, /* multi-comp: attrs for all comps */ 12117c478bd9Sstevel@tonic-gate LKP4_LAST_NAMED_ATTR = 5, /* multi-comp: named attr & attrdir */ 12127c478bd9Sstevel@tonic-gate LKP4_LAST_ATTRDIR = 6, /* multi-comp: just attrdir */ 12137c478bd9Sstevel@tonic-gate LKP4_ALL_ATTR_SECINFO = 7 /* multi-comp: attrs for all comp and */ 12147c478bd9Sstevel@tonic-gate /* secinfo for last comp */ 12157c478bd9Sstevel@tonic-gate }; 12167c478bd9Sstevel@tonic-gate 12177c478bd9Sstevel@tonic-gate /* 12187c478bd9Sstevel@tonic-gate * lookup4_param a set of parameters to nfs4lookup_setup - 12197c478bd9Sstevel@tonic-gate * used to setup a path lookup compound request. 12207c478bd9Sstevel@tonic-gate */ 12217c478bd9Sstevel@tonic-gate typedef struct lookup4_param { 12227c478bd9Sstevel@tonic-gate enum lkp4_attr_setup l4_getattrs; /* (in) get attrs in the lookup? */ 12237c478bd9Sstevel@tonic-gate int header_len; /* (in) num ops before first lookup */ 12247c478bd9Sstevel@tonic-gate int trailer_len; /* (in) num ops after last */ 12257c478bd9Sstevel@tonic-gate /* Lookup/Getattr */ 12267c478bd9Sstevel@tonic-gate bitmap4 ga_bits; /* (in) Which attributes for Getattr */ 12277c478bd9Sstevel@tonic-gate COMPOUND4args_clnt *argsp; /* (in/out) args for compound struct */ 12287c478bd9Sstevel@tonic-gate COMPOUND4res_clnt *resp; /* (in/out) res for compound struct */ 12297c478bd9Sstevel@tonic-gate int arglen; /* (out) argop buffer alloc'd length */ 12307c478bd9Sstevel@tonic-gate struct mntinfo4 *mi; 12317c478bd9Sstevel@tonic-gate } lookup4_param_t; 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate 12347c478bd9Sstevel@tonic-gate #define NFS4_FATTR4_FINISH -1 /* fattr4 index indicating finish */ 12357c478bd9Sstevel@tonic-gate 12367c478bd9Sstevel@tonic-gate typedef int (*nfs4attr_to_os_t)(int, union nfs4_attr_u *, 12377c478bd9Sstevel@tonic-gate struct nfs4attr_to_osattr *); 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate /* 12407c478bd9Sstevel@tonic-gate * The nfs4_error_t is the basic structure to return error values 12417c478bd9Sstevel@tonic-gate * from rfs4call. It encapsulates the unix errno 12427c478bd9Sstevel@tonic-gate * value, the nfsstat4 value and the rpc status value into a single 12437c478bd9Sstevel@tonic-gate * structure. 12447c478bd9Sstevel@tonic-gate * 12457c478bd9Sstevel@tonic-gate * If error is set, then stat is ignored and rpc_status may be 12467c478bd9Sstevel@tonic-gate * set if the error occurred as the result of a CLNT_CALL. If 12477c478bd9Sstevel@tonic-gate * stat is set, then rpc request succeeded, error and 12487c478bd9Sstevel@tonic-gate * rpc_status are set to 0 and stat contains the result of 12497c478bd9Sstevel@tonic-gate * operation, NFS4_OK or one of the NFS4ERR_* values. 12507c478bd9Sstevel@tonic-gate * 12517c478bd9Sstevel@tonic-gate * Functions which want to generate errors independently from 12527c478bd9Sstevel@tonic-gate * rfs4call should set error to the desired errno value and 12537c478bd9Sstevel@tonic-gate * set stat and rpc_status to 0. nfs4_error_init() is a 12547c478bd9Sstevel@tonic-gate * convenient function to do this. 12557c478bd9Sstevel@tonic-gate */ 12567c478bd9Sstevel@tonic-gate typedef struct { 12577c478bd9Sstevel@tonic-gate int error; 12587c478bd9Sstevel@tonic-gate nfsstat4 stat; 12597c478bd9Sstevel@tonic-gate enum clnt_stat rpc_status; 12607c478bd9Sstevel@tonic-gate } nfs4_error_t; 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate /* 12637c478bd9Sstevel@tonic-gate * Shared functions 12647c478bd9Sstevel@tonic-gate */ 12657c478bd9Sstevel@tonic-gate extern void rfs4_op_readdir(nfs_argop4 *, nfs_resop4 *, 12667c478bd9Sstevel@tonic-gate struct svc_req *, struct compound_state *); 12677c478bd9Sstevel@tonic-gate extern void nfs_fh4_copy(nfs_fh4 *, nfs_fh4 *); 12687c478bd9Sstevel@tonic-gate 12697c478bd9Sstevel@tonic-gate extern void nfs4_fattr4_free(fattr4 *); 12707c478bd9Sstevel@tonic-gate 12717c478bd9Sstevel@tonic-gate extern int nfs4lookup_setup(char *, lookup4_param_t *, int); 12727c478bd9Sstevel@tonic-gate extern void nfs4_getattr_otw_norecovery(vnode_t *, 12737c478bd9Sstevel@tonic-gate nfs4_ga_res_t *, nfs4_error_t *, cred_t *, int); 12747c478bd9Sstevel@tonic-gate extern int nfs4_getattr_otw(vnode_t *, nfs4_ga_res_t *, cred_t *, int); 12757c478bd9Sstevel@tonic-gate extern int nfs4cmpfh(const nfs_fh4 *, const nfs_fh4 *); 12767c478bd9Sstevel@tonic-gate extern int nfs4cmpfhandle(nfs4_fhandle_t *, nfs4_fhandle_t *); 12777c478bd9Sstevel@tonic-gate extern int nfs4getattr(vnode_t *, struct vattr *, cred_t *); 12787c478bd9Sstevel@tonic-gate extern int nfs4_waitfor_purge_complete(vnode_t *); 12797c478bd9Sstevel@tonic-gate extern int nfs4_validate_caches(vnode_t *, cred_t *); 12807c478bd9Sstevel@tonic-gate extern int nfs4init(int, char *); 12817c478bd9Sstevel@tonic-gate extern void nfs4fini(void); 12827c478bd9Sstevel@tonic-gate extern int nfs4_vfsinit(void); 12837c478bd9Sstevel@tonic-gate extern void nfs4_vfsfini(void); 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate extern void nfs4_vnops_init(void); 12867c478bd9Sstevel@tonic-gate extern void nfs4_vnops_fini(void); 12877c478bd9Sstevel@tonic-gate extern void nfs_idmap_init(void); 12887c478bd9Sstevel@tonic-gate extern void nfs_idmap_flush(int); 12897c478bd9Sstevel@tonic-gate extern void nfs_idmap_fini(void); 12907c478bd9Sstevel@tonic-gate extern int nfs4_rnode_init(void); 12917c478bd9Sstevel@tonic-gate extern int nfs4_rnode_fini(void); 12927c478bd9Sstevel@tonic-gate extern int nfs4_shadow_init(void); 12937c478bd9Sstevel@tonic-gate extern int nfs4_shadow_fini(void); 12947c478bd9Sstevel@tonic-gate extern int nfs4_acache_init(void); 12957c478bd9Sstevel@tonic-gate extern int nfs4_acache_fini(void); 12967c478bd9Sstevel@tonic-gate extern int nfs4_subr_init(void); 12977c478bd9Sstevel@tonic-gate extern int nfs4_subr_fini(void); 12987c478bd9Sstevel@tonic-gate extern void nfs4_acl_init(void); 12997c478bd9Sstevel@tonic-gate extern void nfs4_acl_free_cache(vsecattr_t *); 13007c478bd9Sstevel@tonic-gate 13017c478bd9Sstevel@tonic-gate extern int geterrno4(nfsstat4); 13027c478bd9Sstevel@tonic-gate extern nfsstat4 puterrno4(int); 13037c478bd9Sstevel@tonic-gate extern int nfs4_need_to_bump_seqid(COMPOUND4res_clnt *); 13047c478bd9Sstevel@tonic-gate extern int nfs4tsize(void); 13057c478bd9Sstevel@tonic-gate extern int checkauth4(struct compound_state *, struct svc_req *); 13067c478bd9Sstevel@tonic-gate extern nfsstat4 call_checkauth4(struct compound_state *, struct svc_req *); 13077c478bd9Sstevel@tonic-gate extern int is_exported_sec(int, struct exportinfo *); 13087c478bd9Sstevel@tonic-gate extern void nfs4_vmask_to_nmask(uint_t, bitmap4 *); 13099720e166Sjasmith extern void nfs4_vmask_to_nmask_set(uint_t, bitmap4 *); 13107c478bd9Sstevel@tonic-gate extern int nfs_idmap_str_uid(utf8string *u8s, uid_t *, bool_t); 13117c478bd9Sstevel@tonic-gate extern int nfs_idmap_str_gid(utf8string *u8s, gid_t *, bool_t); 13127c478bd9Sstevel@tonic-gate extern int nfs_idmap_uid_str(uid_t, utf8string *u8s, bool_t); 13137c478bd9Sstevel@tonic-gate extern int nfs_idmap_gid_str(gid_t gid, utf8string *u8s, bool_t); 13147c478bd9Sstevel@tonic-gate extern int nfs4_time_ntov(nfstime4 *, timestruc_t *); 13157c478bd9Sstevel@tonic-gate extern int nfs4_time_vton(timestruc_t *, nfstime4 *); 13167c478bd9Sstevel@tonic-gate extern char *utf8_to_str(utf8string *, uint_t *, char *); 13177c478bd9Sstevel@tonic-gate extern char *utf8_to_fn(utf8string *, uint_t *, char *); 13187c478bd9Sstevel@tonic-gate extern utf8string *str_to_utf8(char *, utf8string *); 13197c478bd9Sstevel@tonic-gate extern utf8string *utf8_copy(utf8string *, utf8string *); 13207c478bd9Sstevel@tonic-gate extern int utf8_compare(const utf8string *, const utf8string *); 13217c478bd9Sstevel@tonic-gate extern int utf8_dir_verify(utf8string *); 13227c478bd9Sstevel@tonic-gate extern char *utf8_strchr(utf8string *, const char); 13237c478bd9Sstevel@tonic-gate extern int ln_ace4_cmp(nfsace4 *, nfsace4 *, int); 13247c478bd9Sstevel@tonic-gate extern int vs_aent_to_ace4(vsecattr_t *, vsecattr_t *, int, int); 13257c478bd9Sstevel@tonic-gate extern int vs_ace4_to_aent(vsecattr_t *, vsecattr_t *, uid_t, gid_t, 13267c478bd9Sstevel@tonic-gate int, int, int); 13277c478bd9Sstevel@tonic-gate extern int vs_ace4_to_acet(vsecattr_t *, vsecattr_t *, uid_t, gid_t, 1328fa9e4066Sahrens int, int); 1329fa9e4066Sahrens extern int vs_acet_to_ace4(vsecattr_t *, vsecattr_t *, int); 13307c478bd9Sstevel@tonic-gate extern void vs_acet_destroy(vsecattr_t *); 13317c478bd9Sstevel@tonic-gate extern void vs_ace4_destroy(vsecattr_t *); 13327c478bd9Sstevel@tonic-gate extern void vs_aent_destroy(vsecattr_t *); 13337c478bd9Sstevel@tonic-gate 13347c478bd9Sstevel@tonic-gate extern int stateid4_cmp(stateid4 *, stateid4 *); 13357c478bd9Sstevel@tonic-gate 13367c478bd9Sstevel@tonic-gate extern vtype_t nf4_to_vt[]; 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate extern struct nfs4_ntov_map nfs4_ntov_map[]; 13397c478bd9Sstevel@tonic-gate extern uint_t nfs4_ntov_map_size; 13407c478bd9Sstevel@tonic-gate 13417c478bd9Sstevel@tonic-gate extern kstat_named_t *rfsproccnt_v4_ptr; 13427c478bd9Sstevel@tonic-gate extern struct vfsops *nfs4_vfsops; 13437c478bd9Sstevel@tonic-gate extern struct vnodeops *nfs4_vnodeops; 13447c478bd9Sstevel@tonic-gate extern const struct fs_operation_def nfs4_vnodeops_template[]; 1345b9238976Sth199096 extern vnodeops_t *nfs4_trigger_vnodeops; 1346b9238976Sth199096 extern const struct fs_operation_def nfs4_trigger_vnodeops_template[]; 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate extern uint_t nfs4_tsize(struct knetconfig *); 13497c478bd9Sstevel@tonic-gate extern uint_t rfs4_tsize(struct svc_req *); 13507c478bd9Sstevel@tonic-gate 1351eac3aab7Srobinson extern bool_t xdr_inline_decode_nfs_fh4(uint32_t *, nfs_fh4_fmt_t *, 1352eac3aab7Srobinson uint32_t); 13537c46fb7fSek110237 extern bool_t xdr_inline_encode_nfs_fh4(uint32_t **, uint32_t *, 13547c46fb7fSek110237 nfs_fh4_fmt_t *); 13557c46fb7fSek110237 13567c478bd9Sstevel@tonic-gate #ifdef DEBUG 13577c478bd9Sstevel@tonic-gate extern int rfs4_do_pre_op_attr; 13587c478bd9Sstevel@tonic-gate extern int rfs4_do_post_op_attr; 13597c478bd9Sstevel@tonic-gate #endif 13607c478bd9Sstevel@tonic-gate 13617c478bd9Sstevel@tonic-gate extern stateid4 clnt_special0; 13627c478bd9Sstevel@tonic-gate extern stateid4 clnt_special1; 13637c478bd9Sstevel@tonic-gate #define CLNT_ISSPECIAL(id) (stateid4_cmp(id, &clnt_special0) || \ 13647c478bd9Sstevel@tonic-gate stateid4_cmp(id, &clnt_special1)) 13657c478bd9Sstevel@tonic-gate 13667c478bd9Sstevel@tonic-gate /* 13677c478bd9Sstevel@tonic-gate * The NFS Version 4 service procedures. 13687c478bd9Sstevel@tonic-gate */ 13697c478bd9Sstevel@tonic-gate 13707c478bd9Sstevel@tonic-gate extern void rfs4_compound(COMPOUND4args *, COMPOUND4res *, 1371*2e9d26a4Srmesta struct exportinfo *, struct svc_req *, cred_t *, int *); 13727c478bd9Sstevel@tonic-gate extern void rfs4_compound_free(COMPOUND4res *); 13737c478bd9Sstevel@tonic-gate extern void rfs4_compound_flagproc(COMPOUND4args *, int *); 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate extern int rfs4_srvrinit(void); 13767c478bd9Sstevel@tonic-gate extern void rfs4_srvrfini(void); 13777c478bd9Sstevel@tonic-gate extern void rfs4_state_init(void); 13787c478bd9Sstevel@tonic-gate extern void rfs4_state_fini(void); 13797c478bd9Sstevel@tonic-gate 13807c478bd9Sstevel@tonic-gate #endif 13817c478bd9Sstevel@tonic-gate #ifdef __cplusplus 13827c478bd9Sstevel@tonic-gate } 13837c478bd9Sstevel@tonic-gate #endif 13847c478bd9Sstevel@tonic-gate 13857c478bd9Sstevel@tonic-gate #endif /* _NFS4_H */ 1386