Skip to content

Commit

Permalink
cam/iosched: Pass in the disk when initializing
Browse files Browse the repository at this point in the history
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
bsdimp committed Jul 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 148c173 commit 6f1dd60
Showing 5 changed files with 33 additions and 27 deletions.
19 changes: 10 additions & 9 deletions sys/cam/ata/ata_da.c
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 4 additions & 1 deletion sys/cam/cam_iosched.c
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 2 additions & 1 deletion sys/cam/cam_iosched.h
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 9 additions & 8 deletions sys/cam/nvme/nvme_da.c
Original file line number Diff line number Diff line change
@@ -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.
*/
16 changes: 8 additions & 8 deletions sys/cam/scsi/scsi_da.c
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 6f1dd60

Please sign in to comment.