History log of /openbsd-current/sys/dev/softraid_raid1.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.67 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.66 08-Dec-2020 stsp

fix wrong function names in softraid RAID1 debug print statements

ok jsing@ as part of a larger diff


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.65 12-Apr-2016 krw

No need to rescan chunks in each discipline to find appropriate
volume sector size. Determine volume sector size in sr_meta_init().

Pointed out, tweaked and ok jsing@


# 1.64 04-Apr-2016 krw

Enable creation of softraid volumes using disks with non-512 byte
sectors. Volumes created will present a sector size equal to the
largest sector size of the constituent disks.

Softraid Metadata version cranks to 6 due to new field.

ok jsing@ with tweaks that will follow soon.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.63 21-Jul-2015 krw

A few more daddr_t fixes. Rename 'phys_off' variables to 'offset'
since they are now relative to chunks. Use 'blkno' as normal variable
name for daddr_t items rather than mix of 'blkno, blk, offset.
Change field name ssd_data_offset to ssd_data_blkno since it is a
block and not byte quantity.

No intentional functional change.


# 1.62 19-Jul-2015 krw

Remove unneeded #include <disklabel.h>.

ok jsing@


# 1.61 19-Jul-2015 krw

Stop adding and subtracting data offset. Just keep to chunk relative
block offsets until actual i/o is constructed and needs the physical
offset. Eliminate a number of <<DEV_BSIZE shifts as a bonus.

No intentional functional change.

Fixed and ok jsing@


Revision tags: OPENBSD_5_7_BASE
# 1.60 27-Jan-2015 dlg

remove #include <sys/workq.h>. it wont exist anymore soon.


# 1.59 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.58 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.57 12-Jul-2014 blambert

essentially mechanical conversion of softraid rebuild from
workq to taskq

ok jsing@


Revision tags: OPENBSD_5_5_BASE
# 1.56 22-Jan-2014 jsing

Switch metadata saves from the system workq to the system taskq.

ok dlg@


# 1.55 21-Jan-2014 jsing

Order the volume state transitions by state value.


# 1.54 01-Nov-2013 krw

Sprinkle (long long) casts where %lld is being used to print daddr_t
variables. Some random whitespace/knf repairs encountered on the way.

ok miod@ on inspection, feedback & more suggestions from millert@


Revision tags: OPENBSD_5_4_BASE
# 1.53 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.52 21-May-2013 jsing

Provide a function that handles the scheduling of work units. This
simplifies the discipline code, avoids code duplication and moves the
scheduling logic into a single location.

ok krw@


# 1.51 21-May-2013 jsing

Use a state to indicate that a work unit should only be constructed and not
scheduled, rather than trying to imply this from the rebuild flag.


# 1.50 21-Apr-2013 jsing

Convert RAID1 to the new work unit completion functions and generic
interrupt handler. Disciplines such as RAID1/4/5/6 need a way to intercept
I/O when the work unit is complete, but before the SCSI xfer is complete.
This is provided via a sd_scsi_wu_done hook, which enables work units to be
restarted or otherwise modified before the SCSI xfer completion occurs.

ok krw@


# 1.49 31-Mar-2013 jsing

Use consistent error handling when validating the number of chunks
provided.


# 1.48 31-Mar-2013 jsing

More runtime value initialisation functions.


# 1.47 31-Mar-2013 jsing

Provide default resource allocation and free functions. Convert all
disciplines except for AOE and CRYPTO, which require custom handlers.


# 1.46 29-Mar-2013 jsing

Properly release ccbs when restarting a work unit.


# 1.45 29-Mar-2013 jsing

Decouple wakeups on work unit completion from the type of I/O being
performed.

ok krw@


# 1.44 29-Mar-2013 jsing

sd_wu_pending is only decremented when scsi_done() or scsi_io_put() are
called. As a result, factor out the the sd_sync check/wakeup code and move
it to after the scsi_done() call in sr_scsi_done(). Perform the same
sd_sync check/wakeup after scsi_io_put() calls (including the addition of
some that were previously missed).

ok krw@


# 1.43 27-Mar-2013 jsing

Rewrite the work unit handling code in the RAID 1/4/5/6 interrupt handlers.
This simplifies the code and will allow for easier conversion to the workq
based work unit completion routines. It also ensures that work units are
always removed from the pending queue and that colliders are started, even
in the event of an I/O failure.

ok krw@


# 1.42 25-Mar-2013 jsing

Factor out the code that is used to recreate work units - one copy of the
code is sufficient.

ok krw@


# 1.41 02-Mar-2013 jsing

sr_alloc_resources() and sr_free_resources() can never be called without
a valid struct sr_discipline. Remove redundant NULL pointer checks.


Revision tags: OPENBSD_5_3_BASE
# 1.40 18-Jan-2013 jsing

Convert RAID1 to new ccb functions.

ok krw@


# 1.39 17-Jan-2013 jsing

Restructure the RAID1 I/O path so that we only get a ccb once we are
certain that we need one. Also make code more consistent with other
disciplines.

ok krw@


# 1.38 16-Jan-2013 jsing

Consistently call sr_scsi_done instead of scsi_done.

ok krw@


# 1.37 16-Jan-2013 jsing

Add a new capability flag to identify disciplines where read failures are
not necessarily terminal (i.e. we have redundancy).

ok krw@


# 1.36 16-Jan-2013 jsing

Set resid to zero if the scsi transfer completed without error.

ok krw@


# 1.35 16-Jan-2013 jsing

Factor out code used to release ccbs from a workunit.

ok krw@


# 1.34 15-Jan-2013 jsing

Always initialise the discipline name, not just when we are doing a create.


# 1.33 15-Jan-2013 jsing

Keep a function pointer to the per-discipline I/O interrupt handler in the
discipline data structure. To be used with an upcoming diff.


# 1.32 08-Oct-2012 jsing

Provide a mechanism for the kernel to pass data through to the discipline
during volume assembly.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 22-Jan-2012 jsing

Convert softraid(4) to new bio(4) status interface. This allows bioctl(8)
to provide useful feedback, rather than reporting an ioctl failure and
leaving the user to consult dmesg. For now we continue to print most things
to the console, even if the message is a result of an ioctl.


# 1.30 26-Dec-2011 jsing

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.


# 1.29 25-Dec-2011 jsing

Initialise discipline function pointers with defaults and only override
those that are needed by a specific discipline.


# 1.28 25-Dec-2011 jsing

Move chunk state debugging code to a more useful location.


Revision tags: OPENBSD_5_0_BASE
# 1.27 05-Apr-2011 krw

Iopoolification. Testing by marco@.

ok dlg@ marco@


Revision tags: OPENBSD_4_9_BASE
# 1.26 06-Nov-2010 marco

Move raid1 and crypto io to a workq. This is to avoid a potential VOP_
call while in interrupt context.

Contains an additional spl dance as found by thib.

Tested by many opn various arches. Note that raid 0/4/5/6 have not been
moved over yet.


Revision tags: OPENBSD_4_8_BASE
# 1.25 02-Jul-2010 jsing

Determine the data offset using a variable specified within the softraid
metadata. This allows us to implement seamless transitions from the
previous metadata version to the current version, avoiding the need to
recreate the softraid volume.

Joint work with marco@ during c2k10.

ok marco@


# 1.24 01-Jul-2010 thib

make sure that buf's on the stack set the b_bq to NULL.
one memset -> bzero.

ok marco@, jsing@


# 1.23 26-Mar-2010 jsing

Add storage for the boot block and boot loader to the softraid metadata.
Also add a new optional metadata type for boot data. This is the first
step (of many) towards being able to boot from softraid volumes.

WARNING: This version of the softraid metadata is not compatible with
previous versions. As a result, any softraid volumes created with older
kernels will not assemble. Data on existing softraid volumes should be
backed up before upgrading. The volume should then be recreated and the
data restored.

ok marco@


Revision tags: OPENBSD_4_7_BASE
# 1.22 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.21 15-Dec-2009 jsing

Factor out discipline specific create/assemble code.

"in, in, in!" marco@


# 1.20 07-Dec-2009 jsing

Define discipline capabilities using a set of flags.

"shiny!!" marco@


# 1.19 09-Aug-2009 marco

Switch softraid to vnodes to prevent bad things from happening when using
d_open/d_close.

tested by many, ok jsing, thib, krw


# 1.18 12-Jul-2009 jsing

Clean up debug droppings in sr_raid1_set_vol_state().

ok marco@


# 1.17 12-Jul-2009 jsing

Enable hotspare rebuilds for softraid RAID1.

ok marco@


Revision tags: OPENBSD_4_6_BASE
# 1.16 24-Jun-2009 jsing

Abort the current rebuild if the rebuild chunk disappears. Whilst here also
rename the abort flag so that it is more generalised.

ok marco@


# 1.15 18-Jun-2009 jsing

Add other valid chunk state transitions for RAID 1.

ok marco@


# 1.14 02-Jun-2009 marco

Abuse bio layer a little less by marking fake buffers with B_PHYS.
From beck with lots of squealing and ear bleeds.
Issue originally reported by todd.

ok beck


# 1.13 02-Jun-2009 marco

Rebuild can go to degraded


# 1.12 02-Jun-2009 deraadt

marco needs to learn how to do his range checks better, found by Parfait
ok oga guenther


# 1.11 02-Jun-2009 marco

Add an identifier that tells us if we can rebuild this discipline.
KNF & spelling too


# 1.10 02-Jun-2009 marco

First bits for rebuild. Disabled for now.


# 1.9 11-May-2009 jsing

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@


# 1.8 28-Apr-2009 marco

Part one of partial bringup volumes. Plenty of rope to kill your data
use with caution...


Revision tags: OPENBSD_4_5_BASE
# 1.7 25-Nov-2008 marco

Add generic sr_scsi_done function that does the spl dance


Revision tags: OPENBSD_4_4_BASE
# 1.6 19-Jul-2008 marco

Full rewrite of metadata handling. This fixes power failures and crashes
that caused illegal checksums. The new metadata code is more or less ready
to deal with other vendor's metadata formats.

While here clean up the name space.

Fix thib's pool mess by adding removing bad flags in interrupt context.

tested on macppc, amd64, i386, sparc64 & hppa

sparc64 has issues with crypto however those do not seem to be softraid
specific.

help from okan@ ckuethe@ Will Backman and others


Revision tags: OPENBSD_4_3_BASE
# 1.5 05-Feb-2008 marco

Shave off a few more bytes by moving IO collision detection into a generic
fucntion. Fix bug in the crypto code that could casuse data corruption as
a bonus, bad cut & past tedu!


# 1.4 05-Feb-2008 marco

Create a generic function to validate IO instead of copying and pasting
same code in all disciplines. This shaves of a few bytes.

crypto 3185 -> 2690
raid 0 2843 -> 2378
raid 1 3474 -> 2689


# 1.3 24-Jan-2008 marco

Create chunk and state transition functions for RAID 0.
Move RAID 1 chunk and state transition functions into proper file.
Let Crypto use RAID 1 chunk and state transition functions for now but this
needs fixing.


# 1.2 24-Jan-2008 marco

Bring softraid into the world of 16 byte commands; this allows for > 2TB disks
Fix bioctl size output which was off by *512; diagnosed by otto


# 1.1 27-Nov-2007 tedu

also move softraid raid1 into own file, ok marco


# 1.66 08-Dec-2020 stsp

fix wrong function names in softraid RAID1 debug print statements

ok jsing@ as part of a larger diff


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.65 12-Apr-2016 krw

No need to rescan chunks in each discipline to find appropriate
volume sector size. Determine volume sector size in sr_meta_init().

Pointed out, tweaked and ok jsing@


# 1.64 04-Apr-2016 krw

Enable creation of softraid volumes using disks with non-512 byte
sectors. Volumes created will present a sector size equal to the
largest sector size of the constituent disks.

Softraid Metadata version cranks to 6 due to new field.

ok jsing@ with tweaks that will follow soon.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.63 21-Jul-2015 krw

A few more daddr_t fixes. Rename 'phys_off' variables to 'offset'
since they are now relative to chunks. Use 'blkno' as normal variable
name for daddr_t items rather than mix of 'blkno, blk, offset.
Change field name ssd_data_offset to ssd_data_blkno since it is a
block and not byte quantity.

No intentional functional change.


# 1.62 19-Jul-2015 krw

Remove unneeded #include <disklabel.h>.

ok jsing@


# 1.61 19-Jul-2015 krw

Stop adding and subtracting data offset. Just keep to chunk relative
block offsets until actual i/o is constructed and needs the physical
offset. Eliminate a number of <<DEV_BSIZE shifts as a bonus.

No intentional functional change.

Fixed and ok jsing@


Revision tags: OPENBSD_5_7_BASE
# 1.60 27-Jan-2015 dlg

remove #include <sys/workq.h>. it wont exist anymore soon.


# 1.59 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.58 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.57 12-Jul-2014 blambert

essentially mechanical conversion of softraid rebuild from
workq to taskq

ok jsing@


Revision tags: OPENBSD_5_5_BASE
# 1.56 22-Jan-2014 jsing

Switch metadata saves from the system workq to the system taskq.

ok dlg@


# 1.55 21-Jan-2014 jsing

Order the volume state transitions by state value.


# 1.54 01-Nov-2013 krw

Sprinkle (long long) casts where %lld is being used to print daddr_t
variables. Some random whitespace/knf repairs encountered on the way.

ok miod@ on inspection, feedback & more suggestions from millert@


Revision tags: OPENBSD_5_4_BASE
# 1.53 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.52 21-May-2013 jsing

Provide a function that handles the scheduling of work units. This
simplifies the discipline code, avoids code duplication and moves the
scheduling logic into a single location.

ok krw@


# 1.51 21-May-2013 jsing

Use a state to indicate that a work unit should only be constructed and not
scheduled, rather than trying to imply this from the rebuild flag.


# 1.50 21-Apr-2013 jsing

Convert RAID1 to the new work unit completion functions and generic
interrupt handler. Disciplines such as RAID1/4/5/6 need a way to intercept
I/O when the work unit is complete, but before the SCSI xfer is complete.
This is provided via a sd_scsi_wu_done hook, which enables work units to be
restarted or otherwise modified before the SCSI xfer completion occurs.

ok krw@


# 1.49 31-Mar-2013 jsing

Use consistent error handling when validating the number of chunks
provided.


# 1.48 31-Mar-2013 jsing

More runtime value initialisation functions.


# 1.47 31-Mar-2013 jsing

Provide default resource allocation and free functions. Convert all
disciplines except for AOE and CRYPTO, which require custom handlers.


# 1.46 29-Mar-2013 jsing

Properly release ccbs when restarting a work unit.


# 1.45 29-Mar-2013 jsing

Decouple wakeups on work unit completion from the type of I/O being
performed.

ok krw@


# 1.44 29-Mar-2013 jsing

sd_wu_pending is only decremented when scsi_done() or scsi_io_put() are
called. As a result, factor out the the sd_sync check/wakeup code and move
it to after the scsi_done() call in sr_scsi_done(). Perform the same
sd_sync check/wakeup after scsi_io_put() calls (including the addition of
some that were previously missed).

ok krw@


# 1.43 27-Mar-2013 jsing

Rewrite the work unit handling code in the RAID 1/4/5/6 interrupt handlers.
This simplifies the code and will allow for easier conversion to the workq
based work unit completion routines. It also ensures that work units are
always removed from the pending queue and that colliders are started, even
in the event of an I/O failure.

ok krw@


# 1.42 25-Mar-2013 jsing

Factor out the code that is used to recreate work units - one copy of the
code is sufficient.

ok krw@


# 1.41 02-Mar-2013 jsing

sr_alloc_resources() and sr_free_resources() can never be called without
a valid struct sr_discipline. Remove redundant NULL pointer checks.


Revision tags: OPENBSD_5_3_BASE
# 1.40 18-Jan-2013 jsing

Convert RAID1 to new ccb functions.

ok krw@


# 1.39 17-Jan-2013 jsing

Restructure the RAID1 I/O path so that we only get a ccb once we are
certain that we need one. Also make code more consistent with other
disciplines.

ok krw@


# 1.38 16-Jan-2013 jsing

Consistently call sr_scsi_done instead of scsi_done.

ok krw@


# 1.37 16-Jan-2013 jsing

Add a new capability flag to identify disciplines where read failures are
not necessarily terminal (i.e. we have redundancy).

ok krw@


# 1.36 16-Jan-2013 jsing

Set resid to zero if the scsi transfer completed without error.

ok krw@


# 1.35 16-Jan-2013 jsing

Factor out code used to release ccbs from a workunit.

ok krw@


# 1.34 15-Jan-2013 jsing

Always initialise the discipline name, not just when we are doing a create.


# 1.33 15-Jan-2013 jsing

Keep a function pointer to the per-discipline I/O interrupt handler in the
discipline data structure. To be used with an upcoming diff.


# 1.32 08-Oct-2012 jsing

