diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2011-12-26 14:54:53 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2011-12-26 14:54:53 +0000 |
commit | 3b57857da17bb5a3c80aa3244494483ee4190064 (patch) | |
tree | cc1e3e8bd8e49ba8c283a86b19840ba3eec8438c /sys | |
parent | f549c5018ad022aa6daab6a52a0e023a8fc28734 (diff) |
Provide default set chunk state and set volume state functions which
cover the no redundancy/no rebuild case. Use these for the AOE, crypto and
RAID 0 disciplines.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/softraid.c | 114 | ||||
-rw-r--r-- | sys/dev/softraid_aoe.c | 13 | ||||
-rw-r--r-- | sys/dev/softraid_crypto.c | 5 | ||||
-rw-r--r-- | sys/dev/softraid_raid0.c | 112 | ||||
-rw-r--r-- | sys/dev/softraid_raid1.c | 4 | ||||
-rw-r--r-- | sys/dev/softraidvar.h | 8 |
6 files changed, 122 insertions, 134 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 9fdccfdb417..1eee7e40c93 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.259 2011/12/25 15:28:17 jsing Exp $ */ +/* $OpenBSD: softraid.c,v 1.260 2011/12/26 14:54:52 jsing Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -112,6 +112,8 @@ void sr_chunks_unwind(struct sr_softc *, void sr_discipline_free(struct sr_discipline *); void sr_discipline_shutdown(struct sr_discipline *, int); int sr_discipline_init(struct sr_discipline *, int); +void sr_set_chunk_state(struct sr_discipline *, int, int); +void sr_set_vol_state(struct sr_discipline *); /* utility functions */ void sr_shutdown(struct sr_softc *); @@ -3650,8 +3652,8 @@ sr_discipline_init(struct sr_discipline *sd, int level) sd->sd_scsi_start_stop = sr_raid_start_stop; sd->sd_scsi_sync = sr_raid_sync; sd->sd_scsi_rw = NULL; - sd->sd_set_chunk_state = NULL; - sd->sd_set_vol_state = NULL; + sd->sd_set_chunk_state = sr_set_chunk_state; + sd->sd_set_vol_state = sr_set_vol_state; sd->sd_start_discipline = NULL; switch (level) { @@ -3897,6 +3899,112 @@ sr_raid_startwu(struct sr_workunit *wu) } void +sr_set_chunk_state(struct sr_discipline *sd, int c, int new_state) +{ + int old_state, s; + + DNPRINTF(SR_D_STATE, "%s: %s: %s: sr_set_chunk_state %d -> %d\n", + DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname, + sd->sd_vol.sv_chunks[c]->src_meta.scmi.scm_devname, c, new_state); + + /* ok to go to splbio since this only happens in error path */ + s = splbio(); + old_state = sd->sd_vol.sv_chunks[c]->src_meta.scm_status; + + /* multiple IOs to the same chunk that fail will come through here */ + if (old_state == new_state) + goto done; + + switch (old_state) { + case BIOC_SDONLINE: + if (new_state == BIOC_SDOFFLINE) + break; + else + goto die; + break; + + case BIOC_SDOFFLINE: + goto die; + + default: +die: + splx(s); /* XXX */ + panic("%s: %s: %s: invalid chunk state transition " + "%d -> %d\n", DEVNAME(sd->sd_sc), + sd->sd_meta->ssd_devname, + sd->sd_vol.sv_chunks[c]->src_meta.scmi.scm_devname, + old_state, new_state); + /* NOTREACHED */ + } + + sd->sd_vol.sv_chunks[c]->src_meta.scm_status = new_state; + sd->sd_set_vol_state(sd); + + sd->sd_must_flush = 1; + workq_add_task(NULL, 0, sr_meta_save_callback, sd, NULL); +done: + splx(s); +} + +void +sr_set_vol_state(struct sr_discipline *sd) +{ + int states[SR_MAX_STATES]; + int new_state, i, s, nd; + int old_state = sd->sd_vol_status; + + DNPRINTF(SR_D_STATE, "%s: %s: sr_set_vol_state\n", + DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname); + + nd = sd->sd_meta->ssdi.ssd_chunk_no; + + for (i = 0; i < SR_MAX_STATES; i++) + states[i] = 0; + + for (i = 0; i < nd; i++) { + s = sd->sd_vol.sv_chunks[i]->src_meta.scm_status; + if (s >= SR_MAX_STATES) + panic("%s: %s: %s: invalid chunk state", + DEVNAME(sd->sd_sc), + sd->sd_meta->ssd_devname, + sd->sd_vol.sv_chunks[i]->src_meta.scmi.scm_devname); + states[s]++; + } + + if (states[BIOC_SDONLINE] == nd) + new_state = BIOC_SVONLINE; + else + new_state = BIOC_SVOFFLINE; + + DNPRINTF(SR_D_STATE, "%s: %s: sr_set_vol_state %d -> %d\n", + DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname, + old_state, new_state); + + switch (old_state) { + case BIOC_SVONLINE: + if (new_state == BIOC_SVOFFLINE || new_state == BIOC_SVONLINE) + break; + else + goto die; + break; + + case BIOC_SVOFFLINE: + /* XXX this might be a little too much */ + goto die; + + default: +die: + panic("%s: %s: invalid volume state transition " + "%d -> %d\n", DEVNAME(sd->sd_sc), + sd->sd_meta->ssd_devname, + old_state, new_state); + /* NOTREACHED */ + } + + sd->sd_vol_status = new_state; +} + +void sr_checksum_print(u_int8_t *md5) { int i; diff --git a/sys/dev/softraid_aoe.c b/sys/dev/softraid_aoe.c index d067b9d1f43..978a1905c4f 100644 --- a/sys/dev/softraid_aoe.c +++ b/sys/dev/softraid_aoe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_aoe.c,v 1.24 2011/12/25 15:28:17 jsing Exp $ */ +/* $OpenBSD: softraid_aoe.c,v 1.25 2011/12/26 14:54:52 jsing Exp $ */ /* * Copyright (c) 2008 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2008 Marco Peereboom <marco@openbsd.org> @@ -93,9 +93,6 @@ sr_aoe_discipline_init(struct sr_discipline *sd) sd->sd_create = sr_aoe_create; sd->sd_free_resources = sr_aoe_free_resources; sd->sd_scsi_rw = sr_aoe_rw; - /* XXX reuse raid 1 functions for now FIXME */ - sd->sd_set_chunk_state = sr_raid1_set_chunk_state; - sd->sd_set_vol_state = sr_raid1_set_vol_state; } void @@ -107,12 +104,11 @@ sr_aoe_server_discipline_init(struct sr_discipline *sd) sd->sd_capabilities = 0; sd->sd_max_wu = SR_RAIDAOE_NOWU; - /* Setup discipline pointers. */ - sd->sd_create = sr_aoe_server_create; - sd->sd_assemble = sr_aoe_server_assemble; + /* Setup discipline specific function pointers. */ sd->sd_alloc_resources = sr_aoe_server_alloc_resources; + sd->sd_assemble = sr_aoe_server_assemble; + sd->sd_create = sr_aoe_server_create; sd->sd_free_resources = sr_aoe_server_free_resources; - sd->sd_start_discipline = sr_aoe_server_start; sd->sd_scsi_inquiry = NULL; sd->sd_scsi_read_cap = NULL; sd->sd_scsi_tur = NULL; @@ -122,6 +118,7 @@ sr_aoe_server_discipline_init(struct sr_discipline *sd) sd->sd_scsi_rw = NULL; sd->sd_set_chunk_state = NULL; sd->sd_set_vol_state = NULL; + sd->sd_start_discipline = sr_aoe_server_start; } /* AOE initiator */ diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index 2c85ce93227..1e8b55096b6 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.76 2011/12/25 15:28:17 jsing Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.77 2011/12/26 14:54:52 jsing Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org> @@ -128,9 +128,6 @@ sr_crypto_discipline_init(struct sr_discipline *sd) sd->sd_ioctl_handler = sr_crypto_ioctl; sd->sd_meta_opt_handler = sr_crypto_meta_opt_handler; sd->sd_scsi_rw = sr_crypto_rw; - /* XXX reuse raid 1 functions for now FIXME */ - sd->sd_set_chunk_state = sr_raid1_set_chunk_state; - sd->sd_set_vol_state = sr_raid1_set_vol_state; } int diff --git a/sys/dev/softraid_raid0.c b/sys/dev/softraid_raid0.c index b36303eb73e..a9c7e5a7d60 100644 --- a/sys/dev/softraid_raid0.c +++ b/sys/dev/softraid_raid0.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid0.c,v 1.24 2011/12/25 15:28:17 jsing Exp $ */ +/* $OpenBSD: softraid_raid0.c,v 1.25 2011/12/26 14:54:52 jsing Exp $ */ /* * Copyright (c) 2008 Marco Peereboom <marco@peereboom.us> * @@ -52,8 +52,6 @@ int sr_raid0_alloc_resources(struct sr_discipline *); int sr_raid0_free_resources(struct sr_discipline *); int sr_raid0_rw(struct sr_workunit *); void sr_raid0_intr(struct buf *); -void sr_raid0_set_chunk_state(struct sr_discipline *, int, int); -void sr_raid0_set_vol_state(struct sr_discipline *); /* Discipline initialisation. */ void @@ -71,8 +69,6 @@ sr_raid0_discipline_init(struct sr_discipline *sd) sd->sd_create = sr_raid0_create; sd->sd_free_resources = sr_raid0_free_resources; sd->sd_scsi_rw = sr_raid0_rw; - sd->sd_set_chunk_state = sr_raid0_set_chunk_state; - sd->sd_set_vol_state = sr_raid0_set_vol_state; } int @@ -156,112 +152,6 @@ sr_raid0_free_resources(struct sr_discipline *sd) return (rv); } -void -sr_raid0_set_chunk_state(struct sr_discipline *sd, int c, int new_state) -{ - int old_state, s; - - DNPRINTF(SR_D_STATE, "%s: %s: %s: sr_raid_set_chunk_state %d -> %d\n", - DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname, - sd->sd_vol.sv_chunks[c]->src_meta.scmi.scm_devname, c, new_state); - - /* ok to go to splbio since this only happens in error path */ - s = splbio(); - old_state = sd->sd_vol.sv_chunks[c]->src_meta.scm_status; - - /* multiple IOs to the same chunk that fail will come through here */ - if (old_state == new_state) - goto done; - - switch (old_state) { - case BIOC_SDONLINE: - if (new_state == BIOC_SDOFFLINE) - break; - else - goto die; - break; - - case BIOC_SDOFFLINE: - goto die; - - default: -die: - splx(s); /* XXX */ - panic("%s: %s: %s: invalid chunk state transition " - "%d -> %d\n", DEVNAME(sd->sd_sc), - sd->sd_meta->ssd_devname, - sd->sd_vol.sv_chunks[c]->src_meta.scmi.scm_devname, - old_state, new_state); - /* NOTREACHED */ - } - - sd->sd_vol.sv_chunks[c]->src_meta.scm_status = new_state; - sd->sd_set_vol_state(sd); - - sd->sd_must_flush = 1; - workq_add_task(NULL, 0, sr_meta_save_callback, sd, NULL); -done: - splx(s); -} - -void -sr_raid0_set_vol_state(struct sr_discipline *sd) -{ - int states[SR_MAX_STATES]; - int new_state, i, s, nd; - int old_state = sd->sd_vol_status; - - DNPRINTF(SR_D_STATE, "%s: %s: sr_raid_set_vol_state\n", - DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname); - - nd = sd->sd_meta->ssdi.ssd_chunk_no; - - for (i = 0; i < SR_MAX_STATES; i++) - states[i] = 0; - - for (i = 0; i < nd; i++) { - s = sd->sd_vol.sv_chunks[i]->src_meta.scm_status; - if (s >= SR_MAX_STATES) - panic("%s: %s: %s: invalid chunk state", - DEVNAME(sd->sd_sc), - sd->sd_meta->ssd_devname, - sd->sd_vol.sv_chunks[i]->src_meta.scmi.scm_devname); - states[s]++; - } - - if (states[BIOC_SDONLINE] == nd) - new_state = BIOC_SVONLINE; - else - new_state = BIOC_SVOFFLINE; - - DNPRINTF(SR_D_STATE, "%s: %s: sr_raid_set_vol_state %d -> %d\n", - DEVNAME(sd->sd_sc), sd->sd_meta->ssd_devname, - old_state, new_state); - - switch (old_state) { - case BIOC_SVONLINE: - if (new_state == BIOC_SVOFFLINE || new_state == BIOC_SVONLINE) - break; - else - goto die; - break; - - case BIOC_SVOFFLINE: - /* XXX this might be a little too much */ - goto die; - - default: -die: - panic("%s: %s: invalid volume state transition " - "%d -> %d\n", DEVNAME(sd->sd_sc), - sd->sd_meta->ssd_devname, - old_state, new_state); - /* NOTREACHED */ - } - - sd->sd_vol_status = new_state; -} - int sr_raid0_rw(struct sr_workunit *wu) { diff --git a/sys/dev/softraid_raid1.c b/sys/dev/softraid_raid1.c index 8647885e57d..34f7804a4b1 100644 --- a/sys/dev/softraid_raid1.c +++ b/sys/dev/softraid_raid1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid1.c,v 1.29 2011/12/25 15:28:17 jsing Exp $ */ +/* $OpenBSD: softraid_raid1.c,v 1.30 2011/12/26 14:54:52 jsing Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * @@ -53,6 +53,8 @@ int sr_raid1_free_resources(struct sr_discipline *); int sr_raid1_rw(struct sr_workunit *); void sr_raid1_intr(struct buf *); void sr_raid1_recreate_wu(struct sr_workunit *); +void sr_raid1_set_chunk_state(struct sr_discipline *, int, int); +void sr_raid1_set_vol_state(struct sr_discipline *); /* Discipline initialisation. */ void diff --git a/sys/dev/softraidvar.h b/sys/dev/softraidvar.h index e5a8f0de586..5e21721463a 100644 --- a/sys/dev/softraidvar.h +++ b/sys/dev/softraidvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: softraidvar.h,v 1.110 2011/11/11 12:32:11 jsing Exp $ */ +/* $OpenBSD: softraidvar.h,v 1.111 2011/12/26 14:54:52 jsing Exp $ */ /* * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -659,12 +659,6 @@ void sr_crypto_discipline_init(struct sr_discipline *); void sr_aoe_discipline_init(struct sr_discipline *); void sr_aoe_server_discipline_init(struct sr_discipline *); -/* raid 1 */ -/* XXX - currently (ab)used by AOE and CRYPTO. */ -void sr_raid1_set_chunk_state(struct sr_discipline *, - int, int); -void sr_raid1_set_vol_state(struct sr_discipline *); - /* Crypto discipline hooks. */ int sr_crypto_get_kdf(struct bioc_createraid *, struct sr_discipline *); |