summaryrefslogtreecommitdiffstats
path: root/sbin/camcontrol
diff options
context:
space:
mode:
authorken <ken@FreeBSD.org>2001-03-27 05:45:52 +0000
committerken <ken@FreeBSD.org>2001-03-27 05:45:52 +0000
commit24c4b1e75b8af36f530a3eabf2d1a17810637a5f (patch)
tree922f780aaaef7c90e6112b8537c9a1b7abb5b0c7 /sbin/camcontrol
parent37504f69c9fd5f7dee2b8de312ee783f169777a9 (diff)
downloadFreeBSD-src-24c4b1e75b8af36f530a3eabf2d1a17810637a5f.zip
FreeBSD-src-24c4b1e75b8af36f530a3eabf2d1a17810637a5f.tar.gz
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
Diffstat (limited to 'sbin/camcontrol')
-rw-r--r--sbin/camcontrol/Makefile4
-rw-r--r--sbin/camcontrol/camcontrol.c196
2 files changed, 87 insertions, 113 deletions
diff --git a/sbin/camcontrol/Makefile b/sbin/camcontrol/Makefile
index c9afb13..8b047d3 100644
--- a/sbin/camcontrol/Makefile
+++ b/sbin/camcontrol/Makefile
@@ -7,7 +7,7 @@ MAN= camcontrol.8
SDIR= ${.CURDIR}/../../sys
CFLAGS+= -I${SDIR}
-DPADD= ${LIBCAM}
-LDADD+= -lcam
+DPADD= ${LIBCAM} ${LIBSBUF}
+LDADD+= -lcam -lsbuf
.include <bsd.prog.mk>
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index 87e6fb9..5d6dfc2 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -451,12 +451,8 @@ testunitready(struct cam_device *device, int retry_count, int timeout,
perror("error sending test unit ready");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb);
@@ -472,12 +468,8 @@ testunitready(struct cam_device *device, int retry_count, int timeout,
error = 1;
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
}
@@ -522,12 +514,8 @@ scsistart(struct cam_device *device, int startstop, int loadeject,
perror("error sending start unit");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb);
@@ -558,12 +546,8 @@ scsistart(struct cam_device *device, int startstop, int loadeject,
"Error received from stop unit command\n");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
}
@@ -702,12 +686,8 @@ scsiinquiry(struct cam_device *device, int retry_count, int timeout)
perror("error sending SCSI inquiry");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb);
@@ -718,12 +698,8 @@ scsiinquiry(struct cam_device *device, int retry_count, int timeout)
error = 1;
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
}
@@ -792,12 +768,8 @@ scsiserial(struct cam_device *device, int retry_count, int timeout)
warn("error getting serial number");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb);
@@ -809,12 +781,8 @@ scsiserial(struct cam_device *device, int retry_count, int timeout)
error = 1;
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
}
@@ -871,13 +839,9 @@ scsixferrate(struct cam_device *device)
else
warnx(error_string);
- /*
- * If there is an error, it won't be a SCSI error since
- * this isn't a SCSI CCB.
- */
if (arglist & CAM_ARG_VERBOSE)
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
retval = 1;
@@ -1265,28 +1229,23 @@ readdefects(struct cam_device *device, int argc, char **argv,
perror("error reading defect list");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
error = 1;
goto defect_bailout;
}
- if (arglist & CAM_ARG_VERBOSE)
- scsi_sense_print(device, &ccb->csio, stderr);
-
returned_length = scsi_2btoul(((struct
scsi_read_defect_data_hdr_10 *)defect_list)->length);
returned_format = ((struct scsi_read_defect_data_hdr_10 *)
defect_list)->format;
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+ if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR)
+ && (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
+ && ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)) {
struct scsi_sense_data *sense;
int error_code, sense_key, asc, ascq;
@@ -1327,8 +1286,18 @@ readdefects(struct cam_device *device, int argc, char **argv,
} else {
error = 1;
warnx("Error returned from read defect data command");
+ if (arglist & CAM_ARG_VERBOSE)
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
goto defect_bailout;
}
+ } else {
+ error = 1;
+ warnx("Error returned from read defect data command");
+ if (arglist & CAM_ARG_VERBOSE)
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
+ goto defect_bailout;
}
/*
@@ -1484,12 +1453,8 @@ mode_sense(struct cam_device *device, int mode_page, int page_control,
if (((retval = cam_send_ccb(device, ccb)) < 0)
|| ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb);
cam_close_device(device);
@@ -1537,12 +1502,8 @@ mode_select(struct cam_device *device, int save_pages, int retry_count,
if (((retval = cam_send_ccb(device, ccb)) < 0)
|| ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)) {
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb);
cam_close_device(device);
@@ -1826,12 +1787,8 @@ scsicmd(struct cam_device *device, int argc, char **argv, char *combinedopt,
warnx("error sending command");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
error = 1;
@@ -2053,8 +2010,9 @@ tagcontrol(struct cam_device *device, int argc, char **argv,
}
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
- warnx("XPT_REL_SIMQ CCB failed, status %#x",
- ccb->ccb_h.status);
+ warnx("XPT_REL_SIMQ CCB failed");
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
retval = 1;
goto tagcontrol_bailout;
}
@@ -2077,8 +2035,9 @@ tagcontrol(struct cam_device *device, int argc, char **argv,
}
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
- warnx("XPT_GDEV_STATS CCB failed, status %#x",
- ccb->ccb_h.status);
+ warnx("XPT_GDEV_STATS CCB failed");
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
retval = 1;
goto tagcontrol_bailout;
}
@@ -2178,8 +2137,8 @@ get_cpi(struct cam_device *device, struct ccb_pathinq *cpi)
warn("get_cpi: error sending Path Inquiry CCB");
if (arglist & CAM_ARG_VERBOSE)
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
retval = 1;
@@ -2189,8 +2148,8 @@ get_cpi(struct cam_device *device, struct ccb_pathinq *cpi)
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
if (arglist & CAM_ARG_VERBOSE)
- fprintf(stderr, "get_cpi: CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
retval = 1;
@@ -2367,13 +2326,18 @@ get_print_cts(struct cam_device *device, int user_settings, int quiet,
if (cam_send_ccb(device, ccb) < 0) {
perror("error sending XPT_GET_TRAN_SETTINGS CCB");
+ if (arglist & CAM_ARG_VERBOSE)
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
retval = 1;
goto get_print_cts_bailout;
}
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
- warnx("XPT_GET_TRANS_SETTINGS CCB failed, status %#x",
- ccb->ccb_h.status);
+ warnx("XPT_GET_TRANS_SETTINGS CCB failed");
+ if (arglist & CAM_ARG_VERBOSE)
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
retval = 1;
goto get_print_cts_bailout;
}
@@ -2497,13 +2461,20 @@ ratecontrol(struct cam_device *device, int retry_count, int timeout,
if (cam_send_ccb(device, ccb) < 0) {
perror("error sending XPT_PATH_INQ CCB");
+ if (arglist & CAM_ARG_VERBOSE) {
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
+ }
retval = 1;
goto ratecontrol_bailout;
}
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
- warnx("XPT_PATH_INQ CCB failed, status %#x",
- ccb->ccb_h.status);
+ warnx("XPT_PATH_INQ CCB failed");
+ if (arglist & CAM_ARG_VERBOSE) {
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
+ }
retval = 1;
goto ratecontrol_bailout;
}
@@ -2645,13 +2616,20 @@ ratecontrol(struct cam_device *device, int retry_count, int timeout,
if (cam_send_ccb(device, ccb) < 0) {
perror("error sending XPT_SET_TRAN_SETTINGS CCB");
+ if (arglist & CAM_ARG_VERBOSE) {
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
+ }
retval = 1;
goto ratecontrol_bailout;
}
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
- warnx("XPT_SET_TRANS_SETTINGS CCB failed, status %#x",
- ccb->ccb_h.status);
+ warnx("XPT_SET_TRANS_SETTINGS CCB failed");
+ if (arglist & CAM_ARG_VERBOSE) {
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
+ }
retval = 1;
goto ratecontrol_bailout;
}
@@ -2850,12 +2828,8 @@ scsiformat(struct cam_device *device, int argc, char **argv,
warnx(errstr);
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio, stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
error = 1;
goto scsiformat_bailout;
@@ -2904,13 +2878,8 @@ scsiformat(struct cam_device *device, int argc, char **argv,
if (retval < 0) {
warn("error sending CAMIOCOMMAND ioctl");
if (arglist & CAM_ARG_VERBOSE) {
- if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
- CAM_SCSI_STATUS_ERROR)
- scsi_sense_print(device, &ccb->csio,
- stderr);
- else
- fprintf(stderr, "CAM status is %#x\n",
- ccb->ccb_h.status);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
}
error = 1;
goto scsiformat_bailout;
@@ -2919,7 +2888,8 @@ scsiformat(struct cam_device *device, int argc, char **argv,
status = ccb->ccb_h.status & CAM_STATUS_MASK;
if ((status != CAM_REQ_CMP)
- && (status == CAM_SCSI_STATUS_ERROR)) {
+ && (status == CAM_SCSI_STATUS_ERROR)
+ && ((status & CAM_AUTOSNS_VALID) != 0)) {
struct scsi_sense_data *sense;
int error_code, sense_key, asc, ascq;
@@ -2970,13 +2940,17 @@ scsiformat(struct cam_device *device, int argc, char **argv,
sleep(1);
} else {
warnx("Unexpected SCSI error during format");
- scsi_sense_print(device, &ccb->csio, stderr);
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
error = 1;
goto scsiformat_bailout;
}
} else if (status != CAM_REQ_CMP) {
warnx("Unexpected CAM status %#x", status);
+ if (arglist & CAM_ARG_VERBOSE)
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
error = 1;
goto scsiformat_bailout;
}
OpenPOWER on IntegriCloud