xref: /illumos-gate/usr/src/cmd/smbsrv/testoplock/smbsrv/smb_ktypes.h (revision 3aa6c13072f3d4792a18693e916aed260a496c1f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2020 Nexenta by DDN, Inc.  All rights reserved.
24  */
25 
26 /*
27  * Structures and type definitions needed by the "testoplock" program
28  * (a small subset of what the SMB server uses)
29  */
30 
31 #ifndef _SMB_KTYPES_H
32 #define	_SMB_KTYPES_H
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #include <sys/types.h>
39 #include <sys/debug.h>
40 #include <sys/systm.h>
41 #include <sys/cred.h>
42 #include <sys/list.h>
43 #include <sys/sdt.h>
44 
45 typedef struct smb_session smb_session_t;
46 typedef struct smb_user smb_user_t;
47 typedef struct smb_tree smb_tree_t;
48 
49 
50 /*
51  * Destructor object used in the locked-list delete queue.
52  */
53 #define	SMB_DTOR_MAGIC		0x44544F52	/* DTOR */
54 #define	SMB_DTOR_VALID(d)	\
55     ASSERT(((d) != NULL) && ((d)->dt_magic == SMB_DTOR_MAGIC))
56 
57 typedef void (*smb_dtorproc_t)(void *);
58 
59 typedef struct smb_dtor {
60 	list_node_t	dt_lnd;
61 	uint32_t	dt_magic;
62 	void		*dt_object;
63 	smb_dtorproc_t	dt_proc;
64 } smb_dtor_t;
65 
66 typedef struct smb_llist {
67 	krwlock_t	ll_lock;
68 	list_t		ll_list;
69 	uint32_t	ll_count;
70 	uint64_t	ll_wrop;
71 	kmutex_t	ll_mutex;
72 	list_t		ll_deleteq;
73 	uint32_t	ll_deleteq_count;
74 	boolean_t	ll_flushing;
75 } smb_llist_t;
76 
77 /*
78  * Per smb_node oplock state
79  */
80 typedef struct smb_oplock {
81 	kmutex_t		ol_mutex;
82 	boolean_t		ol_fem;		/* fem monitor installed? */
83 	struct smb_ofile	*excl_open;
84 	uint32_t		ol_state;
85 	int32_t			cnt_II;
86 	int32_t			cnt_R;
87 	int32_t			cnt_RH;
88 	int32_t			cnt_RHBQ;
89 	int32_t			waiters;
90 	kcondvar_t		WaitingOpenCV;
91 } smb_oplock_t;
92 
93 /*
94  * Per smb_ofile oplock state
95  */
96 typedef struct smb_oplock_grant {
97 	/* smb protocol-level state */
98 	uint32_t		og_state;	/* latest sent to client */
99 	uint32_t		og_breaking;	/* BREAK_TO... flags */
100 	uint16_t		og_dialect;	/* how to send breaks */
101 	boolean_t		og_closing;
102 	/* File-system level state */
103 	uint8_t			onlist_II;
104 	uint8_t			onlist_R;
105 	uint8_t			onlist_RH;
106 	uint8_t			onlist_RHBQ;
107 	uint8_t			BreakingToRead;
108 } smb_oplock_grant_t;
109 
110 #define	SMB_LEASE_KEY_SZ	16
111 
112 #define	SMB_NODE_MAGIC		0x4E4F4445	/* 'NODE' */
113 #define	SMB_NODE_VALID(p)	ASSERT((p)->n_magic == SMB_NODE_MAGIC)
114 
115 typedef enum {
116 	SMB_NODE_STATE_AVAILABLE = 0,
117 	SMB_NODE_STATE_DESTROYING
118 } smb_node_state_t;
119 
120 /*
121  * waiting_event        # of clients requesting FCN
122  * n_timestamps         cached timestamps
123  * n_allocsz            cached file allocation size
124  * n_dnode              directory node
125  * n_unode              unnamed stream node
126  * delete_on_close_cred credentials for delayed delete
127  */
128 typedef struct smb_node {
129 	list_node_t		n_lnd;
130 	uint32_t		n_magic;
131 	krwlock_t		n_lock;
132 	kmutex_t		n_mutex;
133 	smb_node_state_t	n_state;
134 	uint32_t		n_refcnt;
135 	uint32_t		n_open_count;
136 	volatile int		flags;
137 
138 	smb_llist_t		n_ofile_list;
139 	smb_oplock_t		n_oplock;
140 } smb_node_t;
141 
142 #define	NODE_FLAGS_WRITE_THROUGH	0x00100000
143 #define	NODE_FLAGS_DELETE_COMMITTED	0x20000000
144 #define	NODE_FLAGS_DELETE_ON_CLOSE	0x40000000
145 
146 /*
147  * Some flags for ofile structure
148  *
149  *	SMB_OFLAGS_SET_DELETE_ON_CLOSE
150  *   Set this flag when the corresponding open operation whose
151  *   DELETE_ON_CLOSE bit of the CreateOptions is set. If any
152  *   open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE
153  *   will be set for the file node upon close.
154  */
155 
156 /*	SMB_OFLAGS_READONLY		0x0001 (obsolete) */
157 #define	SMB_OFLAGS_EXECONLY		0x0002
158 #define	SMB_OFLAGS_SET_DELETE_ON_CLOSE	0x0004
159 #define	SMB_OFLAGS_LLF_POS_VALID	0x0008
160 
161 #define	SMB_OFILE_MAGIC		0x4F464C45	/* 'OFLE' */
162 #define	SMB_OFILE_VALID(p)	\
163     ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC))
164 
165 /*
166  * This is the size of the per-handle "Lock Sequence" array.
167  * See LockSequenceIndex in [MS-SMB2] 2.2.26, and smb2_lock.c
168  */
169 #define	SMB_OFILE_LSEQ_MAX		64
170 
171 /* {arg_open,ofile}->dh_vers values */
172 typedef enum {
173 	SMB2_NOT_DURABLE = 0,
174 	SMB2_DURABLE_V1,
175 	SMB2_DURABLE_V2,
176 	SMB2_RESILIENT,
177 } smb_dh_vers_t;
178 
179 /*
180  * See the long "Ofile State Machine" comment in smb_ofile.c
181  */
182 typedef enum {
183 	SMB_OFILE_STATE_ALLOC = 0,
184 	SMB_OFILE_STATE_OPEN,
185 	SMB_OFILE_STATE_SAVE_DH,
186 	SMB_OFILE_STATE_SAVING,
187 	SMB_OFILE_STATE_CLOSING,
188 	SMB_OFILE_STATE_CLOSED,
189 	SMB_OFILE_STATE_ORPHANED,
190 	SMB_OFILE_STATE_RECONNECT,
191 	SMB_OFILE_STATE_EXPIRED,
192 	SMB_OFILE_STATE_SENTINEL
193 } smb_ofile_state_t;
194 
195 typedef struct smb_ofile {
196 	list_node_t		f_tree_lnd;	/* t_ofile_list */
197 	list_node_t		f_node_lnd;	/* n_ofile_list */
198 	list_node_t		f_dh_lnd;	/* sv_persistid_ht */
199 	uint32_t		f_magic;
200 	kmutex_t		f_mutex;
201 	smb_ofile_state_t	f_state;
202 
203 	uint16_t		f_fid;
204 	uint16_t		f_ftype;
205 	uint32_t		f_refcnt;
206 	uint32_t		f_granted_access;
207 	uint32_t		f_share_access;
208 
209 	smb_node_t		*f_node;
210 
211 	smb_oplock_grant_t	f_oplock;
212 	uint8_t			TargetOplockKey[SMB_LEASE_KEY_SZ];
213 	uint8_t			ParentOplockKey[SMB_LEASE_KEY_SZ];
214 	struct smb_lease	*f_lease;
215 
216 } smb_ofile_t;
217 
218 typedef struct smb_request {
219 	list_node_t		sr_session_lnd;
220 	uint32_t		sr_magic;
221 	kmutex_t		sr_mutex;
222 } smb_request_t;
223 
224 #ifdef	__cplusplus
225 }
226 #endif
227 
228 #endif /* _SMB_KTYPES_H */
229