Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Jul 2024 02:59:08 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 6f1dd6071a91 - main - cam/iosched: Pass in the disk when initializing
Message-ID:  <202407200259.46K2x8sA024504@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

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

commit 6f1dd6071a9171b8d1472ba36f6045a7a10b622a
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-07-20 02:53:01 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-07-20 02:53:37 +0000

    cam/iosched: Pass in the disk when initializing
    
    The disk is nice to have at times, especially when you need the sector
    size. At present, the only plans for this are related to logging.
    
    Sponsored by:           Netflix
    Reviewed by:            jhb
    Differential Revision:  https://reviews.freebsd.org/D46035
---
 sys/cam/ata/ata_da.c   | 19 ++++++++++---------
 sys/cam/cam_iosched.c  |  5 ++++-
 sys/cam/cam_iosched.h  |  3 ++-
 sys/cam/nvme/nvme_da.c | 17 +++++++++--------
 sys/cam/scsi/scsi_da.c | 16 ++++++++--------
 5 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c
index 6e008cfc8d22..2c1183b74c1d 100644
--- a/sys/cam/ata/ata_da.c
+++ b/sys/cam/ata/ata_da.c
@@ -1834,13 +1834,6 @@ adaregister(struct cam_periph *periph, void *arg)
 	announce_buf = softc->announce_temp;
 	bzero(announce_buf, ADA_ANNOUNCETMP_SZ);
 
-	if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
-		printf("adaregister: Unable to probe new device. "
-		       "Unable to allocate iosched memory\n");
-		free(softc, M_DEVBUF);
-		return(CAM_REQ_CMP_ERR);
-	}
-
 	periph->softc = softc;
 	xpt_path_inq(&softc->cpi, periph->path);
 
@@ -1901,8 +1894,6 @@ adaregister(struct cam_periph *periph, void *arg)
 	} else {
 		softc->flags |= ADA_FLAG_ROTATING;
 	}
-	cam_iosched_set_sort_queue(softc->cam_iosched,
-	    (softc->flags & ADA_FLAG_ROTATING) ? -1 : 0);
 	softc->disk = disk_alloc();
 	adasetgeom(softc, cgd);
 	softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
@@ -1921,6 +1912,16 @@ adaregister(struct cam_periph *periph, void *arg)
 	softc->disk->d_name = "ada";
 	softc->disk->d_drv1 = periph;
 	softc->disk->d_unit = periph->unit_number;
+
+	if (cam_iosched_init(&softc->cam_iosched, periph, softc->disk) != 0) {
+		printf("adaregister: Unable to probe new device. "
+		       "Unable to allocate iosched memory\n");
+		free(softc, M_DEVBUF);
+		return(CAM_REQ_CMP_ERR);
+	}
+	cam_iosched_set_sort_queue(softc->cam_iosched,
+	    (softc->flags & ADA_FLAG_ROTATING) ? -1 : 0);
+
 	cam_periph_lock(periph);
 
 	dp = &softc->params;
