Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Aug 2020 10:01:03 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r364907 - stable/12/sys/cam
Message-ID:  <202008281001.07SA13gG011188@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Fri Aug 28 10:01:03 2020
New Revision: 364907
URL: https://svnweb.freebsd.org/changeset/base/364907

Log:
  MFC r358864 by imp: Eliminate xpt_copy_path.

Modified:
  stable/12/sys/cam/cam_xpt.c
  stable/12/sys/cam/cam_xpt.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/cam/cam_xpt.c
==============================================================================
--- stable/12/sys/cam/cam_xpt.c	Fri Aug 28 08:54:27 2020	(r364906)
+++ stable/12/sys/cam/cam_xpt.c	Fri Aug 28 10:01:03 2020	(r364907)
@@ -804,7 +804,8 @@ static void
 xpt_scanner_thread(void *dummy)
 {
 	union ccb	*ccb;
-	struct cam_path	 path;
+	struct mtx	*mtx;
+	struct cam_ed	*device;
 
 	xpt_lock_buses();
 	for (;;) {
@@ -816,15 +817,22 @@ xpt_scanner_thread(void *dummy)
 			xpt_unlock_buses();
 
 			/*
-			 * Since lock can be dropped inside and path freed
-			 * by completion callback even before return here,
-			 * take our own path copy for reference.
+			 * We need to lock the device's mutex which we use as
+			 * the path mutex. We can't do it directly because the
+			 * cam_path in the ccb may wind up going away because
+			 * the path lock may be dropped and the path retired in
+			 * the completion callback. We do this directly to keep
+			 * the reference counts in cam_path sane. We also have
+			 * to copy the device pointer because ccb_h.path may
+			 * be freed in the callback.
 			 */
-			xpt_copy_path(&path, ccb->ccb_h.path);
-			xpt_path_lock(&path);
+			mtx = xpt_path_mtx(ccb->ccb_h.path);
+			device = ccb->ccb_h.path->device;
+			xpt_acquire_device(device);
+			mtx_lock(mtx);
 			xpt_action(ccb);
-			xpt_path_unlock(&path);
-			xpt_release_path(&path);
+			mtx_unlock(mtx);
+			xpt_release_device(device);
 
 			xpt_lock_buses();
 		}
@@ -3701,15 +3709,6 @@ xpt_clone_path(struct cam_path **new_path_ptr, struct 
 	new_path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_NOWAIT);
 	if (new_path == NULL)
 		return(CAM_RESRC_UNAVAIL);
-	xpt_copy_path(new_path, path);
-	*new_path_ptr = new_path;
-	return (CAM_REQ_CMP);
-}
-
-void
-xpt_copy_path(struct cam_path *new_path, struct cam_path *path)
-{
-
 	*new_path = *path;
 	if (path->bus != NULL)
 		xpt_acquire_bus(path->bus);
@@ -3717,6 +3716,8 @@ xpt_copy_path(struct cam_path *new_path, struct cam_pa
 		xpt_acquire_target(path->target);
 	if (path->device != NULL)
 		xpt_acquire_device(path->device);
+	*new_path_ptr = new_path;
+	return (CAM_REQ_CMP);
 }
 
 void

Modified: stable/12/sys/cam/cam_xpt.h
==============================================================================
--- stable/12/sys/cam/cam_xpt.h	Fri Aug 28 08:54:27 2020	(r364906)
+++ stable/12/sys/cam/cam_xpt.h	Fri Aug 28 10:01:03 2020	(r364907)
@@ -140,8 +140,6 @@ cam_status		xpt_compile_path(struct cam_path *new_path
 					 lun_id_t lun_id);
 cam_status		xpt_clone_path(struct cam_path **new_path,
 				      struct cam_path *path);
-void			xpt_copy_path(struct cam_path *new_path,
-				      struct cam_path *path);
 
 void			xpt_release_path(struct cam_path *path);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008281001.07SA13gG011188>