2 * Copyright (c) 2009 Rick Macklem, University of Guelph
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 #ifndef _NFS_NFSCLSTATE_H_
30 #define _NFS_NFSCLSTATE_H_
33 * Definitions for NFS V4 client state handling.
35 LIST_HEAD(nfsclopenhead, nfsclopen);
36 LIST_HEAD(nfscllockownerhead, nfscllockowner);
37 SLIST_HEAD(nfscllockownerfhhead, nfscllockownerfh);
38 LIST_HEAD(nfscllockhead, nfscllock);
39 LIST_HEAD(nfsclhead, nfsclclient);
40 LIST_HEAD(nfsclownerhead, nfsclowner);
41 TAILQ_HEAD(nfscldeleghead, nfscldeleg);
42 LIST_HEAD(nfscldeleghash, nfscldeleg);
43 TAILQ_HEAD(nfscllayouthead, nfscllayout);
44 LIST_HEAD(nfscllayouthash, nfscllayout);
45 LIST_HEAD(nfsclflayouthead, nfsclflayout);
46 LIST_HEAD(nfscldevinfohead, nfscldevinfo);
47 LIST_HEAD(nfsclrecalllayouthead, nfsclrecalllayout);
48 #define NFSCLDELEGHASHSIZE 256
49 #define NFSCLDELEGHASH(c, f, l) \
50 (&((c)->nfsc_deleghash[ncl_hash((f), (l)) % NFSCLDELEGHASHSIZE]))
51 #define NFSCLLAYOUTHASHSIZE 256
52 #define NFSCLLAYOUTHASH(c, f, l) \
53 (&((c)->nfsc_layouthash[ncl_hash((f), (l)) % NFSCLLAYOUTHASHSIZE]))
55 /* Structure for NFSv4.1 session stuff. */
57 struct mtx nfsess_mtx;
58 struct nfsslot nfsess_cbslots[NFSV4_CBSLOTS];
59 nfsquad_t nfsess_clientid;
60 uint32_t nfsess_slotseq[64]; /* Max for 64bit nm_slots */
61 uint64_t nfsess_slots;
62 uint32_t nfsess_sequenceid;
63 uint32_t nfsess_maxcache; /* Max size for cached reply. */
64 uint16_t nfsess_foreslots;
65 uint16_t nfsess_backslots;
66 uint8_t nfsess_sessionid[NFSX_V4SESSIONID];
70 * This structure holds the session, clientid and related information
71 * needed for an NFSv4.1 Meta Data Server (MDS) or Data Server (DS).
72 * It is malloc'd to the correct length.
75 TAILQ_ENTRY(nfsclds) nfsclds_list;
76 struct nfsclsession nfsclds_sess;
77 struct mtx nfsclds_mtx;
78 struct nfssockreq *nfsclds_sockp;
79 time_t nfsclds_expire;
80 uint16_t nfsclds_flags;
81 uint16_t nfsclds_servownlen;
82 uint8_t nfsclds_verf[NFSX_VERF];
83 uint8_t nfsclds_serverown[0];
87 * Flags for nfsclds_flags.
89 #define NFSCLDS_HASWRITEVERF 0x0001
90 #define NFSCLDS_MDS 0x0002
91 #define NFSCLDS_DS 0x0004
94 LIST_ENTRY(nfsclclient) nfsc_list;
95 struct nfsclownerhead nfsc_owner;
96 struct nfscldeleghead nfsc_deleg;
97 struct nfscldeleghash nfsc_deleghash[NFSCLDELEGHASHSIZE];
98 struct nfscllayouthead nfsc_layout;
99 struct nfscllayouthash nfsc_layouthash[NFSCLLAYOUTHASHSIZE];
100 struct nfscldevinfohead nfsc_devinfo;
101 struct nfsv4lock nfsc_lock;
102 struct proc *nfsc_renewthread;
103 struct nfsmount *nfsc_nmp;
105 u_int32_t nfsc_clientidrev;
107 u_int32_t nfsc_renew;
108 u_int32_t nfsc_cbident;
109 u_int16_t nfsc_flags;
110 u_int16_t nfsc_idlen;
111 u_int8_t nfsc_id[1]; /* Malloc'd to correct length */
115 * Bits for nfsc_flags.
117 #define NFSCLFLAGS_INITED 0x0001
118 #define NFSCLFLAGS_HASCLIENTID 0x0002
119 #define NFSCLFLAGS_RECOVER 0x0004
120 #define NFSCLFLAGS_UMOUNT 0x0008
121 #define NFSCLFLAGS_HASTHREAD 0x0010
122 #define NFSCLFLAGS_AFINET6 0x0020
123 #define NFSCLFLAGS_EXPIREIT 0x0040
124 #define NFSCLFLAGS_FIRSTDELEG 0x0080
125 #define NFSCLFLAGS_GOTDELEG 0x0100
126 #define NFSCLFLAGS_RECVRINPROG 0x0200
129 LIST_ENTRY(nfsclowner) nfsow_list;
130 struct nfsclopenhead nfsow_open;
131 struct nfsclclient *nfsow_clp;
132 u_int32_t nfsow_seqid;
133 u_int32_t nfsow_defunct;
134 struct nfsv4lock nfsow_rwlock;
135 u_int8_t nfsow_owner[NFSV4CL_LOCKNAMELEN];
139 * MALLOC'd to the correct length to accommodate the file handle.
142 TAILQ_ENTRY(nfscldeleg) nfsdl_list;
143 LIST_ENTRY(nfscldeleg) nfsdl_hash;
144 struct nfsclownerhead nfsdl_owner; /* locally issued state */
145 struct nfscllockownerhead nfsdl_lock;
146 nfsv4stateid_t nfsdl_stateid;
147 struct acl_entry nfsdl_ace; /* Delegation ace */
148 struct nfsclclient *nfsdl_clp;
149 struct nfsv4lock nfsdl_rwlock; /* for active I/O ops */
150 struct nfscred nfsdl_cred; /* Cred. used for Open */
151 time_t nfsdl_timestamp; /* used for stale cleanup */
152 u_int64_t nfsdl_sizelimit; /* Limit for file growth */
153 u_int64_t nfsdl_size; /* saved copy of file size */
154 u_int64_t nfsdl_change; /* and change attribute */
155 struct timespec nfsdl_modtime; /* local modify time */
156 u_int16_t nfsdl_fhlen;
157 u_int8_t nfsdl_flags;
158 u_int8_t nfsdl_fh[1]; /* must be last */
164 #define NFSCLDL_READ 0x01
165 #define NFSCLDL_WRITE 0x02
166 #define NFSCLDL_RECALL 0x04
167 #define NFSCLDL_NEEDRECLAIM 0x08
168 #define NFSCLDL_ZAPPED 0x10
169 #define NFSCLDL_MODTIMESET 0x20
170 #define NFSCLDL_DELEGRET 0x40
173 * MALLOC'd to the correct length to accommodate the file handle.
176 LIST_ENTRY(nfsclopen) nfso_list;
177 struct nfscllockownerhead nfso_lock;
178 nfsv4stateid_t nfso_stateid;
179 struct nfsclowner *nfso_own;
180 struct nfscred nfso_cred; /* Cred. used for Open */
182 u_int32_t nfso_opencnt;
183 u_int16_t nfso_fhlen;
184 u_int8_t nfso_posixlock; /* 1 for POSIX type locking */
185 u_int8_t nfso_fh[1]; /* must be last */
189 * Return values for nfscl_open(). NFSCLOPEN_OK must == 0.
191 #define NFSCLOPEN_OK 0
192 #define NFSCLOPEN_DOOPEN 1
193 #define NFSCLOPEN_DOOPENDOWNGRADE 2
194 #define NFSCLOPEN_SETCRED 3
196 struct nfscllockowner {
197 LIST_ENTRY(nfscllockowner) nfsl_list;
198 struct nfscllockhead nfsl_lock;
199 struct nfsclopen *nfsl_open;
200 NFSPROC_T *nfsl_inprog;
201 nfsv4stateid_t nfsl_stateid;
203 u_int32_t nfsl_seqid;
204 struct nfsv4lock nfsl_rwlock;
205 u_int8_t nfsl_owner[NFSV4CL_LOCKNAMELEN];
206 u_int8_t nfsl_openowner[NFSV4CL_LOCKNAMELEN];
210 * Byte range entry for the above lock owner.
213 LIST_ENTRY(nfscllock) nfslo_list;
214 u_int64_t nfslo_first;
219 /* This structure is used to collect a list of lockowners to free up. */
220 struct nfscllockownerfh {
221 SLIST_ENTRY(nfscllockownerfh) nfslfh_list;
222 struct nfscllockownerhead nfslfh_lock;
224 uint8_t nfslfh_fh[NFSX_V4FHMAX];
228 * MALLOC'd to the correct length to accommodate the file handle.
231 TAILQ_ENTRY(nfscllayout) nfsly_list;
232 LIST_ENTRY(nfscllayout) nfsly_hash;
233 nfsv4stateid_t nfsly_stateid;
234 struct nfsv4lock nfsly_lock;
235 uint64_t nfsly_filesid[2];
236 uint64_t nfsly_lastbyte;
237 struct nfsclflayouthead nfsly_flayread;
238 struct nfsclflayouthead nfsly_flayrw;
239 struct nfsclrecalllayouthead nfsly_recall;
240 time_t nfsly_timestamp;
241 struct nfsclclient *nfsly_clp;
242 uint16_t nfsly_flags;
243 uint16_t nfsly_fhlen;
248 * Flags for nfsly_flags.
250 #define NFSLY_FILES 0x0001
251 #define NFSLY_BLOCK 0x0002
252 #define NFSLY_OBJECT 0x0004
253 #define NFSLY_RECALL 0x0008
254 #define NFSLY_RECALLFILE 0x0010
255 #define NFSLY_RECALLFSID 0x0020
256 #define NFSLY_RECALLALL 0x0040
257 #define NFSLY_RETONCLOSE 0x0080
258 #define NFSLY_WRITTEN 0x0100 /* Has been used to write to a DS. */
261 * MALLOC'd to the correct length to accommodate the file handle list.
262 * These hang off of nfsly_flayread and nfsly_flayrw, sorted in increasing
264 * The nfsly_flayread list holds the ones with iomode == NFSLAYOUTIOMODE_READ,
265 * whereas the nfsly_flayrw holds the ones with iomode == NFSLAYOUTIOMODE_RW.
267 struct nfsclflayout {
268 LIST_ENTRY(nfsclflayout) nfsfl_list;
269 uint8_t nfsfl_dev[NFSX_V4DEVICEID];
272 uint64_t nfsfl_patoff;
273 struct nfscldevinfo *nfsfl_devp;
274 uint32_t nfsfl_iomode;
276 uint32_t nfsfl_stripe1;
277 uint16_t nfsfl_flags;
278 uint16_t nfsfl_fhcnt;
279 struct nfsfh *nfsfl_fh[1]; /* FH list for DS */
283 * Flags for nfsfl_flags.
285 #define NFSFL_RECALL 0x0001 /* File layout has been recalled */
288 * Structure that is used to store a LAYOUTRECALL.
290 struct nfsclrecalllayout {
291 LIST_ENTRY(nfsclrecalllayout) nfsrecly_list;
292 uint64_t nfsrecly_off;
293 uint64_t nfsrecly_len;
294 int nfsrecly_recalltype;
295 uint32_t nfsrecly_iomode;
296 uint32_t nfsrecly_stateseqid;
300 * Stores the NFSv4.1 Device Info. Malloc'd to the correct length to
301 * store the list of network connections and list of indices.
302 * nfsdi_data[] is allocated the following way:
303 * - nfsdi_addrcnt * struct nfsclds
304 * - stripe indices, each stored as one byte, since there can be many
305 * of them. (This implies a limit of 256 on nfsdi_addrcnt, since the
306 * indices select which address.)
308 struct nfscldevinfo {
309 LIST_ENTRY(nfscldevinfo) nfsdi_list;
310 uint8_t nfsdi_deviceid[NFSX_V4DEVICEID];
311 struct nfsclclient *nfsdi_clp;
312 uint32_t nfsdi_refcnt;
313 uint32_t nfsdi_layoutrefs;
314 uint16_t nfsdi_stripecnt;
315 uint16_t nfsdi_addrcnt;
316 struct nfsclds *nfsdi_data[0];
319 /* These inline functions return values from nfsdi_data[]. */
321 * Return a pointer to the address at "pos".
323 static __inline struct nfsclds **
324 nfsfldi_addr(struct nfscldevinfo *ndi, int pos)
327 if (pos >= ndi->nfsdi_addrcnt)
329 return (&ndi->nfsdi_data[pos]);
333 * Return the Nth ("pos") stripe index.
336 nfsfldi_stripeindex(struct nfscldevinfo *ndi, int pos)
340 if (pos >= ndi->nfsdi_stripecnt)
342 valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
348 * Set the Nth ("pos") stripe index to "val".
351 nfsfldi_setstripeindex(struct nfscldevinfo *ndi, int pos, uint8_t val)
355 if (pos >= ndi->nfsdi_stripecnt)
357 valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
363 * Macro for incrementing the seqid#.
365 #define NFSCL_INCRSEQID(s, n) do { \
366 if (((n)->nd_flag & ND_INCRSEQID)) \
370 #endif /* _NFS_NFSCLSTATE_H_ */