diff --git a/sys/cam/cam_iosched.c b/sys/cam/cam_iosched.c
index 330d5ea22b61..cfefc8098d18 100644
--- a/sys/cam/cam_iosched.c
+++ b/sys/cam/cam_iosched.c
@@ -314,6 +314,7 @@ struct control_loop {
 struct cam_iosched_softc {
 	struct bio_queue_head bio_queue;
 	struct bio_queue_head trim_queue;
+	const struct disk *disk;
 				/* scheduler flags < 16, user flags >= 16 */
 	uint32_t	flags;
 	int		sort_io_queue;
@@ -1153,12 +1154,14 @@ cam_iosched_cl_sysctl_fini(struct control_loop *clp)
  * sizeof struct cam_iosched_softc.
  */
 int
-cam_iosched_init(struct cam_iosched_softc **iscp, struct cam_periph *periph)
+cam_iosched_init(struct cam_iosched_softc **iscp, struct cam_periph *periph,
+    const struct disk *dp)
 {
 
 	*iscp = malloc(sizeof(**iscp), M_CAMSCHED, M_NOWAIT | M_ZERO);
 	if (*iscp == NULL)
 		return ENOMEM;
+	(*iscp)->disk = dp;
 #ifdef CAM_IOSCHED_DYNAMIC
 	if (iosched_debug)
 		printf("CAM IOSCHEDULER Allocating entry at %p\n", *iscp);
diff --git a/sys/cam/cam_iosched.h b/sys/cam/cam_iosched.h
index c8e4341f5095..e1019c531579 100644
--- a/sys/cam/cam_iosched.h
+++ b/sys/cam/cam_iosched.h
@@ -80,7 +80,8 @@ cam_iosched_sbintime_t(uintptr_t delta)
 
 typedef void (*cam_iosched_latfcn_t)(void *, sbintime_t, struct bio *);
 
-int cam_iosched_init(struct cam_iosched_softc **, struct cam_periph *periph);
+int cam_iosched_init(struct cam_iosched_softc **, struct cam_periph *periph,
+    const struct disk *dp);
 void cam_iosched_fini(struct cam_iosched_softc *);
 void cam_iosched_sysctl_init(struct cam_iosched_softc *, struct sysctl_ctx_list *, struct sysctl_oid *);
 struct bio *cam_iosched_next_trim(struct cam_iosched_softc *isc);
diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c
index 41c552e2780a..1a93ea71ba77 100644
--- a/sys/cam/nvme/nvme_da.c
+++ b/sys/cam/nvme/nvme_da.c
@@ -862,13 +862,6 @@ ndaregister(struct cam_periph *periph, void *arg)
 		return(CAM_REQ_CMP_ERR);
 	}
 
-	if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
-		printf("ndaregister: Unable to probe new device. "
-		       "Unable to allocate iosched memory\n");
-		free(softc, M_DEVBUF);
-		return(CAM_REQ_CMP_ERR);
-	}
-
 	/* ident_data parsing */
 
 	periph->softc = softc;
@@ -891,7 +884,6 @@ ndaregister(struct cam_periph *periph, void *arg)
 	quirks = softc->quirks;
 	TUNABLE_INT_FETCH(announce_buf, &quirks);
 	softc->quirks = quirks;
-	cam_iosched_set_sort_queue(softc->cam_iosched, 0);
 	softc->disk = disk = disk_alloc();
 	disk->d_rotation_rate = DISK_RR_NON_ROTATING;
 	disk->d_open = ndaopen;
@@ -953,6 +945,15 @@ ndaregister(struct cam_periph *periph, void *arg)
 	    DEVSTAT_ALL_SUPPORTED,
 	    DEVSTAT_TYPE_DIRECT | XPORT_DEVSTAT_TYPE(cpi.transport),
 	    DEVSTAT_PRIORITY_DISK);
+
+	if (cam_iosched_init(&softc->cam_iosched, periph, disk) != 0) {
+		printf("ndaregister: Unable to probe new device. "
+		       "Unable to allocate iosched memory\n");
+		free(softc, M_DEVBUF);
+		return(CAM_REQ_CMP_ERR);
+	}
+	cam_iosched_set_sort_queue(softc->cam_iosched, 0);
+
 	/*
 	 * Add alias for older nvd drives to ease transition.
 	 */
diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c
index 59745231bca5..4ecf8c35aca2 100644
--- a/sys/cam/scsi/scsi_da.c
+++ b/sys/cam/scsi/scsi_da.c
@@ -2804,13 +2804,6 @@ daregister(struct cam_periph *periph, void *arg)
 		return(CAM_REQ_CMP_ERR);
 	}
 
-	if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
-		printf("daregister: Unable to probe new device. "
-		       "Unable to allocate iosched memory\n");
-		free(softc, M_DEVBUF);
-		return(CAM_REQ_CMP_ERR);
-	}
-
 	LIST_INIT(&softc->pending_ccbs);
 	softc->state = DA_STATE_PROBE_WP;
 	bioq_init(&softc->delete_run_queue);
@@ -2979,7 +2972,13 @@ daregister(struct cam_periph *periph, void *arg)
 	softc->disk->d_hba_subdevice = cpi.hba_subdevice;
 	snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
 	    "%s%d", cpi.dev_name, cpi.unit_number);
-	cam_periph_lock(periph);
+
+	if (cam_iosched_init(&softc->cam_iosched, periph, softc->disk) != 0) {
+		printf("daregister: Unable to probe new device. "
+		       "Unable to allocate iosched memory\n");
+		free(softc, M_DEVBUF);
+		return(CAM_REQ_CMP_ERR);
+	}
 
 	/*
 	 * Add async callbacks for events of interest.
@@ -2988,6 +2987,7 @@ daregister(struct cam_periph *periph, void *arg)
 	 * fine without them and the only alternative
 	 * would be to not attach the device on failure.
 	 */
+	cam_periph_lock(periph);
 	xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
 	    AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
 	    AC_INQ_CHANGED, daasync, periph, periph->path);



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