1 /* $OpenBSD: softraidvar.h,v 1.106 2011/07/07 03:50:00 tedu Exp $ */ 2 /* 3 * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us> 4 * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef SOFTRAIDVAR_H 20 #define SOFTRAIDVAR_H 21 22 #include <sys/socket.h> 23 #include <sys/vnode.h> 24 25 #include <net/if.h> 26 #include <netinet/in.h> 27 #include <netinet/if_ether.h> 28 29 #include <crypto/md5.h> 30 31 #define SR_META_VERSION 4 /* bump when sr_metadata changes */ 32 #define SR_META_SIZE 64 /* save space at chunk beginning */ 33 #define SR_META_OFFSET 16 /* skip 8192 bytes at chunk beginning */ 34 35 #define SR_META_V3_SIZE 64 36 #define SR_META_V3_OFFSET 16 37 #define SR_META_V3_DATA_OFFSET (SR_META_V3_OFFSET + SR_META_V3_SIZE) 38 39 #define SR_META_F_NATIVE 0 /* Native metadata format. */ 40 #define SR_META_F_INVALID -1 41 42 #define SR_BOOT_OFFSET (SR_META_OFFSET + SR_META_SIZE) 43 #define SR_BOOT_LOADER_SIZE 320 /* Size of boot loader storage. */ 44 #define SR_BOOT_LOADER_OFFSET SR_BOOT_OFFSET 45 #define SR_BOOT_BLOCKS_SIZE 128 /* Size of boot block storage. */ 46 #define SR_BOOT_BLOCKS_OFFSET (SR_BOOT_LOADER_OFFSET + SR_BOOT_LOADER_SIZE) 47 #define SR_BOOT_SIZE (SR_BOOT_LOADER_SIZE + SR_BOOT_BLOCKS_SIZE) 48 49 #define SR_HEADER_SIZE (SR_META_SIZE + SR_BOOT_SIZE) 50 #define SR_DATA_OFFSET (SR_META_OFFSET + SR_HEADER_SIZE) 51 52 #define SR_HOTSPARE_LEVEL 0xffffffff 53 #define SR_HOTSPARE_VOLID 0xffffffff 54 #define SR_KEYDISK_LEVEL 0xfffffffe 55 #define SR_KEYDISK_VOLID 0xfffffffe 56 57 #define SR_UUID_MAX 16 58 struct sr_uuid { 59 u_int8_t sui_id[SR_UUID_MAX]; 60 } __packed; 61 62 struct sr_disk { 63 dev_t sdk_devno; 64 SLIST_ENTRY(sr_disk) sdk_link; 65 }; 66 SLIST_HEAD(sr_disk_head, sr_disk); 67 68 struct sr_metadata { 69 struct sr_meta_invariant { 70 /* do not change order of ssd_magic, ssd_version */ 71 u_int64_t ssd_magic; /* magic id */ 72 #define SR_MAGIC 0x4d4152436372616dLLU 73 u_int32_t ssd_version; /* meta data version */ 74 u_int32_t ssd_vol_flags; /* volume specific flags. */ 75 struct sr_uuid ssd_uuid; /* unique identifier */ 76 77 /* chunks */ 78 u_int32_t ssd_chunk_no; /* number of chunks */ 79 u_int32_t ssd_chunk_id; /* chunk identifier */ 80 81 /* optional */ 82 u_int32_t ssd_opt_no; /* nr of optional md elements */ 83 u_int32_t ssd_pad; 84 85 /* volume metadata */ 86 u_int32_t ssd_volid; /* volume id */ 87 u_int32_t ssd_level; /* raid level */ 88 int64_t ssd_size; /* virt disk size in blocks */ 89 char ssd_vendor[8]; /* scsi vendor */ 90 char ssd_product[16];/* scsi product */ 91 char ssd_revision[4];/* scsi revision */ 92 /* optional volume members */ 93 u_int32_t ssd_strip_size; /* strip size */ 94 } _sdd_invariant; 95 #define ssdi _sdd_invariant 96 /* MD5 of invariant metadata */ 97 u_int8_t ssd_checksum[MD5_DIGEST_LENGTH]; 98 char ssd_devname[32];/* /dev/XXXXX */ 99 u_int32_t ssd_meta_flags; 100 #define SR_META_DIRTY 0x1 101 u_int32_t ssd_data_offset; 102 u_int64_t ssd_ondisk; /* on disk version counter */ 103 int64_t ssd_rebuild; /* last block of rebuild */ 104 } __packed; 105 106 struct sr_meta_chunk { 107 struct sr_meta_chunk_invariant { 108 u_int32_t scm_volid; /* vd we belong to */ 109 u_int32_t scm_chunk_id; /* chunk id */ 110 char scm_devname[32];/* /dev/XXXXX */ 111 int64_t scm_size; /* size of partition in blocks*/ 112 int64_t scm_coerced_size; /* coerced sz of part in blk*/ 113 struct sr_uuid scm_uuid; /* unique identifier */ 114 } _scm_invariant; 115 #define scmi _scm_invariant 116 /* MD5 of invariant chunk metadata */ 117 u_int8_t scm_checksum[MD5_DIGEST_LENGTH]; 118 u_int32_t scm_status; /* use bio bioc_disk status */ 119 } __packed; 120 121 #define SR_CRYPTO_MAXKEYBYTES 32 /* max bytes in a key (AES-XTS-256) */ 122 #define SR_CRYPTO_MAXKEYS 32 /* max keys per volume */ 123 #define SR_CRYPTO_KEYBITS 512 /* AES-XTS with 2 * 256 bit keys */ 124 #define SR_CRYPTO_KEYBYTES (SR_CRYPTO_KEYBITS >> 3) 125 #define SR_CRYPTO_KDFHINTBYTES 256 /* size of opaque KDF hint */ 126 #define SR_CRYPTO_CHECKBYTES 64 /* size of generic key chksum struct */ 127 #define SR_CRYPTO_KEY_BLKSHIFT 30 /* 0.5TB per key */ 128 129 /* 130 * Check that HMAC-SHA1_k(decrypted scm_key) == sch_mac, where 131 * k = SHA1(masking key) 132 */ 133 struct sr_crypto_chk_hmac_sha1 { 134 u_int8_t sch_mac[20]; 135 } __packed; 136 137 struct sr_meta_crypto { 138 u_int32_t scm_alg; /* vol crypto algorithm */ 139 #define SR_CRYPTOA_AES_XTS_128 1 140 #define SR_CRYPTOA_AES_XTS_256 2 141 u_int32_t scm_flags; /* key & kdfhint valid */ 142 #define SR_CRYPTOF_INVALID (0) 143 #define SR_CRYPTOF_KEY (1<<0) 144 #define SR_CRYPTOF_KDFHINT (1<<1) 145 u_int32_t scm_mask_alg; /* disk key masking crypt alg */ 146 #define SR_CRYPTOM_AES_ECB_256 1 147 u_int32_t scm_pad1; 148 u_int8_t scm_reserved[64]; 149 150 /* symmetric keys used for disk encryption */ 151 u_int8_t scm_key[SR_CRYPTO_MAXKEYS][SR_CRYPTO_KEYBYTES]; 152 /* hint to kdf algorithm (opaque to kernel) */ 153 u_int8_t scm_kdfhint[SR_CRYPTO_KDFHINTBYTES]; 154 155 u_int32_t scm_check_alg; /* key chksum algorithm */ 156 #define SR_CRYPTOC_HMAC_SHA1 1 157 u_int32_t scm_pad2; 158 union { 159 struct sr_crypto_chk_hmac_sha1 chk_hmac_sha1; 160 u_int8_t chk_reserved2[64]; 161 } _scm_chk; 162 #define chk_hmac_sha1 _scm_chk.chk_hmac_sha1 163 } __packed; 164 165 struct sr_meta_boot { 166 u_int64_t sbm_root_uid; 167 u_int32_t sbm_bootblk_size; 168 u_int32_t sbm_bootldr_size; 169 } __packed; 170 171 struct sr_meta_keydisk { 172 u_int8_t skm_maskkey[SR_CRYPTO_MAXKEYBYTES]; 173 } __packed; 174 175 struct sr_meta_opt { 176 struct sr_meta_opt_invariant { 177 u_int32_t som_type; /* optional type */ 178 #define SR_OPT_INVALID 0x00 179 #define SR_OPT_CRYPTO 0x01 180 #define SR_OPT_BOOT 0x02 181 #define SR_OPT_KEYDISK 0x03 182 u_int32_t som_pad; 183 union { 184 struct sr_meta_crypto smm_crypto; 185 struct sr_meta_boot smm_boot; 186 struct sr_meta_keydisk smm_keydisk; 187 } som_meta; 188 } _som_invariant; 189 #define somi _som_invariant 190 #define somi_crypto _som_invariant.smm_crypto 191 #define somi_boot _som_invariant.smm_boot 192 /* MD5 of invariant optional metadata */ 193 u_int8_t som_checksum[MD5_DIGEST_LENGTH]; 194 } __packed; 195 196 struct sr_meta_opt_item { 197 struct sr_meta_opt omi_om; 198 SLIST_ENTRY(sr_meta_opt_item) omi_link; 199 }; 200 201 SLIST_HEAD(sr_meta_opt_head, sr_meta_opt_item); 202 203 /* this is a generic hint for KDF done in userland, not interpreted by the kernel. */ 204 struct sr_crypto_genkdf { 205 u_int32_t len; 206 u_int32_t type; 207 #define SR_CRYPTOKDFT_INVALID 0 208 #define SR_CRYPTOKDFT_PBKDF2 1 209 #define SR_CRYPTOKDFT_KEYDISK 2 210 }; 211 212 /* this is a hint for KDF using PKCS#5. Not interpreted by the kernel */ 213 struct sr_crypto_kdf_pbkdf2 { 214 u_int32_t len; 215 u_int32_t type; 216 u_int32_t rounds; 217 u_int8_t salt[128]; 218 }; 219 220 /* 221 * this structure is used to copy masking keys and KDF hints from/to userland. 222 * the embedded hint structures are not interpreted by the kernel. 223 */ 224 struct sr_crypto_kdfinfo { 225 u_int32_t len; 226 u_int32_t flags; 227 #define SR_CRYPTOKDF_INVALID (0) 228 #define SR_CRYPTOKDF_KEY (1<<0) 229 #define SR_CRYPTOKDF_HINT (1<<1) 230 u_int8_t maskkey[SR_CRYPTO_MAXKEYBYTES]; 231 union { 232 struct sr_crypto_genkdf generic; 233 struct sr_crypto_kdf_pbkdf2 pbkdf2; 234 } _kdfhint; 235 #define genkdf _kdfhint.generic 236 #define pbkdf2 _kdfhint.pbkdf2 237 }; 238 239 #define SR_IOCTL_GET_KDFHINT 0x01 /* Get KDF hint. */ 240 #define SR_IOCTL_CHANGE_PASSPHRASE 0x02 /* Change passphase. */ 241 242 struct sr_crypto_kdfpair { 243 void *kdfinfo1; 244 u_int32_t kdfsize1; 245 void *kdfinfo2; 246 u_int32_t kdfsize2; 247 }; 248 249 struct sr_aoe_config { 250 char nic[IFNAMSIZ]; 251 struct ether_addr dsteaddr; 252 unsigned short shelf; 253 unsigned char slot; 254 }; 255 256 257 #ifdef _KERNEL 258 #include <dev/biovar.h> 259 260 #include <sys/buf.h> 261 #include <sys/pool.h> 262 #include <sys/queue.h> 263 #include <sys/rwlock.h> 264 265 #include <scsi/scsi_all.h> 266 #include <scsi/scsi_disk.h> 267 #include <scsi/scsiconf.h> 268 269 #define DEVNAME(_s) ((_s)->sc_dev.dv_xname) 270 271 /* #define SR_DEBUG */ 272 #ifdef SR_DEBUG 273 extern u_int32_t sr_debug; 274 #define DPRINTF(x...) do { if (sr_debug) printf(x); } while(0) 275 #define DNPRINTF(n,x...) do { if (sr_debug & n) printf(x); } while(0) 276 #define SR_D_CMD 0x0001 277 #define SR_D_INTR 0x0002 278 #define SR_D_MISC 0x0004 279 #define SR_D_IOCTL 0x0008 280 #define SR_D_CCB 0x0010 281 #define SR_D_WU 0x0020 282 #define SR_D_META 0x0040 283 #define SR_D_DIS 0x0080 284 #define SR_D_STATE 0x0100 285 #else 286 #define DPRINTF(x...) 287 #define DNPRINTF(n,x...) 288 #endif 289 290 #define SR_MAXFER MAXPHYS 291 #define SR_MAX_LD 256 292 #define SR_MAX_CMDS 16 293 #define SR_MAX_STATES 7 294 #define SR_VM_IGNORE_DIRTY 1 295 #define SR_REBUILD_IO_SIZE 128 /* blocks */ 296 297 /* forward define to prevent dependency goo */ 298 struct sr_softc; 299 300 struct sr_ccb { 301 struct buf ccb_buf; /* MUST BE FIRST!! */ 302 303 struct sr_workunit *ccb_wu; 304 struct sr_discipline *ccb_dis; 305 306 int ccb_target; 307 int ccb_state; 308 #define SR_CCB_FREE 0 309 #define SR_CCB_INPROGRESS 1 310 #define SR_CCB_OK 2 311 #define SR_CCB_FAILED 3 312 313 int ccb_flag; 314 #define SR_CCBF_FREEBUF (1<<0) /* free ccb_buf.b_data */ 315 316 void *ccb_opaque; /* discipline usable pointer */ 317 318 TAILQ_ENTRY(sr_ccb) ccb_link; 319 }; 320 321 TAILQ_HEAD(sr_ccb_list, sr_ccb); 322 323 struct sr_workunit { 324 struct scsi_xfer *swu_xs; 325 struct sr_discipline *swu_dis; 326 327 int swu_state; 328 #define SR_WU_FREE 0 329 #define SR_WU_INPROGRESS 1 330 #define SR_WU_OK 2 331 #define SR_WU_FAILED 3 332 #define SR_WU_PARTIALLYFAILED 4 333 #define SR_WU_DEFERRED 5 334 #define SR_WU_PENDING 6 335 #define SR_WU_RESTART 7 336 #define SR_WU_REQUEUE 8 337 338 int swu_flags; /* additional hints */ 339 #define SR_WUF_REBUILD (1<<0) /* rebuild io */ 340 #define SR_WUF_REBUILDIOCOMP (1<<1) /* rbuild io complete */ 341 #define SR_WUF_FAIL (1<<2) /* RAID6: failure */ 342 #define SR_WUF_FAILIOCOMP (1<<3) 343 344 int swu_fake; /* faked wu */ 345 /* workunit io range */ 346 daddr64_t swu_blk_start; 347 daddr64_t swu_blk_end; 348 349 /* in flight totals */ 350 u_int32_t swu_ios_complete; 351 u_int32_t swu_ios_failed; 352 u_int32_t swu_ios_succeeded; 353 354 /* number of ios that makes up the whole work unit */ 355 u_int32_t swu_io_count; 356 357 /* colliding wu */ 358 struct sr_workunit *swu_collider; 359 360 /* all ios that make up this workunit */ 361 struct sr_ccb_list swu_ccb; 362 363 /* task memory */ 364 struct workq_task swu_wqt; 365 struct workq_task swu_intr; 366 int swu_cb_active; /* in callback */ 367 368 TAILQ_ENTRY(sr_workunit) swu_link; 369 }; 370 371 TAILQ_HEAD(sr_wu_list, sr_workunit); 372 373 /* RAID 0 */ 374 #define SR_RAID0_NOWU 16 375 struct sr_raid0 { 376 int32_t sr0_strip_bits; 377 }; 378 379 /* RAID 1 */ 380 #define SR_RAID1_NOWU 16 381 struct sr_raid1 { 382 u_int32_t sr1_counter; 383 }; 384 385 /* RAID 4 */ 386 #define SR_RAIDP_NOWU 16 387 struct sr_raidp { 388 int32_t srp_strip_bits; 389 }; 390 391 /* RAID 6 */ 392 #define SR_RAID6_NOWU 16 393 struct sr_raid6 { 394 int32_t sr6_strip_bits; 395 }; 396 397 /* CRYPTO */ 398 TAILQ_HEAD(sr_crypto_wu_head, sr_crypto_wu); 399 #define SR_CRYPTO_NOWU 16 400 401 struct sr_crypto { 402 struct mutex scr_mutex; 403 struct sr_crypto_wu_head scr_wus; 404 struct sr_meta_crypto *scr_meta; 405 struct sr_chunk *key_disk; 406 407 /* XXX only keep scr_sid over time */ 408 u_int8_t scr_key[SR_CRYPTO_MAXKEYS][SR_CRYPTO_KEYBYTES]; 409 u_int8_t scr_maskkey[SR_CRYPTO_MAXKEYBYTES]; 410 u_int64_t scr_sid[SR_CRYPTO_MAXKEYS]; 411 }; 412 413 /* ata over ethernet */ 414 #define SR_RAIDAOE_NOWU 2 415 struct sr_aoe { 416 struct aoe_handler *sra_ah; 417 int sra_tag; 418 struct ifnet *sra_ifp; 419 struct ether_addr sra_eaddr; 420 }; 421 422 struct sr_boot_chunk { 423 struct sr_metadata sbc_metadata; 424 dev_t sbc_mm; 425 u_int32_t sbc_chunk_id; 426 int sbc_used; 427 428 SLIST_ENTRY(sr_boot_chunk) sbc_link; 429 }; 430 431 SLIST_HEAD(sr_boot_chunk_head, sr_boot_chunk); 432 433 struct sr_boot_volume { 434 struct sr_uuid sbv_uuid; /* Volume UUID. */ 435 u_int32_t sbv_level; /* Level. */ 436 u_int32_t sbv_volid; /* Volume ID. */ 437 u_int32_t sbv_chunk_no; /* Number of chunks. */ 438 u_int32_t sbv_dev_no; /* Number of devs discovered. */ 439 440 struct sr_boot_chunk_head sbv_chunks; /* List of chunks. */ 441 442 SLIST_ENTRY(sr_boot_volume) sbv_link; 443 }; 444 445 SLIST_HEAD(sr_boot_volume_head, sr_boot_volume); 446 447 struct sr_chunk { 448 struct sr_meta_chunk src_meta; /* chunk meta data */ 449 450 /* runtime data */ 451 dev_t src_dev_mm; /* major/minor */ 452 struct vnode *src_vn; /* vnode */ 453 454 /* helper members before metadata makes it onto the chunk */ 455 int src_meta_ondisk;/* set when meta is on disk */ 456 char src_devname[32]; 457 int64_t src_size; /* in blocks */ 458 459 SLIST_ENTRY(sr_chunk) src_link; 460 }; 461 462 SLIST_HEAD(sr_chunk_head, sr_chunk); 463 464 struct sr_volume { 465 /* runtime data */ 466 struct sr_chunk_head sv_chunk_list; /* linked list of all chunks */ 467 struct sr_chunk **sv_chunks; /* array to same chunks */ 468 469 /* sensors */ 470 struct ksensor sv_sensor; 471 int sv_sensor_attached; 472 int sv_sensor_valid; 473 }; 474 475 struct sr_discipline { 476 struct sr_softc *sd_sc; /* link back to sr softc */ 477 u_int8_t sd_type; /* type of discipline */ 478 #define SR_MD_RAID0 0 479 #define SR_MD_RAID1 1 480 #define SR_MD_RAID5 2 481 #define SR_MD_CACHE 3 482 #define SR_MD_CRYPTO 4 483 #define SR_MD_AOE_INIT 5 484 #define SR_MD_AOE_TARG 6 485 #define SR_MD_RAID4 7 486 #define SR_MD_RAID6 8 487 char sd_name[10]; /* human readable dis name */ 488 u_int16_t sd_target; /* scsibus target discipline uses */ 489 490 u_int32_t sd_capabilities; 491 #define SR_CAP_SYSTEM_DISK 0x00000001 492 #define SR_CAP_AUTO_ASSEMBLE 0x00000002 493 #define SR_CAP_REBUILD 0x00000004 494 495 union { 496 struct sr_raid0 mdd_raid0; 497 struct sr_raid1 mdd_raid1; 498 struct sr_raidp mdd_raidp; 499 struct sr_raid6 mdd_raid6; 500 struct sr_crypto mdd_crypto; 501 #ifdef AOE 502 struct sr_aoe mdd_aoe; 503 #endif /* AOE */ 504 } sd_dis_specific;/* dis specific members */ 505 #define mds sd_dis_specific 506 507 struct workq *sd_workq; 508 509 /* discipline metadata */ 510 struct sr_metadata *sd_meta; /* in memory copy of metadata */ 511 void *sd_meta_foreign; /* non native metadata */ 512 u_int32_t sd_meta_flags; 513 int sd_meta_type; /* metadata functions */ 514 struct sr_meta_opt_head sd_meta_opt; /* optional metadata. */ 515 516 int sd_sync; 517 int sd_must_flush; 518 519 int sd_deleted; 520 521 struct device *sd_scsibus_dev; 522 523 /* discipline volume */ 524 struct sr_volume sd_vol; /* volume associated */ 525 int sd_vol_status; /* runtime vol status */ 526 /* discipline resources */ 527 struct sr_ccb *sd_ccb; 528 struct sr_ccb_list sd_ccb_freeq; 529 u_int32_t sd_max_ccb_per_wu; 530 531 struct sr_workunit *sd_wu; /* all workunits */ 532 u_int32_t sd_max_wu; 533 int sd_reb_active; /* rebuild in progress */ 534 int sd_reb_abort; /* abort rebuild */ 535 int sd_ready; /* fully operational */ 536 537 struct sr_wu_list sd_wu_freeq; /* free wu queue */ 538 struct sr_wu_list sd_wu_pendq; /* pending wu queue */ 539 struct sr_wu_list sd_wu_defq; /* deferred wu queue */ 540 541 struct mutex sd_wu_mtx; 542 struct scsi_iopool sd_iopool; 543 544 /* discipline stats */ 545 int sd_wu_pending; 546 u_int64_t sd_wu_collisions; 547 548 /* discipline functions */ 549 int (*sd_create)(struct sr_discipline *, 550 struct bioc_createraid *, int, int64_t); 551 int (*sd_assemble)(struct sr_discipline *, 552 struct bioc_createraid *, int); 553 int (*sd_alloc_resources)(struct sr_discipline *); 554 int (*sd_free_resources)(struct sr_discipline *); 555 int (*sd_ioctl_handler)(struct sr_discipline *, 556 struct bioc_discipline *); 557 int (*sd_start_discipline)(struct sr_discipline *); 558 void (*sd_set_chunk_state)(struct sr_discipline *, 559 int, int); 560 void (*sd_set_vol_state)(struct sr_discipline *); 561 int (*sd_openings)(struct sr_discipline *); 562 int (*sd_meta_opt_load)(struct sr_discipline *, 563 struct sr_meta_opt *); 564 565 /* SCSI emulation */ 566 struct scsi_sense_data sd_scsi_sense; 567 int (*sd_scsi_rw)(struct sr_workunit *); 568 int (*sd_scsi_sync)(struct sr_workunit *); 569 int (*sd_scsi_tur)(struct sr_workunit *); 570 int (*sd_scsi_start_stop)(struct sr_workunit *); 571 int (*sd_scsi_inquiry)(struct sr_workunit *); 572 int (*sd_scsi_read_cap)(struct sr_workunit *); 573 int (*sd_scsi_req_sense)(struct sr_workunit *); 574 575 /* background operation */ 576 struct proc *sd_background_proc; 577 }; 578 579 struct sr_softc { 580 struct device sc_dev; 581 582 int (*sc_ioctl)(struct device *, u_long, caddr_t); 583 void (*sc_shutdownhook)(void *); 584 585 struct rwlock sc_lock; 586 587 struct sr_chunk_head sc_hotspare_list; /* List of hotspares. */ 588 struct sr_chunk **sc_hotspares; /* Array to hotspare chunks. */ 589 struct rwlock sc_hs_lock; /* Lock for hotspares list. */ 590 int sc_hotspare_no; /* Number of hotspares. */ 591 592 struct ksensordev sc_sensordev; 593 struct sensor_task *sc_sensor_task; 594 595 struct scsi_link sc_link; /* scsi prototype link */ 596 struct scsibus_softc *sc_scsibus; 597 598 /* 599 * XXX expensive, alternative would be nice but has to be cheap 600 * since the target lookup happens on each IO 601 */ 602 struct sr_discipline *sc_dis[SR_MAX_LD]; 603 }; 604 605 /* hotplug */ 606 void sr_hotplug_register(struct sr_discipline *, void *); 607 void sr_hotplug_unregister(struct sr_discipline *, void *); 608 609 /* Hotspare and rebuild. */ 610 void sr_hotspare_rebuild_callback(void *, void *); 611 612 /* work units & ccbs */ 613 int sr_ccb_alloc(struct sr_discipline *); 614 void sr_ccb_free(struct sr_discipline *); 615 struct sr_ccb *sr_ccb_get(struct sr_discipline *); 616 void sr_ccb_put(struct sr_ccb *); 617 int sr_wu_alloc(struct sr_discipline *); 618 void sr_wu_free(struct sr_discipline *); 619 void *sr_wu_get(void *); 620 void sr_wu_put(void *, void *); 621 622 /* misc functions */ 623 int32_t sr_validate_stripsize(u_int32_t); 624 int sr_meta_read(struct sr_discipline *); 625 int sr_meta_native_read(struct sr_discipline *, dev_t, 626 struct sr_metadata *, void *); 627 int sr_meta_validate(struct sr_discipline *, dev_t, 628 struct sr_metadata *, void *); 629 void sr_meta_save_callback(void *, void *); 630 int sr_meta_save(struct sr_discipline *, u_int32_t); 631 void sr_meta_getdevname(struct sr_softc *, dev_t, char *, 632 int); 633 void sr_checksum(struct sr_softc *, void *, void *, 634 u_int32_t); 635 int sr_validate_io(struct sr_workunit *, daddr64_t *, 636 char *); 637 int sr_check_io_collision(struct sr_workunit *); 638 void sr_scsi_done(struct sr_discipline *, 639 struct scsi_xfer *); 640 int sr_chunk_in_use(struct sr_softc *, dev_t); 641 642 /* discipline functions */ 643 int sr_raid_inquiry(struct sr_workunit *); 644 int sr_raid_read_cap(struct sr_workunit *); 645 int sr_raid_tur(struct sr_workunit *); 646 int sr_raid_request_sense( struct sr_workunit *); 647 int sr_raid_start_stop(struct sr_workunit *); 648 int sr_raid_sync(struct sr_workunit *); 649 void sr_raid_startwu(struct sr_workunit *); 650 651 /* Discipline specific initialisation. */ 652 void sr_raid0_discipline_init(struct sr_discipline *); 653 void sr_raid1_discipline_init(struct sr_discipline *); 654 void sr_raidp_discipline_init(struct sr_discipline *, 655 u_int8_t); 656 void sr_raid6_discipline_init(struct sr_discipline *); 657 void sr_crypto_discipline_init(struct sr_discipline *); 658 void sr_aoe_discipline_init(struct sr_discipline *); 659 void sr_aoe_server_discipline_init(struct sr_discipline *); 660 661 /* raid 1 */ 662 /* XXX - currently (ab)used by AOE and CRYPTO. */ 663 void sr_raid1_set_chunk_state(struct sr_discipline *, 664 int, int); 665 void sr_raid1_set_vol_state(struct sr_discipline *); 666 667 /* Crypto discipline hooks. */ 668 int sr_crypto_get_kdf(struct bioc_createraid *, 669 struct sr_discipline *); 670 int sr_crypto_create_keys(struct sr_discipline *); 671 struct sr_chunk * sr_crypto_create_key_disk(struct sr_discipline *, dev_t); 672 struct sr_chunk * sr_crypto_read_key_disk(struct sr_discipline *, dev_t); 673 674 #ifdef SR_DEBUG 675 void sr_dump_mem(u_int8_t *, int); 676 #endif 677 678 #endif /* _KERNEL */ 679 680 #endif /* SOFTRAIDVAR_H */ 681