Provide a mechanism for the kernel to pass data through to the discipline
during volume assembly.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 22-Jan-2012 jsing

Convert softraid(4) to new bio(4) status interface. This allows bioctl(8)
to provide useful feedback, rather than reporting an ioctl failure and
leaving the user to consult dmesg. For now we continue to print most things
to the console, even if the message is a result of an ioctl.


# 1.30 26-Dec-2011 jsing

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.


# 1.29 25-Dec-2011 jsing

Initialise discipline function pointers with defaults and only override
those that are needed by a specific discipline.


# 1.28 25-Dec-2011 jsing

Move chunk state debugging code to a more useful location.


Revision tags: OPENBSD_5_0_BASE
# 1.27 05-Apr-2011 krw

Iopoolification. Testing by marco@.

ok dlg@ marco@


Revision tags: OPENBSD_4_9_BASE
# 1.26 06-Nov-2010 marco

Move raid1 and crypto io to a workq. This is to avoid a potential VOP_
call while in interrupt context.

Contains an additional spl dance as found by thib.

Tested by many opn various arches. Note that raid 0/4/5/6 have not been
moved over yet.


Revision tags: OPENBSD_4_8_BASE
# 1.25 02-Jul-2010 jsing

Determine the data offset using a variable specified within the softraid
metadata. This allows us to implement seamless transitions from the
previous metadata version to the current version, avoiding the need to
recreate the softraid volume.

Joint work with marco@ during c2k10.

ok marco@


# 1.24 01-Jul-2010 thib

make sure that buf's on the stack set the b_bq to NULL.
one memset -> bzero.

ok marco@, jsing@


# 1.23 26-Mar-2010 jsing

Add storage for the boot block and boot loader to the softraid metadata.
Also add a new optional metadata type for boot data. This is the first
step (of many) towards being able to boot from softraid volumes.

WARNING: This version of the softraid metadata is not compatible with
previous versions. As a result, any softraid volumes created with older
kernels will not assemble. Data on existing softraid volumes should be
backed up before upgrading. The volume should then be recreated and the
data restored.

ok marco@


Revision tags: OPENBSD_4_7_BASE
# 1.22 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.21 15-Dec-2009 jsing

Factor out discipline specific create/assemble code.

"in, in, in!" marco@


# 1.20 07-Dec-2009 jsing

Define discipline capabilities using a set of flags.

"shiny!!" marco@


# 1.19 09-Aug-2009 marco

Switch softraid to vnodes to prevent bad things from happening when using
d_open/d_close.

tested by many, ok jsing, thib, krw


# 1.18 12-Jul-2009 jsing

Clean up debug droppings in sr_raid1_set_vol_state().

ok marco@


# 1.17 12-Jul-2009 jsing

Enable hotspare rebuilds for softraid RAID1.

ok marco@


Revision tags: OPENBSD_4_6_BASE
# 1.16 24-Jun-2009 jsing

Abort the current rebuild if the rebuild chunk disappears. Whilst here also
rename the abort flag so that it is more generalised.

ok marco@


# 1.15 18-Jun-2009 jsing

Add other valid chunk state transitions for RAID 1.

ok marco@


# 1.14 02-Jun-2009 marco

Abuse bio layer a little less by marking fake buffers with B_PHYS.
From beck with lots of squealing and ear bleeds.
Issue originally reported by todd.

ok beck


# 1.13 02-Jun-2009 marco

Rebuild can go to degraded


# 1.12 02-Jun-2009 deraadt

marco needs to learn how to do his range checks better, found by Parfait
ok oga guenther


# 1.11 02-Jun-2009 marco

Add an identifier that tells us if we can rebuild this discipline.
KNF & spelling too


# 1.10 02-Jun-2009 marco

First bits for rebuild. Disabled for now.


# 1.9 11-May-2009 jsing

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@


# 1.8 28-Apr-2009 marco

Part one of partial bringup volumes. Plenty of rope to kill your data
use with caution...


Revision tags: OPENBSD_4_5_BASE
# 1.7 25-Nov-2008 marco

Add generic sr_scsi_done function that does the spl dance


Revision tags: OPENBSD_4_4_BASE
# 1.6 19-Jul-2008 marco

Full rewrite of metadata handling. This fixes power failures and crashes
that caused illegal checksums. The new metadata code is more or less ready
to deal with other vendor's metadata formats.

While here clean up the name space.

Fix thib's pool mess by adding removing bad flags in interrupt context.

tested on macppc, amd64, i386, sparc64 & hppa

sparc64 has issues with crypto however those do not seem to be softraid
specific.

help from okan@ ckuethe@ Will Backman and others


Revision tags: OPENBSD_4_3_BASE
# 1.5 05-Feb-2008 marco

Shave off a few more bytes by moving IO collision detection into a generic
fucntion. Fix bug in the crypto code that could casuse data corruption as
a bonus, bad cut & past tedu!


# 1.4 05-Feb-2008 marco

Create a generic function to validate IO instead of copying and pasting
same code in all disciplines. This shaves of a few bytes.

crypto 3185 -> 2690
raid 0 2843 -> 2378
raid 1 3474 -> 2689


# 1.3 24-Jan-2008 marco

Create chunk and state transition functions for RAID 0.
Move RAID 1 chunk and state transition functions into proper file.
Let Crypto use RAID 1 chunk and state transition functions for now but this
needs fixing.


# 1.2 24-Jan-2008 marco

Bring softraid into the world of 16 byte commands; this allows for > 2TB disks
Fix bioctl size output which was off by *512; diagnosed by otto


# 1.1 27-Nov-2007 tedu

also move softraid raid1 into own file, ok marco


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.65 12-Apr-2016 krw

No need to rescan chunks in each discipline to find appropriate
volume sector size. Determine volume sector size in sr_meta_init().

Pointed out, tweaked and ok jsing@


# 1.64 04-Apr-2016 krw

Enable creation of softraid volumes using disks with non-512 byte
sectors. Volumes created will present a sector size equal to the
largest sector size of the constituent disks.

Softraid Metadata version cranks to 6 due to new field.

ok jsing@ with tweaks that will follow soon.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE
# 1.63 21-Jul-2015 krw

A few more daddr_t fixes. Rename 'phys_off' variables to 'offset'
since they are now relative to chunks. Use 'blkno' as normal variable
name for daddr_t items rather than mix of 'blkno, blk, offset.
Change field name ssd_data_offset to ssd_data_blkno since it is a
block and not byte quantity.

No intentional functional change.


# 1.62 19-Jul-2015 krw

Remove unneeded #include <disklabel.h>.

ok jsing@


# 1.61 19-Jul-2015 krw

Stop adding and subtracting data offset. Just keep to chunk relative
block offsets until actual i/o is constructed and needs the physical
offset. Eliminate a number of <<DEV_BSIZE shifts as a bonus.

No intentional functional change.

Fixed and ok jsing@


Revision tags: OPENBSD_5_7_BASE
# 1.60 27-Jan-2015 dlg

remove #include <sys/workq.h>. it wont exist anymore soon.


# 1.59 18-Nov-2014 tedu

move arc4random prototype to systm.h. more appropriate for most code
to include that than rdnvar.h. ok deraadt dlg


# 1.58 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.57 12-Jul-2014 blambert

essentially mechanical conversion of softraid rebuild from
workq to taskq

ok jsing@


Revision tags: OPENBSD_5_5_BASE
# 1.56 22-Jan-2014 jsing

Switch metadata saves from the system workq to the system taskq.

ok dlg@


# 1.55 21-Jan-2014 jsing

Order the volume state transitions by state value.


# 1.54 01-Nov-2013 krw

Sprinkle (long long) casts where %lld is being used to print daddr_t
variables. Some random whitespace/knf repairs encountered on the way.

ok miod@ on inspection, feedback & more suggestions from millert@


Revision tags: OPENBSD_5_4_BASE
# 1.53 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.52 21-May-2013 jsing

Provide a function that handles the scheduling of work units. This
simplifies the discipline code, avoids code duplication and moves the
scheduling logic into a single location.

ok krw@


# 1.51 21-May-2013 jsing

Use a state to indicate that a work unit should only be constructed and not
scheduled, rather than trying to imply this from the rebuild flag.


# 1.50 21-Apr-2013 jsing

Convert RAID1 to the new work unit completion functions and generic
interrupt handler. Disciplines such as RAID1/4/5/6 need a way to intercept
I/O when the work unit is complete, but before the SCSI xfer is complete.
This is provided via a sd_scsi_wu_done hook, which enables work units to be
restarted or otherwise modified before the SCSI xfer completion occurs.

ok krw@


# 1.49 31-Mar-2013 jsing

Use consistent error handling when validating the number of chunks
provided.


# 1.48 31-Mar-2013 jsing

More runtime value initialisation functions.


# 1.47 31-Mar-2013 jsing

Provide default resource allocation and free functions. Convert all
disciplines except for AOE and CRYPTO, which require custom handlers.


# 1.46 29-Mar-2013 jsing

Properly release ccbs when restarting a work unit.


# 1.45 29-Mar-2013 jsing

Decouple wakeups on work unit completion from the type of I/O being
performed.

ok krw@


# 1.44 29-Mar-2013 jsing

sd_wu_pending is only decremented when scsi_done() or scsi_io_put() are
called. As a result, factor out the the sd_sync check/wakeup code and move
it to after the scsi_done() call in sr_scsi_done(). Perform the same
sd_sync check/wakeup after scsi_io_put() calls (including the addition of
some that were previously missed).

ok krw@


# 1.43 27-Mar-2013 jsing

Rewrite the work unit handling code in the RAID 1/4/5/6 interrupt handlers.
This simplifies the code and will allow for easier conversion to the workq
based work unit completion routines. It also ensures that work units are
always removed from the pending queue and that colliders are started, even
in the event of an I/O failure.

ok krw@


# 1.42 25-Mar-2013 jsing

Factor out the code that is used to recreate work units - one copy of the
code is sufficient.

ok krw@


# 1.41 02-Mar-2013 jsing

sr_alloc_resources() and sr_free_resources() can never be called without
a valid struct sr_discipline. Remove redundant NULL pointer checks.


Revision tags: OPENBSD_5_3_BASE
# 1.40 18-Jan-2013 jsing

Convert RAID1 to new ccb functions.

ok krw@


# 1.39 17-Jan-2013 jsing

Restructure the RAID1 I/O path so that we only get a ccb once we are
certain that we need one. Also make code more consistent with other
disciplines.

ok krw@


# 1.38 16-Jan-2013 jsing

Consistently call sr_scsi_done instead of scsi_done.

ok krw@


# 1.37 16-Jan-2013 jsing

Add a new capability flag to identify disciplines where read failures are
not necessarily terminal (i.e. we have redundancy).

ok krw@


# 1.36 16-Jan-2013 jsing

Set resid to zero if the scsi transfer completed without error.

ok krw@


# 1.35 16-Jan-2013 jsing

Factor out code used to release ccbs from a workunit.

ok krw@


# 1.34 15-Jan-2013 jsing

Always initialise the discipline name, not just when we are doing a create.


# 1.33 15-Jan-2013 jsing

Keep a function pointer to the per-discipline I/O interrupt handler in the
discipline data structure. To be used with an upcoming diff.


# 1.32 08-Oct-2012 jsing

Provide a mechanism for the kernel to pass data through to the discipline
during volume assembly.


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.31 22-Jan-2012 jsing

Convert softraid(4) to new bio(4) status interface. This allows bioctl(8)
to provide useful feedback, rather than reporting an ioctl failure and
leaving the user to consult dmesg. For now we continue to print most things
to the console, even if the message is a result of an ioctl.


# 1.30 26-Dec-2011 jsing

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.


# 1.29 25-Dec-2011 jsing

Initialise discipline function pointers with defaults and only override
those that are needed by a specific discipline.


# 1.28 25-Dec-2011 jsing

Move chunk state debugging code to a more useful location.


Revision tags: OPENBSD_5_0_BASE
# 1.27 05-Apr-2011 krw

Iopoolification. Testing by marco@.

ok dlg@ marco@


Revision tags: OPENBSD_4_9_BASE
# 1.26 06-Nov-2010 marco

Move raid1 and crypto io to a workq. This is to avoid a potential VOP_
call while in interrupt context.

Contains an additional spl dance as found by thib.

Tested by many opn various arches. Note that raid 0/4/5/6 have not been
moved over yet.


Revision tags: OPENBSD_4_8_BASE
# 1.25 02-Jul-2010 jsing

Determine the data offset using a variable specified within the softraid
metadata. This allows us to implement seamless transitions from the
previous metadata version to the current version, avoiding the need to
recreate the softraid volume.

Joint work with marco@ during c2k10.

ok marco@


# 1.24 01-Jul-2010 thib

make sure that buf's on the stack set the b_bq to NULL.
one memset -> bzero.

ok marco@, jsing@


# 1.23 26-Mar-2010 jsing

Add storage for the boot block and boot loader to the softraid metadata.
Also add a new optional metadata type for boot data. This is the first
step (of many) towards being able to boot from softraid volumes.

WARNING: This version of the softraid metadata is not compatible with
previous versions. As a result, any softraid volumes created with older
kernels will not assemble. Data on existing softraid volumes should be
backed up before upgrading. The volume should then be recreated and the
data restored.

ok marco@


Revision tags: OPENBSD_4_7_BASE
# 1.22 09-Jan-2010 krw

Zap all setting of ITSDONE in drivers that don't look at it. Nobody
else cares so it's just noise. Drivers that actually look at ITSDONE
are unchanged.

ok marco@ (for his files) dlg@ beck@


# 1.21 15-Dec-2009 jsing

Factor out discipline specific create/assemble code.

"in, in, in!" marco@


# 1.20 07-Dec-2009 jsing

Define discipline capabilities using a set of flags.

"shiny!!" marco@


# 1.19 09-Aug-2009 marco

Switch softraid to vnodes to prevent bad things from happening when using
d_open/d_close.

tested by many, ok jsing, thib, krw


# 1.18 12-Jul-2009 jsing

Clean up debug droppings in sr_raid1_set_vol_state().

ok marco@


# 1.17 12-Jul-2009 jsing

Enable hotspare rebuilds for softraid RAID1.

ok marco@


Revision tags: OPENBSD_4_6_BASE
# 1.16 24-Jun-2009 jsing

Abort the current rebuild if the rebuild chunk disappears. Whilst here also
rename the abort flag so that it is more generalised.

ok marco@


# 1.15 18-Jun-2009 jsing

Add other valid chunk state transitions for RAID 1.

ok marco@


# 1.14 02-Jun-2009 marco

Abuse bio layer a little less by marking fake buffers with B_PHYS.
From beck with lots of squealing and ear bleeds.
Issue originally reported by todd.

ok beck


# 1.13 02-Jun-2009 marco

Rebuild can go to degraded


# 1.12 02-Jun-2009 deraadt

marco needs to learn how to do his range checks better, found by Parfait
ok oga guenther


# 1.11 02-Jun-2009 marco

Add an identifier that tells us if we can rebuild this discipline.
KNF & spelling too


# 1.10 02-Jun-2009 marco

First bits for rebuild. Disabled for now.


# 1.9 11-May-2009 jsing

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@


# 1.8 28-Apr-2009 marco

Part one of partial bringup volumes. Plenty of rope to kill your data
use with caution...


Revision tags: OPENBSD_4_5_BASE
# 1.7 25-Nov-2008 marco

Add generic sr_scsi_done function that does the spl dance


Revision tags: OPENBSD_4_4_BASE
# 1.6 19-Jul-2008 marco

Full rewrite of metadata handling. This fixes power failures and crashes
that caused illegal checksums. The new metadata code is more or less ready
to deal with other vendor's metadata formats.

While here clean up the name space.

Fix thib's pool mess by adding removing bad flags in interrupt context.

tested on macppc, amd64, i386, sparc64 & hppa

sparc64 has issues with crypto however those do not seem to be softraid
specific.

help from okan@ ckuethe@ Will Backman and others


Revision tags: OPENBSD_4_3_BASE
# 1.5 05-Feb-2008 marco

Shave off a few more bytes by moving IO collision detection into a generic
fucntion. Fix bug in the crypto code that could casuse data corruption as
a bonus, bad cut & past tedu!


# 1.4 05-Feb-2008 marco

Create a generic function to validate IO instead of copying and pasting
same code in all disciplines. This shaves of a few bytes.

crypto 3185 -> 2690
raid 0 2843 -> 2378
raid 1 3474 -> 2689


# 1.3 24-Jan-2008 marco

Create chunk and state transition functions for RAID 0.
Move RAID 1 chunk and state transition functions into proper file.
Let Crypto use RAID 1 chunk and state transition functions for now but this
needs fixing.


# 1.2 24-Jan-2008 marco

Bring softraid into the world of 16 byte commands; this allows for > 2TB disks
Fix bioctl size output which was off by *512; diagnosed by otto


# 1.1 27-Nov-2007 tedu

also move softraid raid1 into own file, ok marco