diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2009-05-11 14:06:22 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2009-05-11 14:06:22 +0000 |
commit | 0db0de08581cd0034c8ad5abaa5d8db6154ff832 (patch) | |
tree | d0179cfabaa94aa9120e36145c405d0286819329 | |
parent | a7e71f851ecff560c7acaa6a3aef45856ce4ba42 (diff) |
Move the discipline initialisation code into discipline specific functions,
rather than initialising everything in softraid.c. This makes a discipline
more self-contained and reduces the number of function declarations needed
in softraidvar.h.
ok marco@
-rw-r--r-- | sys/dev/softraid.c | 106 | ||||
-rw-r--r-- | sys/dev/softraid_aoe.c | 69 | ||||
-rw-r--r-- | sys/dev/softraid_crypto.c | 28 | ||||
-rw-r--r-- | sys/dev/softraid_raid0.c | 38 | ||||
-rw-r--r-- | sys/dev/softraid_raid1.c | 35 | ||||
-rw-r--r-- | sys/dev/softraidvar.h | 36 |
6 files changed, 178 insertions, 134 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 00b6f5282fd..f5a5dbc8339 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.131 2009/04/29 00:52:30 marco Exp $ */ +/* $OpenBSD: softraid.c,v 1.132 2009/05/11 14:06:21 jsing Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -2272,114 +2272,24 @@ sr_discipline_init(struct sr_discipline *sd, int level) switch (level) { case 0: - /* fill out discipline members */ - sd->sd_type = SR_MD_RAID0; - sd->sd_max_ccb_per_wu = - (MAXPHYS / sd->sd_meta->ssdi.ssd_strip_size + 1) * - SR_RAID0_NOWU * sd->sd_meta->ssdi.ssd_chunk_no; - sd->sd_max_wu = SR_RAID0_NOWU; - - /* setup discipline pointers */ - sd->sd_alloc_resources = sr_raid0_alloc_resources; - sd->sd_free_resources = sr_raid0_free_resources; - sd->sd_start_discipline = NULL; - sd->sd_scsi_inquiry = sr_raid_inquiry; - sd->sd_scsi_read_cap = sr_raid_read_cap; - sd->sd_scsi_tur = sr_raid_tur; - sd->sd_scsi_req_sense = sr_raid_request_sense; - sd->sd_scsi_start_stop = sr_raid_start_stop; - sd->sd_scsi_sync = sr_raid_sync; - 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; + sr_raid0_discipline_init(sd); break; case 1: - /* fill out discipline members */ - sd->sd_type = SR_MD_RAID1; - sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; - sd->sd_max_wu = SR_RAID1_NOWU; - - /* setup discipline pointers */ - sd->sd_alloc_resources = sr_raid1_alloc_resources; - sd->sd_free_resources = sr_raid1_free_resources; - sd->sd_start_discipline = NULL; - sd->sd_scsi_inquiry = sr_raid_inquiry; - sd->sd_scsi_read_cap = sr_raid_read_cap; - sd->sd_scsi_tur = sr_raid_tur; - sd->sd_scsi_req_sense = sr_raid_request_sense; - sd->sd_scsi_start_stop = sr_raid_start_stop; - sd->sd_scsi_sync = sr_raid_sync; - sd->sd_scsi_rw = sr_raid1_rw; - sd->sd_set_chunk_state = sr_raid1_set_chunk_state; - sd->sd_set_vol_state = sr_raid1_set_vol_state; + sr_raid1_discipline_init(sd); break; #ifdef AOE - /* target */ + /* AOE target. */ case 'A': - /* fill out discipline members */ - sd->sd_type = SR_MD_AOE_TARG; - sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; - sd->sd_max_wu = SR_RAIDAOE_NOWU; - - /* setup discipline pointers */ - sd->sd_alloc_resources = sr_aoe_server_alloc_resources; - 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; - sd->sd_scsi_req_sense = NULL; - sd->sd_scsi_start_stop = NULL; - sd->sd_scsi_sync = NULL; - sd->sd_scsi_rw = NULL; - sd->sd_set_chunk_state = NULL; - sd->sd_set_vol_state = NULL; - disk = 0; /* we are not a disk */ + sr_aoe_server_discipline_init(sd); break; + /* AOE initiator. */ case 'a': - /* initiator */ - /* fill out discipline members */ - sd->sd_type = SR_MD_AOE_INIT; - sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; - sd->sd_max_wu = SR_RAIDAOE_NOWU; - - /* setup discipline pointers */ - sd->sd_alloc_resources = sr_aoe_alloc_resources; - sd->sd_free_resources = sr_aoe_free_resources; - sd->sd_start_discipline = NULL; - sd->sd_scsi_inquiry = sr_raid_inquiry; - sd->sd_scsi_read_cap = sr_raid_read_cap; - sd->sd_scsi_tur = sr_raid_tur; - sd->sd_scsi_req_sense = sr_raid_request_sense; - sd->sd_scsi_start_stop = sr_raid_start_stop; - sd->sd_scsi_sync = sr_raid_sync; - 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; + sr_aoe_discipline_init(sd); break; #endif #ifdef CRYPTO case 'C': - /* fill out discipline members */ - sd->sd_type = SR_MD_CRYPTO; - sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; - sd->sd_max_wu = SR_CRYPTO_NOWU; - - /* setup discipline pointers */ - sd->sd_alloc_resources = sr_crypto_alloc_resources; - sd->sd_free_resources = sr_crypto_free_resources; - sd->sd_start_discipline = NULL; - sd->sd_scsi_inquiry = sr_raid_inquiry; - sd->sd_scsi_read_cap = sr_raid_read_cap; - sd->sd_scsi_tur = sr_raid_tur; - sd->sd_scsi_req_sense = sr_raid_request_sense; - sd->sd_scsi_start_stop = sr_raid_start_stop; - sd->sd_scsi_sync = sr_raid_sync; - 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; + sr_crypto_discipline_init(sd); break; #endif default: diff --git a/sys/dev/softraid_aoe.c b/sys/dev/softraid_aoe.c index 8855c01485e..6601b68ab96 100644 --- a/sys/dev/softraid_aoe.c +++ b/sys/dev/softraid_aoe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_aoe.c,v 1.4 2009/01/04 20:36:23 thib Exp $ */ +/* $OpenBSD: softraid_aoe.c,v 1.5 2009/05/11 14:06:21 jsing Exp $ */ /* * Copyright (c) 2008 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2008 Marco Peereboom <marco@openbsd.org> @@ -54,9 +54,70 @@ #include <netinet/if_ether.h> #include <net/if_aoe.h> -void sr_aoe_input(struct aoe_handler *, struct mbuf *); -void sr_aoe_setup(struct aoe_handler *, struct mbuf *); -void sr_aoe_timeout(void *); +/* AOE initiator functions. */ +int sr_aoe_alloc_resources(struct sr_discipline *); +int sr_aoe_free_resources(struct sr_discipline *); +int sr_aoe_rw(struct sr_workunit *); + +/* AOE target functions. */ +int sr_aoe_server_alloc_resources(struct sr_discipline *); +int sr_aoe_server_free_resources(struct sr_discipline *); +int sr_aoe_server_start(struct sr_discipline *); + +void sr_aoe_input(struct aoe_handler *, struct mbuf *); +void sr_aoe_setup(struct aoe_handler *, struct mbuf *); +void sr_aoe_timeout(void *); + +/* Discipline initialisation. */ +void +sr_aoe_discipline_init(struct sr_discipline *sd) +{ + + /* Fill out discipline members. */ + sd->sd_type = SR_MD_AOE_INIT; + sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; + sd->sd_max_wu = SR_RAIDAOE_NOWU; + + /* Setup discipline pointers. */ + sd->sd_alloc_resources = sr_aoe_alloc_resources; + sd->sd_free_resources = sr_aoe_free_resources; + sd->sd_start_discipline = NULL; + sd->sd_scsi_inquiry = sr_raid_inquiry; + sd->sd_scsi_read_cap = sr_raid_read_cap; + sd->sd_scsi_tur = sr_raid_tur; + sd->sd_scsi_req_sense = sr_raid_request_sense; + sd->sd_scsi_start_stop = sr_raid_start_stop; + sd->sd_scsi_sync = sr_raid_sync; + 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 +sr_aoe_server_discipline_init(struct sr_dscipline *sd) +{ + + /* Fill out discipline members. */ + sd->sd_type = SR_MD_AOE_TARG; + sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; + sd->sd_max_wu = SR_RAIDAOE_NOWU; + + /* Setup discipline pointers. */ + sd->sd_alloc_resources = sr_aoe_server_alloc_resources; + 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; + sd->sd_scsi_req_sense = NULL; + sd->sd_scsi_start_stop = NULL; + sd->sd_scsi_sync = NULL; + sd->sd_scsi_rw = NULL; + sd->sd_set_chunk_state = NULL; + sd->sd_set_vol_state = NULL; + disk = 0; /* we are not a disk */ +} /* AOE initiator */ void diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index 866def1d1e3..b602681b98d 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.32 2008/11/25 23:05:17 marco Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.33 2009/05/11 14:06:21 jsing Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org> @@ -75,6 +75,32 @@ void sr_crypto_calculate_check_hmac_sha1(struct sr_discipline *, void sr_crypto_dumpkeys(struct sr_discipline *); #endif +/* Discipline initialisation. */ +void +sr_crypto_discipline_init(struct sr_discipline *sd) +{ + + /* Fill out discipline members. */ + sd->sd_type = SR_MD_CRYPTO; + sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; + sd->sd_max_wu = SR_CRYPTO_NOWU; + + /* Setup discipline pointers. */ + sd->sd_alloc_resources = sr_crypto_alloc_resources; + sd->sd_free_resources = sr_crypto_free_resources; + sd->sd_start_discipline = NULL; + sd->sd_scsi_inquiry = sr_raid_inquiry; + sd->sd_scsi_read_cap = sr_raid_read_cap; + sd->sd_scsi_tur = sr_raid_tur; + sd->sd_scsi_req_sense = sr_raid_request_sense; + sd->sd_scsi_start_stop = sr_raid_start_stop; + sd->sd_scsi_sync = sr_raid_sync; + 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; +} + struct cryptop * sr_crypto_getcryptop(struct sr_workunit *wu, int encrypt) { diff --git a/sys/dev/softraid_raid0.c b/sys/dev/softraid_raid0.c index 0eb76ed61ef..b3202858600 100644 --- a/sys/dev/softraid_raid0.c +++ b/sys/dev/softraid_raid0.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid0.c,v 1.12 2009/04/28 02:54:53 marco Exp $ */ +/* $OpenBSD: softraid_raid0.c,v 1.13 2009/05/11 14:06:21 jsing Exp $ */ /* * Copyright (c) 2008 Marco Peereboom <marco@peereboom.us> * @@ -43,7 +43,41 @@ #include <dev/softraidvar.h> #include <dev/rndvar.h> -/* RAID 0 functions */ +/* RAID 0 functions. */ +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 +sr_raid0_discipline_init(struct sr_discipline *sd) +{ + + /* Fill out discipline members. */ + sd->sd_type = SR_MD_RAID0; + sd->sd_max_ccb_per_wu = + (MAXPHYS / sd->sd_meta->ssdi.ssd_strip_size + 1) * + SR_RAID0_NOWU * sd->sd_meta->ssdi.ssd_chunk_no; + sd->sd_max_wu = SR_RAID0_NOWU; + + /* Setup discipline pointers. */ + sd->sd_alloc_resources = sr_raid0_alloc_resources; + sd->sd_free_resources = sr_raid0_free_resources; + sd->sd_start_discipline = NULL; + sd->sd_scsi_inquiry = sr_raid_inquiry; + sd->sd_scsi_read_cap = sr_raid_read_cap; + sd->sd_scsi_tur = sr_raid_tur; + sd->sd_scsi_req_sense = sr_raid_request_sense; + sd->sd_scsi_start_stop = sr_raid_start_stop; + sd->sd_scsi_sync = sr_raid_sync; + 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 sr_raid0_alloc_resources(struct sr_discipline *sd) { diff --git a/sys/dev/softraid_raid1.c b/sys/dev/softraid_raid1.c index 785c8f788e8..9edb0783cfe 100644 --- a/sys/dev/softraid_raid1.c +++ b/sys/dev/softraid_raid1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid1.c,v 1.8 2009/04/28 02:54:53 marco Exp $ */ +/* $OpenBSD: softraid_raid1.c,v 1.9 2009/05/11 14:06:21 jsing Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * @@ -43,7 +43,38 @@ #include <dev/softraidvar.h> #include <dev/rndvar.h> -/* RAID 1 functions */ +/* RAID 1 functions. */ +int sr_raid1_alloc_resources(struct sr_discipline *); +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 *); + +/* Discipline initialisation. */ +void +sr_raid1_discipline_init(struct sr_discipline *sd) +{ + + /* Fill out discipline members. */ + sd->sd_type = SR_MD_RAID1; + sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no; + sd->sd_max_wu = SR_RAID1_NOWU; + + /* Setup discipline pointers. */ + sd->sd_alloc_resources = sr_raid1_alloc_resources; + sd->sd_free_resources = sr_raid1_free_resources; + sd->sd_start_discipline = NULL; + sd->sd_scsi_inquiry = sr_raid_inquiry; + sd->sd_scsi_read_cap = sr_raid_read_cap; + sd->sd_scsi_tur = sr_raid_tur; + sd->sd_scsi_req_sense = sr_raid_request_sense; + sd->sd_scsi_start_stop = sr_raid_start_stop; + sd->sd_scsi_sync = sr_raid_sync; + sd->sd_scsi_rw = sr_raid1_rw; + sd->sd_set_chunk_state = sr_raid1_set_chunk_state; + sd->sd_set_vol_state = sr_raid1_set_vol_state; +} + int sr_raid1_alloc_resources(struct sr_discipline *sd) { diff --git a/sys/dev/softraidvar.h b/sys/dev/softraidvar.h index d2a6c74fe85..4c1b246fdf7 100644 --- a/sys/dev/softraidvar.h +++ b/sys/dev/softraidvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: softraidvar.h,v 1.66 2008/12/24 19:32:02 marco Exp $ */ +/* $OpenBSD: softraidvar.h,v 1.67 2009/05/11 14:06:21 jsing Exp $ */ /* * Copyright (c) 2006 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -477,42 +477,24 @@ int sr_raid_start_stop(struct sr_workunit *); int sr_raid_sync(struct sr_workunit *); void sr_raid_startwu(struct sr_workunit *); -/* raid 0 */ -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 specific initialisation. */ +void sr_raid0_discipline_init(struct sr_discipline *); +void sr_raid1_discipline_init(struct sr_discipline *); +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 */ -int sr_raid1_alloc_resources(struct sr_discipline *); -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 *); +/* 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 */ -int sr_crypto_alloc_resources(struct sr_discipline *); -int sr_crypto_free_resources(struct sr_discipline *); -int sr_crypto_rw(struct sr_workunit *); +/* Crypto discipline hooks. */ int sr_crypto_get_kdf(struct bioc_createraid *, struct sr_discipline *); int sr_crypto_create_keys(struct sr_discipline *); -/* aoe discipline */ -int sr_aoe_alloc_resources(struct sr_discipline *); -int sr_aoe_free_resources(struct sr_discipline *); -int sr_aoe_rw(struct sr_workunit *); -/* aoe target */ -int sr_aoe_server_alloc_resources(struct sr_discipline *); -int sr_aoe_server_free_resources(struct sr_discipline *); -int sr_aoe_server_start(struct sr_discipline *); - #ifdef SR_DEBUG void sr_dump_mem(u_int8_t *, int); #endif |