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