nfsrvstate.h revision 1.3 1 1.3 rillig /* $NetBSD: nfsrvstate.h,v 1.3 2024/09/08 09:36:51 rillig Exp $ */
2 1.1 dholland /*-
3 1.1 dholland * Copyright (c) 2009 Rick Macklem, University of Guelph
4 1.1 dholland * All rights reserved.
5 1.1 dholland *
6 1.1 dholland * Redistribution and use in source and binary forms, with or without
7 1.1 dholland * modification, are permitted provided that the following conditions
8 1.1 dholland * are met:
9 1.1 dholland * 1. Redistributions of source code must retain the above copyright
10 1.1 dholland * notice, this list of conditions and the following disclaimer.
11 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 dholland * notice, this list of conditions and the following disclaimer in the
13 1.1 dholland * documentation and/or other materials provided with the distribution.
14 1.1 dholland *
15 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 dholland * SUCH DAMAGE.
26 1.1 dholland *
27 1.2 pgoyette * FreeBSD: head/sys/fs/nfs/nfsrvstate.h 298788 2016-04-29 16:07:25Z pfg
28 1.3 rillig * $NetBSD: nfsrvstate.h,v 1.3 2024/09/08 09:36:51 rillig Exp $
29 1.1 dholland */
30 1.1 dholland
31 1.1 dholland #ifndef _NFS_NFSRVSTATE_H_
32 1.1 dholland #define _NFS_NFSRVSTATE_H_
33 1.1 dholland
34 1.1 dholland /*
35 1.1 dholland * Definitions for NFS V4 server state handling.
36 1.1 dholland */
37 1.1 dholland
38 1.1 dholland /*
39 1.1 dholland * List heads for nfsclient, nfsstate and nfslockfile.
40 1.1 dholland * (Some systems seem to like to dynamically size these things, but I
41 1.1 dholland * don't see any point in doing so for these ones.)
42 1.1 dholland */
43 1.1 dholland LIST_HEAD(nfsclienthashhead, nfsclient);
44 1.1 dholland LIST_HEAD(nfsstatehead, nfsstate);
45 1.1 dholland LIST_HEAD(nfslockhead, nfslock);
46 1.1 dholland LIST_HEAD(nfslockhashhead, nfslockfile);
47 1.2 pgoyette LIST_HEAD(nfssessionhead, nfsdsession);
48 1.2 pgoyette LIST_HEAD(nfssessionhashhead, nfsdsession);
49 1.1 dholland
50 1.1 dholland /*
51 1.1 dholland * List head for nfsusrgrp.
52 1.1 dholland */
53 1.2 pgoyette TAILQ_HEAD(nfsuserhashhead, nfsusrgrp);
54 1.1 dholland
55 1.1 dholland #define NFSCLIENTHASH(id) \
56 1.2 pgoyette (&nfsclienthash[(id).lval[1] % nfsrv_clienthashsize])
57 1.1 dholland #define NFSSTATEHASH(clp, id) \
58 1.2 pgoyette (&((clp)->lc_stateid[(id).other[2] % nfsrv_statehashsize]))
59 1.1 dholland #define NFSUSERHASH(id) \
60 1.2 pgoyette (&nfsuserhash[(id) % nfsrv_lughashsize])
61 1.1 dholland #define NFSUSERNAMEHASH(p, l) \
62 1.1 dholland (&nfsusernamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \
63 1.2 pgoyette % nfsrv_lughashsize])
64 1.1 dholland #define NFSGROUPHASH(id) \
65 1.2 pgoyette (&nfsgrouphash[(id) % nfsrv_lughashsize])
66 1.1 dholland #define NFSGROUPNAMEHASH(p, l) \
67 1.1 dholland (&nfsgroupnamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \
68 1.2 pgoyette % nfsrv_lughashsize])
69 1.2 pgoyette
70 1.2 pgoyette struct nfssessionhash {
71 1.2 pgoyette struct kmutex mtx;
72 1.2 pgoyette struct nfssessionhashhead list;
73 1.2 pgoyette };
74 1.2 pgoyette #define NFSSESSIONHASH(f) \
75 1.2 pgoyette (&nfssessionhash[nfsrv_hashsessionid(f) % nfsrv_sessionhashsize])
76 1.1 dholland
77 1.1 dholland /*
78 1.1 dholland * Client server structure for V4. It is doubly linked into two lists.
79 1.1 dholland * The first is a hash table based on the clientid and the second is a
80 1.1 dholland * list of all clients maintained in LRU order.
81 1.2 pgoyette * The actual size malloc'd is large enough to accommodate the id string.
82 1.1 dholland */
83 1.1 dholland struct nfsclient {
84 1.1 dholland LIST_ENTRY(nfsclient) lc_hash; /* Clientid hash list */
85 1.2 pgoyette struct nfsstatehead *lc_stateid; /* Stateid hash */
86 1.1 dholland struct nfsstatehead lc_open; /* Open owner list */
87 1.1 dholland struct nfsstatehead lc_deleg; /* Delegations */
88 1.1 dholland struct nfsstatehead lc_olddeleg; /* and old delegations */
89 1.2 pgoyette struct nfssessionhead lc_session; /* List of NFSv4.1 sessions */
90 1.1 dholland time_t lc_expiry; /* Expiry time (sec) */
91 1.1 dholland time_t lc_delegtime; /* Old deleg expiry (sec) */
92 1.1 dholland nfsquad_t lc_clientid; /* 64 bit clientid */
93 1.1 dholland nfsquad_t lc_confirm; /* 64 bit confirm value */
94 1.1 dholland u_int32_t lc_program; /* RPC Program # */
95 1.1 dholland u_int32_t lc_callback; /* Callback id */
96 1.1 dholland u_int32_t lc_stateindex; /* Current state index# */
97 1.1 dholland u_int32_t lc_statemaxindex; /* Max state index# */
98 1.1 dholland u_int32_t lc_cbref; /* Cnt of callbacks */
99 1.1 dholland uid_t lc_uid; /* User credential */
100 1.1 dholland gid_t lc_gid;
101 1.2 pgoyette u_int16_t lc_idlen; /* Client ID and len */
102 1.2 pgoyette u_int16_t lc_namelen; /* plus GSS principal and len */
103 1.1 dholland u_char *lc_name;
104 1.1 dholland struct nfssockreq lc_req; /* Callback info */
105 1.1 dholland u_int32_t lc_flags; /* LCL_ flag bits */
106 1.1 dholland u_char lc_verf[NFSX_VERF]; /* client verifier */
107 1.1 dholland u_char lc_id[1]; /* Malloc'd correct size */
108 1.1 dholland };
109 1.1 dholland
110 1.1 dholland #define CLOPS_CONFIRM 0x0001
111 1.1 dholland #define CLOPS_RENEW 0x0002
112 1.1 dholland #define CLOPS_RENEWOP 0x0004
113 1.1 dholland
114 1.1 dholland /*
115 1.2 pgoyette * Structure for an NFSv4.1 session.
116 1.2 pgoyette * Locking rules for this structure.
117 1.2 pgoyette * To add/delete one of these structures from the lists, you must lock
118 1.2 pgoyette * both: NFSLOCKSTATE() and NFSLOCKSESSION(session hashhead) in that order.
119 1.2 pgoyette * To traverse the lists looking for one of these, you must hold one
120 1.2 pgoyette * of these two locks.
121 1.2 pgoyette * The exception is if the thread holds the exclusive root sleep lock.
122 1.2 pgoyette * In this case, all other nfsd threads are blocked, so locking the
123 1.2 pgoyette * mutexes isn't required.
124 1.2 pgoyette * When manipulating sess_refcnt, NFSLOCKSTATE() must be locked.
125 1.2 pgoyette * When manipulating the fields withinsess_cbsess except nfsess_xprt,
126 1.2 pgoyette * sess_cbsess.nfsess_mtx must be locked.
127 1.2 pgoyette * When manipulating sess_slots and sess_cbsess.nfsess_xprt,
128 1.2 pgoyette * NFSLOCKSESSION(session hashhead) must be locked.
129 1.2 pgoyette */
130 1.2 pgoyette struct nfsdsession {
131 1.2 pgoyette uint64_t sess_refcnt; /* Reference count. */
132 1.2 pgoyette LIST_ENTRY(nfsdsession) sess_hash; /* Hash list of sessions. */
133 1.2 pgoyette LIST_ENTRY(nfsdsession) sess_list; /* List of client sessions. */
134 1.2 pgoyette struct nfsslot sess_slots[NFSV4_SLOTS];
135 1.2 pgoyette struct nfsclient *sess_clp; /* Associated clientid. */
136 1.2 pgoyette uint32_t sess_crflags;
137 1.2 pgoyette uint32_t sess_cbprogram;
138 1.2 pgoyette uint32_t sess_maxreq;
139 1.2 pgoyette uint32_t sess_maxresp;
140 1.2 pgoyette uint32_t sess_maxrespcached;
141 1.2 pgoyette uint32_t sess_maxops;
142 1.2 pgoyette uint32_t sess_maxslots;
143 1.2 pgoyette uint32_t sess_cbmaxreq;
144 1.2 pgoyette uint32_t sess_cbmaxresp;
145 1.2 pgoyette uint32_t sess_cbmaxrespcached;
146 1.2 pgoyette uint32_t sess_cbmaxops;
147 1.2 pgoyette uint8_t sess_sessionid[NFSX_V4SESSIONID];
148 1.2 pgoyette struct nfsclsession sess_cbsess; /* Callback session. */
149 1.2 pgoyette };
150 1.2 pgoyette
151 1.2 pgoyette /*
152 1.1 dholland * Nfs state structure. I couldn't resist overloading this one, since
153 1.1 dholland * it makes cleanup, etc. simpler. These structures are used in four ways:
154 1.1 dholland * - open_owner structures chained off of nfsclient
155 1.1 dholland * - open file structures chained off an open_owner structure
156 1.1 dholland * - lock_owner structures chained off an open file structure
157 1.1 dholland * - delegated file structures chained off of nfsclient and nfslockfile
158 1.1 dholland * - the ls_list field is used for the chain it is in
159 1.1 dholland * - the ls_head structure is used to chain off the sibling structure
160 1.1 dholland * (it is a union between an nfsstate and nfslock structure head)
161 1.1 dholland * If it is a lockowner stateid, nfslock structures hang off it.
162 1.1 dholland * For the open file and lockowner cases, it is in the hash table in
163 1.1 dholland * nfsclient for stateid.
164 1.1 dholland */
165 1.1 dholland struct nfsstate {
166 1.1 dholland LIST_ENTRY(nfsstate) ls_hash; /* Hash list entry */
167 1.1 dholland LIST_ENTRY(nfsstate) ls_list; /* List of opens/delegs */
168 1.1 dholland LIST_ENTRY(nfsstate) ls_file; /* Opens/Delegs for a file */
169 1.1 dholland union {
170 1.1 dholland struct nfsstatehead open; /* Opens list */
171 1.1 dholland struct nfslockhead lock; /* Locks list */
172 1.1 dholland } ls_head;
173 1.1 dholland nfsv4stateid_t ls_stateid; /* The state id */
174 1.1 dholland u_int32_t ls_seq; /* seq id */
175 1.1 dholland uid_t ls_uid; /* uid of locker */
176 1.1 dholland u_int32_t ls_flags; /* Type of lock, etc. */
177 1.1 dholland union {
178 1.1 dholland struct nfsstate *openowner; /* Open only */
179 1.1 dholland u_int32_t opentolockseq; /* Lock call only */
180 1.1 dholland u_int32_t noopens; /* Openowner only */
181 1.1 dholland struct {
182 1.1 dholland u_quad_t filerev; /* Delegations only */
183 1.1 dholland time_t expiry;
184 1.1 dholland time_t limit;
185 1.1 dholland u_int64_t compref;
186 1.1 dholland } deleg;
187 1.1 dholland } ls_un;
188 1.1 dholland struct nfslockfile *ls_lfp; /* Back pointer */
189 1.1 dholland struct nfsrvcache *ls_op; /* Op cache reference */
190 1.1 dholland struct nfsclient *ls_clp; /* Back pointer */
191 1.1 dholland u_short ls_ownerlen; /* Length of ls_owner */
192 1.1 dholland u_char ls_owner[1]; /* malloc'd the correct size */
193 1.1 dholland };
194 1.1 dholland #define ls_lock ls_head.lock
195 1.1 dholland #define ls_open ls_head.open
196 1.1 dholland #define ls_opentolockseq ls_un.opentolockseq
197 1.1 dholland #define ls_openowner ls_un.openowner
198 1.1 dholland #define ls_openstp ls_un.openowner
199 1.1 dholland #define ls_noopens ls_un.noopens
200 1.1 dholland #define ls_filerev ls_un.deleg.filerev
201 1.1 dholland #define ls_delegtime ls_un.deleg.expiry
202 1.1 dholland #define ls_delegtimelimit ls_un.deleg.limit
203 1.1 dholland #define ls_compref ls_un.deleg.compref
204 1.1 dholland
205 1.1 dholland /*
206 1.1 dholland * Nfs lock structure.
207 1.1 dholland * This structure is chained off of the nfsstate (the lockowner) and
208 1.1 dholland * nfslockfile (the file) structures, for the file and owner it
209 1.1 dholland * refers to. It holds flags and a byte range.
210 1.1 dholland * It also has back pointers to the associated lock_owner and lockfile.
211 1.1 dholland */
212 1.1 dholland struct nfslock {
213 1.1 dholland LIST_ENTRY(nfslock) lo_lckowner;
214 1.1 dholland LIST_ENTRY(nfslock) lo_lckfile;
215 1.1 dholland struct nfsstate *lo_stp;
216 1.1 dholland struct nfslockfile *lo_lfp;
217 1.1 dholland u_int64_t lo_first;
218 1.1 dholland u_int64_t lo_end;
219 1.1 dholland u_int32_t lo_flags;
220 1.1 dholland };
221 1.1 dholland
222 1.1 dholland /*
223 1.1 dholland * Structure used to return a conflicting lock. (Must be large
224 1.1 dholland * enough for the largest lock owner we can have.)
225 1.1 dholland */
226 1.1 dholland struct nfslockconflict {
227 1.1 dholland nfsquad_t cl_clientid;
228 1.1 dholland u_int64_t cl_first;
229 1.1 dholland u_int64_t cl_end;
230 1.1 dholland u_int32_t cl_flags;
231 1.1 dholland u_short cl_ownerlen;
232 1.1 dholland u_char cl_owner[NFSV4_OPAQUELIMIT];
233 1.1 dholland };
234 1.1 dholland
235 1.1 dholland /*
236 1.1 dholland * This structure is used to keep track of local locks that might need
237 1.1 dholland * to be rolled back.
238 1.1 dholland */
239 1.1 dholland struct nfsrollback {
240 1.1 dholland LIST_ENTRY(nfsrollback) rlck_list;
241 1.1 dholland uint64_t rlck_first;
242 1.1 dholland uint64_t rlck_end;
243 1.1 dholland int rlck_type;
244 1.1 dholland };
245 1.1 dholland
246 1.1 dholland /*
247 1.1 dholland * This structure refers to a file for which lock(s) and/or open(s) exist.
248 1.1 dholland * Searched via hash table on file handle or found via the back pointer from an
249 1.1 dholland * open or lock owner.
250 1.1 dholland */
251 1.1 dholland struct nfslockfile {
252 1.1 dholland LIST_HEAD(, nfsstate) lf_open; /* Open list */
253 1.1 dholland LIST_HEAD(, nfsstate) lf_deleg; /* Delegation list */
254 1.1 dholland LIST_HEAD(, nfslock) lf_lock; /* Lock list */
255 1.1 dholland LIST_HEAD(, nfslock) lf_locallock; /* Local lock list */
256 1.1 dholland LIST_HEAD(, nfsrollback) lf_rollback; /* Local lock rollback list */
257 1.1 dholland LIST_ENTRY(nfslockfile) lf_hash; /* Hash list entry */
258 1.1 dholland fhandle_t lf_fh; /* The file handle */
259 1.1 dholland struct nfsv4lock lf_locallock_lck; /* serialize local locking */
260 1.1 dholland int lf_usecount; /* Ref count for locking */
261 1.1 dholland };
262 1.1 dholland
263 1.1 dholland /*
264 1.3 rillig * This structure is malloc'd and chained off hash lists for user/group
265 1.1 dholland * names.
266 1.1 dholland */
267 1.1 dholland struct nfsusrgrp {
268 1.2 pgoyette TAILQ_ENTRY(nfsusrgrp) lug_numhash; /* Hash by id# */
269 1.2 pgoyette TAILQ_ENTRY(nfsusrgrp) lug_namehash; /* and by name */
270 1.1 dholland time_t lug_expiry; /* Expiry time in sec */
271 1.1 dholland union {
272 1.1 dholland uid_t un_uid; /* id# */
273 1.1 dholland gid_t un_gid;
274 1.1 dholland } lug_un;
275 1.2 pgoyette struct ucred *lug_cred; /* Cred. with groups list */
276 1.1 dholland int lug_namelen; /* Name length */
277 1.1 dholland u_char lug_name[1]; /* malloc'd correct length */
278 1.1 dholland };
279 1.1 dholland #define lug_uid lug_un.un_uid
280 1.1 dholland #define lug_gid lug_un.un_gid
281 1.1 dholland
282 1.1 dholland /*
283 1.1 dholland * These structures are used for the stable storage restart stuff.
284 1.1 dholland */
285 1.1 dholland /*
286 1.1 dholland * Record at beginning of file.
287 1.1 dholland */
288 1.1 dholland struct nfsf_rec {
289 1.1 dholland u_int32_t lease; /* Lease duration */
290 1.1 dholland u_int32_t numboots; /* Number of boottimes */
291 1.1 dholland };
292 1.1 dholland
293 1.1 dholland #if defined(_KERNEL) || defined(KERNEL)
294 1.1 dholland void nfsrv_cleanclient(struct nfsclient *, NFSPROC_T *);
295 1.1 dholland void nfsrv_freedeleglist(struct nfsstatehead *);
296 1.1 dholland #endif
297 1.1 dholland
298 1.1 dholland #endif /* _NFS_NFSRVSTATE_H_ */
299