diff options
author | 2013-03-31 11:12:06 +0000 | |
---|---|---|
committer | 2013-03-31 11:12:06 +0000 | |
commit | fc627a5c7c1ac06c524fde49b452d96cf7c96cf0 (patch) | |
tree | 20cdfecbe8bfae948ea0ebcfa2d59b599f1a89e8 | |
parent | Pull the initialisation of runtime values out into a separate init (diff) | |
download | wireguard-openbsd-fc627a5c7c1ac06c524fde49b452d96cf7c96cf0.tar.xz wireguard-openbsd-fc627a5c7c1ac06c524fde49b452d96cf7c96cf0.zip |
Provide default resource allocation and free functions. Convert all
disciplines except for AOE and CRYPTO, which require custom handlers.
-rw-r--r-- | sys/dev/softraid.c | 32 | ||||
-rw-r--r-- | sys/dev/softraid_concat.c | 39 | ||||
-rw-r--r-- | sys/dev/softraid_raid0.c | 39 | ||||
-rw-r--r-- | sys/dev/softraid_raid1.c | 39 | ||||
-rw-r--r-- | sys/dev/softraid_raid6.c | 39 | ||||
-rw-r--r-- | sys/dev/softraid_raidp.c | 39 |
6 files changed, 34 insertions, 193 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index 126e3727e78..f53c3643890 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.295 2013/03/30 14:41:36 jsing Exp $ */ +/* $OpenBSD: softraid.c,v 1.296 2013/03/31 11:12:06 jsing Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -117,6 +117,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); +int sr_alloc_resources(struct sr_discipline *); +int sr_free_resources(struct sr_discipline *); void sr_set_chunk_state(struct sr_discipline *, int, int); void sr_set_vol_state(struct sr_discipline *); @@ -3875,10 +3877,10 @@ sr_discipline_init(struct sr_discipline *sd, int level) int rv = 1; /* Initialise discipline function pointers with defaults. */ - sd->sd_alloc_resources = NULL; + sd->sd_alloc_resources = sr_alloc_resources; sd->sd_assemble = NULL; sd->sd_create = NULL; - sd->sd_free_resources = NULL; + sd->sd_free_resources = sr_free_resources; sd->sd_ioctl_handler = NULL; sd->sd_openings = NULL; sd->sd_meta_opt_handler = NULL; @@ -4181,6 +4183,30 @@ sr_raid_recreate_wu(struct sr_workunit *wu) } while (wup); } +int +sr_alloc_resources(struct sr_discipline *sd) +{ + if (sr_wu_alloc(sd)) { + sr_error(sd->sd_sc, "unable to allocate work units"); + return (ENOMEM); + } + if (sr_ccb_alloc(sd)) { + sr_error(sd->sd_sc, "unable to allocate ccbs"); + return (ENOMEM); + } + + return (0); +} + +int +sr_free_resources(struct sr_discipline *sd) +{ + sr_wu_free(sd); + sr_ccb_free(sd); + + return (0); +} + void sr_set_chunk_state(struct sr_discipline *sd, int c, int new_state) { diff --git a/sys/dev/softraid_concat.c b/sys/dev/softraid_concat.c index e5f6ee270e8..1243da84d82 100644 --- a/sys/dev/softraid_concat.c +++ b/sys/dev/softraid_concat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_concat.c,v 1.12 2013/03/30 02:02:14 jsing Exp $ */ +/* $OpenBSD: softraid_concat.c,v 1.13 2013/03/31 11:12:06 jsing Exp $ */ /* * Copyright (c) 2008 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2011 Joel Sing <jsing@openbsd.org> @@ -36,8 +36,6 @@ int sr_concat_create(struct sr_discipline *, struct bioc_createraid *, int, int64_t); int sr_concat_assemble(struct sr_discipline *, struct bioc_createraid *, int, void *); -int sr_concat_alloc_resources(struct sr_discipline *); -int sr_concat_free_resources(struct sr_discipline *); int sr_concat_rw(struct sr_workunit *); /* Discipline initialisation. */ @@ -52,10 +50,8 @@ sr_concat_discipline_init(struct sr_discipline *sd) sd->sd_max_wu = SR_CONCAT_NOWU; /* Setup discipline specific function pointers. */ - sd->sd_alloc_resources = sr_concat_alloc_resources; sd->sd_assemble = sr_concat_assemble; sd->sd_create = sr_concat_create; - sd->sd_free_resources = sr_concat_free_resources; sd->sd_scsi_rw = sr_concat_rw; } @@ -89,39 +85,6 @@ sr_concat_assemble(struct sr_discipline *sd, struct bioc_createraid *bc, } int -sr_concat_alloc_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_concat_alloc_resources\n", - DEVNAME(sd->sd_sc)); - - if (sr_wu_alloc(sd)) - goto bad; - if (sr_ccb_alloc(sd)) - goto bad; - - rv = 0; -bad: - return (rv); -} - -int -sr_concat_free_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_concat_free_resources\n", - DEVNAME(sd->sd_sc)); - - sr_wu_free(sd); - sr_ccb_free(sd); - - rv = 0; - return (rv); -} - -int sr_concat_rw(struct sr_workunit *wu) { struct sr_discipline *sd = wu->swu_dis; diff --git a/sys/dev/softraid_raid0.c b/sys/dev/softraid_raid0.c index 700e401b08c..fbe6529f750 100644 --- a/sys/dev/softraid_raid0.c +++ b/sys/dev/softraid_raid0.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid0.c,v 1.37 2013/03/31 10:41:16 jsing Exp $ */ +/* $OpenBSD: softraid_raid0.c,v 1.38 2013/03/31 11:12:06 jsing Exp $ */ /* * Copyright (c) 2008 Marco Peereboom <marco@peereboom.us> * @@ -49,8 +49,6 @@ int sr_raid0_create(struct sr_discipline *, struct bioc_createraid *, int sr_raid0_assemble(struct sr_discipline *, struct bioc_createraid *, int, void *); int sr_raid0_init(struct sr_discipline *); -int sr_raid0_alloc_resources(struct sr_discipline *); -int sr_raid0_free_resources(struct sr_discipline *); int sr_raid0_rw(struct sr_workunit *); /* Discipline initialisation. */ @@ -65,10 +63,8 @@ sr_raid0_discipline_init(struct sr_discipline *sd) sd->sd_max_wu = SR_RAID0_NOWU; /* Setup discipline specific function pointers. */ - sd->sd_alloc_resources = sr_raid0_alloc_resources; sd->sd_assemble = sr_raid0_assemble; sd->sd_create = sr_raid0_create; - sd->sd_free_resources = sr_raid0_free_resources; sd->sd_scsi_rw = sr_raid0_rw; } @@ -117,39 +113,6 @@ sr_raid0_init(struct sr_discipline *sd) } int -sr_raid0_alloc_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raid0_alloc_resources\n", - DEVNAME(sd->sd_sc)); - - if (sr_wu_alloc(sd)) - goto bad; - if (sr_ccb_alloc(sd)) - goto bad; - - rv = 0; -bad: - return (rv); -} - -int -sr_raid0_free_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raid0_free_resources\n", - DEVNAME(sd->sd_sc)); - - sr_wu_free(sd); - sr_ccb_free(sd); - - rv = 0; - return (rv); -} - -int sr_raid0_rw(struct sr_workunit *wu) { struct sr_discipline *sd = wu->swu_dis; diff --git a/sys/dev/softraid_raid1.c b/sys/dev/softraid_raid1.c index 48776e14a96..48942ab8548 100644 --- a/sys/dev/softraid_raid1.c +++ b/sys/dev/softraid_raid1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid1.c,v 1.46 2013/03/29 15:26:45 jsing Exp $ */ +/* $OpenBSD: softraid_raid1.c,v 1.47 2013/03/31 11:12:06 jsing Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * @@ -48,8 +48,6 @@ int sr_raid1_create(struct sr_discipline *, struct bioc_createraid *, int, int64_t); int sr_raid1_assemble(struct sr_discipline *, struct bioc_createraid *, int, void *); -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_set_chunk_state(struct sr_discipline *, int, int); @@ -67,10 +65,8 @@ sr_raid1_discipline_init(struct sr_discipline *sd) sd->sd_max_wu = SR_RAID1_NOWU; /* Setup discipline specific function pointers. */ - sd->sd_alloc_resources = sr_raid1_alloc_resources; sd->sd_assemble = sr_raid1_assemble; sd->sd_create = sr_raid1_create; - sd->sd_free_resources = sr_raid1_free_resources; sd->sd_scsi_rw = sr_raid1_rw; sd->sd_scsi_intr = sr_raid1_intr; sd->sd_set_chunk_state = sr_raid1_set_chunk_state; @@ -104,39 +100,6 @@ sr_raid1_assemble(struct sr_discipline *sd, struct bioc_createraid *bc, return 0; } -int -sr_raid1_alloc_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raid1_alloc_resources\n", - DEVNAME(sd->sd_sc)); - - if (sr_wu_alloc(sd)) - goto bad; - if (sr_ccb_alloc(sd)) - goto bad; - - rv = 0; -bad: - return (rv); -} - -int -sr_raid1_free_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raid1_free_resources\n", - DEVNAME(sd->sd_sc)); - - sr_wu_free(sd); - sr_ccb_free(sd); - - rv = 0; - return (rv); -} - void sr_raid1_set_chunk_state(struct sr_discipline *sd, int c, int new_state) { diff --git a/sys/dev/softraid_raid6.c b/sys/dev/softraid_raid6.c index d2b052f10f4..1c9d67bb402 100644 --- a/sys/dev/softraid_raid6.c +++ b/sys/dev/softraid_raid6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raid6.c,v 1.42 2013/03/31 10:41:16 jsing Exp $ */ +/* $OpenBSD: softraid_raid6.c,v 1.43 2013/03/31 11:12:06 jsing Exp $ */ /* * Copyright (c) 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2009 Jordan Hargrave <jordan@openbsd.org> @@ -54,8 +54,6 @@ int sr_raid6_create(struct sr_discipline *, struct bioc_createraid *, int sr_raid6_assemble(struct sr_discipline *, struct bioc_createraid *, int, void *); int sr_raid6_init(struct sr_discipline *); -int sr_raid6_alloc_resources(struct sr_discipline *); -int sr_raid6_free_resources(struct sr_discipline *); int sr_raid6_rw(struct sr_workunit *); int sr_raid6_openings(struct sr_discipline *); void sr_raid6_intr(struct buf *); @@ -105,10 +103,8 @@ sr_raid6_discipline_init(struct sr_discipline *sd) sd->sd_max_wu = SR_RAID6_NOWU; /* Setup discipline specific function pointers. */ - sd->sd_alloc_resources = sr_raid6_alloc_resources; sd->sd_assemble = sr_raid6_assemble; sd->sd_create = sr_raid6_create; - sd->sd_free_resources = sr_raid6_free_resources; sd->sd_openings = sr_raid6_openings; sd->sd_scsi_rw = sr_raid6_rw; sd->sd_scsi_intr = sr_raid6_intr; @@ -166,39 +162,6 @@ sr_raid6_openings(struct sr_discipline *sd) return (sd->sd_max_wu >> 1); /* 2 wu's per IO */ } -int -sr_raid6_alloc_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raid6_alloc_resources\n", - DEVNAME(sd->sd_sc)); - - if (sr_wu_alloc(sd)) - goto bad; - if (sr_ccb_alloc(sd)) - goto bad; - - rv = 0; -bad: - return (rv); -} - -int -sr_raid6_free_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raid6_free_resources\n", - DEVNAME(sd->sd_sc)); - - sr_wu_free(sd); - sr_ccb_free(sd); - - rv = 0; - return (rv); -} - void sr_raid6_set_chunk_state(struct sr_discipline *sd, int c, int new_state) { diff --git a/sys/dev/softraid_raidp.c b/sys/dev/softraid_raidp.c index 86179ec02b0..573cb43c243 100644 --- a/sys/dev/softraid_raidp.c +++ b/sys/dev/softraid_raidp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_raidp.c,v 1.39 2013/03/31 10:41:16 jsing Exp $ */ +/* $OpenBSD: softraid_raidp.c,v 1.40 2013/03/31 11:12:06 jsing Exp $ */ /* * Copyright (c) 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2009 Jordan Hargrave <jordan@openbsd.org> @@ -50,8 +50,6 @@ int sr_raidp_create(struct sr_discipline *, struct bioc_createraid *, int sr_raidp_assemble(struct sr_discipline *, struct bioc_createraid *, int, void *); int sr_raidp_init(struct sr_discipline *); -int sr_raidp_alloc_resources(struct sr_discipline *); -int sr_raidp_free_resources(struct sr_discipline *); int sr_raidp_rw(struct sr_workunit *); int sr_raidp_openings(struct sr_discipline *); void sr_raidp_intr(struct buf *); @@ -83,10 +81,8 @@ sr_raidp_discipline_init(struct sr_discipline *sd, u_int8_t type) sd->sd_max_wu = SR_RAIDP_NOWU; /* Setup discipline specific function pointers. */ - sd->sd_alloc_resources = sr_raidp_alloc_resources; sd->sd_assemble = sr_raidp_assemble; sd->sd_create = sr_raidp_create; - sd->sd_free_resources = sr_raidp_free_resources; sd->sd_openings = sr_raidp_openings; sd->sd_scsi_rw = sr_raidp_rw; sd->sd_scsi_intr = sr_raidp_intr; @@ -141,39 +137,6 @@ sr_raidp_openings(struct sr_discipline *sd) return (sd->sd_max_wu >> 1); /* 2 wu's per IO */ } -int -sr_raidp_alloc_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raidp_alloc_resources\n", - DEVNAME(sd->sd_sc)); - - if (sr_wu_alloc(sd)) - goto bad; - if (sr_ccb_alloc(sd)) - goto bad; - - rv = 0; -bad: - return (rv); -} - -int -sr_raidp_free_resources(struct sr_discipline *sd) -{ - int rv = EINVAL; - - DNPRINTF(SR_D_DIS, "%s: sr_raidp_free_resources\n", - DEVNAME(sd->sd_sc)); - - sr_wu_free(sd); - sr_ccb_free(sd); - - rv = 0; - return (rv); -} - void sr_raidp_set_chunk_state(struct sr_discipline *sd, int c, int new_state) { |