1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2017 RackTop Systems. 14 */ 15 16 #ifndef _NFS4X_H 17 #define _NFS4X_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #ifdef _KERNEL 24 25 #include <sys/cred.h> 26 #include <nfs/nfs4_kprot.h> 27 28 /* 29 * 24 bytes of rpc header 30 * 12 bytes for compound header 31 * 44 bytes for SEQUENCE response 32 */ 33 #define NFS4_MIN_HDR_SEQSZ (24 + 12 + 44) 34 35 /* 36 * NFSv4.1: slot support (reply cache) 37 */ 38 39 #define RFS4_SLOT_INUSE (1 << 0) 40 #define RFS4_SLOT_CACHED (1 << 1) 41 42 /* Slot entry structure */ 43 typedef struct rfs4_slot { 44 uint32_t se_flags; 45 sequenceid4 se_seqid; 46 COMPOUND4res se_buf; /* Buf for slot and replays */ 47 kmutex_t se_lock; 48 } rfs4_slot_t; 49 50 /* 51 * NFSv4.1 Sessions 52 */ 53 54 typedef struct rfs41_csr { /* contrived create_session result */ 55 sequenceid4 xi_sid; /* seqid response to EXCHG_ID */ 56 nfsstat4 cs_status; 57 CREATE_SESSION4resok cs_res; /* cached results if NFS4_OK */ 58 } rfs41_csr_t; 59 60 /* 61 * Sessions Callback Infrastructure 62 * 63 * Locking: 64 * 65 * . cn_lock protects all fields in sess_channel_t, but since 66 * fore/back and dir don't change often, we serialize only 67 * the occasional update. 68 * 69 * cn_lock: cn_lock 70 * bsd_rwlock: cn_lock -> bsd_rwlock 71 */ 72 73 #define MAX_CH_CACHE 10 74 typedef struct { /* Back Chan Specific Data */ 75 rfs4_slot_t *bsd_slots; /* opaque token for slot tab */ 76 nfsstat4 bsd_stat; 77 krwlock_t bsd_rwlock; /* protect slot tab info */ 78 uint64_t bsd_idx; /* Index of next spare CLNT */ 79 uint64_t bsd_cur; /* Most recent added CLNT */ 80 int bsd_ch_free; 81 CLIENT *bsd_clnt[MAX_CH_CACHE]; 82 } sess_bcsd_t; 83 84 typedef struct { 85 channel_dir_from_server4 cn_dir; /* Chan Direction */ 86 channel_attrs4 cn_attrs; /* chan Attrs */ 87 channel_attrs4 cn_back_attrs; /* back channel Attrs */ 88 sess_bcsd_t *cn_csd; /* Chan Specific Data */ 89 krwlock_t cn_lock; 90 } sess_channel_t; 91 92 /* 93 * Maximum number of concurrent COMPOUND requests per session 94 */ 95 #define MAXSLOTS 256 96 #define MAXSLOTS_BACK 4 97 98 typedef struct { 99 state_protect_how4 sp_type; 100 } rfs41_sprot_t; 101 102 /* 103 * NFSv4.1 Sessions (cont'd) 104 * 105 * rfs4_session_t rfs4_client_t 106 * +-------------+ +--------------------+ 107 * | sn_sessid | | clientid | 108 * | sn_clnt * -|---------->| : | 109 * | sn_fore | +--------------------+ 110 * | sn_back | 111 * | sn_slots * -|---------> +--------------------------------+ 112 * +-------------+ | (slot_ent_t) | 113 * | +----------------------------+| 114 * | | status, slot, seqid, resp *||------><Res> 115 * | +----------------------------+| 116 * | | status, slot, seqid, resp *|| 117 * | +----------------------------+| 118 * | | status, slot, seqid, resp *|| 119 * | +----------------------------+| 120 * | . | 121 * | : | 122 * +--------------------------------+ 123 * stok_t 124 */ 125 struct rfs4_client; 126 struct rfs4_dbe; 127 128 typedef struct { 129 nfsstat4 cs_error; 130 struct rfs4_client *cs_client; 131 struct svc_req *cs_req; 132 uint32_t cs_id; 133 CREATE_SESSION4args cs_aotw; 134 } session41_create_t; 135 136 /* 137 * sn_seq4 - sequence result bit accounting info (session scope) 138 * CB_PATH_DOWN_SESSION, CB_GSS_CONTEXT_EXPIRING, 139 * CB_GSS_CONTEXT_EXPIRED, BACKCHANNEL_FAULT 140 */ 141 typedef struct rfs4_session { 142 struct rfs4_dbe *sn_dbe; 143 sessionid4 sn_sessid; /* session id */ 144 struct rfs4_client *sn_clnt; /* back ptr to client state */ 145 sess_channel_t *sn_fore; /* fore chan for this session */ 146 sess_channel_t *sn_back; /* back chan for this session */ 147 rfs4_slot_t *sn_slots; /* slot replay cache */ 148 time_t sn_laccess; /* struct was last accessed */ 149 int sn_csflags; /* create_session only flags */ 150 uint32_t sn_flags; /* SEQ4 status bits */ 151 list_node_t sn_node; /* link node to rfs4_client */ 152 struct { 153 uint32_t pngcnt; /* conn pings outstanding */ 154 uint32_t progno; /* cb_program number */ 155 uint32_t failed:1; /* TRUE if no cb path avail */ 156 uint32_t pnginprog:1; 157 } sn_bc; 158 uint32_t sn_rcached; /* cached replies, for stat */ 159 } rfs4_session_t; 160 161 #define SN_CB_CHAN_EST(x) ((x)->sn_back != NULL) 162 #define SN_CB_CHAN_OK(x) ((x)->sn_bc.failed == 0) 163 164 /* error code for internal use */ 165 #define nfserr_replay_cache NFS4ERR_REPLAY_CACHE 166 167 /* Session end */ 168 169 /* 170 * Set of RPC credentials used for a particular operation. 171 * Used for operations like SETCLIENTID_CONFIRM where the 172 * credentials needs to match those used at SETCLIENTID. 173 * For EXCHANGE_ID (NFSv4.1+) 174 */ 175 176 typedef struct { 177 cred_t *cp_cr; 178 int cp_aflavor; 179 int cp_secmod; 180 caddr_t cp_princ; 181 } cred_set_t; 182 183 /* NFSv4.1 Functions */ 184 extern int rfs4x_dispatch(struct svc_req *, SVCXPRT *, char *); 185 186 void rfs4_free_cred_set(cred_set_t *); 187 void rfs4x_session_rele(rfs4_session_t *); 188 rfs4_session_t *rfs4x_createsession(session41_create_t *); 189 nfsstat4 rfs4x_destroysession(rfs4_session_t *, unsigned useref); 190 void rfs4x_client_session_remove(struct rfs4_client *); 191 rfs4_session_t *rfs4x_findsession_by_id(sessionid4); 192 void rfs4x_session_hold(rfs4_session_t *); 193 void rfs4x_session_rele(rfs4_session_t *); 194 195 /* Some init/fini helpers */ 196 struct rfs4_srv; 197 struct compound_state; 198 void rfs4x_state_init_locked(struct nfs4_srv *); 199 void rfs4x_state_fini(struct nfs4_srv *); 200 int rfs4x_sequence_prep(COMPOUND4args *, COMPOUND4res *, 201 struct compound_state *, SVCXPRT *); 202 void rfs4x_sequence_done(COMPOUND4res *, struct compound_state *); 203 204 #endif /* _KERNEL */ 205 206 #ifdef __cplusplus 207 } 208 #endif 209 210 #endif /* _NFS4X_H */ 211