Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Apr 2007 08:00:28 GMT
From:      Scott Long <scottl@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 118145 for review
Message-ID:  <200704150800.l3F80S5s019741@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=118145

Change 118145 by scottl@scottl-x64 on 2007/04/15 07:59:43

	Finish locking the scsi_sa periph, remove spls.

Affected files ...

.. //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_sa.c#12 edit

Differences ...

==== //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_sa.c#12 (text+ko) ====

@@ -456,6 +456,7 @@
 	}
 
 	cam_periph_lock(periph);
+
 	softc = (struct sa_softc *)periph->softc;
 
 	CAM_DEBUG(periph->path, CAM_DEBUG_TRACE|CAM_DEBUG_INFO,
@@ -467,6 +468,12 @@
 		return (0);
 	}
 
+	if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
+		cam_periph_unlock(periph);
+		cam_periph_release(periph);
+		return (error);
+	}
+
 	if (softc->flags & SA_FLAG_OPEN) {
 		error = EBUSY;
 	} else if (softc->flags & SA_FLAG_INVALID) {
@@ -488,12 +495,14 @@
 		if (error && (flags & O_NONBLOCK)) {
 			softc->flags |= SA_FLAG_OPEN;
 			softc->open_pending_mount = 1;
+			cam_periph_unhold(periph);
 			cam_periph_unlock(periph);
 			return (0);
 		}
 	}
 
 	if (error) {
+		cam_periph_unhold(periph);
 		cam_periph_unlock(periph);
 		cam_periph_release(periph);
 		return (error);
@@ -502,6 +511,7 @@
 	saprevent(periph, PR_PREVENT);
 	softc->flags |= SA_FLAG_OPEN;
 
+	cam_periph_unhold(periph);
 	cam_periph_unlock(periph);
 	return (error);
 }
@@ -520,10 +530,10 @@
 	if (periph == NULL)
 		return (ENXIO);	
 
+	cam_periph_lock(periph);
+
 	softc = (struct sa_softc *)periph->softc;
 
-	cam_periph_lock(periph);
-
 	CAM_DEBUG(periph->path, CAM_DEBUG_TRACE|CAM_DEBUG_INFO,
 	    ("saclose(%d): dev=0x%x softc=0x%x\n", unit, unit, softc->flags));
 
@@ -544,6 +554,11 @@
 		return (0);
 	}
 
+	if ((error = cam_periph_hold(periph, PRIBIO)) != 0) {
+		cam_periph_unlock(periph);
+		return (error);
+	}
+
 	/*
 	 * Were we writing the tape?
 	 */
@@ -651,6 +666,7 @@
 	if ((softc->flags & SA_FLAG_TAPE_MOUNTED) == 0)
 		sareservereleaseunit(periph, FALSE);
 
+	cam_periph_unhold(periph);
 	cam_periph_unlock(periph);
 	cam_periph_release(periph);
 
@@ -678,10 +694,10 @@
 		biofinish(bp, NULL, ENXIO);
 		return;
 	}
+	cam_periph_lock(periph);
+
 	softc = (struct sa_softc *)periph->softc;
 
-	cam_periph_lock(periph);
-
 	if (softc->flags & SA_FLAG_INVALID) {
 		cam_periph_unlock(periph);
 		biofinish(bp, NULL, ENXIO);
@@ -803,7 +819,6 @@
 	struct sa_softc *softc;
 	scsi_space_code spaceop;
 	int didlockperiph = 0;
-	int s;
 	int mode;
 	int error = 0;
 
@@ -815,6 +830,7 @@
 	if (periph == NULL)
 		return (ENXIO);	
 
+	cam_periph_lock(periph);
 	softc = (struct sa_softc *)periph->softc;
 
 	/*
@@ -840,9 +856,10 @@
 			 * other thread that has this device open to do
 			 * an MTIOCERRSTAT that would clear latched status.
 			 */
-			s = splsoftcam();
 			if ((periph->flags & CAM_PERIPH_LOCKED) == 0) {
-				cam_periph_lock(periph);
+				error = cam_periph_hold(periph, PRIBIO|PCATCH);
+				 if (error != 0)
+					return (error);
 				didlockperiph = 1;
 			}
 			break;
@@ -875,8 +892,9 @@
 			 * than at open time because we are sharing writable
 			 * access to data structures.
 			 */
-			s = splsoftcam();
-			cam_periph_lock(periph);
+			error = cam_periph_hold(periph, PRIBIO|PCATCH);
+			if (error != 0)
+				return (error);
 			didlockperiph = 1;
 			break;
 
@@ -1303,8 +1321,9 @@
 		}
 	}
 	if (didlockperiph) {
-		cam_periph_unlock(periph);
+		cam_periph_unhold(periph);
 	}
+	cam_periph_unlock(periph);
 	return (error);
 }
 
@@ -1347,7 +1366,6 @@
 {
 	struct sa_softc *softc;
 	struct ccb_setasync csa;
-	int s;
 
 	softc = (struct sa_softc *)periph->softc;
 
@@ -1365,20 +1383,12 @@
 	softc->flags |= SA_FLAG_INVALID;
 
 	/*
-	 * Although the oninvalidate() routines are always called at
-	 * splsoftcam, we need to be at splbio() here to keep the buffer
-	 * queue from being modified while we traverse it.
-	 */
-	s = splbio();
-
-	/*
 	 * Return all queued I/O with ENXIO.
 	 * XXX Handle any transactions queued to the card
 	 *     with XPT_ABORT_CCB.
 	 */
 	bioq_flush(&softc->bio_queue, NULL, ENXIO);
 	softc->queue_count = 0;
-	splx(s);
 
 	xpt_print(periph->path, "lost device\n");
 
@@ -1585,12 +1595,10 @@
 	{
 		/* Pull a buffer from the queue and get going on it */		
 		struct bio *bp;
-		int s;
 
 		/*
 		 * See if there is a buf with work for us to do..
 		 */
-		s = splbio();
 		bp = bioq_first(&softc->bio_queue);
 		if (periph->immediate_priority <= periph->pinfo.priority) {
 			CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE,
@@ -1599,10 +1607,8 @@
 			SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
 					  periph_links.sle);
 			periph->immediate_priority = CAM_PRIORITY_NONE;
-			splx(s);
 			wakeup(&periph->ccb_list);
 		} else if (bp == NULL) {
-			splx(s);
 			xpt_release_ccb(start_ccb);
 		} else if ((softc->flags & SA_FLAG_ERR_PENDING) != 0) {
 			struct bio *done_bp;
@@ -1645,7 +1651,6 @@
 			    "%d more buffers queued up\n",
 			    (softc->flags & SA_FLAG_ERR_PENDING),
 			    (bp != NULL)? "not " : " ", softc->queue_count));
-			splx(s);
 			xpt_release_ccb(start_ccb);
 			biodone(done_bp);
 		} else {
@@ -1665,7 +1670,6 @@
 					bp->bio_error = EIO;
 					xpt_print(periph->path, "zero blocksize"
 					    " for FIXED length writes?\n");
-					splx(s);
 					biodone(bp);
 					break;
 				}
@@ -1716,7 +1720,6 @@
 			Set_CCB_Type(start_ccb, SA_CCB_BUFFER_IO);
 			start_ccb->ccb_h.ccb_bp = bp;
 			bp = bioq_first(&softc->bio_queue);
-			splx(s);
 			xpt_action(start_ccb);
 		}
 		
@@ -1761,7 +1764,6 @@
 		}
 
 		if (error == EIO) {
-			int s;			
 
 			/*
 			 * Catastrophic error. Mark the tape as frozen
@@ -1774,10 +1776,8 @@
 			 *
 			 */
 
-			s = splbio();
 			softc->flags |= SA_FLAG_TAPE_FROZEN;
 			bioq_flush(&softc->bio_queue, NULL, EIO);
-			splx(s);
 		}
 		if (error != 0) {
 			bp->bio_resid = bp->bio_bcount;



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