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 * 24 * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 25 */ 26 27 #ifndef _STMF_SBD_H 28 #define _STMF_SBD_H 29 30 #include <sys/dkio.h> 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 typedef stmf_status_t sbd_status_t; 37 extern char sbd_vendor_id[]; 38 extern char sbd_product_id[]; 39 extern char sbd_revision[]; 40 extern char *sbd_mgmt_url; 41 extern uint16_t sbd_mgmt_url_alloc_size; 42 extern krwlock_t sbd_global_prop_lock; 43 44 /* 45 * Error codes 46 */ 47 #define SBD_SUCCESS STMF_SUCCESS 48 #define SBD_FAILURE STMF_LU_FAILURE 49 50 #define SBD_ALREADY (SBD_FAILURE | STMF_FSC(1)) 51 #define SBD_NOT_SUPPORTED (SBD_FAILURE | STMF_FSC(2)) 52 #define SBD_META_CORRUPTED (SBD_FAILURE | STMF_FSC(3)) 53 #define SBD_INVALID_ARG (SBD_FAILURE | STMF_FSC(4)) 54 #define SBD_NOT_FOUND (SBD_FAILURE | STMF_FSC(5)) 55 #define SBD_ALLOC_FAILURE (SBD_FAILURE | STMF_FSC(6)) 56 #define SBD_FILEIO_FAILURE (SBD_FAILURE | STMF_FSC(7)) 57 #define SBD_IO_PAST_EOF (SBD_FAILURE | STMF_FSC(8)) 58 #define SBD_BUSY (SBD_FAILURE | STMF_FSC(9)) 59 60 #define SHARED_META_DATA_SIZE 65536 61 #define SBD_META_OFFSET 4096 62 #define SBD_MIN_LU_SIZE (1024 * 1024) 63 64 /* 65 * sms endianess 66 */ 67 #define SMS_BIG_ENDIAN 0x00 68 #define SMS_LITTLE_ENDIAN 0xFF 69 70 #ifdef _BIG_ENDIAN 71 #define SMS_DATA_ORDER SMS_BIG_ENDIAN 72 #else 73 #define SMS_DATA_ORDER SMS_LITTLE_ENDIAN 74 #endif 75 76 #define SBD_MAGIC 0x53554e5342444c55 77 78 #define SBD_VER_MAJOR 1 79 #define SBD_VER_MINOR 1 80 #define SBD_VER_SUBMINOR 0 81 82 #if 0 83 typedef struct sbd_meta_start { 84 uint64_t sm_magic; 85 uint64_t sm_meta_size; 86 uint64_t sm_meta_size_used; 87 uint64_t sm_rsvd1; /* Defaults to zero */ 88 uint64_t sm_rsvd2; 89 uint16_t sm_ver_major; 90 uint16_t sm_ver_minor; 91 uint16_t sm_ver_subminor; 92 uint8_t sm_flags; 93 uint8_t sm_chksum; 94 } sbd_meta_start_t; 95 #endif 96 97 typedef struct sm_section_hdr { 98 uint64_t sms_offset; /* Offset of this section */ 99 uint32_t sms_size; /* Includes the header and padding */ 100 uint16_t sms_id; /* Section identifier */ 101 uint8_t sms_data_order; /* 0x00 or 0xff */ 102 uint8_t sms_chksum; 103 } sm_section_hdr_t; 104 105 /* 106 * sbd meta section identifiers 107 */ 108 #define SMS_ID_LU_INFO_1_0 0 109 #define SMS_ID_LU_INFO_1_1 1 110 #define SMS_ID_PGR_INFO 2 111 #define SMS_ID_UNUSED 0x1000 112 113 typedef struct sbd_lu_info_1_0 { 114 sm_section_hdr_t sli_sms_header; 115 uint64_t sli_total_store_size; 116 uint64_t sli_total_meta_size; 117 uint64_t sli_lu_data_offset; 118 uint64_t sli_lu_data_size; 119 uint32_t sli_flags; 120 uint16_t sli_blocksize; 121 uint8_t sli_data_order; 122 uint8_t rsvd1; 123 uint8_t sli_lu_devid[20]; 124 uint32_t rsvd2; 125 } sbd_lu_info_1_0_t; 126 127 typedef struct sbd_lu_info_1_1 { 128 sm_section_hdr_t sli_sms_header; 129 uint32_t sli_flags; 130 char sli_rev[4]; 131 char sli_vid[8]; 132 char sli_pid[16]; 133 uint64_t sli_lu_size; /* Read capacity size */ 134 135 /* 136 * Essetially zfs volume name for zvols to verify that the 137 * metadata is coming in from the correct zvol and not from a 138 * clone. Has no meaning in any other case. 139 */ 140 uint64_t sli_meta_fname_offset; 141 142 /* 143 * Data filename or the media filename when the metadata is in 144 * a separate file. Its not needed if the metadata is shared 145 * with data as the user supplied name is the data filename. 146 */ 147 uint64_t sli_data_fname_offset; 148 uint64_t sli_serial_offset; 149 uint64_t sli_alias_offset; 150 uint8_t sli_data_blocksize_shift; 151 uint8_t sli_data_order; 152 uint8_t sli_serial_size; 153 uint8_t sli_rsvd1; 154 uint8_t sli_device_id[20]; 155 uint64_t sli_mgmt_url_offset; 156 uint8_t sli_rsvd2[248]; 157 158 /* 159 * In case there is no separate meta, sli_meta_fname_offset wont 160 * be valid. The same is true for zfs based metadata. The data_fname 161 * is the zvol. 162 */ 163 uint8_t sli_buf[8]; 164 } sbd_lu_info_1_1_t; 165 166 /* 167 * sli flags 168 */ 169 #define SLI_SEPARATE_META 0x0001 170 #define SLI_WRITE_PROTECTED 0x0002 171 #define SLI_VID_VALID 0x0004 172 #define SLI_PID_VALID 0x0008 173 #define SLI_REV_VALID 0x0010 174 #define SLI_META_FNAME_VALID 0x0020 175 #define SLI_DATA_FNAME_VALID 0x0040 176 #define SLI_SERIAL_VALID 0x0080 177 #define SLI_ALIAS_VALID 0x0100 178 #define SLI_WRITEBACK_CACHE_DISABLE 0x0200 179 #define SLI_ZFS_META 0x0400 180 #define SLI_MGMT_URL_VALID 0x0800 181 182 struct sbd_it_data; 183 184 typedef struct sbd_lu { 185 struct sbd_lu *sl_next; 186 stmf_lu_t *sl_lu; 187 uint32_t sl_alloc_size; 188 189 /* Current LU state */ 190 kmutex_t sl_lock; 191 uint32_t sl_flags; 192 uint8_t sl_trans_op; 193 uint8_t sl_state:7, 194 sl_state_not_acked:1; 195 196 char *sl_name; /* refers to meta or data */ 197 198 /* Metadata */ 199 kmutex_t sl_metadata_lock; 200 krwlock_t sl_access_state_lock; 201 char *sl_alias; 202 char *sl_meta_filename; /* If applicable */ 203 char *sl_mgmt_url; 204 vnode_t *sl_meta_vp; 205 vtype_t sl_meta_vtype; 206 uint8_t sl_device_id[20]; /* 4(hdr) + 16(GUID) */ 207 uint8_t sl_meta_blocksize_shift; /* Left shift multiplier */ 208 uint8_t sl_data_blocksize_shift; 209 uint8_t sl_data_fs_nbits; 210 uint8_t sl_serial_no_size; 211 uint64_t sl_total_meta_size; 212 uint64_t sl_meta_size_used; 213 uint8_t *sl_serial_no; /* optional */ 214 char sl_vendor_id[8]; 215 char sl_product_id[16]; 216 char sl_revision[4]; 217 uint32_t sl_data_fname_alloc_size; /* for an explicit alloc */ 218 uint16_t sl_alias_alloc_size; 219 uint16_t sl_mgmt_url_alloc_size; 220 uint8_t sl_serial_no_alloc_size; 221 uint8_t sl_access_state; 222 uint64_t sl_meta_offset; 223 224 /* zfs metadata */ 225 krwlock_t sl_zfs_meta_lock; 226 char *sl_zfs_meta; 227 minor_t sl_zvol_minor; /* for direct zvol calls */ 228 /* opaque handles for zvol direct calls */ 229 void *sl_zvol_minor_hdl; 230 void *sl_zvol_objset_hdl; 231 void *sl_zvol_zil_hdl; 232 void *sl_zvol_rl_hdl; 233 void *sl_zvol_dn_hdl; 234 235 /* Backing store */ 236 char *sl_data_filename; 237 vnode_t *sl_data_vp; 238 vtype_t sl_data_vtype; 239 uint64_t sl_total_data_size; 240 uint64_t sl_data_readable_size; /* read() fails after this */ 241 uint64_t sl_data_offset; /* After the metadata,if any */ 242 uint64_t sl_lu_size; /* READ CAPACITY size */ 243 uint64_t sl_blksize; /* used for zvols */ 244 uint64_t sl_max_xfer_len; /* used for zvols */ 245 246 struct sbd_it_data *sl_it_list; 247 struct sbd_pgr *sl_pgr; 248 uint64_t sl_rs_owner_session_id; 249 } sbd_lu_t; 250 251 /* 252 * sl_flags 253 */ 254 #define SL_LINKED 0x00000001 255 #define SL_META_OPENED 0x00000002 256 #define SL_REGISTERED 0x00000004 257 #define SL_META_NEEDS_FLUSH 0x00000008 258 #define SL_DATA_NEEDS_FLUSH 0x00000010 259 #define SL_VID_VALID 0x00000020 260 #define SL_PID_VALID 0x00000040 261 #define SL_REV_VALID 0x00000080 262 #define SL_WRITE_PROTECTED 0x00000100 263 #define SL_MEDIA_LOADED 0x00000200 264 #define SL_LU_HAS_SCSI2_RESERVATION 0x00000400 265 #define SL_WRITEBACK_CACHE_DISABLE 0x00000800 266 #define SL_SAVED_WRITE_CACHE_DISABLE 0x00001000 267 #define SL_MEDIUM_REMOVAL_PREVENTED 0x00002000 268 #define SL_NO_DATA_DKIOFLUSH 0x00004000 269 #define SL_SHARED_META 0x00008000 270 #define SL_ZFS_META 0x00010000 271 #define SL_WRITEBACK_CACHE_SET_UNSUPPORTED 0x00020000 272 #define SL_FLUSH_ON_DISABLED_WRITECACHE 0x00040000 273 #define SL_CALL_ZVOL 0x00080000 274 #define SL_UNMAP_ENABLED 0x00100000 275 276 /* 277 * sl_trans_op. LU is undergoing some transition and this field 278 * tells what kind of transition that is. 279 */ 280 #define SL_OP_NONE 0 281 #define SL_OP_CREATE_REGISTER_LU 1 282 #define SL_OP_IMPORT_LU 2 283 #define SL_OP_DELETE_LU 3 284 #define SL_OP_MODIFY_LU 4 285 #define SL_OP_LU_PROPS 5 286 287 sbd_status_t sbd_data_read(sbd_lu_t *sl, scsi_task_t *task, 288 uint64_t offset, uint64_t size, uint8_t *buf); 289 sbd_status_t sbd_data_write(sbd_lu_t *sl, scsi_task_t *task, 290 uint64_t offset, uint64_t size, uint8_t *buf); 291 stmf_status_t sbd_task_alloc(struct scsi_task *task); 292 void sbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf); 293 void sbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf); 294 void sbd_send_status_done(struct scsi_task *task); 295 void sbd_task_free(struct scsi_task *task); 296 stmf_status_t sbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg, 297 uint32_t flags); 298 void sbd_ctl(struct stmf_lu *lu, int cmd, void *arg); 299 stmf_status_t sbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg, uint8_t *buf, 300 uint32_t *bufsizep); 301 sbd_status_t sbd_write_lu_info(sbd_lu_t *sl); 302 sbd_status_t sbd_flush_data_cache(sbd_lu_t *sl, int fsync_done); 303 sbd_status_t sbd_wcd_set(int wcd, sbd_lu_t *sl); 304 void sbd_wcd_get(int *wcd, sbd_lu_t *sl); 305 int sbd_unmap(sbd_lu_t *sl, dkioc_free_list_t *dfl); 306 307 #ifdef __cplusplus 308 } 309 #endif 310 311 #endif /* _STMF_SBD_H */ 312