summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2009-12-15 13:19:38 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2009-12-15 13:19:38 +0000
commit8ed27ec4f664b4978413fa34ae76cb7285d1c652 (patch)
tree45b5fb394bc8c16dd1edd4c81e42098ece90d41c /sys
parent1fdae7d88513e611e8f7756a3c456d97a6797a16 (diff)
Factor out discipline specific create/assemble code.
"in, in, in!" marco@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/softraid.c171
-rw-r--r--sys/dev/softraid_aoe.c68
-rw-r--r--sys/dev/softraid_crypto.c93
-rw-r--r--sys/dev/softraid_raid0.c47
-rw-r--r--sys/dev/softraid_raid1.c35
-rw-r--r--sys/dev/softraid_raid6.c45
-rw-r--r--sys/dev/softraid_raidp.c41
-rw-r--r--sys/dev/softraidvar.h6
8 files changed, 347 insertions, 159 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c
index edf333f6276..cd1908e56d8 100644
--- a/sys/dev/softraid.c
+++ b/sys/dev/softraid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.185 2009/12/15 13:04:04 jsing Exp $ */
+/* $OpenBSD: softraid.c,v 1.186 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -2681,8 +2681,6 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user)
dev_t *dt;
int i, s, no_chunk, rv = EINVAL, vol;
int no_meta, updatemeta = 0;
- u_int64_t vol_size;
- int32_t strip_size = 0;
struct sr_chunk_head *cl;
struct sr_discipline *sd = NULL;
struct sr_chunk *ch_entry;
@@ -2704,8 +2702,13 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user)
} else
bcopy(bc->bc_dev_list, dt, bc->bc_dev_list_len);
+ /* Initialise discipline. */
sd = malloc(sizeof(struct sr_discipline), M_DEVBUF, M_WAITOK | M_ZERO);
sd->sd_sc = sc;
+ if (sr_discipline_init(sd, bc->bc_level)) {
+ printf("%s: could not initialize discipline\n", DEVNAME(sc));
+ goto unwind;
+ }
no_chunk = bc->bc_dev_list_len / sizeof(dev_t);
cl = &sd->sd_vol.sv_chunk_list;
@@ -2756,124 +2759,22 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user)
sr_meta_chunks_create(sc, cl);
ch_entry = SLIST_FIRST(cl);
- /* no metadata available */
- switch (bc->bc_level) {
- case 0:
- if (no_chunk < 2)
- goto unwind;
- strlcpy(sd->sd_name, "RAID 0", sizeof(sd->sd_name));
- /*
- * XXX add variable strip size later even though
- * MAXPHYS is really the clever value, users like
- * to tinker with that type of stuff
- */
- strip_size = MAXPHYS;
- vol_size =
- (ch_entry->src_meta.scmi.scm_coerced_size &
- ~((strip_size >> DEV_BSHIFT) - 1)) * no_chunk;
- break;
- case 1:
- if (no_chunk < 2)
- goto unwind;
- strlcpy(sd->sd_name, "RAID 1", sizeof(sd->sd_name));
- vol_size = ch_entry->src_meta.scmi.scm_coerced_size;
- break;
- case 4:
- case 5:
- if (no_chunk < 3)
- goto unwind;
- if (bc->bc_level == 4)
- strlcpy(sd->sd_name, "RAID 4",
- sizeof(sd->sd_name));
- else
- strlcpy(sd->sd_name, "RAID 5",
- sizeof(sd->sd_name));
- /*
- * XXX add variable strip size later even though
- * MAXPHYS is really the clever value, users like
- * to tinker with that type of stuff
- */
- strip_size = MAXPHYS;
- vol_size =
- (ch_entry->src_meta.scmi.scm_coerced_size &
- ~((strip_size >> DEV_BSHIFT) - 1)) * (no_chunk - 1);
- break;
-//#ifdef not_yet
- case 6:
- if (no_chunk < 4)
- goto unwind;
- strlcpy(sd->sd_name, "RAID 6",
- sizeof(sd->sd_name));
- /*
- * XXX add variable strip size later even though
- * MAXPHYS is really the clever value, users like
- * to tinker with that type of stuff
- */
- strip_size = MAXPHYS;
- vol_size =
- (ch_entry->src_meta.scmi.scm_coerced_size &
- ~((strip_size >> DEV_BSHIFT) - 1)) * (no_chunk - 2);
- break;
-//#endif /* not_yet */
-#ifdef AOE
-#ifdef not_yet
- case 'A':
- /* target */
- if (no_chunk != 1)
- goto unwind;
- strlcpy(sd->sd_name, "AOE TARG", sizeof(sd->sd_name));
- vol_size = ch_entry->src_meta.scmi.scm_coerced_size;
- break;
- case 'a':
- /* initiator */
- if (no_chunk != 1)
- goto unwind;
- strlcpy(sd->sd_name, "AOE INIT", sizeof(sd->sd_name));
- break;
-#endif /* not_yet */
-#endif /* AOE */
-#ifdef CRYPTO
- case 'C':
- DNPRINTF(SR_D_IOCTL,
- "%s: sr_ioctl_createraid: no_chunk %d\n",
- DEVNAME(sc), no_chunk);
-
- if (no_chunk != 1)
- goto unwind;
+ sd->sd_vol_status = BIOC_SVONLINE;
+ sd->sd_meta->ssdi.ssd_level = bc->bc_level;
+ sd->sd_meta->ssdi.ssd_chunk_no = no_chunk;
- /* no hint available yet */
- if (bc->bc_opaque_flags & BIOC_SOOUT) {
- bc->bc_opaque_status = BIOC_SOINOUT_FAILED;
- rv = 0;
+ if (sd->sd_create) {
+ if ((i = sd->sd_create(sd, bc, no_chunk,
+ ch_entry->src_meta.scmi.scm_coerced_size))) {
+ rv = i;
goto unwind;
}
-
- if (!(bc->bc_flags & BIOC_SCNOAUTOASSEMBLE))
- goto unwind;
-
- if (sr_crypto_get_kdf(bc, sd))
- goto unwind;
-
- strlcpy(sd->sd_name, "CRYPTO", sizeof(sd->sd_name));
- vol_size = ch_entry->src_meta.scmi.scm_size;
-
- sr_crypto_create_keys(sd);
-
- break;
-#endif /* CRYPTO */
- default:
- goto unwind;
}
/* fill out all volume metadata */
DNPRINTF(SR_D_IOCTL,
"%s: sr_ioctl_createraid: vol_size: %lld\n",
- DEVNAME(sc), vol_size);
- sd->sd_meta->ssdi.ssd_chunk_no = no_chunk;
- sd->sd_meta->ssdi.ssd_size = vol_size;
- sd->sd_vol_status = BIOC_SVONLINE;
- sd->sd_meta->ssdi.ssd_level = bc->bc_level;
- sd->sd_meta->ssdi.ssd_strip_size = strip_size;
+ DEVNAME(sc), sd->sd_meta->ssdi.ssd_size);
strlcpy(sd->sd_meta->ssdi.ssd_vendor, "OPENBSD",
sizeof(sd->sd_meta->ssdi.ssd_vendor));
snprintf(sd->sd_meta->ssdi.ssd_product,
@@ -2900,31 +2801,14 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user)
printf(" already assembled\n");
goto unwind;
}
-#ifdef CRYPTO
- /* provide userland with kdf hint */
- if (bc->bc_opaque_flags & BIOC_SOOUT) {
- if (bc->bc_opaque == NULL)
- goto unwind;
-
- if (sizeof(sd->mds.mdd_crypto.scr_meta.scm_kdfhint) <
- bc->bc_opaque_size)
- goto unwind;
-
- if (copyout(sd->mds.mdd_crypto.scr_meta.scm_kdfhint,
- bc->bc_opaque, bc->bc_opaque_size))
- goto unwind;
- /* we're done */
- bc->bc_opaque_status = BIOC_SOINOUT_OK;
- rv = 0;
- goto unwind;
- }
- /* get kdf with maskkey from userland */
- if (bc->bc_opaque_flags & BIOC_SOIN) {
- if (sr_crypto_get_kdf(bc, sd))
+ if (sd->sd_assemble) {
+ if ((i = sd->sd_assemble(sd, bc, no_chunk))) {
+ rv = i;
goto unwind;
+ }
}
-#endif /* CRYPTO */
+
DNPRINTF(SR_D_META, "%s: disk assembled from metadata\n",
DEVNAME(sc));
updatemeta = 0;
@@ -2940,6 +2824,14 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user)
"assemble it\n");
goto unwind;
}
+
+ if (sd->sd_assemble) {
+ if ((i = sd->sd_assemble(sd, bc, no_chunk))) {
+ rv = i;
+ goto unwind;
+ }
+ }
+
printf("%s: trying to bring up %s degraded\n", DEVNAME(sc),
sd->sd_meta->ssd_devname);
}
@@ -2953,11 +2845,6 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user)
goto unwind;
}
- if (sr_discipline_init(sd, sd->sd_meta->ssdi.ssd_level)) {
- printf("%s: could not initialize discipline\n", DEVNAME(sc));
- goto unwind;
- }
-
/* allocate all resources */
if ((rv = sd->sd_alloc_resources(sd)))
goto unwind;
@@ -3073,6 +2960,10 @@ sr_ioctl_createraid(struct sr_softc *sc, struct bioc_createraid *bc, int user)
unwind:
sr_discipline_shutdown(sd);
+ /* XXX - use internal status values! */
+ if (rv == EAGAIN)
+ rv = 0;
+
return (rv);
}
diff --git a/sys/dev/softraid_aoe.c b/sys/dev/softraid_aoe.c
index 58991f14905..a6ae5b78687 100644
--- a/sys/dev/softraid_aoe.c
+++ b/sys/dev/softraid_aoe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_aoe.c,v 1.11 2009/12/07 14:27:12 jsing Exp $ */
+/* $OpenBSD: softraid_aoe.c,v 1.12 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2008 Ted Unangst <tedu@openbsd.org>
* Copyright (c) 2008 Marco Peereboom <marco@openbsd.org>
@@ -55,11 +55,19 @@
#include <net/if_aoe.h>
/* AOE initiator functions. */
+int sr_aoe_create(struct sr_discipline *, struct bioc_createraid *,
+ int, int64t);
+int sr_aoe_assemble(struct sr_discipline *, struct bioc_createraid *,
+ int);
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_create(struct sr_discipline *, struct bioc_createraid *,
+ int, int64t);
+int sr_aoe_server_assemble(struct sr_discipline *, struct bioc_createraid *,
+ int);
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 *);
@@ -76,10 +84,11 @@ sr_aoe_discipline_init(struct sr_discipline *sd)
/* Fill out discipline members. */
sd->sd_type = SR_MD_AOE_INIT;
sd->sd_capabilities = SR_CAP_SYSTEM_DISK;
- 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_create = sr_aoe_create;
+ sd->sd_assemble = sr_aoe_assemble;
sd->sd_alloc_resources = sr_aoe_alloc_resources;
sd->sd_free_resources = sr_aoe_free_resources;
sd->sd_start_discipline = NULL;
@@ -102,10 +111,11 @@ sr_aoe_server_discipline_init(struct sr_discipline *sd)
/* Fill out discipline members. */
sd->sd_type = SR_MD_AOE_TARG;
sd->sd_capabilities = 0;
- 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_create = sr_aoe_server_create;
+ sd->sd_assemble = sr_aoe_server_assemble;
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;
@@ -121,6 +131,31 @@ sr_aoe_server_discipline_init(struct sr_discipline *sd)
}
/* AOE initiator */
+int
+sr_aoe_create(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk, int64t coerced_size)
+{
+
+ if (no_chunk != 1)
+ return EINVAL;
+
+ strlcpy(sd->sd_name, "AOE INIT", sizeof(sd->sd_name));
+
+ sd->sd_max_ccb_per_wu = no_chunk;
+
+ return 0;
+}
+
+int
+sr_aoe_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk);
+{
+
+ sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no;
+
+ return 0;
+}
+
void
sr_aoe_setup(struct aoe_handler *ah, struct mbuf *m)
{
@@ -570,6 +605,33 @@ void sr_aoe_server_create_thread(void *);
void sr_aoe_server_thread(void *);
int
+sr_aoe_server_create(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk, int64t coerced_size)
+{
+
+ if (no_chunk != 1)
+ return EINVAL;
+
+ sd->sd_meta->ssdi.ssd_size = coerced_size;
+
+ strlcpy(sd->sd_name, "AOE TARG", sizeof(sd->sd_name));
+
+ sd->sd_max_ccb_per_wu = no_chunk;
+
+ return 0;
+}
+
+int
+sr_aoe_server_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk);
+{
+
+ sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no;
+
+ return 0;
+}
+
+int
sr_aoe_server_alloc_resources(struct sr_discipline *sd)
{
int s, rv = EINVAL;
diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c
index 8b0d7f03729..4b7fba4778a 100644
--- a/sys/dev/softraid_crypto.c
+++ b/sys/dev/softraid_crypto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_crypto.c,v 1.43 2009/12/07 14:27:12 jsing Exp $ */
+/* $OpenBSD: softraid_crypto.c,v 1.44 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2007 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org>
@@ -64,6 +64,10 @@ int sr_crypto_encrypt(u_char *, u_char *, u_char *, size_t, int);
int sr_crypto_decrypt_key(struct sr_discipline *);
int sr_crypto_change_maskkey(struct sr_discipline *,
struct sr_crypto_kdfinfo *, struct sr_crypto_kdfinfo *);
+int sr_crypto_create(struct sr_discipline *,
+ struct bioc_createraid *, int, int64_t);
+int sr_crypto_assemble(struct sr_discipline *,
+ struct bioc_createraid *, int);
int sr_crypto_alloc_resources(struct sr_discipline *);
int sr_crypto_free_resources(struct sr_discipline *);
int sr_crypto_ioctl(struct sr_discipline *,
@@ -86,14 +90,19 @@ void sr_crypto_dumpkeys(struct sr_discipline *);
void
sr_crypto_discipline_init(struct sr_discipline *sd)
{
+ int i;
/* Fill out discipline members. */
sd->sd_type = SR_MD_CRYPTO;
sd->sd_capabilities = SR_CAP_SYSTEM_DISK;
- sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no;
sd->sd_max_wu = SR_CRYPTO_NOWU;
+ for (i = 0; i < SR_CRYPTO_MAXKEYS; i++)
+ sd->mds.mdd_crypto.scr_sid[i] = (u_int64_t)-1;
+
/* Setup discipline pointers. */
+ sd->sd_create = sr_crypto_create;
+ sd->sd_assemble = sr_crypto_assemble;
sd->sd_alloc_resources = sr_crypto_alloc_resources;
sd->sd_free_resources = sr_crypto_free_resources;
sd->sd_start_discipline = NULL;
@@ -110,6 +119,77 @@ sr_crypto_discipline_init(struct sr_discipline *sd)
sd->sd_set_vol_state = sr_raid1_set_vol_state;
}
+int
+sr_crypto_create(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk, int64_t coerced_size)
+{
+ int rv = EINVAL;
+
+ if (no_chunk != 1)
+ goto done;
+
+ /* no hint available yet */
+ if (bc->bc_opaque_flags & BIOC_SOOUT) {
+ bc->bc_opaque_status = BIOC_SOINOUT_FAILED;
+ rv = EAGAIN;
+ goto done;
+ }
+
+ if (!(bc->bc_flags & BIOC_SCNOAUTOASSEMBLE))
+ goto done;
+
+ if (sr_crypto_get_kdf(bc, sd))
+ goto done;
+
+ strlcpy(sd->sd_name, "CRYPTO", sizeof(sd->sd_name));
+ sd->sd_meta->ssdi.ssd_size = coerced_size;
+
+ sr_crypto_create_keys(sd);
+
+ sd->sd_max_ccb_per_wu = no_chunk;
+
+ rv = 0;
+done:
+ return (rv);
+}
+
+int
+sr_crypto_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk)
+{
+ int rv = EINVAL;
+
+ /* provide userland with kdf hint */
+ if (bc->bc_opaque_flags & BIOC_SOOUT) {
+ if (bc->bc_opaque == NULL)
+ goto done;
+
+ if (sizeof(sd->mds.mdd_crypto.scr_meta.scm_kdfhint) <
+ bc->bc_opaque_size)
+ goto done;
+
+ if (copyout(sd->mds.mdd_crypto.scr_meta.scm_kdfhint,
+ bc->bc_opaque, bc->bc_opaque_size))
+ goto done;
+
+ /* we're done */
+ bc->bc_opaque_status = BIOC_SOINOUT_OK;
+ rv = EAGAIN;
+ goto done;
+ }
+
+ /* get kdf with maskkey from userland */
+ if (bc->bc_opaque_flags & BIOC_SOIN)
+ if (sr_crypto_get_kdf(bc, sd))
+ goto done;
+
+ sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no;
+
+ rv = 0;
+done:
+ return (rv);
+}
+
struct cryptop *
sr_crypto_getcryptop(struct sr_workunit *wu, int encrypt)
{
@@ -594,16 +674,17 @@ sr_crypto_free_resources(struct sr_discipline *sd)
sr_hotplug_unregister(sd, sr_crypto_hotplug);
for (i = 0; sd->mds.mdd_crypto.scr_sid[i] != (u_int64_t)-1; i++) {
- crypto_freesession(
- sd->mds.mdd_crypto.scr_sid[i]);
+ crypto_freesession(sd->mds.mdd_crypto.scr_sid[i]);
sd->mds.mdd_crypto.scr_sid[i] = (u_int64_t)-1;
}
sr_wu_free(sd);
sr_ccb_free(sd);
- pool_destroy(&sd->mds.mdd_crypto.sr_uiopl);
- pool_destroy(&sd->mds.mdd_crypto.sr_iovpl);
+ if (sd->mds.mdd_crypto.sr_uiopl.pr_serial != 0)
+ pool_destroy(&sd->mds.mdd_crypto.sr_uiopl);
+ if (sd->mds.mdd_crypto.sr_iovpl.pr_serial != 0)
+ pool_destroy(&sd->mds.mdd_crypto.sr_iovpl);
rv = 0;
return (rv);
diff --git a/sys/dev/softraid_raid0.c b/sys/dev/softraid_raid0.c
index a772849d556..e202010eff5 100644
--- a/sys/dev/softraid_raid0.c
+++ b/sys/dev/softraid_raid0.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_raid0.c,v 1.17 2009/12/07 14:27:12 jsing Exp $ */
+/* $OpenBSD: softraid_raid0.c,v 1.18 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2008 Marco Peereboom <marco@peereboom.us>
*
@@ -44,6 +44,10 @@
#include <dev/rndvar.h>
/* RAID 0 functions. */
+int sr_raid0_create(struct sr_discipline *, struct bioc_createraid *,
+ int, int64_t);
+int sr_raid0_assemble(struct sr_discipline *, struct bioc_createraid *,
+ int);
int sr_raid0_alloc_resources(struct sr_discipline *);
int sr_raid0_free_resources(struct sr_discipline *);
int sr_raid0_rw(struct sr_workunit *);
@@ -59,12 +63,11 @@ sr_raid0_discipline_init(struct sr_discipline *sd)
/* Fill out discipline members. */
sd->sd_type = SR_MD_RAID0;
sd->sd_capabilities = SR_CAP_SYSTEM_DISK | SR_CAP_AUTO_ASSEMBLE;
- 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_create = sr_raid0_create;
+ sd->sd_assemble = sr_raid0_assemble;
sd->sd_alloc_resources = sr_raid0_alloc_resources;
sd->sd_free_resources = sr_raid0_free_resources;
sd->sd_start_discipline = NULL;
@@ -80,6 +83,42 @@ sr_raid0_discipline_init(struct sr_discipline *sd)
}
int
+sr_raid0_create(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk, int64_t coerced_size)
+{
+
+ if (no_chunk < 2)
+ return EINVAL;
+
+ /*
+ * XXX add variable strip size later even though MAXPHYS is really
+ * the clever value, users like to tinker with that type of stuff.
+ */
+ strlcpy(sd->sd_name, "RAID 0", sizeof(sd->sd_name));
+ sd->sd_meta->ssdi.ssd_strip_size = MAXPHYS;
+ sd->sd_meta->ssdi.ssd_size = (coerced_size &
+ ~((sd->sd_meta->ssdi.ssd_strip_size >> DEV_BSHIFT) - 1)) * no_chunk;
+
+ sd->sd_max_ccb_per_wu =
+ (MAXPHYS / sd->sd_meta->ssdi.ssd_strip_size + 1) *
+ SR_RAID0_NOWU * no_chunk;
+
+ return 0;
+}
+
+int
+sr_raid0_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunks)
+{
+
+ 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;
+
+ return 0;
+}
+
+int
sr_raid0_alloc_resources(struct sr_discipline *sd)
{
int rv = EINVAL;
diff --git a/sys/dev/softraid_raid1.c b/sys/dev/softraid_raid1.c
index 939afa3f602..cab77bc65a0 100644
--- a/sys/dev/softraid_raid1.c
+++ b/sys/dev/softraid_raid1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_raid1.c,v 1.20 2009/12/07 14:27:12 jsing Exp $ */
+/* $OpenBSD: softraid_raid1.c,v 1.21 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2007 Marco Peereboom <marco@peereboom.us>
*
@@ -44,6 +44,10 @@
#include <dev/rndvar.h>
/* RAID 1 functions. */
+int sr_raid1_create(struct sr_discipline *, struct bioc_createraid *,
+ int, int64_t);
+int sr_raid1_assemble(struct sr_discipline *, struct bioc_createraid *,
+ int);
int sr_raid1_alloc_resources(struct sr_discipline *);
int sr_raid1_free_resources(struct sr_discipline *);
int sr_raid1_rw(struct sr_workunit *);
@@ -59,10 +63,11 @@ sr_raid1_discipline_init(struct sr_discipline *sd)
sd->sd_type = SR_MD_RAID1;
sd->sd_capabilities = SR_CAP_SYSTEM_DISK | SR_CAP_AUTO_ASSEMBLE |
SR_CAP_REBUILD;
- 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_create = sr_raid1_create;
+ sd->sd_assemble = sr_raid1_assemble;
sd->sd_alloc_resources = sr_raid1_alloc_resources;
sd->sd_free_resources = sr_raid1_free_resources;
sd->sd_start_discipline = NULL;
@@ -78,6 +83,32 @@ sr_raid1_discipline_init(struct sr_discipline *sd)
}
int
+sr_raid1_create(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk, int64_t coerced_size)
+{
+
+ if (no_chunk < 2)
+ return EINVAL;
+
+ strlcpy(sd->sd_name, "RAID 1", sizeof(sd->sd_name));
+ sd->sd_meta->ssdi.ssd_size = coerced_size;
+
+ sd->sd_max_ccb_per_wu = no_chunk;
+
+ return 0;
+}
+
+int
+sr_raid1_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk)
+{
+
+ sd->sd_max_ccb_per_wu = sd->sd_meta->ssdi.ssd_chunk_no;
+
+ return 0;
+}
+
+int
sr_raid1_alloc_resources(struct sr_discipline *sd)
{
int rv = EINVAL;
diff --git a/sys/dev/softraid_raid6.c b/sys/dev/softraid_raid6.c
index 1d7eca7ef17..70f08400231 100644
--- a/sys/dev/softraid_raid6.c
+++ b/sys/dev/softraid_raid6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_raid6.c,v 1.9 2009/12/07 14:33:38 jsing Exp $ */
+/* $OpenBSD: softraid_raid6.c,v 1.10 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2009 Jordan Hargrave <jordan@openbsd.org>
@@ -49,6 +49,10 @@ uint8_t gf_pow[768];
int gf_log[256];
/* RAID 6 functions. */
+int sr_raid6_create(struct sr_discipline *, struct bioc_createraid *,
+ int, int64_t);
+int sr_raid6_assemble(struct sr_discipline *, struct bioc_createraid *,
+ int);
int sr_raid6_alloc_resources(struct sr_discipline *);
int sr_raid6_free_resources(struct sr_discipline *);
int sr_raid6_rw(struct sr_workunit *);
@@ -131,10 +135,11 @@ sr_raid6_discipline_init(struct sr_discipline *sd)
/* fill out discipline members. */
sd->sd_type = SR_MD_RAID6;
sd->sd_capabilities = SR_CAP_SYSTEM_DISK | SR_CAP_AUTO_ASSEMBLE;
- sd->sd_max_ccb_per_wu = max(6, 2 * sd->sd_meta->ssdi.ssd_chunk_no); /* only if stripsize <= MAXPHYS */
sd->sd_max_wu = SR_RAID6_NOWU;
/* setup discipline pointers. */
+ sd->sd_create = sr_raid6_create;
+ sd->sd_assemble = sr_raid6_assemble;
sd->sd_alloc_resources = sr_raid6_alloc_resources;
sd->sd_free_resources = sr_raid6_free_resources;
sd->sd_start_discipline = NULL;
@@ -151,6 +156,42 @@ sr_raid6_discipline_init(struct sr_discipline *sd)
}
int
+sr_raid6_create(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk, int64_t coerced_size)
+{
+
+ if (no_chunk < 4)
+ return EINVAL;
+
+ strlcpy(sd->sd_name, "RAID 6", sizeof(sd->sd_name));
+
+ /*
+ * XXX add variable strip size later even though MAXPHYS is really
+ * the clever value, users like * to tinker with that type of stuff.
+ */
+ sd->sd_meta->ssdi.ssd_strip_size = MAXPHYS;
+ sd->sd_meta->ssdi.ssd_size = (coerced_size &
+ ~((sd->sd_meta->ssdi.ssd_strip_size >> DEV_BSHIFT) - 1)) *
+ (no_chunk - 2);
+
+ /* only if stripsize <= MAXPHYS */
+ sd->sd_max_ccb_per_wu = max(6, 2 * no_chunk);
+
+ return 0;
+}
+
+int
+sr_raid6_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk)
+{
+
+ /* only if stripsize <= MAXPHYS */
+ sd->sd_max_ccb_per_wu = max(6, 2 * sd->sd_meta->ssdi.ssd_chunk_no);
+
+ return 0;
+}
+
+int
sr_raid6_openings(struct sr_discipline *sd)
{
return (sd->sd_max_wu >> 1); /* 2 wu's per IO */
diff --git a/sys/dev/softraid_raidp.c b/sys/dev/softraid_raidp.c
index 7ff4ff89dd2..930e6bc31b3 100644
--- a/sys/dev/softraid_raidp.c
+++ b/sys/dev/softraid_raidp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_raidp.c,v 1.12 2009/12/07 14:33:38 jsing Exp $ */
+/* $OpenBSD: softraid_raidp.c,v 1.13 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2009 Jordan Hargrave <jordan@openbsd.org>
@@ -45,6 +45,10 @@
#include <dev/rndvar.h>
/* RAID P functions. */
+int sr_raidp_create(struct sr_discipline *, struct bioc_createraid *,
+ int, int64_t);
+int sr_raidp_assemble(struct sr_discipline *, struct bioc_createraid *,
+ int);
int sr_raidp_alloc_resources(struct sr_discipline *);
int sr_raidp_free_resources(struct sr_discipline *);
int sr_raidp_rw(struct sr_workunit *);
@@ -75,6 +79,8 @@ sr_raidp_discipline_init(struct sr_discipline *sd, u_int8_t type)
sd->sd_max_wu = SR_RAIDP_NOWU;
/* setup discipline pointers. */
+ sd->sd_create = sr_raidp_create;
+ sd->sd_assemble = sr_raidp_assemble;
sd->sd_alloc_resources = sr_raidp_alloc_resources;
sd->sd_free_resources = sr_raidp_free_resources;
sd->sd_start_discipline = NULL;
@@ -91,6 +97,39 @@ sr_raidp_discipline_init(struct sr_discipline *sd, u_int8_t type)
}
int
+sr_raidp_create(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk, int64_t coerced_size)
+{
+
+ if (no_chunk < 3)
+ return EINVAL;
+
+ if (sd->sd_type == SR_MD_RAID4)
+ strlcpy(sd->sd_name, "RAID 4", sizeof(sd->sd_name));
+ else
+ strlcpy(sd->sd_name, "RAID 5", sizeof(sd->sd_name));
+
+ /*
+ * XXX add variable strip size later even though MAXPHYS is really
+ * the clever value, users like to tinker with that type of stuff.
+ */
+ sd->sd_meta->ssdi.ssd_strip_size = MAXPHYS;
+ sd->sd_meta->ssdi.ssd_size = (coerced_size &
+ ~((sd->sd_meta->ssdi.ssd_strip_size >> DEV_BSHIFT) - 1)) *
+ (no_chunk - 1);
+
+ return 0;
+}
+
+int
+sr_raidp_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
+ int no_chunk)
+{
+
+ return 0;
+}
+
+int
sr_raidp_openings(struct sr_discipline *sd)
{
return (sd->sd_max_wu >> 1); /* 2 wu's per IO */
diff --git a/sys/dev/softraidvar.h b/sys/dev/softraidvar.h
index 786e9af9f65..ba89cf52b36 100644
--- a/sys/dev/softraidvar.h
+++ b/sys/dev/softraidvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraidvar.h,v 1.86 2009/12/07 14:33:38 jsing Exp $ */
+/* $OpenBSD: softraidvar.h,v 1.87 2009/12/15 13:19:37 jsing Exp $ */
/*
* Copyright (c) 2006 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -475,6 +475,10 @@ struct sr_discipline {
u_int64_t sd_wu_collisions;
/* discipline functions */
+ int (*sd_create)(struct sr_discipline *,
+ struct bioc_createraid *, int, int64_t);
+ int (*sd_assemble)(struct sr_discipline *,
+ struct bioc_createraid *, int);
int (*sd_alloc_resources)(struct sr_discipline *);
int (*sd_free_resources)(struct sr_discipline *);
int (*sd_ioctl_handler)(struct sr_discipline *,