nfsclstate.h revision 227743
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 227743 2011-11-20 00:39:15Z 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); 37LIST_HEAD(nfscllockhead, nfscllock); 38LIST_HEAD(nfsclhead, nfsclclient); 39LIST_HEAD(nfsclownerhead, nfsclowner); 40TAILQ_HEAD(nfscldeleghead, nfscldeleg); 41LIST_HEAD(nfscldeleghash, nfscldeleg); 42#define NFSCLDELEGHASHSIZE 256 43#define NFSCLDELEGHASH(c, f, l) \ 44 (&((c)->nfsc_deleghash[ncl_hash((f), (l)) % NFSCLDELEGHASHSIZE])) 45 46struct 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 nfsv4lock nfsc_lock; 52 struct proc *nfsc_renewthread; 53 struct nfsmount *nfsc_nmp; 54 nfsquad_t nfsc_clientid; 55 time_t nfsc_expire; 56 u_int32_t nfsc_clientidrev; 57 u_int32_t nfsc_renew; 58 u_int32_t nfsc_cbident; 59 u_int16_t nfsc_flags; 60 u_int16_t nfsc_idlen; 61 u_int8_t nfsc_id[1]; /* Malloc'd to correct length */ 62}; 63 64/* 65 * Bits for nfsc_flags. 66 */ 67#define NFSCLFLAGS_INITED 0x0001 68#define NFSCLFLAGS_HASCLIENTID 0x0002 69#define NFSCLFLAGS_RECOVER 0x0004 70#define NFSCLFLAGS_UMOUNT 0x0008 71#define NFSCLFLAGS_HASTHREAD 0x0010 72#define NFSCLFLAGS_AFINET6 0x0020 73#define NFSCLFLAGS_EXPIREIT 0x0040 74#define NFSCLFLAGS_FIRSTDELEG 0x0080 75#define NFSCLFLAGS_GOTDELEG 0x0100 76#define NFSCLFLAGS_RECVRINPROG 0x0200 77 78struct 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 */ 91struct 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#define NFSCLDL_DELEGRET 0x40 121 122/* 123 * MALLOC'd to the correct length to accommodate the file handle. 124 */ 125struct nfsclopen { 126 LIST_ENTRY(nfsclopen) nfso_list; 127 struct nfscllockownerhead nfso_lock; 128 nfsv4stateid_t nfso_stateid; 129 struct nfsclowner *nfso_own; 130 struct nfscred nfso_cred; /* Cred. used for Open */ 131 u_int32_t nfso_mode; 132 u_int32_t nfso_opencnt; 133 u_int16_t nfso_fhlen; 134 u_int8_t nfso_posixlock; /* 1 for POSIX type locking */ 135 u_int8_t nfso_fh[1]; /* must be last */ 136}; 137 138/* 139 * Return values for nfscl_open(). NFSCLOPEN_OK must == 0. 140 */ 141#define NFSCLOPEN_OK 0 142#define NFSCLOPEN_DOOPEN 1 143#define NFSCLOPEN_DOOPENDOWNGRADE 2 144#define NFSCLOPEN_SETCRED 3 145 146struct nfscllockowner { 147 LIST_ENTRY(nfscllockowner) nfsl_list; 148 struct nfscllockhead nfsl_lock; 149 struct nfsclopen *nfsl_open; 150 NFSPROC_T *nfsl_inprog; 151 nfsv4stateid_t nfsl_stateid; 152 u_int32_t nfsl_seqid; 153 u_int32_t nfsl_defunct; 154 struct nfsv4lock nfsl_rwlock; 155 u_int8_t nfsl_owner[NFSV4CL_LOCKNAMELEN]; 156 u_int8_t nfsl_openowner[NFSV4CL_LOCKNAMELEN]; 157}; 158 159/* 160 * Byte range entry for the above lock owner. 161 */ 162struct nfscllock { 163 LIST_ENTRY(nfscllock) nfslo_list; 164 u_int64_t nfslo_first; 165 u_int64_t nfslo_end; 166 short nfslo_type; 167}; 168 169/* 170 * Macro for incrementing the seqid#. 171 */ 172#define NFSCL_INCRSEQID(s, n) do { \ 173 if (((n)->nd_flag & ND_INCRSEQID)) \ 174 (s)++; \ 175 } while (0) 176 177#endif /* _NFS_NFSCLSTATE_H_ */ 178