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