git: bd86f0508e46 - main - da: Update trim stats with the periph lock held

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 06 Oct 2026 22:58:51 UTC
The branch main has been updated by imp:

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

commit bd86f0508e461526ba7342e52bd9778394b183f7
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2026-10-06 22:45:46 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-10-06 22:46:23 +0000

    da: Update trim stats with the periph lock held
    
    Separate the updating the stats for the completion from the biodone for
    each one.
    
    Sponsored by:           Netflix
    Reviewed by:            ali_mashtizadeh.com
    Differential Revision:  https://reviews.freebsd.org/D60156
---
 sys/cam/scsi/scsi_da.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c
index 04f924c7a91e..ee5066592f1a 100644
--- a/sys/cam/scsi/scsi_da.c
+++ b/sys/cam/scsi/scsi_da.c
@@ -4658,6 +4658,7 @@ static void
 dadone(struct cam_periph *periph, union ccb *done_ccb)
 {
 	struct bio *bp, *bp1;
+	struct bio_queue queue;
 	struct da_softc *softc;
 	struct ccb_scsiio *csio;
 	da_ccb_state state;
@@ -4788,16 +4789,21 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
 	 * the case of sendfile can be quite extensive. Release the periph
 	 * refcount taken in dastart() for each CCB.
 	 */
-	cam_iosched_bio_update_stats(softc->cam_iosched, bp, done_ccb);
+	if (state == DA_CCB_DELETE) {
+		TAILQ_INIT(&queue);
+		TAILQ_INSERT_HEAD(&queue, bp, bio_queue);
+		TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue,
+		    bio_queue);
+		softc->delete_run_queue.insert_point = NULL;
+		cam_iosched_bio_queue_update_stats(softc->cam_iosched, &queue,
+		    done_ccb, bp->bio_error);
+	} else {
+		cam_iosched_bio_update_stats(softc->cam_iosched, bp, done_ccb);
+	}
 	xpt_release_ccb(done_ccb);
 	KASSERT(softc->refcount >= 1, ("dadone softc %p refcount %d", softc, softc->refcount));
 	softc->refcount--;
 	if (state == DA_CCB_DELETE) {
-		TAILQ_HEAD(, bio) queue;
-
-		TAILQ_INIT(&queue);
-		TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
-		softc->delete_run_queue.insert_point = NULL;
 		/*
 		 * Normally, the xpt_release_ccb() above would make sure
 		 * that when we have more work to do, that work would
@@ -4813,20 +4819,14 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
 		cam_periph_unlock(periph);
 		while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
 			TAILQ_REMOVE(&queue, bp1, bio_queue);
-			bp1->bio_error = bp->bio_error;
-			if (bp->bio_flags & BIO_ERROR) {
-				bp1->bio_flags |= BIO_ERROR;
-				bp1->bio_resid = bp1->bio_bcount;
-			} else
-				bp1->bio_resid = 0;
 			biodone(bp1);
 		}
 	} else {
 		daschedule(periph);
 		cam_periph_unlock(periph);
+		if (bp != NULL)
+			biodone(bp);
 	}
-	if (bp != NULL)
-		biodone(bp);
 	return;
 }