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 SVCXPRT *nfsess_xprt; /* For backchannel callback */
61 uint32_t nfsess_slotseq[64]; /* Max for 64bit nm_slots */
62 uint64_t nfsess_slots;
63 uint32_t nfsess_sequenceid;
64 uint32_t nfsess_maxcache; /* Max size for cached reply. */
65 uint16_t nfsess_foreslots;
66 uint16_t nfsess_backslots;
67 uint8_t nfsess_sessionid[NFSX_V4SESSIONID];
71 * This structure holds the session, clientid and related information
72 * needed for an NFSv4.1 Meta Data Server (MDS) or Data Server (DS).
73 * It is malloc'd to the correct length.
76 TAILQ_ENTRY(nfsclds) nfsclds_list;
77 struct nfsclsession nfsclds_sess;
78 struct mtx nfsclds_mtx;
79 struct nfssockreq *nfsclds_sockp;
80 time_t nfsclds_expire;
81 uint16_t nfsclds_flags;
82 uint16_t nfsclds_servownlen;
83 uint8_t nfsclds_verf[NFSX_VERF];
84 uint8_t nfsclds_serverown[0];
88 * Flags for nfsclds_flags.
90 #define NFSCLDS_HASWRITEVERF 0x0001
91 #define NFSCLDS_MDS 0x0002
92 #define NFSCLDS_DS 0x0004
95 LIST_ENTRY(nfsclclient) nfsc_list;
96 struct nfsclownerhead nfsc_owner;
97 struct nfscldeleghead nfsc_deleg;
98 struct nfscldeleghash nfsc_deleghash[NFSCLDELEGHASHSIZE];
99 struct nfscllayouthead nfsc_layout;
100 struct nfscllayouthash nfsc_layouthash[NFSCLLAYOUTHASHSIZE];
101 struct nfscldevinfohead nfsc_devinfo;
102 struct nfsv4lock nfsc_lock;
103 struct proc *nfsc_renewthread;
104 struct nfsmount *nfsc_nmp;
106 u_int32_t nfsc_clientidrev;
108 u_int32_t nfsc_renew;
109 u_int32_t nfsc_cbident;
110 u_int16_t nfsc_flags;
111 u_int16_t nfsc_idlen;
112 u_int8_t nfsc_id[1]; /* Malloc'd to correct length */
116 * Bits for nfsc_flags.
118 #define NFSCLFLAGS_INITED 0x0001
119 #define NFSCLFLAGS_HASCLIENTID 0x0002
120 #define NFSCLFLAGS_RECOVER 0x0004
121 #define NFSCLFLAGS_UMOUNT 0x0008
122 #define NFSCLFLAGS_HASTHREAD 0x0010
123 #define NFSCLFLAGS_AFINET6 0x0020
124 #define NFSCLFLAGS_EXPIREIT 0x0040
125 #define NFSCLFLAGS_FIRSTDELEG 0x0080
126 #define NFSCLFLAGS_GOTDELEG 0x0100
127 #define NFSCLFLAGS_RECVRINPROG 0x0200
130 LIST_ENTRY(nfsclowner) nfsow_list;
131 struct nfsclopenhead nfsow_open;
132 struct nfsclclient *nfsow_clp;
133 u_int32_t nfsow_seqid;
134 u_int32_t nfsow_defunct;
135 struct nfsv4lock nfsow_rwlock;
136 u_int8_t nfsow_owner[NFSV4CL_LOCKNAMELEN];
140 * MALLOC'd to the correct length to accommodate the file handle.
143 TAILQ_ENTRY(nfscldeleg) nfsdl_list;
144 LIST_ENTRY(nfscldeleg) nfsdl_hash;
145 struct nfsclownerhead nfsdl_owner; /* locally issued state */
146 struct nfscllockownerhead nfsdl_lock;
147 nfsv4stateid_t nfsdl_stateid;
148 struct acl_entry nfsdl_ace; /* Delegation ace */
149 struct nfsclclient *nfsdl_clp;
150 struct nfsv4lock nfsdl_rwlock; /* for active I/O ops */
151 struct nfscred nfsdl_cred; /* Cred. used for Open */
152 time_t nfsdl_timestamp; /* used for stale cleanup */
153 u_int64_t nfsdl_sizelimit; /* Limit for file growth */
154 u_int64_t nfsdl_size; /* saved copy of file size */
155 u_int64_t nfsdl_change; /* and change attribute */
156 struct timespec nfsdl_modtime; /* local modify time */
157 u_int16_t nfsdl_fhlen;
158 u_int8_t nfsdl_flags;
159 u_int8_t nfsdl_fh[1]; /* must be last */
165 #define NFSCLDL_READ 0x01
166 #define NFSCLDL_WRITE 0x02
167 #define NFSCLDL_RECALL 0x04
168 #define NFSCLDL_NEEDRECLAIM 0x08
169 #define NFSCLDL_ZAPPED 0x10
170 #define NFSCLDL_MODTIMESET 0x20
171 #define NFSCLDL_DELEGRET 0x40
174 * MALLOC'd to the correct length to accommodate the file handle.
177 LIST_ENTRY(nfsclopen) nfso_list;
178 struct nfscllockownerhead nfso_lock;
179 nfsv4stateid_t nfso_stateid;
180 struct nfsclowner *nfso_own;
181 struct nfscred nfso_cred; /* Cred. used for Open */
183 u_int32_t nfso_opencnt;
184 u_int16_t nfso_fhlen;
185 u_int8_t nfso_posixlock; /* 1 for POSIX type locking */
186 u_int8_t nfso_fh[1]; /* must be last */
190 * Return values for nfscl_open(). NFSCLOPEN_OK must == 0.
192 #define NFSCLOPEN_OK 0
193 #define NFSCLOPEN_DOOPEN 1
194 #define NFSCLOPEN_DOOPENDOWNGRADE 2
195 #define NFSCLOPEN_SETCRED 3
197 struct nfscllockowner {
198 LIST_ENTRY(nfscllockowner) nfsl_list;
199 struct nfscllockhead nfsl_lock;
200 struct nfsclopen *nfsl_open;
201 NFSPROC_T *nfsl_inprog;
202 nfsv4stateid_t nfsl_stateid;
204 u_int32_t nfsl_seqid;
205 struct nfsv4lock nfsl_rwlock;
206 u_int8_t nfsl_owner[NFSV4CL_LOCKNAMELEN];
207 u_int8_t nfsl_openowner[NFSV4CL_LOCKNAMELEN];
211 * Byte range entry for the above lock owner.
214 LIST_ENTRY(nfscllock) nfslo_list;
215 u_int64_t nfslo_first;
220 /* This structure is used to collect a list of lockowners to free up. */
221 struct nfscllockownerfh {
222 SLIST_ENTRY(nfscllockownerfh) nfslfh_list;
223 struct nfscllockownerhead nfslfh_lock;
225 uint8_t nfslfh_fh[NFSX_V4FHMAX];
229 * MALLOC'd to the correct length to accommodate the file handle.
232 TAILQ_ENTRY(nfscllayout) nfsly_list;
233 LIST_ENTRY(nfscllayout) nfsly_hash;
234 nfsv4stateid_t nfsly_stateid;
235 struct nfsv4lock nfsly_lock;
236 uint64_t nfsly_filesid[2];
237 uint64_t nfsly_lastbyte;
238 struct nfsclflayouthead nfsly_flayread;
239 struct nfsclflayouthead nfsly_flayrw;
240 struct nfsclrecalllayouthead nfsly_recall;
241 time_t nfsly_timestamp;
242 struct nfsclclient *nfsly_clp;
243 uint16_t nfsly_flags;
244 uint16_t nfsly_fhlen;
249 * Flags for nfsly_flags.
251 #define NFSLY_FILES 0x0001
252 #define NFSLY_BLOCK 0x0002
253 #define NFSLY_OBJECT 0x0004
254 #define NFSLY_RECALL 0x0008
255 #define NFSLY_RECALLFILE 0x0010
256 #define NFSLY_RECALLFSID 0x0020
257 #define NFSLY_RECALLALL 0x0040
258 #define NFSLY_RETONCLOSE 0x0080
259 #define NFSLY_WRITTEN 0x0100 /* Has been used to write to a DS. */
262 * MALLOC'd to the correct length to accommodate the file handle list.
263 * These hang off of nfsly_flayread and nfsly_flayrw, sorted in increasing
265 * The nfsly_flayread list holds the ones with iomode == NFSLAYOUTIOMODE_READ,
266 * whereas the nfsly_flayrw holds the ones with iomode == NFSLAYOUTIOMODE_RW.
268 struct nfsclflayout {
269 LIST_ENTRY(nfsclflayout) nfsfl_list;
270 uint8_t nfsfl_dev[NFSX_V4DEVICEID];
273 uint64_t nfsfl_patoff;
274 struct nfscldevinfo *nfsfl_devp;
275 uint32_t nfsfl_iomode;
277 uint32_t nfsfl_stripe1;
278 uint16_t nfsfl_flags;
279 uint16_t nfsfl_fhcnt;
280 struct nfsfh *nfsfl_fh[1]; /* FH list for DS */
284 * Flags for nfsfl_flags.
286 #define NFSFL_RECALL 0x0001 /* File layout has been recalled */
289 * Structure that is used to store a LAYOUTRECALL.
291 struct nfsclrecalllayout {
292 LIST_ENTRY(nfsclrecalllayout) nfsrecly_list;
293 uint64_t nfsrecly_off;
294 uint64_t nfsrecly_len;
295 int nfsrecly_recalltype;
296 uint32_t nfsrecly_iomode;
297 uint32_t nfsrecly_stateseqid;
301 * Stores the NFSv4.1 Device Info. Malloc'd to the correct length to
302 * store the list of network connections and list of indices.
303 * nfsdi_data[] is allocated the following way:
304 * - nfsdi_addrcnt * struct nfsclds
305 * - stripe indices, each stored as one byte, since there can be many
306 * of them. (This implies a limit of 256 on nfsdi_addrcnt, since the
307 * indices select which address.)
309 struct nfscldevinfo {
310 LIST_ENTRY(nfscldevinfo) nfsdi_list;
311 uint8_t nfsdi_deviceid[NFSX_V4DEVICEID];
312 struct nfsclclient *nfsdi_clp;
313 uint32_t nfsdi_refcnt;
314 uint32_t nfsdi_layoutrefs;
315 uint16_t nfsdi_stripecnt;
316 uint16_t nfsdi_addrcnt;
317 struct nfsclds *nfsdi_data[0];
320 /* These inline functions return values from nfsdi_data[]. */
322 * Return a pointer to the address at "pos".
324 static __inline struct nfsclds **
325 nfsfldi_addr(struct nfscldevinfo *ndi, int pos)
328 if (pos >= ndi->nfsdi_addrcnt)
330 return (&ndi->nfsdi_data[pos]);
334 * Return the Nth ("pos") stripe index.
337 nfsfldi_stripeindex(struct nfscldevinfo *ndi, int pos)
341 if (pos >= ndi->nfsdi_stripecnt)
343 valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
349 * Set the Nth ("pos") stripe index to "val".
352 nfsfldi_setstripeindex(struct nfscldevinfo *ndi, int pos, uint8_t val)
356 if (pos >= ndi->nfsdi_stripecnt)
358 valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
364 * Macro for incrementing the seqid#.
366 #define NFSCL_INCRSEQID(s, n) do { \
367 if (((n)->nd_flag & ND_INCRSEQID)) \
371 #endif /* _NFS_NFSCLSTATE_H_ */