xref: /illumos-gate/usr/src/cmd/smbsrv/testoplock/smbsrv/smb_ktypes.h (revision 5801b0f01c3c34499a929ed96164a5a68b470945)
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 2018 Nexenta Systems, 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 	/* File-system level state */
102 	uint8_t			onlist_II;
103 	uint8_t			onlist_R;
104 	uint8_t			onlist_RH;
105 	uint8_t			onlist_RHBQ;
106 	uint8_t			BreakingToRead;
107 } smb_oplock_grant_t;
108 
109 #define	SMB_LEASE_KEY_SZ	16
110 
111 #define	SMB_NODE_MAGIC		0x4E4F4445	/* 'NODE' */
112 #define	SMB_NODE_VALID(p)	ASSERT((p)->n_magic == SMB_NODE_MAGIC)
113 
114 typedef enum {
115 	SMB_NODE_STATE_AVAILABLE = 0,
116 	SMB_NODE_STATE_DESTROYING
117 } smb_node_state_t;
118 
119 /*
120  * waiting_event        # of clients requesting FCN
121  * n_timestamps         cached timestamps
122  * n_allocsz            cached file allocation size
123  * n_dnode              directory node
124  * n_unode              unnamed stream node
125  * delete_on_close_cred credentials for delayed delete
126  */
127 typedef struct smb_node {
128 	list_node_t		n_lnd;
129 	uint32_t		n_magic;
130 	krwlock_t		n_lock;
131 	kmutex_t		n_mutex;
132 	smb_node_state_t	n_state;
133 	uint32_t		n_refcnt;
134 	uint32_t		n_open_count;
135 	volatile int		flags;
136 
137 	smb_llist_t		n_ofile_list;
138 	smb_oplock_t		n_oplock;
139 } smb_node_t;
140 
141 #define	NODE_FLAGS_WRITE_THROUGH	0x00100000
142 #define	NODE_FLAGS_DELETE_COMMITTED	0x20000000
143 #define	NODE_FLAGS_DELETE_ON_CLOSE	0x40000000
144 
145 /*
146  * Some flags for ofile structure
147  *
148  *	SMB_OFLAGS_SET_DELETE_ON_CLOSE
149  *   Set this flag when the corresponding open operation whose
150  *   DELETE_ON_CLOSE bit of the CreateOptions is set. If any
151  *   open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE
152  *   will be set for the file node upon close.
153  */
154 
155 /*	SMB_OFLAGS_READONLY		0x0001 (obsolete) */
156 #define	SMB_OFLAGS_EXECONLY		0x0002
157 #define	SMB_OFLAGS_SET_DELETE_ON_CLOSE	0x0004
158 #define	SMB_OFLAGS_LLF_POS_VALID	0x0008
159 
160 #define	SMB_OFILE_MAGIC		0x4F464C45	/* 'OFLE' */
161 #define	SMB_OFILE_VALID(p)	\
162     ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC))
163 
164 /*
165  * This is the size of the per-handle "Lock Sequence" array.
166  * See LockSequenceIndex in [MS-SMB2] 2.2.26, and smb2_lock.c
167  */
168 #define	SMB_OFILE_LSEQ_MAX		64
169 
170 /* {arg_open,ofile}->dh_vers values */
171 typedef enum {
172 	SMB2_NOT_DURABLE = 0,
173 	SMB2_DURABLE_V1,
174 	SMB2_DURABLE_V2,
175 	SMB2_RESILIENT,
176 } smb_dh_vers_t;
177 
178 /*
179  * See the long "Ofile State Machine" comment in smb_ofile.c
180  */
181 typedef enum {
182 	SMB_OFILE_STATE_ALLOC = 0,
183 	SMB_OFILE_STATE_OPEN,
184 	SMB_OFILE_STATE_SAVE_DH,
185 	SMB_OFILE_STATE_SAVING,
186 	SMB_OFILE_STATE_CLOSING,
187 	SMB_OFILE_STATE_CLOSED,
188 	SMB_OFILE_STATE_ORPHANED,
189 	SMB_OFILE_STATE_RECONNECT,
190 	SMB_OFILE_STATE_EXPIRED,
191 	SMB_OFILE_STATE_SENTINEL
192 } smb_ofile_state_t;
193 
194 typedef struct smb_ofile {
195 	list_node_t		f_tree_lnd;	/* t_ofile_list */
196 	list_node_t		f_node_lnd;	/* n_ofile_list */
197 	list_node_t		f_dh_lnd;	/* sv_persistid_ht */
198 	uint32_t		f_magic;
199 	kmutex_t		f_mutex;
200 	smb_ofile_state_t	f_state;
201 
202 	uint16_t		f_fid;
203 	uint16_t		f_ftype;
204 	uint32_t		f_refcnt;
205 	uint32_t		f_granted_access;
206 	uint32_t		f_share_access;
207 
208 	smb_node_t		*f_node;
209 
210 	smb_oplock_grant_t	f_oplock;
211 	uint8_t			TargetOplockKey[SMB_LEASE_KEY_SZ];
212 	uint8_t			ParentOplockKey[SMB_LEASE_KEY_SZ];
213 	struct smb_lease	*f_lease;
214 
215 } smb_ofile_t;
216 
217 typedef struct smb_request {
218 	list_node_t		sr_session_lnd;
219 	uint32_t		sr_magic;
220 	kmutex_t		sr_mutex;
221 } smb_request_t;
222 
223 #ifdef	__cplusplus
224 }
225 #endif
226 
227 #endif /* _SMB_KTYPES_H */
228