public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: "Richard Weinberger" <richard@nod.at>,
	"Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Ilya Dryomov" <idryomov@gmail.com>,
	"Dongsheng Yang" <dongsheng.yang@easystack.cn>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	linux-um@lists.infradead.org, linux-block@vger.kernel.org,
	nbd@other.debian.org, ceph-devel@vger.kernel.org,
	xen-devel@lists.xenproject.org, linux-scsi@vger.kernel.org,
	"Damien Le Moal" <dlemoal@kernel.org>
Subject: [PATCH 12/14] sr: convert to the atomic queue limits API
Date: Fri, 31 May 2024 09:48:07 +0200	[thread overview]
Message-ID: <20240531074837.1648501-13-hch@lst.de> (raw)
In-Reply-To: <20240531074837.1648501-1-hch@lst.de>

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: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
---
 drivers/scsi/sr.c | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 7ab000942b97fc..3f491019103e0c 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -111,7 +111,7 @@ static struct lock_class_key sr_bio_compl_lkclass;
 static int sr_open(struct cdrom_device_info *, int);
 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 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)
 	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;
 
 	/* if the unit is not ready, nothing more to do */
 	if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
-		return;
+		return 0;
 	sr_cd_check(&cd->cdi);
-	get_sectorsize(cd);
+	return get_sectorsize(cd);
 }
 
 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;
 
 	scsi_autopm_get_device(sdev);
-	if (disk_check_media_change(disk))
-		sr_revalidate_disk(cd);
+	if (disk_check_media_change(disk)) {
+		ret = sr_revalidate_disk(cd);
+		if (ret)
+			goto out;
+	}
 
 	mutex_lock(&cd->lock);
 	ret = cdrom_open(&cd->cdi, mode);
 	mutex_unlock(&cd->lock);
-
+out:
 	scsi_autopm_put_device(sdev);
 	if (ret)
 		scsi_device_put(cd->device);
@@ -685,7 +688,9 @@ static int sr_probe(struct device *dev)
 	blk_pm_runtime_init(sdev->request_queue, dev);
 
 	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);
 	if (error)
@@ -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 };
 	unsigned char buffer[8] = { };
-	int the_result;
+	struct queue_limits lim;
+	int err;
 	int sector_size;
-	struct request_queue *queue;
 	struct scsi_failure failure_defs[] = {
 		{
 			.result = SCMD_FAILURE_RESULT_ANY,
@@ -736,10 +742,10 @@ static void get_sectorsize(struct scsi_cd *cd)
 	};
 
 	/* 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,
 				      &exec_args);
-	if (the_result) {
+	if (err) {
 		cd->capacity = 0x1fffff;
 		sector_size = 2048;	/* A guess, just in case */
 	} else {
@@ -789,10 +795,12 @@ static void get_sectorsize(struct scsi_cd *cd)
 		set_capacity(cd->disk, cd->capacity);
 	}
 
-	queue = cd->device->request_queue;
-	blk_queue_logical_block_size(queue, sector_size);
-
-	return;
+	lim = queue_limits_start_update(q);
+	lim.logical_block_size = sector_size;
+	blk_mq_freeze_queue(q);
+	err = queue_limits_commit_update(q, &lim);
+	blk_mq_unfreeze_queue(q);
+	return err;
 }
 
 static int get_capabilities(struct scsi_cd *cd)
-- 
2.43.0


  parent reply	other threads:[~2024-05-31  7:49 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31  7:47 convert the SCSI ULDs to the atomic queue limits API v2 Christoph Hellwig
2024-05-31  7:47 ` [PATCH 01/14] ubd: refactor the interrupt handler Christoph Hellwig
2024-06-14  1:35   ` Martin K. Petersen
2024-06-14  7:28   ` Anton Ivanov
2024-05-31  7:47 ` [PATCH 02/14] ubd: untagle discard vs write zeroes not support handling Christoph Hellwig
2024-06-14  1:36   ` Martin K. Petersen
2024-06-14  7:29   ` Anton Ivanov
2024-05-31  7:47 ` [PATCH 03/14] rbd: increase io_opt again Christoph Hellwig
2024-05-31  9:08   ` Ilya Dryomov
2024-06-14  1:36   ` Martin K. Petersen
2024-05-31  7:47 ` [PATCH 04/14] block: take io_opt and io_min into account for max_sectors Christoph Hellwig
2024-05-31  9:11   ` Ilya Dryomov
2024-06-14  1:40   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 05/14] sd: simplify the ZBC case in provisioning_mode_store Christoph Hellwig
2024-06-14  1:41   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 06/14] sd: add a sd_disable_discard helper Christoph Hellwig
2024-06-14  1:41   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 07/14] sd: add a sd_disable_write_same helper Christoph Hellwig
2024-06-14  1:42   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 08/14] sd: simplify the disable case in sd_config_discard Christoph Hellwig
2024-06-14  1:43   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 09/14] sd: factor out a sd_discard_mode helper Christoph Hellwig
2024-06-14  1:43   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 10/14] sd: cleanup zoned queue limits initialization Christoph Hellwig
2024-06-14  1:44   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 11/14] sd: convert to the atomic queue limits API Christoph Hellwig
2024-05-31 11:34   ` John Garry
2024-06-14  1:47   ` Martin K. Petersen
2024-05-31  7:48 ` Christoph Hellwig [this message]
2024-06-14  1:48   ` [PATCH 12/14] sr: " Martin K. Petersen
2024-05-31  7:48 ` [PATCH 13/14] block: remove unused " Christoph Hellwig
2024-05-31 11:12   ` John Garry
2024-05-31 13:55   ` Nitesh Shetty
2024-06-14  1:48   ` Martin K. Petersen
2024-05-31  7:48 ` [PATCH 14/14] block: add special APIs for run-time disabling of discard and friends Christoph Hellwig
2024-05-31 10:58   ` Nitesh Shetty
2024-05-31 11:12   ` John Garry
2024-06-14  1:49   ` Martin K. Petersen
2024-05-31 11:29 ` convert the SCSI ULDs to the atomic queue limits API v2 John Garry
2024-05-31 12:07 ` Martin K. Petersen
2024-05-31 12:23   ` Christoph Hellwig
2024-06-14 16:23 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240531074837.1648501-13-hch@lst.de \
    --to=hch@lst.de \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=axboe@kernel.dk \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=dongsheng.yang@easystack.cn \
    --cc=idryomov@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=martin.petersen@oracle.com \
    --cc=nbd@other.debian.org \
    --cc=richard@nod.at \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox