2000-12-13 19:51:07 +00:00
|
|
|
/*-
|
2008-08-09 10:26:21 +00:00
|
|
|
* Copyright (c) 2000-2008 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2000-2008 Dag-Erling Coïdan Smørgrav
|
2000-12-13 19:51:07 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
2008-08-09 10:26:21 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2000-12-13 19:51:07 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
#include <sys/param.h>
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
|
|
|
|
#ifdef _KERNEL
|
2001-09-29 00:32:46 +00:00
|
|
|
#include <sys/ctype.h>
|
2010-09-09 17:49:18 +00:00
|
|
|
#include <sys/errno.h>
|
2000-12-13 19:51:07 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/systm.h>
|
2001-09-29 00:32:46 +00:00
|
|
|
#include <sys/uio.h>
|
2000-12-13 19:51:07 +00:00
|
|
|
#include <machine/stdarg.h>
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#else /* _KERNEL */
|
2001-09-29 00:32:46 +00:00
|
|
|
#include <ctype.h>
|
2010-09-09 17:49:18 +00:00
|
|
|
#include <errno.h>
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#include <stdarg.h>
|
2002-01-06 08:38:23 +00:00
|
|
|
#include <stdio.h>
|
2001-06-16 07:02:47 +00:00
|
|
|
#include <stdlib.h>
|
2002-01-06 08:38:23 +00:00
|
|
|
#include <string.h>
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#endif /* _KERNEL */
|
2000-12-13 19:51:07 +00:00
|
|
|
|
2001-09-29 00:32:46 +00:00
|
|
|
#include <sys/sbuf.h>
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#ifdef _KERNEL
|
2005-02-10 12:02:37 +00:00
|
|
|
static MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers");
|
2013-09-22 23:47:56 +00:00
|
|
|
#define SBMALLOC(size) malloc(size, M_SBUF, M_WAITOK|M_ZERO)
|
2002-01-09 07:29:28 +00:00
|
|
|
#define SBFREE(buf) free(buf, M_SBUF)
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#else /* _KERNEL */
|
2002-01-09 07:29:28 +00:00
|
|
|
#define KASSERT(e, m)
|
2013-09-22 23:47:56 +00:00
|
|
|
#define SBMALLOC(size) calloc(1, size)
|
2002-01-09 07:29:28 +00:00
|
|
|
#define SBFREE(buf) free(buf)
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#endif /* _KERNEL */
|
2000-12-13 19:51:07 +00:00
|
|
|
|
2001-01-28 00:13:01 +00:00
|
|
|
/*
|
|
|
|
* Predicates
|
|
|
|
*/
|
2002-01-09 07:29:28 +00:00
|
|
|
#define SBUF_ISDYNAMIC(s) ((s)->s_flags & SBUF_DYNAMIC)
|
|
|
|
#define SBUF_ISDYNSTRUCT(s) ((s)->s_flags & SBUF_DYNSTRUCT)
|
|
|
|
#define SBUF_ISFINISHED(s) ((s)->s_flags & SBUF_FINISHED)
|
|
|
|
#define SBUF_HASROOM(s) ((s)->s_len < (s)->s_size - 1)
|
2011-05-17 06:36:32 +00:00
|
|
|
#define SBUF_FREESPACE(s) ((s)->s_size - ((s)->s_len + 1))
|
2002-01-06 08:38:23 +00:00
|
|
|
#define SBUF_CANEXTEND(s) ((s)->s_flags & SBUF_AUTOEXTEND)
|
2013-04-11 19:49:18 +00:00
|
|
|
#define SBUF_ISSECTION(s) ((s)->s_flags & SBUF_INSECTION)
|
2001-01-28 00:13:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set / clear flags
|
|
|
|
*/
|
2002-01-09 07:29:28 +00:00
|
|
|
#define SBUF_SETFLAG(s, f) do { (s)->s_flags |= (f); } while (0)
|
|
|
|
#define SBUF_CLEARFLAG(s, f) do { (s)->s_flags &= ~(f); } while (0)
|
2001-01-28 00:13:01 +00:00
|
|
|
|
2002-01-09 07:29:28 +00:00
|
|
|
#define SBUF_MINEXTENDSIZE 16 /* Should be power of 2. */
|
2011-05-17 06:36:32 +00:00
|
|
|
|
|
|
|
#ifdef PAGE_SIZE
|
2002-01-09 07:29:28 +00:00
|
|
|
#define SBUF_MAXEXTENDSIZE PAGE_SIZE
|
|
|
|
#define SBUF_MAXEXTENDINCR PAGE_SIZE
|
2011-05-17 06:36:32 +00:00
|
|
|
#else
|
|
|
|
#define SBUF_MAXEXTENDSIZE 4096
|
|
|
|
#define SBUF_MAXEXTENDINCR 4096
|
|
|
|
#endif
|
2002-01-06 08:38:23 +00:00
|
|
|
|
2001-01-28 00:13:01 +00:00
|
|
|
/*
|
|
|
|
* Debugging support
|
|
|
|
*/
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#if defined(_KERNEL) && defined(INVARIANTS)
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
static void
|
2002-03-19 10:56:46 +00:00
|
|
|
_assert_sbuf_integrity(const char *fun, struct sbuf *s)
|
2000-12-13 19:51:07 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
KASSERT(s != NULL,
|
2001-03-06 17:48:26 +00:00
|
|
|
("%s called with a NULL sbuf pointer", fun));
|
2000-12-13 19:51:07 +00:00
|
|
|
KASSERT(s->s_buf != NULL,
|
2002-01-06 08:38:23 +00:00
|
|
|
("%s called with uninitialized or corrupt sbuf", fun));
|
2000-12-13 19:51:07 +00:00
|
|
|
KASSERT(s->s_len < s->s_size,
|
2011-05-16 16:18:40 +00:00
|
|
|
("wrote past end of sbuf (%jd >= %jd)",
|
|
|
|
(intmax_t)s->s_len, (intmax_t)s->s_size));
|
2000-12-13 19:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-19 10:56:46 +00:00
|
|
|
_assert_sbuf_state(const char *fun, struct sbuf *s, int state)
|
2000-12-13 19:51:07 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
KASSERT((s->s_flags & SBUF_FINISHED) == state,
|
2001-03-06 17:48:26 +00:00
|
|
|
("%s called with %sfinished or corrupt sbuf", fun,
|
2000-12-13 19:51:07 +00:00
|
|
|
(state ? "un" : "")));
|
|
|
|
}
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2002-01-09 07:29:28 +00:00
|
|
|
#define assert_sbuf_integrity(s) _assert_sbuf_integrity(__func__, (s))
|
|
|
|
#define assert_sbuf_state(s, i) _assert_sbuf_state(__func__, (s), (i))
|
2008-08-09 10:26:21 +00:00
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#else /* _KERNEL && INVARIANTS */
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2002-01-09 07:29:28 +00:00
|
|
|
#define assert_sbuf_integrity(s) do { } while (0)
|
|
|
|
#define assert_sbuf_state(s, i) do { } while (0)
|
2008-08-09 10:26:21 +00:00
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
#endif /* _KERNEL && INVARIANTS */
|
2000-12-13 19:51:07 +00:00
|
|
|
|
2010-09-03 17:42:17 +00:00
|
|
|
#ifdef CTASSERT
|
2010-09-03 16:09:17 +00:00
|
|
|
CTASSERT(powerof2(SBUF_MAXEXTENDSIZE));
|
|
|
|
CTASSERT(powerof2(SBUF_MAXEXTENDINCR));
|
2010-09-03 17:23:26 +00:00
|
|
|
#endif
|
2010-09-03 16:09:17 +00:00
|
|
|
|
2002-01-06 08:38:23 +00:00
|
|
|
static int
|
|
|
|
sbuf_extendsize(int size)
|
|
|
|
{
|
|
|
|
int newsize;
|
|
|
|
|
2010-09-03 16:09:17 +00:00
|
|
|
if (size < (int)SBUF_MAXEXTENDSIZE) {
|
|
|
|
newsize = SBUF_MINEXTENDSIZE;
|
|
|
|
while (newsize < size)
|
2002-01-06 08:38:23 +00:00
|
|
|
newsize *= 2;
|
2010-09-03 16:09:17 +00:00
|
|
|
} else {
|
|
|
|
newsize = roundup2(size, SBUF_MAXEXTENDINCR);
|
2002-01-06 08:38:23 +00:00
|
|
|
}
|
2010-09-03 16:12:39 +00:00
|
|
|
KASSERT(newsize >= size, ("%s: %d < %d\n", __func__, newsize, size));
|
2002-01-06 08:38:23 +00:00
|
|
|
return (newsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extend an sbuf.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sbuf_extend(struct sbuf *s, int addlen)
|
|
|
|
{
|
|
|
|
char *newbuf;
|
2014-07-28 07:20:22 +00:00
|
|
|
int newsize;
|
2002-01-06 08:38:23 +00:00
|
|
|
|
|
|
|
if (!SBUF_CANEXTEND(s))
|
|
|
|
return (-1);
|
|
|
|
newsize = sbuf_extendsize(s->s_size + addlen);
|
2008-08-09 10:26:21 +00:00
|
|
|
newbuf = SBMALLOC(newsize);
|
2002-01-06 08:38:23 +00:00
|
|
|
if (newbuf == NULL)
|
|
|
|
return (-1);
|
2011-05-17 11:04:50 +00:00
|
|
|
memcpy(newbuf, s->s_buf, s->s_size);
|
2002-01-06 08:38:23 +00:00
|
|
|
if (SBUF_ISDYNAMIC(s))
|
|
|
|
SBFREE(s->s_buf);
|
|
|
|
else
|
|
|
|
SBUF_SETFLAG(s, SBUF_DYNAMIC);
|
|
|
|
s->s_buf = newbuf;
|
|
|
|
s->s_size = newsize;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-05-17 11:04:50 +00:00
|
|
|
/*
|
|
|
|
* Initialize the internals of an sbuf.
|
|
|
|
* If buf is non-NULL, it points to a static or already-allocated string
|
|
|
|
* big enough to hold at least length characters.
|
|
|
|
*/
|
|
|
|
static struct sbuf *
|
2014-07-28 07:20:22 +00:00
|
|
|
sbuf_newbuf(struct sbuf *s, char *buf, int length, int flags)
|
2011-05-17 11:04:50 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
memset(s, 0, sizeof(*s));
|
|
|
|
s->s_flags = flags;
|
|
|
|
s->s_size = length;
|
|
|
|
s->s_buf = buf;
|
|
|
|
|
|
|
|
if ((s->s_flags & SBUF_AUTOEXTEND) == 0) {
|
2011-08-19 08:29:10 +00:00
|
|
|
KASSERT(s->s_size >= 0,
|
2011-05-17 11:04:50 +00:00
|
|
|
("attempt to create a too small sbuf"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->s_buf != NULL)
|
|
|
|
return (s);
|
|
|
|
|
|
|
|
if ((flags & SBUF_AUTOEXTEND) != 0)
|
|
|
|
s->s_size = sbuf_extendsize(s->s_size);
|
|
|
|
|
|
|
|
s->s_buf = SBMALLOC(s->s_size);
|
|
|
|
if (s->s_buf == NULL)
|
|
|
|
return (NULL);
|
|
|
|
SBUF_SETFLAG(s, SBUF_DYNAMIC);
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
/*
|
|
|
|
* Initialize an sbuf.
|
|
|
|
* If buf is non-NULL, it points to a static or already-allocated string
|
|
|
|
* big enough to hold at least length characters.
|
|
|
|
*/
|
2001-06-10 15:48:04 +00:00
|
|
|
struct sbuf *
|
2001-01-28 00:13:01 +00:00
|
|
|
sbuf_new(struct sbuf *s, char *buf, int length, int flags)
|
2000-12-13 19:51:07 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2001-01-28 00:13:01 +00:00
|
|
|
KASSERT(length >= 0,
|
|
|
|
("attempt to create an sbuf of negative length (%d)", length));
|
2002-01-06 08:38:23 +00:00
|
|
|
KASSERT((flags & ~SBUF_USRFLAGMSK) == 0,
|
|
|
|
("%s called with invalid flags", __func__));
|
2000-12-13 19:51:07 +00:00
|
|
|
|
2002-01-06 08:38:23 +00:00
|
|
|
flags &= SBUF_USRFLAGMSK;
|
2011-05-17 11:04:50 +00:00
|
|
|
if (s != NULL)
|
|
|
|
return (sbuf_newbuf(s, buf, length, flags));
|
|
|
|
|
|
|
|
s = SBMALLOC(sizeof(*s));
|
|
|
|
if (s == NULL)
|
|
|
|
return (NULL);
|
|
|
|
if (sbuf_newbuf(s, buf, length, flags) == NULL) {
|
|
|
|
SBFREE(s);
|
2001-06-10 15:48:04 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
2011-05-17 11:04:50 +00:00
|
|
|
SBUF_SETFLAG(s, SBUF_DYNSTRUCT);
|
2001-06-10 15:48:04 +00:00
|
|
|
return (s);
|
2000-12-13 19:51:07 +00:00
|
|
|
}
|
|
|
|
|
2001-09-29 00:32:46 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
|
|
|
* Create an sbuf with uio data
|
|
|
|
*/
|
|
|
|
struct sbuf *
|
|
|
|
sbuf_uionew(struct sbuf *s, struct uio *uio, int *error)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2001-09-29 00:32:46 +00:00
|
|
|
KASSERT(uio != NULL,
|
2001-12-10 05:51:45 +00:00
|
|
|
("%s called with NULL uio pointer", __func__));
|
2001-09-29 00:32:46 +00:00
|
|
|
KASSERT(error != NULL,
|
2001-12-10 05:51:45 +00:00
|
|
|
("%s called with NULL error pointer", __func__));
|
2001-09-29 00:32:46 +00:00
|
|
|
|
|
|
|
s = sbuf_new(s, NULL, uio->uio_resid + 1, 0);
|
|
|
|
if (s == NULL) {
|
|
|
|
*error = ENOMEM;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
*error = uiomove(s->s_buf, uio->uio_resid, uio);
|
|
|
|
if (*error != 0) {
|
|
|
|
sbuf_delete(s);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
s->s_len = s->s_size - 1;
|
2013-04-11 19:49:18 +00:00
|
|
|
if (SBUF_ISSECTION(s))
|
|
|
|
s->s_sect_len = s->s_size - 1;
|
2001-09-29 00:32:46 +00:00
|
|
|
*error = 0;
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-28 00:13:01 +00:00
|
|
|
/*
|
2002-01-06 08:38:23 +00:00
|
|
|
* Clear an sbuf and reset its position.
|
2001-01-28 00:13:01 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbuf_clear(struct sbuf *s)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2001-01-28 00:13:01 +00:00
|
|
|
assert_sbuf_integrity(s);
|
2001-01-28 00:33:58 +00:00
|
|
|
/* don't care if it's finished or not */
|
2001-01-28 00:13:01 +00:00
|
|
|
|
|
|
|
SBUF_CLEARFLAG(s, SBUF_FINISHED);
|
2010-09-09 17:49:18 +00:00
|
|
|
s->s_error = 0;
|
2001-01-28 00:13:01 +00:00
|
|
|
s->s_len = 0;
|
2013-04-11 19:49:18 +00:00
|
|
|
s->s_sect_len = 0;
|
2001-01-28 00:13:01 +00:00
|
|
|
}
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
/*
|
2002-01-06 08:38:23 +00:00
|
|
|
* Set the sbuf's end position to an arbitrary value.
|
|
|
|
* Effectively truncates the sbuf at the new position.
|
2000-12-13 19:51:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2014-07-28 07:20:22 +00:00
|
|
|
sbuf_setpos(struct sbuf *s, ssize_t pos)
|
2000-12-13 19:51:07 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2014-07-28 07:20:22 +00:00
|
|
|
KASSERT(pos >= 0,
|
|
|
|
("attempt to seek to a negative position (%jd)", (intmax_t)pos));
|
2000-12-13 19:51:07 +00:00
|
|
|
KASSERT(pos < s->s_size,
|
2011-05-16 16:18:40 +00:00
|
|
|
("attempt to seek past end of sbuf (%jd >= %jd)",
|
|
|
|
(intmax_t)pos, (intmax_t)s->s_size));
|
2013-04-11 19:49:18 +00:00
|
|
|
KASSERT(!SBUF_ISSECTION(s),
|
|
|
|
("attempt to seek when in a section"));
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2014-07-28 07:20:22 +00:00
|
|
|
if (pos < 0 || pos > s->s_len)
|
2000-12-13 19:51:07 +00:00
|
|
|
return (-1);
|
|
|
|
s->s_len = pos;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2010-09-09 17:49:18 +00:00
|
|
|
/*
|
|
|
|
* Set up a drain function and argument on an sbuf to flush data to
|
|
|
|
* when the sbuf buffer overflows.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbuf_set_drain(struct sbuf *s, sbuf_drain_func *func, void *ctx)
|
|
|
|
{
|
|
|
|
|
|
|
|
assert_sbuf_state(s, 0);
|
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
KASSERT(func == s->s_drain_func || s->s_len == 0,
|
|
|
|
("Cannot change drain to %p on non-empty sbuf %p", func, s));
|
|
|
|
s->s_drain_func = func;
|
|
|
|
s->s_drain_arg = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the drain and process the return.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sbuf_drain(struct sbuf *s)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
KASSERT(s->s_len > 0, ("Shouldn't drain empty sbuf %p", s));
|
2010-09-10 16:42:16 +00:00
|
|
|
KASSERT(s->s_error == 0, ("Called %s with error on %p", __func__, s));
|
2010-09-09 17:49:18 +00:00
|
|
|
len = s->s_drain_func(s->s_drain_arg, s->s_buf, s->s_len);
|
|
|
|
if (len < 0) {
|
|
|
|
s->s_error = -len;
|
|
|
|
return (s->s_error);
|
|
|
|
}
|
2010-09-16 16:13:12 +00:00
|
|
|
KASSERT(len > 0 && len <= s->s_len,
|
|
|
|
("Bad drain amount %d for sbuf %p", len, s));
|
2010-09-09 17:49:18 +00:00
|
|
|
s->s_len -= len;
|
|
|
|
/*
|
|
|
|
* Fast path for the expected case where all the data was
|
|
|
|
* drained.
|
|
|
|
*/
|
|
|
|
if (s->s_len == 0)
|
|
|
|
return (0);
|
|
|
|
/*
|
|
|
|
* Move the remaining characters to the beginning of the
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
memmove(s->s_buf, s->s_buf + len, s->s_len);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:51:52 +00:00
|
|
|
/*
|
|
|
|
* Append a byte to an sbuf. This is the core function for appending
|
|
|
|
* to an sbuf and is the main place that deals with extending the
|
|
|
|
* buffer and marking overflow.
|
|
|
|
*/
|
|
|
|
static void
|
2011-05-17 06:36:32 +00:00
|
|
|
sbuf_put_byte(struct sbuf *s, int c)
|
2010-09-09 16:51:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2010-09-09 16:51:52 +00:00
|
|
|
return;
|
|
|
|
if (SBUF_FREESPACE(s) <= 0) {
|
2011-05-17 06:36:32 +00:00
|
|
|
/*
|
2010-09-09 17:49:18 +00:00
|
|
|
* If there is a drain, use it, otherwise extend the
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
if (s->s_drain_func != NULL)
|
|
|
|
(void)sbuf_drain(s);
|
|
|
|
else if (sbuf_extend(s, 1) < 0)
|
2010-09-10 16:42:16 +00:00
|
|
|
s->s_error = ENOMEM;
|
|
|
|
if (s->s_error != 0)
|
2010-09-09 16:51:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->s_buf[s->s_len++] = c;
|
2013-04-11 19:49:18 +00:00
|
|
|
if (SBUF_ISSECTION(s))
|
|
|
|
s->s_sect_len++;
|
2010-09-09 16:51:52 +00:00
|
|
|
}
|
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
/*
|
|
|
|
* Append a byte string to an sbuf.
|
|
|
|
*/
|
|
|
|
int
|
2004-07-09 11:37:44 +00:00
|
|
|
sbuf_bcat(struct sbuf *s, const void *buf, size_t len)
|
2001-06-11 17:05:52 +00:00
|
|
|
{
|
2004-07-09 11:37:44 +00:00
|
|
|
const char *str = buf;
|
2010-09-09 16:51:52 +00:00
|
|
|
const char *end = str + len;
|
2004-07-09 11:35:30 +00:00
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2001-06-11 17:05:52 +00:00
|
|
|
return (-1);
|
2010-09-09 16:51:52 +00:00
|
|
|
for (; str < end; str++) {
|
2011-05-17 06:36:32 +00:00
|
|
|
sbuf_put_byte(s, *str);
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2010-09-09 16:51:52 +00:00
|
|
|
return (-1);
|
2011-05-17 06:36:32 +00:00
|
|
|
}
|
2001-06-11 17:05:52 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
|
|
|
* Copy a byte string from userland into an sbuf.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbuf_bcopyin(struct sbuf *s, const void *uaddr, size_t len)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2010-09-09 17:49:18 +00:00
|
|
|
KASSERT(s->s_drain_func == NULL,
|
|
|
|
("Nonsensical copyin to sbuf %p with a drain", s));
|
2001-06-11 17:05:52 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2001-06-11 17:05:52 +00:00
|
|
|
return (-1);
|
|
|
|
if (len == 0)
|
|
|
|
return (0);
|
2002-01-06 08:38:23 +00:00
|
|
|
if (len > SBUF_FREESPACE(s)) {
|
|
|
|
sbuf_extend(s, len - SBUF_FREESPACE(s));
|
2010-09-03 17:42:12 +00:00
|
|
|
if (SBUF_FREESPACE(s) < len)
|
|
|
|
len = SBUF_FREESPACE(s);
|
2002-01-06 08:38:23 +00:00
|
|
|
}
|
2001-06-11 18:36:18 +00:00
|
|
|
if (copyin(uaddr, s->s_buf + s->s_len, len) != 0)
|
|
|
|
return (-1);
|
2001-06-11 18:43:32 +00:00
|
|
|
s->s_len += len;
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a byte string into an sbuf.
|
|
|
|
*/
|
|
|
|
int
|
2004-07-09 11:37:44 +00:00
|
|
|
sbuf_bcpy(struct sbuf *s, const void *buf, size_t len)
|
2001-06-11 17:05:52 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
sbuf_clear(s);
|
2004-07-09 11:37:44 +00:00
|
|
|
return (sbuf_bcat(s, buf, len));
|
2001-06-11 17:05:52 +00:00
|
|
|
}
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
/*
|
|
|
|
* Append a string to an sbuf.
|
|
|
|
*/
|
|
|
|
int
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
sbuf_cat(struct sbuf *s, const char *str)
|
2000-12-13 19:51:07 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2000-12-13 19:51:07 +00:00
|
|
|
return (-1);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2010-09-03 17:42:12 +00:00
|
|
|
while (*str != '\0') {
|
2011-05-17 06:36:32 +00:00
|
|
|
sbuf_put_byte(s, *str++);
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2010-09-09 16:51:52 +00:00
|
|
|
return (-1);
|
2000-12-13 19:51:07 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
2002-01-06 08:38:23 +00:00
|
|
|
* Append a string from userland to an sbuf.
|
2001-06-11 17:05:52 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbuf_copyin(struct sbuf *s, const void *uaddr, size_t len)
|
|
|
|
{
|
|
|
|
size_t done;
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2001-06-11 17:05:52 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2010-09-09 17:49:18 +00:00
|
|
|
KASSERT(s->s_drain_func == NULL,
|
|
|
|
("Nonsensical copyin to sbuf %p with a drain", s));
|
2001-06-11 17:05:52 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2001-06-11 17:05:52 +00:00
|
|
|
return (-1);
|
|
|
|
|
2002-01-06 08:38:23 +00:00
|
|
|
if (len == 0)
|
|
|
|
len = SBUF_FREESPACE(s); /* XXX return 0? */
|
|
|
|
if (len > SBUF_FREESPACE(s)) {
|
|
|
|
sbuf_extend(s, len);
|
2010-09-03 17:42:12 +00:00
|
|
|
if (SBUF_FREESPACE(s) < len)
|
|
|
|
len = SBUF_FREESPACE(s);
|
2002-01-06 08:38:23 +00:00
|
|
|
}
|
2001-06-11 17:05:52 +00:00
|
|
|
switch (copyinstr(uaddr, s->s_buf + s->s_len, len + 1, &done)) {
|
|
|
|
case ENAMETOOLONG:
|
2010-09-10 16:42:16 +00:00
|
|
|
s->s_error = ENOMEM;
|
2001-06-11 17:05:52 +00:00
|
|
|
/* fall through */
|
|
|
|
case 0:
|
|
|
|
s->s_len += done - 1;
|
2013-04-11 19:49:18 +00:00
|
|
|
if (SBUF_ISSECTION(s))
|
|
|
|
s->s_sect_len += done - 1;
|
2001-06-11 17:05:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (-1); /* XXX */
|
|
|
|
}
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2005-12-23 11:49:53 +00:00
|
|
|
return (done);
|
2001-06-11 17:05:52 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
/*
|
|
|
|
* Copy a string into an sbuf.
|
|
|
|
*/
|
|
|
|
int
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
sbuf_cpy(struct sbuf *s, const char *str)
|
2000-12-13 19:51:07 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2001-01-28 00:13:01 +00:00
|
|
|
sbuf_clear(s);
|
2000-12-13 19:51:07 +00:00
|
|
|
return (sbuf_cat(s, str));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-01-06 08:38:23 +00:00
|
|
|
* Format the given argument list and append the resulting string to an sbuf.
|
2000-12-13 19:51:07 +00:00
|
|
|
*/
|
2010-09-09 16:51:52 +00:00
|
|
|
#ifdef _KERNEL
|
2011-05-17 06:36:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a non-NUL character to an sbuf. This prototype signature is
|
|
|
|
* suitable for use with kvprintf(9).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sbuf_putc_func(int c, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (c != '\0')
|
|
|
|
sbuf_put_byte(arg, c);
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:51:52 +00:00
|
|
|
int
|
|
|
|
sbuf_vprintf(struct sbuf *s, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
|
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
|
|
|
|
|
|
|
KASSERT(fmt != NULL,
|
|
|
|
("%s called with a NULL format string", __func__));
|
|
|
|
|
|
|
|
(void)kvprintf(fmt, sbuf_putc_func, s, 10, ap);
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2010-09-09 16:51:52 +00:00
|
|
|
return (-1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#else /* !_KERNEL */
|
2000-12-13 19:51:07 +00:00
|
|
|
int
|
2002-01-06 08:38:23 +00:00
|
|
|
sbuf_vprintf(struct sbuf *s, const char *fmt, va_list ap)
|
2000-12-13 19:51:07 +00:00
|
|
|
{
|
2003-05-25 19:03:08 +00:00
|
|
|
va_list ap_copy;
|
2014-07-28 07:20:22 +00:00
|
|
|
int error, len;
|
2000-12-13 19:51:07 +00:00
|
|
|
|
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2002-01-06 08:38:23 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
KASSERT(fmt != NULL,
|
2001-12-10 05:51:45 +00:00
|
|
|
("%s called with a NULL format string", __func__));
|
2002-01-06 08:38:23 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2000-12-13 19:51:07 +00:00
|
|
|
return (-1);
|
|
|
|
|
2010-09-09 16:51:52 +00:00
|
|
|
/*
|
|
|
|
* For the moment, there is no way to get vsnprintf(3) to hand
|
|
|
|
* back a character at a time, to push everything into
|
|
|
|
* sbuf_putc_func() as was done for the kernel.
|
2010-09-09 17:49:18 +00:00
|
|
|
*
|
|
|
|
* In userspace, while drains are useful, there's generally
|
|
|
|
* not a problem attempting to malloc(3) on out of space. So
|
|
|
|
* expand a userland sbuf if there is not enough room for the
|
|
|
|
* data produced by sbuf_[v]printf(3).
|
2010-09-09 16:51:52 +00:00
|
|
|
*/
|
|
|
|
|
2010-09-09 17:49:18 +00:00
|
|
|
error = 0;
|
2002-01-06 08:38:23 +00:00
|
|
|
do {
|
2003-05-25 19:03:08 +00:00
|
|
|
va_copy(ap_copy, ap);
|
2002-01-06 08:38:23 +00:00
|
|
|
len = vsnprintf(&s->s_buf[s->s_len], SBUF_FREESPACE(s) + 1,
|
2003-05-25 19:03:08 +00:00
|
|
|
fmt, ap_copy);
|
|
|
|
va_end(ap_copy);
|
2010-09-09 17:49:18 +00:00
|
|
|
|
|
|
|
if (SBUF_FREESPACE(s) >= len)
|
|
|
|
break;
|
|
|
|
/* Cannot print with the current available space. */
|
|
|
|
if (s->s_drain_func != NULL && s->s_len > 0)
|
|
|
|
error = sbuf_drain(s);
|
|
|
|
else
|
|
|
|
error = sbuf_extend(s, len - SBUF_FREESPACE(s));
|
|
|
|
} while (error == 0);
|
2000-12-13 19:51:07 +00:00
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
/*
|
|
|
|
* s->s_len is the length of the string, without the terminating nul.
|
|
|
|
* When updating s->s_len, we must subtract 1 from the length that
|
|
|
|
* we passed into vsnprintf() because that length includes the
|
|
|
|
* terminating nul.
|
|
|
|
*
|
|
|
|
* vsnprintf() returns the amount that would have been copied,
|
2010-09-03 17:42:12 +00:00
|
|
|
* given sufficient space, so don't over-increment s_len.
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
*/
|
2010-09-03 17:42:12 +00:00
|
|
|
if (SBUF_FREESPACE(s) < len)
|
|
|
|
len = SBUF_FREESPACE(s);
|
|
|
|
s->s_len += len;
|
2013-04-11 19:49:18 +00:00
|
|
|
if (SBUF_ISSECTION(s))
|
|
|
|
s->s_sect_len += len;
|
2002-01-22 11:22:55 +00:00
|
|
|
if (!SBUF_HASROOM(s) && !SBUF_CANEXTEND(s))
|
2010-09-10 16:42:16 +00:00
|
|
|
s->s_error = ENOMEM;
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
KASSERT(s->s_len < s->s_size,
|
|
|
|
("wrote past end of sbuf (%d >= %d)", s->s_len, s->s_size));
|
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2000-12-13 19:51:07 +00:00
|
|
|
return (-1);
|
|
|
|
return (0);
|
|
|
|
}
|
2010-09-09 16:51:52 +00:00
|
|
|
#endif /* _KERNEL */
|
2000-12-13 19:51:07 +00:00
|
|
|
|
2002-01-06 08:38:23 +00:00
|
|
|
/*
|
|
|
|
* Format the given arguments and append the resulting string to an sbuf.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbuf_printf(struct sbuf *s, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
result = sbuf_vprintf(s, fmt, ap);
|
|
|
|
va_end(ap);
|
2008-08-09 10:26:21 +00:00
|
|
|
return (result);
|
2002-01-06 08:38:23 +00:00
|
|
|
}
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
/*
|
|
|
|
* Append a character to an sbuf.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbuf_putc(struct sbuf *s, int c)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2011-05-17 06:36:32 +00:00
|
|
|
sbuf_put_byte(s, c);
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2000-12-13 19:51:07 +00:00
|
|
|
return (-1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-09-29 00:32:46 +00:00
|
|
|
/*
|
2002-01-06 08:38:23 +00:00
|
|
|
* Trim whitespace characters from end of an sbuf.
|
2001-09-29 00:32:46 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
sbuf_trim(struct sbuf *s)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2001-09-29 00:32:46 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2010-09-09 17:49:18 +00:00
|
|
|
KASSERT(s->s_drain_func == NULL,
|
|
|
|
("%s makes no sense on sbuf %p with drain", __func__, s));
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2001-09-29 00:32:46 +00:00
|
|
|
return (-1);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2013-04-11 19:49:18 +00:00
|
|
|
while (s->s_len > 0 && isspace(s->s_buf[s->s_len-1])) {
|
2001-09-29 00:32:46 +00:00
|
|
|
--s->s_len;
|
2013-04-11 19:49:18 +00:00
|
|
|
if (SBUF_ISSECTION(s))
|
|
|
|
s->s_sect_len--;
|
|
|
|
}
|
2001-09-29 00:32:46 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
/*
|
2010-09-10 16:42:16 +00:00
|
|
|
* Check if an sbuf has an error.
|
2000-12-13 19:51:07 +00:00
|
|
|
*/
|
|
|
|
int
|
2011-05-16 16:18:40 +00:00
|
|
|
sbuf_error(const struct sbuf *s)
|
2001-01-28 00:13:01 +00:00
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
return (s->s_error);
|
2001-01-28 00:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish off an sbuf.
|
|
|
|
*/
|
2010-09-09 17:49:18 +00:00
|
|
|
int
|
2000-12-13 19:51:07 +00:00
|
|
|
sbuf_finish(struct sbuf *s)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2010-09-09 17:49:18 +00:00
|
|
|
if (s->s_drain_func != NULL) {
|
2011-05-17 06:36:32 +00:00
|
|
|
while (s->s_len > 0 && s->s_error == 0)
|
|
|
|
s->s_error = sbuf_drain(s);
|
2010-09-10 16:42:16 +00:00
|
|
|
}
|
2001-03-06 17:48:26 +00:00
|
|
|
s->s_buf[s->s_len] = '\0';
|
2000-12-13 19:51:07 +00:00
|
|
|
SBUF_SETFLAG(s, SBUF_FINISHED);
|
2010-09-09 17:49:18 +00:00
|
|
|
#ifdef _KERNEL
|
2011-05-17 06:36:32 +00:00
|
|
|
return (s->s_error);
|
2010-09-09 17:49:18 +00:00
|
|
|
#else
|
2013-05-16 18:13:10 +00:00
|
|
|
if (s->s_error != 0) {
|
|
|
|
errno = s->s_error;
|
2011-05-17 06:36:32 +00:00
|
|
|
return (-1);
|
2013-05-16 18:13:10 +00:00
|
|
|
}
|
2011-05-17 06:36:32 +00:00
|
|
|
return (0);
|
2010-09-09 17:49:18 +00:00
|
|
|
#endif
|
2000-12-13 19:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a pointer to the sbuf data.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
sbuf_data(struct sbuf *s)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, SBUF_FINISHED);
|
2010-09-09 17:49:18 +00:00
|
|
|
KASSERT(s->s_drain_func == NULL,
|
|
|
|
("%s makes no sense on sbuf %p with drain", __func__, s));
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2008-08-09 10:26:21 +00:00
|
|
|
return (s->s_buf);
|
2000-12-13 19:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the length of the sbuf data.
|
|
|
|
*/
|
2011-05-16 16:18:40 +00:00
|
|
|
ssize_t
|
2000-12-13 19:51:07 +00:00
|
|
|
sbuf_len(struct sbuf *s)
|
|
|
|
{
|
2008-08-09 10:26:21 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
assert_sbuf_integrity(s);
|
2001-01-28 00:33:58 +00:00
|
|
|
/* don't care if it's finished or not */
|
2010-09-09 17:49:18 +00:00
|
|
|
KASSERT(s->s_drain_func == NULL,
|
|
|
|
("%s makes no sense on sbuf %p with drain", __func__, s));
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2010-09-10 16:42:16 +00:00
|
|
|
if (s->s_error != 0)
|
2001-01-28 00:13:01 +00:00
|
|
|
return (-1);
|
2008-08-09 10:26:21 +00:00
|
|
|
return (s->s_len);
|
2000-12-13 19:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear an sbuf, free its buffer if necessary.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbuf_delete(struct sbuf *s)
|
|
|
|
{
|
2001-12-19 19:04:57 +00:00
|
|
|
int isdyn;
|
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
/* don't care if it's finished or not */
|
2004-02-17 10:21:03 +00:00
|
|
|
|
2000-12-13 19:51:07 +00:00
|
|
|
if (SBUF_ISDYNAMIC(s))
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
SBFREE(s->s_buf);
|
2001-12-19 19:04:57 +00:00
|
|
|
isdyn = SBUF_ISDYNSTRUCT(s);
|
2011-05-17 11:04:50 +00:00
|
|
|
memset(s, 0, sizeof(*s));
|
2001-12-19 19:04:57 +00:00
|
|
|
if (isdyn)
|
2001-06-10 15:48:04 +00:00
|
|
|
SBFREE(s);
|
2000-12-13 19:51:07 +00:00
|
|
|
}
|
2002-10-04 09:58:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if an sbuf has been finished.
|
|
|
|
*/
|
|
|
|
int
|
2011-05-16 16:18:40 +00:00
|
|
|
sbuf_done(const struct sbuf *s)
|
2002-10-04 09:58:17 +00:00
|
|
|
{
|
|
|
|
|
2008-08-09 10:26:21 +00:00
|
|
|
return (SBUF_ISFINISHED(s));
|
2002-10-04 09:58:17 +00:00
|
|
|
}
|
2013-04-11 19:49:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start a section.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sbuf_start_section(struct sbuf *s, ssize_t *old_lenp)
|
|
|
|
{
|
|
|
|
|
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
|
|
|
|
|
|
|
if (!SBUF_ISSECTION(s)) {
|
|
|
|
KASSERT(s->s_sect_len == 0,
|
|
|
|
("s_sect_len != 0 when starting a section"));
|
|
|
|
if (old_lenp != NULL)
|
|
|
|
*old_lenp = -1;
|
|
|
|
SBUF_SETFLAG(s, SBUF_INSECTION);
|
|
|
|
} else {
|
|
|
|
KASSERT(old_lenp != NULL,
|
|
|
|
("s_sect_len should be saved when starting a subsection"));
|
|
|
|
*old_lenp = s->s_sect_len;
|
|
|
|
s->s_sect_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* End the section padding to the specified length with the specified
|
|
|
|
* character.
|
|
|
|
*/
|
|
|
|
ssize_t
|
|
|
|
sbuf_end_section(struct sbuf *s, ssize_t old_len, size_t pad, int c)
|
|
|
|
{
|
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
assert_sbuf_integrity(s);
|
|
|
|
assert_sbuf_state(s, 0);
|
|
|
|
KASSERT(SBUF_ISSECTION(s),
|
|
|
|
("attempt to end a section when not in a section"));
|
|
|
|
|
|
|
|
if (pad > 1) {
|
|
|
|
len = roundup(s->s_sect_len, pad) - s->s_sect_len;
|
|
|
|
for (; s->s_error == 0 && len > 0; len--)
|
|
|
|
sbuf_put_byte(s, c);
|
|
|
|
}
|
|
|
|
len = s->s_sect_len;
|
|
|
|
if (old_len == -1) {
|
|
|
|
s->s_sect_len = 0;
|
|
|
|
SBUF_CLEARFLAG(s, SBUF_INSECTION);
|
|
|
|
} else {
|
|
|
|
s->s_sect_len += old_len;
|
|
|
|
}
|
|
|
|
if (s->s_error != 0)
|
|
|
|
return (-1);
|
|
|
|
return (len);
|
|
|
|
}
|