1 1.2 pgoyette /* $NetBSD: nfsclstate.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $ */ 2 1.1 dholland /*- 3 1.1 dholland * Copyright (c) 2009 Rick Macklem, University of Guelph 4 1.1 dholland * All rights reserved. 5 1.1 dholland * 6 1.1 dholland * Redistribution and use in source and binary forms, with or without 7 1.1 dholland * modification, are permitted provided that the following conditions 8 1.1 dholland * are met: 9 1.1 dholland * 1. Redistributions of source code must retain the above copyright 10 1.1 dholland * notice, this list of conditions and the following disclaimer. 11 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 dholland * notice, this list of conditions and the following disclaimer in the 13 1.1 dholland * documentation and/or other materials provided with the distribution. 14 1.1 dholland * 15 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 1.1 dholland * SUCH DAMAGE. 26 1.1 dholland * 27 1.2 pgoyette * FreeBSD: head/sys/fs/nfs/nfsclstate.h 268115 2014-07-01 20:47:16Z rmacklem 28 1.2 pgoyette * $NetBSD: nfsclstate.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $ 29 1.1 dholland */ 30 1.1 dholland 31 1.1 dholland #ifndef _NFS_NFSCLSTATE_H_ 32 1.1 dholland #define _NFS_NFSCLSTATE_H_ 33 1.1 dholland 34 1.1 dholland /* 35 1.1 dholland * Definitions for NFS V4 client state handling. 36 1.1 dholland */ 37 1.1 dholland LIST_HEAD(nfsclopenhead, nfsclopen); 38 1.1 dholland LIST_HEAD(nfscllockownerhead, nfscllockowner); 39 1.1 dholland SLIST_HEAD(nfscllockownerfhhead, nfscllockownerfh); 40 1.1 dholland LIST_HEAD(nfscllockhead, nfscllock); 41 1.1 dholland LIST_HEAD(nfsclhead, nfsclclient); 42 1.1 dholland LIST_HEAD(nfsclownerhead, nfsclowner); 43 1.1 dholland TAILQ_HEAD(nfscldeleghead, nfscldeleg); 44 1.1 dholland LIST_HEAD(nfscldeleghash, nfscldeleg); 45 1.1 dholland TAILQ_HEAD(nfscllayouthead, nfscllayout); 46 1.1 dholland LIST_HEAD(nfscllayouthash, nfscllayout); 47 1.1 dholland LIST_HEAD(nfsclflayouthead, nfsclflayout); 48 1.1 dholland LIST_HEAD(nfscldevinfohead, nfscldevinfo); 49 1.1 dholland LIST_HEAD(nfsclrecalllayouthead, nfsclrecalllayout); 50 1.1 dholland #define NFSCLDELEGHASHSIZE 256 51 1.1 dholland #define NFSCLDELEGHASH(c, f, l) \ 52 1.1 dholland (&((c)->nfsc_deleghash[ncl_hash((f), (l)) % NFSCLDELEGHASHSIZE])) 53 1.1 dholland #define NFSCLLAYOUTHASHSIZE 256 54 1.1 dholland #define NFSCLLAYOUTHASH(c, f, l) \ 55 1.1 dholland (&((c)->nfsc_layouthash[ncl_hash((f), (l)) % NFSCLLAYOUTHASHSIZE])) 56 1.1 dholland 57 1.1 dholland /* Structure for NFSv4.1 session stuff. */ 58 1.1 dholland struct nfsclsession { 59 1.2 pgoyette kmutex_t nfsess_mtx; 60 1.1 dholland struct nfsslot nfsess_cbslots[NFSV4_CBSLOTS]; 61 1.1 dholland nfsquad_t nfsess_clientid; 62 1.2 pgoyette SVCXPRT *nfsess_xprt; /* For backchannel callback */ 63 1.1 dholland uint32_t nfsess_slotseq[64]; /* Max for 64bit nm_slots */ 64 1.1 dholland uint64_t nfsess_slots; 65 1.1 dholland uint32_t nfsess_sequenceid; 66 1.1 dholland uint32_t nfsess_maxcache; /* Max size for cached reply. */ 67 1.1 dholland uint16_t nfsess_foreslots; 68 1.1 dholland uint16_t nfsess_backslots; 69 1.1 dholland uint8_t nfsess_sessionid[NFSX_V4SESSIONID]; 70 1.1 dholland }; 71 1.1 dholland 72 1.1 dholland /* 73 1.1 dholland * This structure holds the session, clientid and related information 74 1.1 dholland * needed for an NFSv4.1 Meta Data Server (MDS) or Data Server (DS). 75 1.1 dholland * It is malloc'd to the correct length. 76 1.1 dholland */ 77 1.1 dholland struct nfsclds { 78 1.1 dholland TAILQ_ENTRY(nfsclds) nfsclds_list; 79 1.1 dholland struct nfsclsession nfsclds_sess; 80 1.2 pgoyette kmutex_t nfsclds_mtx; 81 1.1 dholland struct nfssockreq *nfsclds_sockp; 82 1.1 dholland time_t nfsclds_expire; 83 1.1 dholland uint16_t nfsclds_flags; 84 1.1 dholland uint16_t nfsclds_servownlen; 85 1.1 dholland uint8_t nfsclds_verf[NFSX_VERF]; 86 1.1 dholland uint8_t nfsclds_serverown[0]; 87 1.1 dholland }; 88 1.1 dholland 89 1.1 dholland /* 90 1.1 dholland * Flags for nfsclds_flags. 91 1.1 dholland */ 92 1.1 dholland #define NFSCLDS_HASWRITEVERF 0x0001 93 1.1 dholland #define NFSCLDS_MDS 0x0002 94 1.1 dholland #define NFSCLDS_DS 0x0004 95 1.1 dholland 96 1.1 dholland struct nfsclclient { 97 1.1 dholland LIST_ENTRY(nfsclclient) nfsc_list; 98 1.1 dholland struct nfsclownerhead nfsc_owner; 99 1.1 dholland struct nfscldeleghead nfsc_deleg; 100 1.1 dholland struct nfscldeleghash nfsc_deleghash[NFSCLDELEGHASHSIZE]; 101 1.1 dholland struct nfscllayouthead nfsc_layout; 102 1.1 dholland struct nfscllayouthash nfsc_layouthash[NFSCLLAYOUTHASHSIZE]; 103 1.1 dholland struct nfscldevinfohead nfsc_devinfo; 104 1.1 dholland struct nfsv4lock nfsc_lock; 105 1.1 dholland struct proc *nfsc_renewthread; 106 1.1 dholland struct nfsmount *nfsc_nmp; 107 1.1 dholland time_t nfsc_expire; 108 1.1 dholland u_int32_t nfsc_clientidrev; 109 1.1 dholland u_int32_t nfsc_rev; 110 1.1 dholland u_int32_t nfsc_renew; 111 1.1 dholland u_int32_t nfsc_cbident; 112 1.1 dholland u_int16_t nfsc_flags; 113 1.1 dholland u_int16_t nfsc_idlen; 114 1.1 dholland u_int8_t nfsc_id[1]; /* Malloc'd to correct length */ 115 1.1 dholland }; 116 1.1 dholland 117 1.1 dholland /* 118 1.1 dholland * Bits for nfsc_flags. 119 1.1 dholland */ 120 1.1 dholland #define NFSCLFLAGS_INITED 0x0001 121 1.1 dholland #define NFSCLFLAGS_HASCLIENTID 0x0002 122 1.1 dholland #define NFSCLFLAGS_RECOVER 0x0004 123 1.1 dholland #define NFSCLFLAGS_UMOUNT 0x0008 124 1.1 dholland #define NFSCLFLAGS_HASTHREAD 0x0010 125 1.1 dholland #define NFSCLFLAGS_AFINET6 0x0020 126 1.1 dholland #define NFSCLFLAGS_EXPIREIT 0x0040 127 1.1 dholland #define NFSCLFLAGS_FIRSTDELEG 0x0080 128 1.1 dholland #define NFSCLFLAGS_GOTDELEG 0x0100 129 1.1 dholland #define NFSCLFLAGS_RECVRINPROG 0x0200 130 1.1 dholland 131 1.1 dholland struct nfsclowner { 132 1.1 dholland LIST_ENTRY(nfsclowner) nfsow_list; 133 1.1 dholland struct nfsclopenhead nfsow_open; 134 1.1 dholland struct nfsclclient *nfsow_clp; 135 1.1 dholland u_int32_t nfsow_seqid; 136 1.1 dholland u_int32_t nfsow_defunct; 137 1.1 dholland struct nfsv4lock nfsow_rwlock; 138 1.1 dholland u_int8_t nfsow_owner[NFSV4CL_LOCKNAMELEN]; 139 1.1 dholland }; 140 1.1 dholland 141 1.1 dholland /* 142 1.1 dholland * MALLOC'd to the correct length to accommodate the file handle. 143 1.1 dholland */ 144 1.1 dholland struct nfscldeleg { 145 1.1 dholland TAILQ_ENTRY(nfscldeleg) nfsdl_list; 146 1.1 dholland LIST_ENTRY(nfscldeleg) nfsdl_hash; 147 1.1 dholland struct nfsclownerhead nfsdl_owner; /* locally issued state */ 148 1.1 dholland struct nfscllockownerhead nfsdl_lock; 149 1.1 dholland nfsv4stateid_t nfsdl_stateid; 150 1.1 dholland struct acl_entry nfsdl_ace; /* Delegation ace */ 151 1.1 dholland struct nfsclclient *nfsdl_clp; 152 1.1 dholland struct nfsv4lock nfsdl_rwlock; /* for active I/O ops */ 153 1.1 dholland struct nfscred nfsdl_cred; /* Cred. used for Open */ 154 1.1 dholland time_t nfsdl_timestamp; /* used for stale cleanup */ 155 1.1 dholland u_int64_t nfsdl_sizelimit; /* Limit for file growth */ 156 1.1 dholland u_int64_t nfsdl_size; /* saved copy of file size */ 157 1.1 dholland u_int64_t nfsdl_change; /* and change attribute */ 158 1.1 dholland struct timespec nfsdl_modtime; /* local modify time */ 159 1.1 dholland u_int16_t nfsdl_fhlen; 160 1.1 dholland u_int8_t nfsdl_flags; 161 1.1 dholland u_int8_t nfsdl_fh[1]; /* must be last */ 162 1.1 dholland }; 163 1.1 dholland 164 1.1 dholland /* 165 1.1 dholland * nfsdl_flags bits. 166 1.1 dholland */ 167 1.1 dholland #define NFSCLDL_READ 0x01 168 1.1 dholland #define NFSCLDL_WRITE 0x02 169 1.1 dholland #define NFSCLDL_RECALL 0x04 170 1.1 dholland #define NFSCLDL_NEEDRECLAIM 0x08 171 1.1 dholland #define NFSCLDL_ZAPPED 0x10 172 1.1 dholland #define NFSCLDL_MODTIMESET 0x20 173 1.1 dholland #define NFSCLDL_DELEGRET 0x40 174 1.1 dholland 175 1.1 dholland /* 176 1.1 dholland * MALLOC'd to the correct length to accommodate the file handle. 177 1.1 dholland */ 178 1.1 dholland struct nfsclopen { 179 1.1 dholland LIST_ENTRY(nfsclopen) nfso_list; 180 1.1 dholland struct nfscllockownerhead nfso_lock; 181 1.1 dholland nfsv4stateid_t nfso_stateid; 182 1.1 dholland struct nfsclowner *nfso_own; 183 1.1 dholland struct nfscred nfso_cred; /* Cred. used for Open */ 184 1.1 dholland u_int32_t nfso_mode; 185 1.1 dholland u_int32_t nfso_opencnt; 186 1.1 dholland u_int16_t nfso_fhlen; 187 1.1 dholland u_int8_t nfso_posixlock; /* 1 for POSIX type locking */ 188 1.1 dholland u_int8_t nfso_fh[1]; /* must be last */ 189 1.1 dholland }; 190 1.1 dholland 191 1.1 dholland /* 192 1.1 dholland * Return values for nfscl_open(). NFSCLOPEN_OK must == 0. 193 1.1 dholland */ 194 1.1 dholland #define NFSCLOPEN_OK 0 195 1.1 dholland #define NFSCLOPEN_DOOPEN 1 196 1.1 dholland #define NFSCLOPEN_DOOPENDOWNGRADE 2 197 1.1 dholland #define NFSCLOPEN_SETCRED 3 198 1.1 dholland 199 1.1 dholland struct nfscllockowner { 200 1.1 dholland LIST_ENTRY(nfscllockowner) nfsl_list; 201 1.1 dholland struct nfscllockhead nfsl_lock; 202 1.1 dholland struct nfsclopen *nfsl_open; 203 1.1 dholland NFSPROC_T *nfsl_inprog; 204 1.1 dholland nfsv4stateid_t nfsl_stateid; 205 1.1 dholland int nfsl_lockflags; 206 1.1 dholland u_int32_t nfsl_seqid; 207 1.1 dholland struct nfsv4lock nfsl_rwlock; 208 1.1 dholland u_int8_t nfsl_owner[NFSV4CL_LOCKNAMELEN]; 209 1.1 dholland u_int8_t nfsl_openowner[NFSV4CL_LOCKNAMELEN]; 210 1.1 dholland }; 211 1.1 dholland 212 1.1 dholland /* 213 1.1 dholland * Byte range entry for the above lock owner. 214 1.1 dholland */ 215 1.1 dholland struct nfscllock { 216 1.1 dholland LIST_ENTRY(nfscllock) nfslo_list; 217 1.1 dholland u_int64_t nfslo_first; 218 1.1 dholland u_int64_t nfslo_end; 219 1.1 dholland short nfslo_type; 220 1.1 dholland }; 221 1.1 dholland 222 1.1 dholland /* This structure is used to collect a list of lockowners to free up. */ 223 1.1 dholland struct nfscllockownerfh { 224 1.1 dholland SLIST_ENTRY(nfscllockownerfh) nfslfh_list; 225 1.1 dholland struct nfscllockownerhead nfslfh_lock; 226 1.1 dholland int nfslfh_len; 227 1.1 dholland uint8_t nfslfh_fh[NFSX_V4FHMAX]; 228 1.1 dholland }; 229 1.1 dholland 230 1.1 dholland /* 231 1.1 dholland * MALLOC'd to the correct length to accommodate the file handle. 232 1.1 dholland */ 233 1.1 dholland struct nfscllayout { 234 1.1 dholland TAILQ_ENTRY(nfscllayout) nfsly_list; 235 1.1 dholland LIST_ENTRY(nfscllayout) nfsly_hash; 236 1.1 dholland nfsv4stateid_t nfsly_stateid; 237 1.1 dholland struct nfsv4lock nfsly_lock; 238 1.1 dholland uint64_t nfsly_filesid[2]; 239 1.1 dholland uint64_t nfsly_lastbyte; 240 1.1 dholland struct nfsclflayouthead nfsly_flayread; 241 1.1 dholland struct nfsclflayouthead nfsly_flayrw; 242 1.1 dholland struct nfsclrecalllayouthead nfsly_recall; 243 1.1 dholland time_t nfsly_timestamp; 244 1.1 dholland struct nfsclclient *nfsly_clp; 245 1.1 dholland uint16_t nfsly_flags; 246 1.1 dholland uint16_t nfsly_fhlen; 247 1.1 dholland uint8_t nfsly_fh[1]; 248 1.1 dholland }; 249 1.1 dholland 250 1.1 dholland /* 251 1.1 dholland * Flags for nfsly_flags. 252 1.1 dholland */ 253 1.1 dholland #define NFSLY_FILES 0x0001 254 1.1 dholland #define NFSLY_BLOCK 0x0002 255 1.1 dholland #define NFSLY_OBJECT 0x0004 256 1.1 dholland #define NFSLY_RECALL 0x0008 257 1.1 dholland #define NFSLY_RECALLFILE 0x0010 258 1.1 dholland #define NFSLY_RECALLFSID 0x0020 259 1.1 dholland #define NFSLY_RECALLALL 0x0040 260 1.1 dholland #define NFSLY_RETONCLOSE 0x0080 261 1.1 dholland #define NFSLY_WRITTEN 0x0100 /* Has been used to write to a DS. */ 262 1.1 dholland 263 1.1 dholland /* 264 1.1 dholland * MALLOC'd to the correct length to accommodate the file handle list. 265 1.1 dholland * These hang off of nfsly_flayread and nfsly_flayrw, sorted in increasing 266 1.1 dholland * offset order. 267 1.1 dholland * The nfsly_flayread list holds the ones with iomode == NFSLAYOUTIOMODE_READ, 268 1.1 dholland * whereas the nfsly_flayrw holds the ones with iomode == NFSLAYOUTIOMODE_RW. 269 1.1 dholland */ 270 1.1 dholland struct nfsclflayout { 271 1.1 dholland LIST_ENTRY(nfsclflayout) nfsfl_list; 272 1.1 dholland uint8_t nfsfl_dev[NFSX_V4DEVICEID]; 273 1.1 dholland uint64_t nfsfl_off; 274 1.1 dholland uint64_t nfsfl_end; 275 1.1 dholland uint64_t nfsfl_patoff; 276 1.1 dholland struct nfscldevinfo *nfsfl_devp; 277 1.1 dholland uint32_t nfsfl_iomode; 278 1.1 dholland uint32_t nfsfl_util; 279 1.1 dholland uint32_t nfsfl_stripe1; 280 1.1 dholland uint16_t nfsfl_flags; 281 1.1 dholland uint16_t nfsfl_fhcnt; 282 1.1 dholland struct nfsfh *nfsfl_fh[1]; /* FH list for DS */ 283 1.1 dholland }; 284 1.1 dholland 285 1.1 dholland /* 286 1.1 dholland * Flags for nfsfl_flags. 287 1.1 dholland */ 288 1.1 dholland #define NFSFL_RECALL 0x0001 /* File layout has been recalled */ 289 1.1 dholland 290 1.1 dholland /* 291 1.1 dholland * Structure that is used to store a LAYOUTRECALL. 292 1.1 dholland */ 293 1.1 dholland struct nfsclrecalllayout { 294 1.1 dholland LIST_ENTRY(nfsclrecalllayout) nfsrecly_list; 295 1.1 dholland uint64_t nfsrecly_off; 296 1.1 dholland uint64_t nfsrecly_len; 297 1.1 dholland int nfsrecly_recalltype; 298 1.1 dholland uint32_t nfsrecly_iomode; 299 1.1 dholland uint32_t nfsrecly_stateseqid; 300 1.1 dholland }; 301 1.1 dholland 302 1.1 dholland /* 303 1.1 dholland * Stores the NFSv4.1 Device Info. Malloc'd to the correct length to 304 1.1 dholland * store the list of network connections and list of indices. 305 1.1 dholland * nfsdi_data[] is allocated the following way: 306 1.1 dholland * - nfsdi_addrcnt * struct nfsclds 307 1.1 dholland * - stripe indices, each stored as one byte, since there can be many 308 1.1 dholland * of them. (This implies a limit of 256 on nfsdi_addrcnt, since the 309 1.1 dholland * indices select which address.) 310 1.1 dholland */ 311 1.1 dholland struct nfscldevinfo { 312 1.1 dholland LIST_ENTRY(nfscldevinfo) nfsdi_list; 313 1.1 dholland uint8_t nfsdi_deviceid[NFSX_V4DEVICEID]; 314 1.1 dholland struct nfsclclient *nfsdi_clp; 315 1.1 dholland uint32_t nfsdi_refcnt; 316 1.1 dholland uint32_t nfsdi_layoutrefs; 317 1.1 dholland uint16_t nfsdi_stripecnt; 318 1.1 dholland uint16_t nfsdi_addrcnt; 319 1.1 dholland struct nfsclds *nfsdi_data[0]; 320 1.1 dholland }; 321 1.1 dholland 322 1.1 dholland /* These inline functions return values from nfsdi_data[]. */ 323 1.1 dholland /* 324 1.1 dholland * Return a pointer to the address at "pos". 325 1.1 dholland */ 326 1.1 dholland static __inline struct nfsclds ** 327 1.1 dholland nfsfldi_addr(struct nfscldevinfo *ndi, int pos) 328 1.1 dholland { 329 1.1 dholland 330 1.1 dholland if (pos >= ndi->nfsdi_addrcnt) 331 1.1 dholland return (NULL); 332 1.1 dholland return (&ndi->nfsdi_data[pos]); 333 1.1 dholland } 334 1.1 dholland 335 1.1 dholland /* 336 1.1 dholland * Return the Nth ("pos") stripe index. 337 1.1 dholland */ 338 1.1 dholland static __inline int 339 1.1 dholland nfsfldi_stripeindex(struct nfscldevinfo *ndi, int pos) 340 1.1 dholland { 341 1.1 dholland uint8_t *valp; 342 1.1 dholland 343 1.1 dholland if (pos >= ndi->nfsdi_stripecnt) 344 1.1 dholland return (-1); 345 1.1 dholland valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt]; 346 1.1 dholland valp += pos; 347 1.1 dholland return ((int)*valp); 348 1.1 dholland } 349 1.1 dholland 350 1.1 dholland /* 351 1.1 dholland * Set the Nth ("pos") stripe index to "val". 352 1.1 dholland */ 353 1.1 dholland static __inline void 354 1.1 dholland nfsfldi_setstripeindex(struct nfscldevinfo *ndi, int pos, uint8_t val) 355 1.1 dholland { 356 1.1 dholland uint8_t *valp; 357 1.1 dholland 358 1.1 dholland if (pos >= ndi->nfsdi_stripecnt) 359 1.1 dholland return; 360 1.1 dholland valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt]; 361 1.1 dholland valp += pos; 362 1.1 dholland *valp = val; 363 1.1 dholland } 364 1.1 dholland 365 1.1 dholland /* 366 1.1 dholland * Macro for incrementing the seqid#. 367 1.1 dholland */ 368 1.1 dholland #define NFSCL_INCRSEQID(s, n) do { \ 369 1.1 dholland if (((n)->nd_flag & ND_INCRSEQID)) \ 370 1.1 dholland (s)++; \ 371 1.1 dholland } while (0) 372 1.1 dholland 373 1.1 dholland #endif /* _NFS_NFSCLSTATE_H_ */ 374