cam: fix xpt_bus_register and xpt_bus_deregister return errno

xpt_bus_register and xpt_bus_deregister returns a hybrid error that's
neither a cam_status, nor an errno, but a mix of both.  Update
xpt_bus_register and xpt_bus_deregister to return an errno. The vast
majority of current users compare against zero, which can also be
spelled CAM_SUCCESS. Nobody uses CAM_FAILURE, so remove that symbol
to prevent comfusion (nothing returns it either).

Where the return value is saved, ensure that the variable 'error' is
used to store an errno and 'status' is used to store a cam_status where
it makes the code clearer (usually just in functions that already mix
and match). Where the return value isn't used at all, avoid storing it
at all.

Reviewed by:		scottl@, mav@ (earlier version)
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30860
This commit is contained in:
Warner Losh
2021-06-28 16:01:30 -06:00
parent dcd5dea965
commit 30f8afd027
7 changed files with 28 additions and 30 deletions
-1
View File
@@ -1299,7 +1299,6 @@ struct ccb_eng_exec { /* This structure must match SCSIIO size */
#define CAM_TIME_INFINITY 0xFFFFFFFF /* Infinite timeout */
#define CAM_SUCCESS 0 /* For signaling general success */
#define CAM_FAILURE 1 /* For signaling general failure */
#define CAM_FALSE 0
#define CAM_TRUE 1
+11 -11
View File
@@ -930,9 +930,9 @@ xpt_init(void *dummy)
if (xpt_sim == NULL)
return (ENOMEM);
if ((status = xpt_bus_register(xpt_sim, NULL, 0)) != CAM_SUCCESS) {
printf("xpt_init: xpt_bus_register failed with status %#x,"
" failing attach\n", status);
if ((error = xpt_bus_register(xpt_sim, NULL, 0)) != CAM_SUCCESS) {
printf("xpt_init: xpt_bus_register failed with errno %d,"
" failing attach\n", error);
return (EINVAL);
}
@@ -3999,8 +3999,8 @@ CAM_XPT_XPORT(xport_default);
* information specified by the user. Once interrupt services are
* available, the bus will be probed.
*/
int32_t
xpt_bus_register(struct cam_sim *sim, device_t parent, u_int32_t bus)
int
xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus)
{
struct cam_eb *new_bus;
struct cam_eb *old_bus;
@@ -4013,7 +4013,7 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, u_int32_t bus)
M_CAMXPT, M_NOWAIT|M_ZERO);
if (new_bus == NULL) {
/* Couldn't satisfy request */
return (CAM_RESRC_UNAVAIL);
return (ENOMEM);
}
mtx_init(&new_bus->eb_mtx, "CAM bus lock", NULL, MTX_DEF);
@@ -4051,7 +4051,7 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, u_int32_t bus)
CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
if (status != CAM_REQ_CMP) {
xpt_release_bus(new_bus);
return (CAM_RESRC_UNAVAIL);
return (ENOMEM);
}
xpt_path_inq(&cpi, path);
@@ -4070,7 +4070,7 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, u_int32_t bus)
"No transport found for %d\n", cpi.transport);
xpt_release_bus(new_bus);
free(path, M_CAMXPT);
return (CAM_RESRC_UNAVAIL);
return (EINVAL);
}
}
@@ -4099,7 +4099,7 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, u_int32_t bus)
return (CAM_SUCCESS);
}
int32_t
int
xpt_bus_deregister(path_id_t pathid)
{
struct cam_path bus_path;
@@ -4108,7 +4108,7 @@ xpt_bus_deregister(path_id_t pathid)
status = xpt_compile_path(&bus_path, NULL, pathid,
CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
if (status != CAM_REQ_CMP)
return (status);
return (ENOMEM);
xpt_async(AC_LOST_DEVICE, &bus_path, NULL);
xpt_async(AC_PATH_DEREGISTERED, &bus_path, NULL);
@@ -4117,7 +4117,7 @@ xpt_bus_deregister(path_id_t pathid)
xpt_release_bus(bus_path.bus);
xpt_release_path(&bus_path);
return (CAM_REQ_CMP);
return (CAM_SUCCESS);
}
static path_id_t
+3 -3
View File
@@ -39,9 +39,9 @@
/* Functions accessed by SIM drivers */
#ifdef _KERNEL
int32_t xpt_bus_register(struct cam_sim *sim, device_t parent,
u_int32_t bus);
int32_t xpt_bus_deregister(path_id_t path_id);
int xpt_bus_register(struct cam_sim *sim, device_t parent,
uint32_t bus);
int xpt_bus_deregister(path_id_t path_id);
u_int32_t xpt_freeze_simq(struct cam_sim *sim, u_int count);
void xpt_release_simq(struct cam_sim *sim, int run_queue);
u_int32_t xpt_freeze_devq(struct cam_path *path, u_int count);
+1 -2
View File
@@ -1506,8 +1506,7 @@ iscsi_ioctl_daemon_handoff(struct iscsi_softc *sc,
return (ENOMEM);
}
error = xpt_bus_register(is->is_sim, NULL, 0);
if (error != 0) {
if (xpt_bus_register(is->is_sim, NULL, 0) != 0) {
ISCSI_SESSION_UNLOCK(is);
ISCSI_SESSION_WARN(is, "failed to register bus");
iscsi_session_terminate(is);
+4 -4
View File
@@ -1204,7 +1204,7 @@ register_sim(struct pqisrc_softstate *softs, int card_index)
{
int max_transactions;
union ccb *ccb = NULL;
cam_status status = 0;
int error;
struct ccb_setasync csa;
struct cam_sim *sim;
@@ -1231,9 +1231,9 @@ register_sim(struct pqisrc_softstate *softs, int card_index)
softs->os_specific.sim = sim;
mtx_lock(&softs->os_specific.cam_lock);
status = xpt_bus_register(sim, softs->os_specific.pqi_dev, 0);
if (status != CAM_SUCCESS) {
DBG_ERR("xpt_bus_register failed status=%d\n", status);
error = xpt_bus_register(sim, softs->os_specific.pqi_dev, 0);
if (error != CAM_SUCCESS) {
DBG_ERR("xpt_bus_register failed errno %d\n", error);
cam_sim_free(softs->os_specific.sim, FALSE);
cam_simq_free(softs->os_specific.devq);
mtx_unlock(&softs->os_specific.cam_lock);
+5 -5
View File
@@ -2129,11 +2129,11 @@ umass_cam_attach(struct umass_softc *sc)
static void
umass_cam_detach_sim(struct umass_softc *sc)
{
cam_status status;
int error;
if (sc->sc_sim != NULL) {
status = xpt_bus_deregister(cam_sim_path(sc->sc_sim));
if (status == CAM_REQ_CMP) {
error = xpt_bus_deregister(cam_sim_path(sc->sc_sim));
if (error == 0) {
/* accessing the softc is not possible after this */
sc->sc_sim->softc = NULL;
DPRINTF(sc, UDMASS_SCSI, "%s: %s:%d:%d caling "
@@ -2143,8 +2143,8 @@ umass_cam_detach_sim(struct umass_softc *sc)
sc->sc_sim->refcount, sc->sc_sim->mtx);
cam_sim_free(sc->sc_sim, /* free_devq */ TRUE);
} else {
panic("%s: %s: CAM layer is busy: %#x\n",
__func__, sc->sc_name, status);
panic("%s: %s: CAM layer is busy: errno %d\n",
__func__, sc->sc_name, error);
}
sc->sc_sim = NULL;
}
+4 -4
View File
@@ -1548,16 +1548,16 @@ pvscsi_free_all(struct pvscsi_softc *sc)
{
if (sc->sim) {
int32_t status;
int error;
if (sc->bus_path) {
xpt_free_path(sc->bus_path);
}
status = xpt_bus_deregister(cam_sim_path(sc->sim));
if (status != CAM_REQ_CMP) {
error = xpt_bus_deregister(cam_sim_path(sc->sim));
if (error != 0) {
device_printf(sc->dev,
"Error deregistering bus, status=%d\n", status);
"Error deregistering bus, error %d\n", error);
}
cam_sim_free(sc->sim, TRUE);