1 /*- 2 * Copyright (c) 2009 Rick Macklem, University of Guelph 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _NFS_NFSCLSTATE_H_ 30 #define _NFS_NFSCLSTATE_H_ 31 32 /* 33 * Definitions for NFS V4 client state handling. 34 */ 35 LIST_HEAD(nfsclopenhead, nfsclopen); 36 LIST_HEAD(nfscllockownerhead, nfscllockowner); 37 LIST_HEAD(nfscllockhead, nfscllock); 38 LIST_HEAD(nfsclhead, nfsclclient); 39 LIST_HEAD(nfsclownerhead, nfsclowner); 40 TAILQ_HEAD(nfscldeleghead, nfscldeleg); 41 LIST_HEAD(nfscldeleghash, nfscldeleg); 42 #define NFSCLDELEGHASHSIZE 256 43 #define NFSCLDELEGHASH(c, f, l) \ 44 (&((c)->nfsc_deleghash[ncl_hash((f), (l)) % NFSCLDELEGHASHSIZE])) 45 46 struct nfsclclient { 47 LIST_ENTRY(nfsclclient) nfsc_list; 48 struct nfsclownerhead nfsc_owner; 49 struct nfscldeleghead nfsc_deleg; 50 struct nfscldeleghash nfsc_deleghash[NFSCLDELEGHASHSIZE]; 51 struct nfscllockownerhead nfsc_defunctlockowner; 52 struct nfsv4lock nfsc_lock; 53 struct proc *nfsc_renewthread; 54 struct nfsmount *nfsc_nmp; 55 nfsquad_t nfsc_clientid; 56 time_t nfsc_expire; 57 u_int32_t nfsc_clientidrev; 58 u_int32_t nfsc_renew; 59 u_int32_t nfsc_cbident; 60 u_int16_t nfsc_flags; 61 u_int16_t nfsc_idlen; 62 u_int8_t nfsc_id[1]; /* Malloc'd to correct length */ 63 }; 64 65 /* 66 * Bits for nfsc_flags. 67 */ 68 #define NFSCLFLAGS_INITED 0x0001 69 #define NFSCLFLAGS_HASCLIENTID 0x0002 70 #define NFSCLFLAGS_RECOVER 0x0004 71 #define NFSCLFLAGS_UMOUNT 0x0008 72 #define NFSCLFLAGS_HASTHREAD 0x0010 73 #define NFSCLFLAGS_AFINET6 0x0020 74 #define NFSCLFLAGS_EXPIREIT 0x0040 75 #define NFSCLFLAGS_FIRSTDELEG 0x0080 76 #define NFSCLFLAGS_GOTDELEG 0x0100 77 78 struct nfsclowner { 79 LIST_ENTRY(nfsclowner) nfsow_list; 80 struct nfsclopenhead nfsow_open; 81 struct nfsclclient *nfsow_clp; 82 u_int32_t nfsow_seqid; 83 u_int32_t nfsow_defunct; 84 struct nfsv4lock nfsow_rwlock; 85 u_int8_t nfsow_owner[NFSV4CL_LOCKNAMELEN]; 86 }; 87 88 /* 89 * MALLOC'd to the correct length to accommodate the file handle. 90 */ 91 struct nfscldeleg { 92 TAILQ_ENTRY(nfscldeleg) nfsdl_list; 93 LIST_ENTRY(nfscldeleg) nfsdl_hash; 94 struct nfsclownerhead nfsdl_owner; /* locally issued state */ 95 struct nfscllockownerhead nfsdl_lock; 96 nfsv4stateid_t nfsdl_stateid; 97 struct acl_entry nfsdl_ace; /* Delegation ace */ 98 struct nfsclclient *nfsdl_clp; 99 struct nfsv4lock nfsdl_rwlock; /* for active I/O ops */ 100 struct nfscred nfsdl_cred; /* Cred. used for Open */ 101 time_t nfsdl_timestamp; /* used for stale cleanup */ 102 u_int64_t nfsdl_sizelimit; /* Limit for file growth */ 103 u_int64_t nfsdl_size; /* saved copy of file size */ 104 u_int64_t nfsdl_change; /* and change attribute */ 105 struct timespec nfsdl_modtime; /* local modify time */ 106 u_int16_t nfsdl_fhlen; 107 u_int8_t nfsdl_flags; 108 u_int8_t nfsdl_fh[1]; /* must be last */ 109 }; 110 111 /* 112 * nfsdl_flags bits. 113 */ 114 #define NFSCLDL_READ 0x01 115 #define NFSCLDL_WRITE 0x02 116 #define NFSCLDL_RECALL 0x04 117 #define NFSCLDL_NEEDRECLAIM 0x08 118 #define NFSCLDL_ZAPPED 0x10 119 #define NFSCLDL_MODTIMESET 0x20 120 121 /* 122 * MALLOC'd to the correct length to accommodate the file handle. 123 */ 124 struct nfsclopen { 125 LIST_ENTRY(nfsclopen) nfso_list; 126 struct nfscllockownerhead nfso_lock; 127 nfsv4stateid_t nfso_stateid; 128 struct nfsclowner *nfso_own; 129 struct nfscred nfso_cred; /* Cred. used for Open */ 130 u_int32_t nfso_mode; 131 u_int32_t nfso_opencnt; 132 u_int16_t nfso_fhlen; 133 u_int8_t nfso_posixlock; /* 1 for POSIX type locking */ 134 u_int8_t nfso_fh[1]; /* must be last */ 135 }; 136 137 /* 138 * Return values for nfscl_open(). NFSCLOPEN_OK must == 0. 139 */ 140 #define NFSCLOPEN_OK 0 141 #define NFSCLOPEN_DOOPEN 1 142 #define NFSCLOPEN_DOOPENDOWNGRADE 2 143 144 struct nfscllockowner { 145 LIST_ENTRY(nfscllockowner) nfsl_list; 146 struct nfscllockhead nfsl_lock; 147 struct nfsclopen *nfsl_open; 148 NFSPROC_T *nfsl_inprog; 149 nfsv4stateid_t nfsl_stateid; 150 u_int32_t nfsl_seqid; 151 u_int32_t nfsl_defunct; 152 struct nfsv4lock nfsl_rwlock; 153 u_int8_t nfsl_owner[NFSV4CL_LOCKNAMELEN]; 154 u_int8_t nfsl_openowner[NFSV4CL_LOCKNAMELEN]; 155 }; 156 157 /* 158 * Byte range entry for the above lock owner. 159 */ 160 struct nfscllock { 161 LIST_ENTRY(nfscllock) nfslo_list; 162 u_int64_t nfslo_first; 163 u_int64_t nfslo_end; 164 short nfslo_type; 165 }; 166 167 /* 168 * Macro for incrementing the seqid#. 169 */ 170 #define NFSCL_INCRSEQID(s, n) do { \ 171 if (((n)->nd_flag & ND_INCRSEQID)) \ 172 (s)++; \ 173 } while (0) 174 175 #endif /* _NFS_NFSCLSTATE_H_ */ 176