Commit 969f17e1 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

sr: convert to the atomic queue limits API

Assign all queue limits through a local queue_limits variable and
queue_limits_commit_update so that we can't race updating them from
multiple places, and free the queue when updating them so that
in-progress I/O submissions don't see half-updated limits.

Also use the chance to clean up variable names to standard ones.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20240531074837.1648501-13-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 804e498e
...@@ -111,7 +111,7 @@ static struct lock_class_key sr_bio_compl_lkclass; ...@@ -111,7 +111,7 @@ static struct lock_class_key sr_bio_compl_lkclass;
static int sr_open(struct cdrom_device_info *, int); static int sr_open(struct cdrom_device_info *, int);
static void sr_release(struct cdrom_device_info *); static void sr_release(struct cdrom_device_info *);
static void get_sectorsize(struct scsi_cd *); static int get_sectorsize(struct scsi_cd *);
static int get_capabilities(struct scsi_cd *); static int get_capabilities(struct scsi_cd *);
static unsigned int sr_check_events(struct cdrom_device_info *cdi, static unsigned int sr_check_events(struct cdrom_device_info *cdi,
...@@ -473,15 +473,15 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt) ...@@ -473,15 +473,15 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt)
return BLK_STS_IOERR; return BLK_STS_IOERR;
} }
static void sr_revalidate_disk(struct scsi_cd *cd) static int sr_revalidate_disk(struct scsi_cd *cd)
{ {
struct scsi_sense_hdr sshdr; struct scsi_sense_hdr sshdr;
/* if the unit is not ready, nothing more to do */ /* if the unit is not ready, nothing more to do */
if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr)) if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
return; return 0;
sr_cd_check(&cd->cdi); sr_cd_check(&cd->cdi);
get_sectorsize(cd); return get_sectorsize(cd);
} }
static int sr_block_open(struct gendisk *disk, blk_mode_t mode) static int sr_block_open(struct gendisk *disk, blk_mode_t mode)
...@@ -494,13 +494,16 @@ static int sr_block_open(struct gendisk *disk, blk_mode_t mode) ...@@ -494,13 +494,16 @@ static int sr_block_open(struct gendisk *disk, blk_mode_t mode)
return -ENXIO; return -ENXIO;
scsi_autopm_get_device(sdev); scsi_autopm_get_device(sdev);
if (disk_check_media_change(disk)) if (disk_check_media_change(disk)) {
sr_revalidate_disk(cd); ret = sr_revalidate_disk(cd);
if (ret)
goto out;
}
mutex_lock(&cd->lock); mutex_lock(&cd->lock);
ret = cdrom_open(&cd->cdi, mode); ret = cdrom_open(&cd->cdi, mode);
mutex_unlock(&cd->lock); mutex_unlock(&cd->lock);
out:
scsi_autopm_put_device(sdev); scsi_autopm_put_device(sdev);
if (ret) if (ret)
scsi_device_put(cd->device); scsi_device_put(cd->device);
...@@ -685,7 +688,9 @@ static int sr_probe(struct device *dev) ...@@ -685,7 +688,9 @@ static int sr_probe(struct device *dev)
blk_pm_runtime_init(sdev->request_queue, dev); blk_pm_runtime_init(sdev->request_queue, dev);
dev_set_drvdata(dev, cd); dev_set_drvdata(dev, cd);
sr_revalidate_disk(cd); error = sr_revalidate_disk(cd);
if (error)
goto unregister_cdrom;
error = device_add_disk(&sdev->sdev_gendev, disk, NULL); error = device_add_disk(&sdev->sdev_gendev, disk, NULL);
if (error) if (error)
...@@ -714,13 +719,14 @@ static int sr_probe(struct device *dev) ...@@ -714,13 +719,14 @@ static int sr_probe(struct device *dev)
} }
static void get_sectorsize(struct scsi_cd *cd) static int get_sectorsize(struct scsi_cd *cd)
{ {
struct request_queue *q = cd->device->request_queue;
static const u8 cmd[10] = { READ_CAPACITY }; static const u8 cmd[10] = { READ_CAPACITY };
unsigned char buffer[8] = { }; unsigned char buffer[8] = { };
int the_result; struct queue_limits lim;
int err;
int sector_size; int sector_size;
struct request_queue *queue;
struct scsi_failure failure_defs[] = { struct scsi_failure failure_defs[] = {
{ {
.result = SCMD_FAILURE_RESULT_ANY, .result = SCMD_FAILURE_RESULT_ANY,
...@@ -736,10 +742,10 @@ static void get_sectorsize(struct scsi_cd *cd) ...@@ -736,10 +742,10 @@ static void get_sectorsize(struct scsi_cd *cd)
}; };
/* Do the command and wait.. */ /* Do the command and wait.. */
the_result = scsi_execute_cmd(cd->device, cmd, REQ_OP_DRV_IN, buffer, err = scsi_execute_cmd(cd->device, cmd, REQ_OP_DRV_IN, buffer,
sizeof(buffer), SR_TIMEOUT, MAX_RETRIES, sizeof(buffer), SR_TIMEOUT, MAX_RETRIES,
&exec_args); &exec_args);
if (the_result) { if (err) {
cd->capacity = 0x1fffff; cd->capacity = 0x1fffff;
sector_size = 2048; /* A guess, just in case */ sector_size = 2048; /* A guess, just in case */
} else { } else {
...@@ -789,10 +795,12 @@ static void get_sectorsize(struct scsi_cd *cd) ...@@ -789,10 +795,12 @@ static void get_sectorsize(struct scsi_cd *cd)
set_capacity(cd->disk, cd->capacity); set_capacity(cd->disk, cd->capacity);
} }
queue = cd->device->request_queue; lim = queue_limits_start_update(q);
blk_queue_logical_block_size(queue, sector_size); lim.logical_block_size = sector_size;
blk_mq_freeze_queue(q);
return; err = queue_limits_commit_update(q, &lim);
blk_mq_unfreeze_queue(q);
return err;
} }
static int get_capabilities(struct scsi_cd *cd) static int get_capabilities(struct scsi_cd *cd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment