1 /* $NetBSD: nfsrvstate.h,v 1.1.1.1 2013/09/30 07:19:42 dholland Exp $ */ 2 /*- 3 * Copyright (c) 2009 Rick Macklem, University of Guelph 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * FreeBSD: head/sys/fs/nfs/nfsrvstate.h 205941 2010-03-30 23:11:50Z rmacklem 28 * $NetBSD: nfsrvstate.h,v 1.1.1.1 2013/09/30 07:19:42 dholland Exp $ 29 */ 30 31 #ifndef _NFS_NFSRVSTATE_H_ 32 #define _NFS_NFSRVSTATE_H_ 33 34 /* 35 * Definitions for NFS V4 server state handling. 36 */ 37 38 /* 39 * List heads for nfsclient, nfsstate and nfslockfile. 40 * (Some systems seem to like to dynamically size these things, but I 41 * don't see any point in doing so for these ones.) 42 */ 43 LIST_HEAD(nfsclienthashhead, nfsclient); 44 LIST_HEAD(nfsstatehead, nfsstate); 45 LIST_HEAD(nfslockhead, nfslock); 46 LIST_HEAD(nfslockhashhead, nfslockfile); 47 48 /* 49 * List head for nfsusrgrp. 50 */ 51 LIST_HEAD(nfsuserhashhead, nfsusrgrp); 52 TAILQ_HEAD(nfsuserlruhead, nfsusrgrp); 53 54 #define NFSCLIENTHASH(id) \ 55 (&nfsclienthash[(id).lval[1] % NFSCLIENTHASHSIZE]) 56 #define NFSSTATEHASH(clp, id) \ 57 (&((clp)->lc_stateid[(id).other[2] % NFSSTATEHASHSIZE])) 58 #define NFSUSERHASH(id) \ 59 (&nfsuserhash[(id) % NFSUSERHASHSIZE]) 60 #define NFSUSERNAMEHASH(p, l) \ 61 (&nfsusernamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \ 62 % NFSUSERHASHSIZE]) 63 #define NFSGROUPHASH(id) \ 64 (&nfsgrouphash[(id) % NFSGROUPHASHSIZE]) 65 #define NFSGROUPNAMEHASH(p, l) \ 66 (&nfsgroupnamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \ 67 % NFSGROUPHASHSIZE]) 68 69 /* 70 * Client server structure for V4. It is doubly linked into two lists. 71 * The first is a hash table based on the clientid and the second is a 72 * list of all clients maintained in LRU order. 73 * The actual size malloc'd is large enough to accomodate the id string. 74 */ 75 struct nfsclient { 76 LIST_ENTRY(nfsclient) lc_hash; /* Clientid hash list */ 77 struct nfsstatehead lc_stateid[NFSSTATEHASHSIZE]; /* stateid hash */ 78 struct nfsstatehead lc_open; /* Open owner list */ 79 struct nfsstatehead lc_deleg; /* Delegations */ 80 struct nfsstatehead lc_olddeleg; /* and old delegations */ 81 time_t lc_expiry; /* Expiry time (sec) */ 82 time_t lc_delegtime; /* Old deleg expiry (sec) */ 83 nfsquad_t lc_clientid; /* 64 bit clientid */ 84 nfsquad_t lc_confirm; /* 64 bit confirm value */ 85 u_int32_t lc_program; /* RPC Program # */ 86 u_int32_t lc_callback; /* Callback id */ 87 u_int32_t lc_stateindex; /* Current state index# */ 88 u_int32_t lc_statemaxindex; /* Max state index# */ 89 u_int32_t lc_cbref; /* Cnt of callbacks */ 90 uid_t lc_uid; /* User credential */ 91 gid_t lc_gid; 92 u_int16_t lc_namelen; 93 u_char *lc_name; 94 struct nfssockreq lc_req; /* Callback info */ 95 u_short lc_idlen; /* Length of id string */ 96 u_int32_t lc_flags; /* LCL_ flag bits */ 97 u_char lc_verf[NFSX_VERF]; /* client verifier */ 98 u_char lc_id[1]; /* Malloc'd correct size */ 99 }; 100 101 #define CLOPS_CONFIRM 0x0001 102 #define CLOPS_RENEW 0x0002 103 #define CLOPS_RENEWOP 0x0004 104 105 /* 106 * Nfs state structure. I couldn't resist overloading this one, since 107 * it makes cleanup, etc. simpler. These structures are used in four ways: 108 * - open_owner structures chained off of nfsclient 109 * - open file structures chained off an open_owner structure 110 * - lock_owner structures chained off an open file structure 111 * - delegated file structures chained off of nfsclient and nfslockfile 112 * - the ls_list field is used for the chain it is in 113 * - the ls_head structure is used to chain off the sibling structure 114 * (it is a union between an nfsstate and nfslock structure head) 115 * If it is a lockowner stateid, nfslock structures hang off it. 116 * For the open file and lockowner cases, it is in the hash table in 117 * nfsclient for stateid. 118 */ 119 struct nfsstate { 120 LIST_ENTRY(nfsstate) ls_hash; /* Hash list entry */ 121 LIST_ENTRY(nfsstate) ls_list; /* List of opens/delegs */ 122 LIST_ENTRY(nfsstate) ls_file; /* Opens/Delegs for a file */ 123 union { 124 struct nfsstatehead open; /* Opens list */ 125 struct nfslockhead lock; /* Locks list */ 126 } ls_head; 127 nfsv4stateid_t ls_stateid; /* The state id */ 128 u_int32_t ls_seq; /* seq id */ 129 uid_t ls_uid; /* uid of locker */ 130 u_int32_t ls_flags; /* Type of lock, etc. */ 131 union { 132 struct nfsstate *openowner; /* Open only */ 133 u_int32_t opentolockseq; /* Lock call only */ 134 u_int32_t noopens; /* Openowner only */ 135 struct { 136 u_quad_t filerev; /* Delegations only */ 137 time_t expiry; 138 time_t limit; 139 u_int64_t compref; 140 } deleg; 141 } ls_un; 142 struct nfslockfile *ls_lfp; /* Back pointer */ 143 struct nfsrvcache *ls_op; /* Op cache reference */ 144 struct nfsclient *ls_clp; /* Back pointer */ 145 u_short ls_ownerlen; /* Length of ls_owner */ 146 u_char ls_owner[1]; /* malloc'd the correct size */ 147 }; 148 #define ls_lock ls_head.lock 149 #define ls_open ls_head.open 150 #define ls_opentolockseq ls_un.opentolockseq 151 #define ls_openowner ls_un.openowner 152 #define ls_openstp ls_un.openowner 153 #define ls_noopens ls_un.noopens 154 #define ls_filerev ls_un.deleg.filerev 155 #define ls_delegtime ls_un.deleg.expiry 156 #define ls_delegtimelimit ls_un.deleg.limit 157 #define ls_compref ls_un.deleg.compref 158 159 /* 160 * Nfs lock structure. 161 * This structure is chained off of the nfsstate (the lockowner) and 162 * nfslockfile (the file) structures, for the file and owner it 163 * refers to. It holds flags and a byte range. 164 * It also has back pointers to the associated lock_owner and lockfile. 165 */ 166 struct nfslock { 167 LIST_ENTRY(nfslock) lo_lckowner; 168 LIST_ENTRY(nfslock) lo_lckfile; 169 struct nfsstate *lo_stp; 170 struct nfslockfile *lo_lfp; 171 u_int64_t lo_first; 172 u_int64_t lo_end; 173 u_int32_t lo_flags; 174 }; 175 176 /* 177 * Structure used to return a conflicting lock. (Must be large 178 * enough for the largest lock owner we can have.) 179 */ 180 struct nfslockconflict { 181 nfsquad_t cl_clientid; 182 u_int64_t cl_first; 183 u_int64_t cl_end; 184 u_int32_t cl_flags; 185 u_short cl_ownerlen; 186 u_char cl_owner[NFSV4_OPAQUELIMIT]; 187 }; 188 189 /* 190 * This structure is used to keep track of local locks that might need 191 * to be rolled back. 192 */ 193 struct nfsrollback { 194 LIST_ENTRY(nfsrollback) rlck_list; 195 uint64_t rlck_first; 196 uint64_t rlck_end; 197 int rlck_type; 198 }; 199 200 /* 201 * This structure refers to a file for which lock(s) and/or open(s) exist. 202 * Searched via hash table on file handle or found via the back pointer from an 203 * open or lock owner. 204 */ 205 struct nfslockfile { 206 LIST_HEAD(, nfsstate) lf_open; /* Open list */ 207 LIST_HEAD(, nfsstate) lf_deleg; /* Delegation list */ 208 LIST_HEAD(, nfslock) lf_lock; /* Lock list */ 209 LIST_HEAD(, nfslock) lf_locallock; /* Local lock list */ 210 LIST_HEAD(, nfsrollback) lf_rollback; /* Local lock rollback list */ 211 LIST_ENTRY(nfslockfile) lf_hash; /* Hash list entry */ 212 fhandle_t lf_fh; /* The file handle */ 213 struct nfsv4lock lf_locallock_lck; /* serialize local locking */ 214 int lf_usecount; /* Ref count for locking */ 215 }; 216 217 /* 218 * This structure is malloc'd an chained off hash lists for user/group 219 * names. 220 */ 221 struct nfsusrgrp { 222 TAILQ_ENTRY(nfsusrgrp) lug_lru; /* LRU list */ 223 LIST_ENTRY(nfsusrgrp) lug_numhash; /* Hash by id# */ 224 LIST_ENTRY(nfsusrgrp) lug_namehash; /* and by name */ 225 time_t lug_expiry; /* Expiry time in sec */ 226 union { 227 uid_t un_uid; /* id# */ 228 gid_t un_gid; 229 } lug_un; 230 int lug_namelen; /* Name length */ 231 u_char lug_name[1]; /* malloc'd correct length */ 232 }; 233 #define lug_uid lug_un.un_uid 234 #define lug_gid lug_un.un_gid 235 236 /* 237 * These structures are used for the stable storage restart stuff. 238 */ 239 /* 240 * Record at beginning of file. 241 */ 242 struct nfsf_rec { 243 u_int32_t lease; /* Lease duration */ 244 u_int32_t numboots; /* Number of boottimes */ 245 }; 246 247 #if defined(_KERNEL) || defined(KERNEL) 248 void nfsrv_cleanclient(struct nfsclient *, NFSPROC_T *); 249 void nfsrv_freedeleglist(struct nfsstatehead *); 250 #endif 251 252 #endif /* _NFS_NFSRVSTATE_H_ */ 253