git: 30f8afd0270e - main - cam: fix xpt_bus_register and xpt_bus_deregister return errno

Warner Losh imp at FreeBSD.org
Mon Jun 28 22:24:10 UTC 2021


The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=30f8afd0270e0bb70e1e0df1cf8de7a841797a30

commit 30f8afd0270e0bb70e1e0df1cf8de7a841797a30
Author:     Warner Losh <imp at FreeBSD.org>
AuthorDate: 2021-06-28 22:01:30 +0000
Commit:     Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-06-28 22:13:03 +0000

    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
---
 sys/cam/cam_ccb.h               |  1 -
 sys/cam/cam_xpt.c               | 22 +++++++++++-----------
 sys/cam/cam_xpt_sim.h           |  6 +++---
 sys/dev/iscsi/iscsi.c           |  3 +--
 sys/dev/smartpqi/smartpqi_cam.c |  8 ++++----
 sys/dev/usb/storage/umass.c     | 10 +++++-----
 sys/dev/vmware/pvscsi/pvscsi.c  |  8 ++++----
 7 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h
index 3a01cde1a442..f0150d680d2f 100644
--- a/sys/cam/cam_ccb.h
+++ b/sys/cam/cam_ccb.h
@@ -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
diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c
index ee216451bd6d..016f0e6a38be 100644
--- a/sys/cam/cam_xpt.c
+++ b/sys/cam/cam_xpt.c
@@ -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
diff --git a/sys/cam/cam_xpt_sim.h b/sys/cam/cam_xpt_sim.h
index aa9746019981..569ed09c23d2 100644
--- a/sys/cam/cam_xpt_sim.h
+++ b/sys/cam/cam_xpt_sim.h
@@ -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);
diff --git a/sys/dev/iscsi/iscsi.c b/sys/dev/iscsi/iscsi.c
index 7ddb5a9ce1ec..9a1b539e539b 100644
--- a/sys/dev/iscsi/iscsi.c
+++ b/sys/dev/iscsi/iscsi.c
@@ -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);
diff --git a/sys/dev/smartpqi/smartpqi_cam.c b/sys/dev/smartpqi/smartpqi_cam.c
index e389eb143e4a..1278434131d9 100644
--- a/sys/dev/smartpqi/smartpqi_cam.c
+++ b/sys/dev/smartpqi/smartpqi_cam.c
@@ -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);
diff --git a/sys/dev/usb/storage/umass.c b/sys/dev/usb/storage/umass.c
index bc07fe50b6ab..65c72b06e244 100644
--- a/sys/dev/usb/storage/umass.c
+++ b/sys/dev/usb/storage/umass.c
@@ -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;
 	}
diff --git a/sys/dev/vmware/pvscsi/pvscsi.c b/sys/dev/vmware/pvscsi/pvscsi.c
index ad32d2ab4959..f64b20863f60 100644
--- a/sys/dev/vmware/pvscsi/pvscsi.c
+++ b/sys/dev/vmware/pvscsi/pvscsi.c
@@ -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);


More information about the dev-commits-src-all mailing list