nfsrvstate.h revision 191783
1191783Srmacklem/*- 2191783Srmacklem * Copyright (c) 2009 Rick Macklem, University of Guelph 3191783Srmacklem * All rights reserved. 4191783Srmacklem * 5191783Srmacklem * Redistribution and use in source and binary forms, with or without 6191783Srmacklem * modification, are permitted provided that the following conditions 7191783Srmacklem * are met: 8191783Srmacklem * 1. Redistributions of source code must retain the above copyright 9191783Srmacklem * notice, this list of conditions and the following disclaimer. 10191783Srmacklem * 2. Redistributions in binary form must reproduce the above copyright 11191783Srmacklem * notice, this list of conditions and the following disclaimer in the 12191783Srmacklem * documentation and/or other materials provided with the distribution. 13191783Srmacklem * 14191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15191783Srmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16191783Srmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17191783Srmacklem * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18191783Srmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19191783Srmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20191783Srmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21191783Srmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22191783Srmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23191783Srmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24191783Srmacklem * SUCH DAMAGE. 25191783Srmacklem * 26191783Srmacklem * $FreeBSD: head/sys/fs/nfs/nfsrvstate.h 191783 2009-05-04 15:23:58Z rmacklem $ 27191783Srmacklem */ 28191783Srmacklem 29191783Srmacklem#ifndef _NFS_NFSRVSTATE_H_ 30191783Srmacklem#define _NFS_NFSRVSTATE_H_ 31191783Srmacklem 32191783Srmacklem/* 33191783Srmacklem * Definitions for NFS V4 server state handling. 34191783Srmacklem */ 35191783Srmacklem 36191783Srmacklem/* 37191783Srmacklem * List heads for nfsclient, nfsstate and nfslockfile. 38191783Srmacklem * (Some systems seem to like to dynamically size these things, but I 39191783Srmacklem * don't see any point in doing so for these ones.) 40191783Srmacklem */ 41191783SrmacklemLIST_HEAD(nfsclienthashhead, nfsclient); 42191783SrmacklemLIST_HEAD(nfsstatehead, nfsstate); 43191783SrmacklemLIST_HEAD(nfslockhead, nfslock); 44191783SrmacklemLIST_HEAD(nfslockhashhead, nfslockfile); 45191783Srmacklem 46191783Srmacklem/* 47191783Srmacklem * List head for nfsusrgrp. 48191783Srmacklem */ 49191783SrmacklemLIST_HEAD(nfsuserhashhead, nfsusrgrp); 50191783SrmacklemTAILQ_HEAD(nfsuserlruhead, nfsusrgrp); 51191783Srmacklem 52191783Srmacklem#define NFSCLIENTHASH(id) \ 53191783Srmacklem (&nfsclienthash[(id).lval[1] % NFSCLIENTHASHSIZE]) 54191783Srmacklem#define NFSSTATEHASH(clp, id) \ 55191783Srmacklem (&((clp)->lc_stateid[(id).other[2] % NFSSTATEHASHSIZE])) 56191783Srmacklem#define NFSUSERHASH(id) \ 57191783Srmacklem (&nfsuserhash[(id) % NFSUSERHASHSIZE]) 58191783Srmacklem#define NFSUSERNAMEHASH(p, l) \ 59191783Srmacklem (&nfsusernamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \ 60191783Srmacklem % NFSUSERHASHSIZE]) 61191783Srmacklem#define NFSGROUPHASH(id) \ 62191783Srmacklem (&nfsgrouphash[(id) % NFSGROUPHASHSIZE]) 63191783Srmacklem#define NFSGROUPNAMEHASH(p, l) \ 64191783Srmacklem (&nfsgroupnamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \ 65191783Srmacklem % NFSGROUPHASHSIZE]) 66191783Srmacklem 67191783Srmacklem/* 68191783Srmacklem * Client server structure for V4. It is doubly linked into two lists. 69191783Srmacklem * The first is a hash table based on the clientid and the second is a 70191783Srmacklem * list of all clients maintained in LRU order. 71191783Srmacklem * The actual size malloc'd is large enough to accomodate the id string. 72191783Srmacklem */ 73191783Srmacklemstruct nfsclient { 74191783Srmacklem LIST_ENTRY(nfsclient) lc_hash; /* Clientid hash list */ 75191783Srmacklem struct nfsstatehead lc_stateid[NFSSTATEHASHSIZE]; /* stateid hash */ 76191783Srmacklem struct nfsstatehead lc_open; /* Open owner list */ 77191783Srmacklem struct nfsstatehead lc_deleg; /* Delegations */ 78191783Srmacklem struct nfsstatehead lc_olddeleg; /* and old delegations */ 79191783Srmacklem time_t lc_expiry; /* Expiry time (sec) */ 80191783Srmacklem time_t lc_delegtime; /* Old deleg expiry (sec) */ 81191783Srmacklem nfsquad_t lc_clientid; /* 64 bit clientid */ 82191783Srmacklem nfsquad_t lc_confirm; /* 64 bit confirm value */ 83191783Srmacklem u_int32_t lc_program; /* RPC Program # */ 84191783Srmacklem u_int32_t lc_callback; /* Callback id */ 85191783Srmacklem u_int32_t lc_stateindex; /* Current state index# */ 86191783Srmacklem u_int32_t lc_statemaxindex; /* Max state index# */ 87191783Srmacklem u_int32_t lc_cbref; /* Cnt of callbacks */ 88191783Srmacklem uid_t lc_uid; /* User credential */ 89191783Srmacklem gid_t lc_gid; 90191783Srmacklem u_int16_t lc_namelen; 91191783Srmacklem u_char *lc_name; 92191783Srmacklem struct nfssockreq lc_req; /* Callback info */ 93191783Srmacklem u_short lc_idlen; /* Length of id string */ 94191783Srmacklem u_int32_t lc_flags; /* LCL_ flag bits */ 95191783Srmacklem u_char lc_verf[NFSX_VERF]; /* client verifier */ 96191783Srmacklem u_char lc_id[1]; /* Malloc'd correct size */ 97191783Srmacklem}; 98191783Srmacklem 99191783Srmacklem#define CLOPS_CONFIRM 0x0001 100191783Srmacklem#define CLOPS_RENEW 0x0002 101191783Srmacklem#define CLOPS_RENEWOP 0x0004 102191783Srmacklem 103191783Srmacklem/* 104191783Srmacklem * Nfs state structure. I couldn't resist overloading this one, since 105191783Srmacklem * it makes cleanup, etc. simpler. These structures are used in four ways: 106191783Srmacklem * - open_owner structures chained off of nfsclient 107191783Srmacklem * - open file structures chained off an open_owner structure 108191783Srmacklem * - lock_owner structures chained off an open file structure 109191783Srmacklem * - delegated file structures chained off of nfsclient and nfslockfile 110191783Srmacklem * - the ls_list field is used for the chain it is in 111191783Srmacklem * - the ls_head structure is used to chain off the sibling structure 112191783Srmacklem * (it is a union between an nfsstate and nfslock structure head) 113191783Srmacklem * If it is a lockowner stateid, nfslock structures hang off it. 114191783Srmacklem * For the open file and lockowner cases, it is in the hash table in 115191783Srmacklem * nfsclient for stateid. 116191783Srmacklem */ 117191783Srmacklemstruct nfsstate { 118191783Srmacklem LIST_ENTRY(nfsstate) ls_hash; /* Hash list entry */ 119191783Srmacklem LIST_ENTRY(nfsstate) ls_list; /* List of opens/delegs */ 120191783Srmacklem LIST_ENTRY(nfsstate) ls_file; /* Opens/Delegs for a file */ 121191783Srmacklem union { 122191783Srmacklem struct nfsstatehead open; /* Opens list */ 123191783Srmacklem struct nfslockhead lock; /* Locks list */ 124191783Srmacklem } ls_head; 125191783Srmacklem nfsv4stateid_t ls_stateid; /* The state id */ 126191783Srmacklem u_int32_t ls_seq; /* seq id */ 127191783Srmacklem uid_t ls_uid; /* uid of locker */ 128191783Srmacklem u_int32_t ls_flags; /* Type of lock, etc. */ 129191783Srmacklem union { 130191783Srmacklem struct nfsstate *openowner; /* Open only */ 131191783Srmacklem u_int32_t opentolockseq; /* Lock call only */ 132191783Srmacklem u_int32_t noopens; /* Openowner only */ 133191783Srmacklem struct { 134191783Srmacklem u_quad_t filerev; /* Delegations only */ 135191783Srmacklem time_t expiry; 136191783Srmacklem time_t limit; 137191783Srmacklem u_int64_t compref; 138191783Srmacklem } deleg; 139191783Srmacklem } ls_un; 140191783Srmacklem struct nfslockfile *ls_lfp; /* Back pointer */ 141191783Srmacklem struct nfsrvcache *ls_op; /* Op cache reference */ 142191783Srmacklem struct nfsclient *ls_clp; /* Back pointer */ 143191783Srmacklem u_short ls_ownerlen; /* Length of ls_owner */ 144191783Srmacklem u_char ls_owner[1]; /* malloc'd the correct size */ 145191783Srmacklem}; 146191783Srmacklem#define ls_lock ls_head.lock 147191783Srmacklem#define ls_open ls_head.open 148191783Srmacklem#define ls_opentolockseq ls_un.opentolockseq 149191783Srmacklem#define ls_openowner ls_un.openowner 150191783Srmacklem#define ls_openstp ls_un.openowner 151191783Srmacklem#define ls_noopens ls_un.noopens 152191783Srmacklem#define ls_filerev ls_un.deleg.filerev 153191783Srmacklem#define ls_delegtime ls_un.deleg.expiry 154191783Srmacklem#define ls_delegtimelimit ls_un.deleg.limit 155191783Srmacklem#define ls_compref ls_un.deleg.compref 156191783Srmacklem 157191783Srmacklem/* 158191783Srmacklem * Nfs lock structure. 159191783Srmacklem * This structure is chained off of the nfsstate (the lockowner) and 160191783Srmacklem * nfslockfile (the file) structures, for the file and owner it 161191783Srmacklem * refers to. It holds flags and a byte range. 162191783Srmacklem * It also has back pointers to the associated lock_owner and lockfile. 163191783Srmacklem */ 164191783Srmacklemstruct nfslock { 165191783Srmacklem LIST_ENTRY(nfslock) lo_lckowner; 166191783Srmacklem LIST_ENTRY(nfslock) lo_lckfile; 167191783Srmacklem struct nfsstate *lo_stp; 168191783Srmacklem struct nfslockfile *lo_lfp; 169191783Srmacklem u_int64_t lo_first; 170191783Srmacklem u_int64_t lo_end; 171191783Srmacklem u_int32_t lo_flags; 172191783Srmacklem}; 173191783Srmacklem 174191783Srmacklem/* 175191783Srmacklem * Structure used to return a conflicting lock. (Must be large 176191783Srmacklem * enough for the largest lock owner we can have.) 177191783Srmacklem */ 178191783Srmacklemstruct nfslockconflict { 179191783Srmacklem nfsquad_t cl_clientid; 180191783Srmacklem u_int64_t cl_first; 181191783Srmacklem u_int64_t cl_end; 182191783Srmacklem u_int32_t cl_flags; 183191783Srmacklem u_short cl_ownerlen; 184191783Srmacklem u_char cl_owner[NFSV4_OPAQUELIMIT]; 185191783Srmacklem}; 186191783Srmacklem 187191783Srmacklem/* 188191783Srmacklem * This structure refers to a file for which lock(s) and/or open(s) exist. 189191783Srmacklem * Searched via hash table on file handle or found via the back pointer from an 190191783Srmacklem * open or lock owner. 191191783Srmacklem */ 192191783Srmacklemstruct nfslockfile { 193191783Srmacklem LIST_HEAD(, nfsstate) lf_open; /* Open list */ 194191783Srmacklem LIST_HEAD(, nfsstate) lf_deleg; /* Delegation list */ 195191783Srmacklem LIST_HEAD(, nfslock) lf_lock; /* Lock list */ 196191783Srmacklem LIST_ENTRY(nfslockfile) lf_hash; /* Hash list entry */ 197191783Srmacklem fhandle_t lf_fh; /* The file handle */ 198191783Srmacklem}; 199191783Srmacklem 200191783Srmacklem/* 201191783Srmacklem * This structure is malloc'd an chained off hash lists for user/group 202191783Srmacklem * names. 203191783Srmacklem */ 204191783Srmacklemstruct nfsusrgrp { 205191783Srmacklem TAILQ_ENTRY(nfsusrgrp) lug_lru; /* LRU list */ 206191783Srmacklem LIST_ENTRY(nfsusrgrp) lug_numhash; /* Hash by id# */ 207191783Srmacklem LIST_ENTRY(nfsusrgrp) lug_namehash; /* and by name */ 208191783Srmacklem time_t lug_expiry; /* Expiry time in sec */ 209191783Srmacklem union { 210191783Srmacklem uid_t un_uid; /* id# */ 211191783Srmacklem gid_t un_gid; 212191783Srmacklem } lug_un; 213191783Srmacklem int lug_namelen; /* Name length */ 214191783Srmacklem u_char lug_name[1]; /* malloc'd correct length */ 215191783Srmacklem}; 216191783Srmacklem#define lug_uid lug_un.un_uid 217191783Srmacklem#define lug_gid lug_un.un_gid 218191783Srmacklem 219191783Srmacklem/* 220191783Srmacklem * These structures are used for the stable storage restart stuff. 221191783Srmacklem */ 222191783Srmacklem/* 223191783Srmacklem * Record at beginning of file. 224191783Srmacklem */ 225191783Srmacklemstruct nfsf_rec { 226191783Srmacklem u_int32_t lease; /* Lease duration */ 227191783Srmacklem u_int32_t numboots; /* Number of boottimes */ 228191783Srmacklem}; 229191783Srmacklem 230191783Srmacklem#if defined(_KERNEL) || defined(KERNEL) 231191783Srmacklemvoid nfsrv_cleanclient(struct nfsclient *, NFSPROC_T *); 232191783Srmacklemvoid nfsrv_freedeleglist(struct nfsstatehead *); 233191783Srmacklem#endif 234191783Srmacklem 235191783Srmacklem#endif /* _NFS_NFSRVSTATE_H_ */ 236