From 3393f8daa3b4b18786cd585c1a37aa16dd03d410 Mon Sep 17 00:00:00 2001 From: "Kenneth D. Merry" Date: Tue, 27 Mar 2001 05:45:52 +0000 Subject: 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 --- lib/Makefile | 3 ++- lib/libcam/Makefile | 71 +++++++++++++++++++++++++++------------------------- lib/libsbuf/Makefile | 11 ++++++++ 3 files changed, 50 insertions(+), 35 deletions(-) create mode 100644 lib/libsbuf/Makefile (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 1ff9da177c69..6dfc7a3d40da 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -16,11 +16,12 @@ # libskey must be built before libpam. # libtacplus must be built before libpam. # libutil must be built before libpam. +# libsbuf must be built before libcam. # # Otherwise, the SUBDIR list should be in alphabetical order. SUBDIR= ${_csu} libcom_err libcrypt msun libmd \ - libncurses libradius libskey libtacplus libutil \ + libncurses libradius libskey libtacplus libutil libsbuf \ ${_compat} libalias libatm ${_libbind} libc ${_libc_r} libcalendar \ libcam libcompat libdevstat libdisk libedit libfetch libform \ libftpio libgnumalloc ${_libio} libipsec libipx libisc libkvm libmenu \ diff --git a/lib/libcam/Makefile b/lib/libcam/Makefile index a66251092481..c201f771d96b 100644 --- a/lib/libcam/Makefile +++ b/lib/libcam/Makefile @@ -2,39 +2,42 @@ MAINTAINER=ken@FreeBSD.ORG -LIB= cam -SRCS= camlib.c scsi_cmdparse.c scsi_all.c scsi_da.c scsi_sa.c cam.c -INCS= camlib.h - -MAN3= cam.3 cam_cdbparse.3 - - -MLINKS+=cam.3 cam_open_device.3 \ - cam.3 cam_open_spec_device.3 \ - cam.3 cam_open_btl.3 \ - cam.3 cam_open_pass.3 \ - cam.3 cam_close_device.3 \ - cam.3 cam_close_spec_device.3 \ - cam.3 cam_getccb.3 \ - cam.3 cam_send_ccb.3 \ - cam.3 cam_freeccb.3 \ - cam.3 cam_path_string.3 \ - cam.3 cam_device_dup.3 \ - cam.3 cam_device_copy.3 \ - cam.3 cam_get_device.3 \ - cam_cdbparse.3 csio_build.3 \ - cam_cdbparse.3 csio_build_visit.3 \ - cam_cdbparse.3 csio_decode.3 \ - cam_cdbparse.3 csio_decode_visit.3 \ - cam_cdbparse.3 buff_decode.3 \ - cam_cdbparse.3 buff_decode_visit.3 \ - cam_cdbparse.3 csio_encode.3 \ - cam_cdbparse.3 csio_encode_visit.3 \ - cam_cdbparse.3 buff_encode_visit.3 - -.PATH: ${.CURDIR}/../../sys/cam/scsi ${.CURDIR}/../../sys/cam - -SDIR= ${.CURDIR}/../../sys -CFLAGS+=-I${.CURDIR} -I${SDIR} +LIB= cam +SRCS= camlib.c scsi_cmdparse.c scsi_all.c scsi_da.c scsi_sa.c cam.c +INCS= camlib.h + +DPADD+= ${LIBSBUF} +LDADD+= -lsbuf + +MAN3= cam.3 cam_cdbparse.3 + + +MLINKS+= cam.3 cam_open_device.3 \ + cam.3 cam_open_spec_device.3 \ + cam.3 cam_open_btl.3 \ + cam.3 cam_open_pass.3 \ + cam.3 cam_close_device.3 \ + cam.3 cam_close_spec_device.3 \ + cam.3 cam_getccb.3 \ + cam.3 cam_send_ccb.3 \ + cam.3 cam_freeccb.3 \ + cam.3 cam_path_string.3 \ + cam.3 cam_device_dup.3 \ + cam.3 cam_device_copy.3 \ + cam.3 cam_get_device.3 \ + cam_cdbparse.3 csio_build.3 \ + cam_cdbparse.3 csio_build_visit.3 \ + cam_cdbparse.3 csio_decode.3 \ + cam_cdbparse.3 csio_decode_visit.3 \ + cam_cdbparse.3 buff_decode.3 \ + cam_cdbparse.3 buff_decode_visit.3 \ + cam_cdbparse.3 csio_encode.3 \ + cam_cdbparse.3 csio_encode_visit.3 \ + cam_cdbparse.3 buff_encode_visit.3 + +.PATH: ${.CURDIR}/../../sys/cam/scsi ${.CURDIR}/../../sys/cam + +SDIR= ${.CURDIR}/../../sys +CFLAGS+= -I${.CURDIR} -I${SDIR} .include diff --git a/lib/libsbuf/Makefile b/lib/libsbuf/Makefile new file mode 100644 index 000000000000..a443545ca6f4 --- /dev/null +++ b/lib/libsbuf/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +LIB= sbuf +SRCS= subr_sbuf.c + +.PATH: ${.CURDIR}/../../sys/kern + +SDIR= ${.CURDIR}/../../sys +CFLAGS+=-I${SDIR} + +.include -- cgit v1.2.3