xref: /freebsd/sys/fs/nfs/nfsclstate.h (revision 3157ba21)
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 #define	NFSCLFLAGS_RECVRINPROG	0x0200
78 
79 struct 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  */
92 struct 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 
122 /*
123  * MALLOC'd to the correct length to accommodate the file handle.
124  */
125 struct 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 
146 struct 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  */
162 struct 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