nfsclstate.h revision 228217
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: head/sys/fs/nfs/nfsclstate.h 228217 2011-12-03 02:27:26Z rmacklem $ 27 */ 28 29#ifndef _NFS_NFSCLSTATE_H_ 30#define _NFS_NFSCLSTATE_H_ 31 32/* 33 * Definitions for NFS V4 client state handling. 34 */ 35LIST_HEAD(nfsclopenhead, nfsclopen); 36LIST_HEAD(nfscllockownerhead, nfscllockowner); 37SLIST_HEAD(nfscllockownerfhhead, nfscllockownerfh); 38LIST_HEAD(nfscllockhead, nfscllock); 39LIST_HEAD(nfsclhead, nfsclclient); 40LIST_HEAD(nfsclownerhead, nfsclowner); 41TAILQ_HEAD(nfscldeleghead, nfscldeleg); 42LIST_HEAD(nfscldeleghash, nfscldeleg); 43#define NFSCLDELEGHASHSIZE 256 44#define NFSCLDELEGHASH(c, f, l) \ 45 (&((c)->nfsc_deleghash[ncl_hash((f), (l)) % NFSCLDELEGHASHSIZE])) 46 47struct nfsclclient { 48 LIST_ENTRY(nfsclclient) nfsc_list; 49 struct nfsclownerhead nfsc_owner; 50 struct nfscldeleghead nfsc_deleg; 51 struct nfscldeleghash nfsc_deleghash[NFSCLDELEGHASHSIZE]; 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#define NFSCLFLAGS_RECVRINPROG 0x0200 78 79struct nfsclowner { 80 LIST_ENTRY(nfsclowner) nfsow_list; 81 struct nfsclopenhead nfsow_open; 82 struct nfsclclient *nfsow_clp; 83 u_int32_t nfsow_seqid; 84 u_int32_t nfsow_defunct; 85 struct nfsv4lock nfsow_rwlock; 86 u_int8_t nfsow_owner[NFSV4CL_LOCKNAMELEN]; 87}; 88 89/* 90 * MALLOC'd to the correct length to accommodate the file handle. 91 */ 92struct nfscldeleg { 93 TAILQ_ENTRY(nfscldeleg) nfsdl_list; 94 LIST_ENTRY(nfscldeleg) nfsdl_hash; 95 struct nfsclownerhead nfsdl_owner; /* locally issued state */ 96 struct nfscllockownerhead nfsdl_lock; 97 nfsv4stateid_t nfsdl_stateid; 98 struct acl_entry nfsdl_ace; /* Delegation ace */ 99 struct nfsclclient *nfsdl_clp; 100 struct nfsv4lock nfsdl_rwlock; /* for active I/O ops */ 101 struct nfscred nfsdl_cred; /* Cred. used for Open */ 102 time_t nfsdl_timestamp; /* used for stale cleanup */ 103 u_int64_t nfsdl_sizelimit; /* Limit for file growth */ 104 u_int64_t nfsdl_size; /* saved copy of file size */ 105 u_int64_t nfsdl_change; /* and change attribute */ 106 struct timespec nfsdl_modtime; /* local modify time */ 107 u_int16_t nfsdl_fhlen; 108 u_int8_t nfsdl_flags; 109 u_int8_t nfsdl_fh[1]; /* must be last */ 110}; 111 112/* 113 * nfsdl_flags bits. 114 */ 115#define NFSCLDL_READ 0x01 116#define NFSCLDL_WRITE 0x02 117#define NFSCLDL_RECALL 0x04 118#define NFSCLDL_NEEDRECLAIM 0x08 119#define NFSCLDL_ZAPPED 0x10 120#define NFSCLDL_MODTIMESET 0x20 121#define NFSCLDL_DELEGRET 0x40 122 123/* 124 * MALLOC'd to the correct length to accommodate the file handle. 125 */ 126struct nfsclopen { 127 LIST_ENTRY(nfsclopen) nfso_list; 128 struct nfscllockownerhead nfso_lock; 129 nfsv4stateid_t nfso_stateid; 130 struct nfsclowner *nfso_own; 131 struct nfscred nfso_cred; /* Cred. used for Open */ 132 u_int32_t nfso_mode; 133 u_int32_t nfso_opencnt; 134 u_int16_t nfso_fhlen; 135 u_int8_t nfso_posixlock; /* 1 for POSIX type locking */ 136 u_int8_t nfso_fh[1]; /* must be last */ 137}; 138 139/* 140 * Return values for nfscl_open(). NFSCLOPEN_OK must == 0. 141 */ 142#define NFSCLOPEN_OK 0 143#define NFSCLOPEN_DOOPEN 1 144#define NFSCLOPEN_DOOPENDOWNGRADE 2 145#define NFSCLOPEN_SETCRED 3 146 147struct nfscllockowner { 148 LIST_ENTRY(nfscllockowner) nfsl_list; 149 struct nfscllockhead nfsl_lock; 150 struct nfsclopen *nfsl_open; 151 NFSPROC_T *nfsl_inprog; 152 nfsv4stateid_t nfsl_stateid; 153 int nfsl_lockflags; 154 u_int32_t nfsl_seqid; 155 struct nfsv4lock nfsl_rwlock; 156 u_int8_t nfsl_owner[NFSV4CL_LOCKNAMELEN]; 157 u_int8_t nfsl_openowner[NFSV4CL_LOCKNAMELEN]; 158}; 159 160/* 161 * Byte range entry for the above lock owner. 162 */ 163struct nfscllock { 164 LIST_ENTRY(nfscllock) nfslo_list; 165 u_int64_t nfslo_first; 166 u_int64_t nfslo_end; 167 short nfslo_type; 168}; 169 170/* This structure is used to collect a list of lockowners to free up. */ 171struct nfscllockownerfh { 172 SLIST_ENTRY(nfscllockownerfh) nfslfh_list; 173 struct nfscllockownerhead nfslfh_lock; 174 int nfslfh_len; 175 uint8_t nfslfh_fh[NFSX_V4FHMAX]; 176}; 177 178/* 179 * Macro for incrementing the seqid#. 180 */ 181#define NFSCL_INCRSEQID(s, n) do { \ 182 if (((n)->nd_flag & ND_INCRSEQID)) \ 183 (s)++; \ 184 } while (0) 185 186#endif /* _NFS_NFSCLSTATE_H_ */ 187