Unify cam_send_ccb() error reporting.

Error there mean that command was not even executed, and all information
we have about it is errno, and cam_error_print() call is not very useful.
Plus it is most likely a programmatic error, that shoud not happen.

MFC after:	1 week
Sponsored by:	iXsystems, Inc.
This commit is contained in:
mav 2019-09-07 16:52:40 +00:00
parent df3d8d3b51
commit f55899f5a9
3 changed files with 17 additions and 126 deletions

View File

@ -344,12 +344,6 @@ scsiattrib(struct cam_device *device, int argc, char **argv, char *combinedopt,
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("error sending %s ATTRIBUTE", (read_attr != 0) ? warn("error sending %s ATTRIBUTE", (read_attr != 0) ?
"READ" : "WRITE"); "READ" : "WRITE");
if (verbosemode != 0) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
error = 1; error = 1;
goto bailout; goto bailout;
} }

View File

@ -420,7 +420,7 @@ getdevlist(struct cam_device *device)
ccb->cgdl.status = CAM_GDEVLIST_MORE_DEVS; ccb->cgdl.status = CAM_GDEVLIST_MORE_DEVS;
while (ccb->cgdl.status == CAM_GDEVLIST_MORE_DEVS) { while (ccb->cgdl.status == CAM_GDEVLIST_MORE_DEVS) {
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error getting device list"); warn("error getting device list");
cam_freeccb(ccb); cam_freeccb(ccb);
return (1); return (1);
} }
@ -769,7 +769,7 @@ print_dev_mmcsd(struct device_match_result *dev_result, char *tmpstr)
advi->buf = (uint8_t *)&mmc_ident_data; advi->buf = (uint8_t *)&mmc_ident_data;
if (cam_send_ccb(dev, ccb) < 0) { if (cam_send_ccb(dev, ccb) < 0) {
warn("error sending CAMIOCOMMAND ioctl"); warn("error sending XPT_DEV_ADVINFO CCB");
cam_freeccb(ccb); cam_freeccb(ccb);
cam_close_device(dev); cam_close_device(dev);
return (1); return (1);
@ -811,7 +811,7 @@ nvme_get_cdata(struct cam_device *dev, struct nvme_controller_data *cdata)
advi->buf = (uint8_t *)cdata; advi->buf = (uint8_t *)cdata;
if (cam_send_ccb(dev, ccb) < 0) { if (cam_send_ccb(dev, ccb) < 0) {
warn("error sending CAMIOCOMMAND ioctl"); warn("error sending XPT_DEV_ADVINFO CCB");
cam_freeccb(ccb); cam_freeccb(ccb);
cam_close_device(dev); cam_close_device(dev);
return(1); return(1);
@ -876,13 +876,7 @@ testunitready(struct cam_device *device, int task_attr, int retry_count,
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
if (quiet == 0) if (quiet == 0)
perror("error sending test unit ready"); warn("error sending TEST UNIT READY command");
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb); cam_freeccb(ccb);
return (1); return (1);
} }
@ -945,13 +939,7 @@ scsistart(struct cam_device *device, int startstop, int loadeject,
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER; ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error sending start unit"); warn("error sending START STOP UNIT command");
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb); cam_freeccb(ccb);
return (1); return (1);
} }
@ -1114,13 +1102,7 @@ scsiinquiry(struct cam_device *device, int task_attr, int retry_count,
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER; ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error sending SCSI inquiry"); warn("error sending INQUIRY command");
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb); cam_freeccb(ccb);
return (1); return (1);
} }
@ -1196,13 +1178,7 @@ scsiserial(struct cam_device *device, int task_attr, int retry_count,
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER; ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("error getting serial number"); warn("error sending INQUIRY command");
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
cam_freeccb(ccb); cam_freeccb(ccb);
free(serial_buf); free(serial_buf);
return (1); return (1);
@ -1802,12 +1778,6 @@ scsi_cam_pass_16_send(struct cam_device *device, union ccb *ccb, int quiet)
warn("error sending ATA %s via pass_16", warn("error sending ATA %s via pass_16",
ata_op_string(&ata_cmd)); ata_op_string(&ata_cmd));
} }
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
return (1); return (1);
} }
@ -1849,12 +1819,6 @@ ata_cam_send(struct cam_device *device, union ccb *ccb, int quiet)
warn("error sending ATA %s", warn("error sending ATA %s",
ata_op_string(&(ccb->ataio.cmd))); ata_op_string(&(ccb->ataio.cmd)));
} }
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
return (1); return (1);
} }
@ -4127,13 +4091,7 @@ readdefects(struct cam_device *device, int argc, char **argv,
ccb->ccb_h.flags |= CAM_DEV_QFRZDIS; ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error reading defect list"); warn("error sending READ DEFECT DATA command");
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
error = 1; error = 1;
goto defect_bailout; goto defect_bailout;
} }
@ -5268,7 +5226,7 @@ tagcontrol(struct cam_device *device, int argc, char **argv,
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error sending XPT_REL_SIMQ CCB"); warn("error sending XPT_REL_SIMQ CCB");
retval = 1; retval = 1;
goto tagcontrol_bailout; goto tagcontrol_bailout;
} }
@ -5292,7 +5250,7 @@ tagcontrol(struct cam_device *device, int argc, char **argv,
ccb->ccb_h.func_code = XPT_GDEV_STATS; ccb->ccb_h.func_code = XPT_GDEV_STATS;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error sending XPT_GDEV_STATS CCB"); warn("error sending XPT_GDEV_STATS CCB");
retval = 1; retval = 1;
goto tagcontrol_bailout; goto tagcontrol_bailout;
} }
@ -5508,9 +5466,6 @@ get_cpi(struct cam_device *device, struct ccb_pathinq *cpi)
ccb->ccb_h.func_code = XPT_PATH_INQ; ccb->ccb_h.func_code = XPT_PATH_INQ;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("get_cpi: error sending Path Inquiry CCB"); warn("get_cpi: error sending Path Inquiry CCB");
if (arglist & CAM_ARG_VERBOSE)
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
retval = 1; retval = 1;
goto get_cpi_bailout; goto get_cpi_bailout;
} }
@ -5545,10 +5500,7 @@ get_cgd(struct cam_device *device, struct ccb_getdev *cgd)
CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cgd); CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cgd);
ccb->ccb_h.func_code = XPT_GDEV_TYPE; ccb->ccb_h.func_code = XPT_GDEV_TYPE;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("get_cgd: error sending Path Inquiry CCB"); warn("get_cgd: error sending Get type information CCB");
if (arglist & CAM_ARG_VERBOSE)
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
retval = 1; retval = 1;
goto get_cgd_bailout; goto get_cgd_bailout;
} }
@ -6104,10 +6056,7 @@ get_print_cts(struct cam_device *device, int user_settings, int quiet,
ccb->cts.type = CTS_TYPE_USER_SETTINGS; ccb->cts.type = CTS_TYPE_USER_SETTINGS;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error sending XPT_GET_TRAN_SETTINGS CCB"); warn("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; retval = 1;
goto get_print_cts_bailout; goto get_print_cts_bailout;
} }
@ -6234,32 +6183,13 @@ ratecontrol(struct cam_device *device, int task_attr, int retry_count,
break; break;
} }
} }
CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cpi);
/* /*
* Grab path inquiry information, so we can determine whether * Grab path inquiry information, so we can determine whether
* or not the initiator is capable of the things that the user * or not the initiator is capable of the things that the user
* requests. * requests.
*/ */
ccb->ccb_h.func_code = XPT_PATH_INQ; if ((retval = get_cpi(device, &cpi)) != 0)
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; goto ratecontrol_bailout;
}
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
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;
}
bcopy(&ccb->cpi, &cpi, sizeof(struct ccb_pathinq));
CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cts); CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cts);
if (quiet == 0) { if (quiet == 0) {
fprintf(stdout, "%s parameters:\n", fprintf(stdout, "%s parameters:\n",
@ -6447,11 +6377,7 @@ ratecontrol(struct cam_device *device, int task_attr, int retry_count,
} }
ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS; ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error sending XPT_SET_TRAN_SETTINGS CCB"); warn("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; retval = 1;
goto ratecontrol_bailout; goto ratecontrol_bailout;
} }
@ -6685,11 +6611,7 @@ scsiformat(struct cam_device *device, int argc, char **argv,
* errors are expected. * errors are expected.
*/ */
if (retval < 0) { if (retval < 0) {
warn("error sending CAMIOCOMMAND ioctl"); warn("error sending TEST UNIT READY command");
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
error = 1; error = 1;
goto scsiformat_bailout; goto scsiformat_bailout;
} }
@ -6876,11 +6798,7 @@ sanitize_wait_scsi(struct cam_device *device, union ccb *ccb, int task_attr, int
* errors are expected. * errors are expected.
*/ */
if (retval < 0) { if (retval < 0) {
warn("error sending CAMIOCOMMAND ioctl"); warn("error sending TEST UNIT READY command");
if (arglist & CAM_ARG_VERBOSE) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
return (1); return (1);
} }
@ -7418,11 +7336,6 @@ scsireportluns(struct cam_device *device, int argc, char **argv,
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("error sending REPORT LUNS command"); warn("error sending REPORT LUNS command");
if (arglist & CAM_ARG_VERBOSE)
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
retval = 1; retval = 1;
goto bailout; goto bailout;
} }
@ -7674,11 +7587,6 @@ scsireadcapacity(struct cam_device *device, int argc, char **argv,
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("error sending READ CAPACITY command"); warn("error sending READ CAPACITY command");
if (arglist & CAM_ARG_VERBOSE)
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
retval = 1; retval = 1;
goto bailout; goto bailout;
} }
@ -7721,11 +7629,6 @@ scsireadcapacity(struct cam_device *device, int argc, char **argv,
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("error sending READ CAPACITY (16) command"); warn("error sending READ CAPACITY (16) command");
if (arglist & CAM_ARG_VERBOSE)
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
retval = 1; retval = 1;
goto bailout; goto bailout;
} }
@ -9579,7 +9482,7 @@ scsigetopcodes(struct cam_device *device, int opcode_set, int opcode,
ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER; ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
perror("error sending REPORT SUPPORTED OPERATION CODES"); warn("error sending REPORT SUPPORTED OPERATION CODES command");
retval = 1; retval = 1;
goto bailout; goto bailout;
} }

View File

@ -858,12 +858,6 @@ scsipersist(struct cam_device *device, int argc, char **argv, char *combinedopt,
if (cam_send_ccb(device, ccb) < 0) { if (cam_send_ccb(device, ccb) < 0) {
warn("error sending PERSISTENT RESERVE %s", (in != 0) ? warn("error sending PERSISTENT RESERVE %s", (in != 0) ?
"IN" : "OUT"); "IN" : "OUT");
if (verbosemode != 0) {
cam_error_print(device, ccb, CAM_ESF_ALL,
CAM_EPF_ALL, stderr);
}
error = 1; error = 1;
goto bailout; goto bailout;
} }