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 * Copyright 2022 RackTop Systems, Inc. 25 */ 26 27 /* 28 * Structures and type definitions needed by the "testoplock" program 29 * (a small subset of what the SMB server uses) 30 */ 31 32 #ifndef _SMB_KTYPES_H 33 #define _SMB_KTYPES_H 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #include <sys/types.h> 40 #include <sys/debug.h> 41 #include <sys/systm.h> 42 #include <sys/cred.h> 43 #include <sys/list.h> 44 #include <sys/sdt.h> 45 46 typedef struct smb_session smb_session_t; 47 typedef struct smb_user smb_user_t; 48 typedef struct smb_tree smb_tree_t; 49 50 51 /* 52 * Destructor object used in the locked-list delete queue. 53 */ 54 #define SMB_DTOR_MAGIC 0x44544F52 /* DTOR */ 55 #define SMB_DTOR_VALID(d) \ 56 ASSERT(((d) != NULL) && ((d)->dt_magic == SMB_DTOR_MAGIC)) 57 58 typedef void (*smb_dtorproc_t)(void *); 59 60 typedef struct smb_dtor { 61 list_node_t dt_lnd; 62 uint32_t dt_magic; 63 void *dt_object; 64 smb_dtorproc_t dt_proc; 65 } smb_dtor_t; 66 67 typedef struct smb_llist { 68 krwlock_t ll_lock; 69 list_t ll_list; 70 uint32_t ll_count; 71 uint64_t ll_wrop; 72 kmutex_t ll_mutex; 73 list_t ll_deleteq; 74 uint32_t ll_deleteq_count; 75 boolean_t ll_flushing; 76 } smb_llist_t; 77 78 /* 79 * Per smb_node oplock state 80 */ 81 typedef struct smb_oplock { 82 kmutex_t ol_mutex; 83 boolean_t ol_fem; /* fem monitor installed? */ 84 struct smb_ofile *excl_open; 85 uint32_t ol_state; 86 int32_t cnt_II; 87 int32_t cnt_R; 88 int32_t cnt_RH; 89 int32_t cnt_RHBQ; 90 int32_t waiters; 91 kcondvar_t WaitingOpenCV; 92 } smb_oplock_t; 93 94 /* 95 * Per smb_ofile oplock state 96 */ 97 typedef struct smb_oplock_grant { 98 /* smb protocol-level state */ 99 uint32_t og_state; /* what client has now */ 100 uint32_t og_breakto; /* level breaking to */ 101 boolean_t og_breaking; 102 uint16_t og_dialect; /* how to send breaks */ 103 kcondvar_t og_ack_cv; /* Wait for ACK */ 104 /* File-system level state */ 105 uint8_t onlist_II; 106 uint8_t onlist_R; 107 uint8_t onlist_RH; 108 uint8_t onlist_RHBQ; 109 uint8_t BreakingToRead; 110 } smb_oplock_grant_t; 111 112 #define SMB_LEASE_KEY_SZ 16 113 114 struct smb_lease; 115 116 #define SMB_NODE_MAGIC 0x4E4F4445 /* 'NODE' */ 117 #define SMB_NODE_VALID(p) ASSERT((p)->n_magic == SMB_NODE_MAGIC) 118 119 typedef enum { 120 SMB_NODE_STATE_AVAILABLE = 0, 121 SMB_NODE_STATE_DESTROYING 122 } smb_node_state_t; 123 124 /* 125 * waiting_event # of clients requesting FCN 126 * n_timestamps cached timestamps 127 * n_allocsz cached file allocation size 128 * n_dnode directory node 129 * n_unode unnamed stream node 130 * delete_on_close_cred credentials for delayed delete 131 */ 132 typedef struct smb_node { 133 list_node_t n_lnd; 134 uint32_t n_magic; 135 krwlock_t n_lock; 136 kmutex_t n_mutex; 137 smb_node_state_t n_state; 138 uint32_t n_refcnt; 139 uint32_t n_open_count; 140 volatile int flags; 141 142 smb_llist_t n_ofile_list; 143 smb_oplock_t n_oplock; 144 } smb_node_t; 145 146 #define NODE_FLAGS_WRITE_THROUGH 0x00100000 147 #define NODE_FLAGS_DELETE_COMMITTED 0x20000000 148 #define NODE_FLAGS_DELETE_ON_CLOSE 0x40000000 149 150 /* 151 * Some flags for ofile structure 152 * 153 * SMB_OFLAGS_SET_DELETE_ON_CLOSE 154 * Set this flag when the corresponding open operation whose 155 * DELETE_ON_CLOSE bit of the CreateOptions is set. If any 156 * open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE 157 * will be set for the file node upon close. 158 */ 159 160 /* SMB_OFLAGS_READONLY 0x0001 (obsolete) */ 161 #define SMB_OFLAGS_EXECONLY 0x0002 162 #define SMB_OFLAGS_SET_DELETE_ON_CLOSE 0x0004 163 #define SMB_OFLAGS_LLF_POS_VALID 0x0008 164 165 #define SMB_OFILE_MAGIC 0x4F464C45 /* 'OFLE' */ 166 #define SMB_OFILE_VALID(p) \ 167 ASSERT((p != NULL) && ((p)->f_magic == SMB_OFILE_MAGIC)) 168 169 /* 170 * This is the size of the per-handle "Lock Sequence" array. 171 * See LockSequenceIndex in [MS-SMB2] 2.2.26, and smb2_lock.c 172 */ 173 #define SMB_OFILE_LSEQ_MAX 64 174 175 /* {arg_open,ofile}->dh_vers values */ 176 typedef enum { 177 SMB2_NOT_DURABLE = 0, 178 SMB2_DURABLE_V1, 179 SMB2_DURABLE_V2, 180 SMB2_RESILIENT, 181 } smb_dh_vers_t; 182 183 /* 184 * See the long "Ofile State Machine" comment in smb_ofile.c 185 */ 186 typedef enum { 187 SMB_OFILE_STATE_ALLOC = 0, 188 SMB_OFILE_STATE_OPEN, 189 SMB_OFILE_STATE_SAVE_DH, 190 SMB_OFILE_STATE_SAVING, 191 SMB_OFILE_STATE_CLOSING, 192 SMB_OFILE_STATE_CLOSED, 193 SMB_OFILE_STATE_ORPHANED, 194 SMB_OFILE_STATE_RECONNECT, 195 SMB_OFILE_STATE_EXPIRED, 196 SMB_OFILE_STATE_SENTINEL 197 } smb_ofile_state_t; 198 199 typedef struct smb_ofile { 200 list_node_t f_tree_lnd; /* t_ofile_list */ 201 list_node_t f_node_lnd; /* n_ofile_list */ 202 list_node_t f_dh_lnd; /* sv_persistid_ht */ 203 uint32_t f_magic; 204 kmutex_t f_mutex; 205 smb_ofile_state_t f_state; 206 207 uint16_t f_fid; 208 uint16_t f_ftype; 209 uint32_t f_refcnt; 210 uint32_t f_granted_access; 211 uint32_t f_share_access; 212 213 smb_node_t *f_node; 214 215 smb_oplock_grant_t f_oplock; 216 boolean_t f_oplock_closing; 217 uint8_t TargetOplockKey[SMB_LEASE_KEY_SZ]; 218 uint8_t ParentOplockKey[SMB_LEASE_KEY_SZ]; 219 struct smb_lease *f_lease; 220 221 } smb_ofile_t; 222 223 typedef struct smb_request { 224 list_node_t sr_session_lnd; 225 uint32_t sr_magic; 226 kmutex_t sr_mutex; 227 } smb_request_t; 228 229 #ifdef __cplusplus 230 } 231 #endif 232 233 #endif /* _SMB_KTYPES_H */ 234