public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] SCSI disk source code cleanup
@ 2024-07-30 21:00 Bart Van Assche
  2024-07-30 21:00 ` [PATCH 1/6] scsi: sd: Move the sd_remove() function definition Bart Van Assche
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Bart Van Assche @ 2024-07-30 21:00 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke,
	Bart Van Assche

Hi Martin,

This patch series removes multiple forward declarations from the SCSI disk (sd)
driver and also makes error messages easier to find with grep. Please consider
this patch series for the next merge window.

Thanks,

Bart.

Bart Van Assche (6):
  scsi: sd: Move the sd_remove() function definition
  scsi: sd: Move the sd_config_discard() function definition
  scsi: sd: Move the sd_config_write_same() function definition
  scsi: sd: Move the scsi_disk_release() function definition
  scsi: sd: Move the sd_fops definition
  scsi: sd: Do not split error messages

 drivers/scsi/sd.c | 411 ++++++++++++++++++++++------------------------
 1 file changed, 198 insertions(+), 213 deletions(-)


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/6] scsi: sd: Move the sd_remove() function definition
  2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
@ 2024-07-30 21:00 ` Bart Van Assche
  2024-07-30 23:41   ` Damien Le Moal
  2024-07-30 21:00 ` [PATCH 2/6] scsi: sd: Move the sd_config_discard() " Bart Van Assche
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Bart Van Assche @ 2024-07-30 21:00 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke,
	Bart Van Assche, James E.J. Bottomley

Move the sd_remove() function definition such that the sd_shutdown()
forward declaration can be removed.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/sd.c | 53 +++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index adeaa8ab9951..58ea8c06205b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -109,7 +109,6 @@ static void sd_config_write_same(struct scsi_disk *sdkp,
 		struct queue_limits *lim);
 static int  sd_revalidate_disk(struct gendisk *);
 static void sd_unlock_native_capacity(struct gendisk *disk);
-static void sd_shutdown(struct device *);
 static void scsi_disk_release(struct device *cdev);
 
 static DEFINE_IDA(sd_index_ida);
@@ -4042,32 +4041,6 @@ static int sd_probe(struct device *dev)
 	return error;
 }
 
-/**
- *	sd_remove - called whenever a scsi disk (previously recognized by
- *	sd_probe) is detached from the system. It is called (potentially
- *	multiple times) during sd module unload.
- *	@dev: pointer to device object
- *
- *	Note: this function is invoked from the scsi mid-level.
- *	This function potentially frees up a device name (e.g. /dev/sdc)
- *	that could be re-used by a subsequent sd_probe().
- *	This function is not called when the built-in sd driver is "exit-ed".
- **/
-static int sd_remove(struct device *dev)
-{
-	struct scsi_disk *sdkp = dev_get_drvdata(dev);
-
-	scsi_autopm_get_device(sdkp->device);
-
-	device_del(&sdkp->disk_dev);
-	del_gendisk(sdkp->disk);
-	if (!sdkp->suspended)
-		sd_shutdown(dev);
-
-	put_disk(sdkp->disk);
-	return 0;
-}
-
 static void scsi_disk_release(struct device *dev)
 {
 	struct scsi_disk *sdkp = to_scsi_disk(dev);
@@ -4147,6 +4120,32 @@ static void sd_shutdown(struct device *dev)
 	}
 }
 
+/**
+ *	sd_remove - called whenever a scsi disk (previously recognized by
+ *	sd_probe) is detached from the system. It is called (potentially
+ *	multiple times) during sd module unload.
+ *	@dev: pointer to device object
+ *
+ *	Note: this function is invoked from the scsi mid-level.
+ *	This function potentially frees up a device name (e.g. /dev/sdc)
+ *	that could be re-used by a subsequent sd_probe().
+ *	This function is not called when the built-in sd driver is "exit-ed".
+ **/
+static int sd_remove(struct device *dev)
+{
+	struct scsi_disk *sdkp = dev_get_drvdata(dev);
+
+	scsi_autopm_get_device(sdkp->device);
+
+	device_del(&sdkp->disk_dev);
+	del_gendisk(sdkp->disk);
+	if (!sdkp->suspended)
+		sd_shutdown(dev);
+
+	put_disk(sdkp->disk);
+	return 0;
+}
+
 static inline bool sd_do_start_stop(struct scsi_device *sdev, bool runtime)
 {
 	return (sdev->manage_system_start_stop && !runtime) ||

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 2/6] scsi: sd: Move the sd_config_discard() function definition
  2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
  2024-07-30 21:00 ` [PATCH 1/6] scsi: sd: Move the sd_remove() function definition Bart Van Assche
@ 2024-07-30 21:00 ` Bart Van Assche
  2024-07-30 23:42   ` Damien Le Moal
  2024-07-30 21:00 ` [PATCH 3/6] scsi: sd: Move the sd_config_write_same() " Bart Van Assche
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Bart Van Assche @ 2024-07-30 21:00 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke,
	Bart Van Assche, James E.J. Bottomley

Move the sd_config_discard() function definition such that its
forward declaration can be removed.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/sd.c | 114 +++++++++++++++++++++++-----------------------
 1 file changed, 56 insertions(+), 58 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 58ea8c06205b..8b8a355435b4 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -103,8 +103,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 
 #define SD_MINORS	16
 
-static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
-		unsigned int mode);
 static void sd_config_write_same(struct scsi_disk *sdkp,
 		struct queue_limits *lim);
 static int  sd_revalidate_disk(struct gendisk *);
@@ -121,6 +119,62 @@ static const char *sd_cache_types[] = {
 	"write back, no read (daft)"
 };
 
+static void sd_disable_discard(struct scsi_disk *sdkp)
+{
+	sdkp->provisioning_mode = SD_LBP_DISABLE;
+	blk_queue_disable_discard(sdkp->disk->queue);
+}
+
+static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
+		unsigned int mode)
+{
+	unsigned int logical_block_size = sdkp->device->sector_size;
+	unsigned int max_blocks = 0;
+
+	lim->discard_alignment = sdkp->unmap_alignment * logical_block_size;
+	lim->discard_granularity = max(sdkp->physical_block_size,
+			sdkp->unmap_granularity * logical_block_size);
+	sdkp->provisioning_mode = mode;
+
+	switch (mode) {
+
+	case SD_LBP_FULL:
+	case SD_LBP_DISABLE:
+		break;
+
+	case SD_LBP_UNMAP:
+		max_blocks = min_not_zero(sdkp->max_unmap_blocks,
+					  (u32)SD_MAX_WS16_BLOCKS);
+		break;
+
+	case SD_LBP_WS16:
+		if (sdkp->device->unmap_limit_for_ws)
+			max_blocks = sdkp->max_unmap_blocks;
+		else
+			max_blocks = sdkp->max_ws_blocks;
+
+		max_blocks = min_not_zero(max_blocks, (u32)SD_MAX_WS16_BLOCKS);
+		break;
+
+	case SD_LBP_WS10:
+		if (sdkp->device->unmap_limit_for_ws)
+			max_blocks = sdkp->max_unmap_blocks;
+		else
+			max_blocks = sdkp->max_ws_blocks;
+
+		max_blocks = min_not_zero(max_blocks, (u32)SD_MAX_WS10_BLOCKS);
+		break;
+
+	case SD_LBP_ZERO:
+		max_blocks = min_not_zero(sdkp->max_ws_blocks,
+					  (u32)SD_MAX_WS10_BLOCKS);
+		break;
+	}
+
+	lim->max_hw_discard_sectors = max_blocks *
+		(logical_block_size >> SECTOR_SHIFT);
+}
+
 static void sd_set_flush_flag(struct scsi_disk *sdkp,
 		struct queue_limits *lim)
 {
@@ -841,62 +895,6 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,
 	return protect;
 }
 
-static void sd_disable_discard(struct scsi_disk *sdkp)
-{
-	sdkp->provisioning_mode = SD_LBP_DISABLE;
-	blk_queue_disable_discard(sdkp->disk->queue);
-}
-
-static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
-		unsigned int mode)
-{
-	unsigned int logical_block_size = sdkp->device->sector_size;
-	unsigned int max_blocks = 0;
-
-	lim->discard_alignment = sdkp->unmap_alignment * logical_block_size;
-	lim->discard_granularity = max(sdkp->physical_block_size,
-			sdkp->unmap_granularity * logical_block_size);
-	sdkp->provisioning_mode = mode;
-
-	switch (mode) {
-
-	case SD_LBP_FULL:
-	case SD_LBP_DISABLE:
-		break;
-
-	case SD_LBP_UNMAP:
-		max_blocks = min_not_zero(sdkp->max_unmap_blocks,
-					  (u32)SD_MAX_WS16_BLOCKS);
-		break;
-
-	case SD_LBP_WS16:
-		if (sdkp->device->unmap_limit_for_ws)
-			max_blocks = sdkp->max_unmap_blocks;
-		else
-			max_blocks = sdkp->max_ws_blocks;
-
-		max_blocks = min_not_zero(max_blocks, (u32)SD_MAX_WS16_BLOCKS);
-		break;
-
-	case SD_LBP_WS10:
-		if (sdkp->device->unmap_limit_for_ws)
-			max_blocks = sdkp->max_unmap_blocks;
-		else
-			max_blocks = sdkp->max_ws_blocks;
-
-		max_blocks = min_not_zero(max_blocks, (u32)SD_MAX_WS10_BLOCKS);
-		break;
-
-	case SD_LBP_ZERO:
-		max_blocks = min_not_zero(sdkp->max_ws_blocks,
-					  (u32)SD_MAX_WS10_BLOCKS);
-		break;
-	}
-
-	lim->max_hw_discard_sectors = max_blocks *
-		(logical_block_size >> SECTOR_SHIFT);
-}
-
 static void *sd_set_special_bvec(struct request *rq, unsigned int data_len)
 {
 	struct page *page;

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 3/6] scsi: sd: Move the sd_config_write_same() function definition
  2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
  2024-07-30 21:00 ` [PATCH 1/6] scsi: sd: Move the sd_remove() function definition Bart Van Assche
  2024-07-30 21:00 ` [PATCH 2/6] scsi: sd: Move the sd_config_discard() " Bart Van Assche
@ 2024-07-30 21:00 ` Bart Van Assche
  2024-07-30 23:43   ` Damien Le Moal
  2024-07-30 21:00 ` [PATCH 4/6] scsi: sd: Move the scsi_disk_release() " Bart Van Assche
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Bart Van Assche @ 2024-07-30 21:00 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke,
	Bart Van Assche, James E.J. Bottomley

Move the sd_config_write_same() function definition such that its forward
declaration can be removed.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/sd.c | 136 +++++++++++++++++++++++-----------------------
 1 file changed, 67 insertions(+), 69 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 8b8a355435b4..30c1792df1b3 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -103,8 +103,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 
 #define SD_MINORS	16
 
-static void sd_config_write_same(struct scsi_disk *sdkp,
-		struct queue_limits *lim);
 static int  sd_revalidate_disk(struct gendisk *);
 static void sd_unlock_native_capacity(struct gendisk *disk);
 static void scsi_disk_release(struct device *cdev);
@@ -175,6 +173,73 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,
 		(logical_block_size >> SECTOR_SHIFT);
 }
 
+static void sd_disable_write_same(struct scsi_disk *sdkp)
+{
+	sdkp->device->no_write_same = 1;
+	sdkp->max_ws_blocks = 0;
+	blk_queue_disable_write_zeroes(sdkp->disk->queue);
+}
+
+static void sd_config_write_same(struct scsi_disk *sdkp,
+		struct queue_limits *lim)
+{
+	unsigned int logical_block_size = sdkp->device->sector_size;
+
+	if (sdkp->device->no_write_same) {
+		sdkp->max_ws_blocks = 0;
+		goto out;
+	}
+
+	/* Some devices can not handle block counts above 0xffff despite
+	 * supporting WRITE SAME(16). Consequently we default to 64k
+	 * blocks per I/O unless the device explicitly advertises a
+	 * bigger limit.
+	 */
+	if (sdkp->max_ws_blocks > SD_MAX_WS10_BLOCKS)
+		sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks,
+						   (u32)SD_MAX_WS16_BLOCKS);
+	else if (sdkp->ws16 || sdkp->ws10 || sdkp->device->no_report_opcodes)
+		sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks,
+						   (u32)SD_MAX_WS10_BLOCKS);
+	else {
+		sdkp->device->no_write_same = 1;
+		sdkp->max_ws_blocks = 0;
+	}
+
+	if (sdkp->lbprz && sdkp->lbpws)
+		sdkp->zeroing_mode = SD_ZERO_WS16_UNMAP;
+	else if (sdkp->lbprz && sdkp->lbpws10)
+		sdkp->zeroing_mode = SD_ZERO_WS10_UNMAP;
+	else if (sdkp->max_ws_blocks)
+		sdkp->zeroing_mode = SD_ZERO_WS;
+	else
+		sdkp->zeroing_mode = SD_ZERO_WRITE;
+
+	if (sdkp->max_ws_blocks &&
+	    sdkp->physical_block_size > logical_block_size) {
+		/*
+		 * Reporting a maximum number of blocks that is not aligned
+		 * on the device physical size would cause a large write same
+		 * request to be split into physically unaligned chunks by
+		 * __blkdev_issue_write_zeroes() even if the caller of this
+		 * functions took care to align the large request. So make sure
+		 * the maximum reported is aligned to the device physical block
+		 * size. This is only an optional optimization for regular
+		 * disks, but this is mandatory to avoid failure of large write
+		 * same requests directed at sequential write required zones of
+		 * host-managed ZBC disks.
+		 */
+		sdkp->max_ws_blocks =
+			round_down(sdkp->max_ws_blocks,
+				   bytes_to_logical(sdkp->device,
+						    sdkp->physical_block_size));
+	}
+
+out:
+	lim->max_write_zeroes_sectors =
+		sdkp->max_ws_blocks * (logical_block_size >> SECTOR_SHIFT);
+}
+
 static void sd_set_flush_flag(struct scsi_disk *sdkp,
 		struct queue_limits *lim)
 {
@@ -1078,73 +1143,6 @@ static blk_status_t sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd)
 	return sd_setup_write_same10_cmnd(cmd, false);
 }
 
-static void sd_disable_write_same(struct scsi_disk *sdkp)
-{
-	sdkp->device->no_write_same = 1;
-	sdkp->max_ws_blocks = 0;
-	blk_queue_disable_write_zeroes(sdkp->disk->queue);
-}
-
-static void sd_config_write_same(struct scsi_disk *sdkp,
-		struct queue_limits *lim)
-{
-	unsigned int logical_block_size = sdkp->device->sector_size;
-
-	if (sdkp->device->no_write_same) {
-		sdkp->max_ws_blocks = 0;
-		goto out;
-	}
-
-	/* Some devices can not handle block counts above 0xffff despite
-	 * supporting WRITE SAME(16). Consequently we default to 64k
-	 * blocks per I/O unless the device explicitly advertises a
-	 * bigger limit.
-	 */
-	if (sdkp->max_ws_blocks > SD_MAX_WS10_BLOCKS)
-		sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks,
-						   (u32)SD_MAX_WS16_BLOCKS);
-	else if (sdkp->ws16 || sdkp->ws10 || sdkp->device->no_report_opcodes)
-		sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks,
-						   (u32)SD_MAX_WS10_BLOCKS);
-	else {
-		sdkp->device->no_write_same = 1;
-		sdkp->max_ws_blocks = 0;
-	}
-
-	if (sdkp->lbprz && sdkp->lbpws)
-		sdkp->zeroing_mode = SD_ZERO_WS16_UNMAP;
-	else if (sdkp->lbprz && sdkp->lbpws10)
-		sdkp->zeroing_mode = SD_ZERO_WS10_UNMAP;
-	else if (sdkp->max_ws_blocks)
-		sdkp->zeroing_mode = SD_ZERO_WS;
-	else
-		sdkp->zeroing_mode = SD_ZERO_WRITE;
-
-	if (sdkp->max_ws_blocks &&
-	    sdkp->physical_block_size > logical_block_size) {
-		/*
-		 * Reporting a maximum number of blocks that is not aligned
-		 * on the device physical size would cause a large write same
-		 * request to be split into physically unaligned chunks by
-		 * __blkdev_issue_write_zeroes() even if the caller of this
-		 * functions took care to align the large request. So make sure
-		 * the maximum reported is aligned to the device physical block
-		 * size. This is only an optional optimization for regular
-		 * disks, but this is mandatory to avoid failure of large write
-		 * same requests directed at sequential write required zones of
-		 * host-managed ZBC disks.
-		 */
-		sdkp->max_ws_blocks =
-			round_down(sdkp->max_ws_blocks,
-				   bytes_to_logical(sdkp->device,
-						    sdkp->physical_block_size));
-	}
-
-out:
-	lim->max_write_zeroes_sectors =
-		sdkp->max_ws_blocks * (logical_block_size >> SECTOR_SHIFT);
-}
-
 static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd)
 {
 	struct request *rq = scsi_cmd_to_rq(cmd);

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 4/6] scsi: sd: Move the scsi_disk_release() function definition
  2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
                   ` (2 preceding siblings ...)
  2024-07-30 21:00 ` [PATCH 3/6] scsi: sd: Move the sd_config_write_same() " Bart Van Assche
@ 2024-07-30 21:00 ` Bart Van Assche
  2024-07-30 23:43   ` Damien Le Moal
  2024-07-30 21:00 ` [PATCH 5/6] scsi: sd: Move the sd_fops definition Bart Van Assche
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Bart Van Assche @ 2024-07-30 21:00 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke,
	Bart Van Assche, James E.J. Bottomley

Move the scsi_disk_release() function definition such that its forward
declaration can be removed.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/sd.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 30c1792df1b3..cefc40de6ee8 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -105,7 +105,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 
 static int  sd_revalidate_disk(struct gendisk *);
 static void sd_unlock_native_capacity(struct gendisk *disk);
-static void scsi_disk_release(struct device *cdev);
 
 static DEFINE_IDA(sd_index_ida);
 
@@ -792,6 +791,17 @@ static struct attribute *sd_disk_attrs[] = {
 };
 ATTRIBUTE_GROUPS(sd_disk);
 
+static void scsi_disk_release(struct device *dev)
+{
+	struct scsi_disk *sdkp = to_scsi_disk(dev);
+
+	ida_free(&sd_index_ida, sdkp->index);
+	put_device(&sdkp->device->sdev_gendev);
+	free_opal_dev(sdkp->opal_dev);
+
+	kfree(sdkp);
+}
+
 static struct class sd_disk_class = {
 	.name		= "scsi_disk",
 	.dev_release	= scsi_disk_release,
@@ -4037,17 +4047,6 @@ static int sd_probe(struct device *dev)
 	return error;
 }
 
-static void scsi_disk_release(struct device *dev)
-{
-	struct scsi_disk *sdkp = to_scsi_disk(dev);
-
-	ida_free(&sd_index_ida, sdkp->index);
-	put_device(&sdkp->device->sdev_gendev);
-	free_opal_dev(sdkp->opal_dev);
-
-	kfree(sdkp);
-}
-
 static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
 {
 	unsigned char cmd[6] = { START_STOP };	/* START_VALID */

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 5/6] scsi: sd: Move the sd_fops definition
  2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
                   ` (3 preceding siblings ...)
  2024-07-30 21:00 ` [PATCH 4/6] scsi: sd: Move the scsi_disk_release() " Bart Van Assche
@ 2024-07-30 21:00 ` Bart Van Assche
  2024-07-30 23:44   ` Damien Le Moal
  2024-07-30 21:00 ` [PATCH 6/6] scsi: sd: Do not split error messages Bart Van Assche
  2024-07-31  1:12 ` [PATCH 0/6] SCSI disk source code cleanup Himanshu Madhani
  6 siblings, 1 reply; 15+ messages in thread
From: Bart Van Assche @ 2024-07-30 21:00 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke,
	Bart Van Assche, James E.J. Bottomley

Move the sd_fops definition such that the sd_unlock_native_capacity()
forward declaration can be removed.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/sd.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cefc40de6ee8..3f4df58f2bbc 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -104,7 +104,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 #define SD_MINORS	16
 
 static int  sd_revalidate_disk(struct gendisk *);
-static void sd_unlock_native_capacity(struct gendisk *disk);
 
 static DEFINE_IDA(sd_index_ida);
 
@@ -2140,21 +2139,6 @@ static void scsi_disk_free_disk(struct gendisk *disk)
 	put_device(&sdkp->disk_dev);
 }
 
-static const struct block_device_operations sd_fops = {
-	.owner			= THIS_MODULE,
-	.open			= sd_open,
-	.release		= sd_release,
-	.ioctl			= sd_ioctl,
-	.getgeo			= sd_getgeo,
-	.compat_ioctl		= blkdev_compat_ptr_ioctl,
-	.check_events		= sd_check_events,
-	.unlock_native_capacity	= sd_unlock_native_capacity,
-	.report_zones		= sd_zbc_report_zones,
-	.get_unique_id		= sd_get_unique_id,
-	.free_disk		= scsi_disk_free_disk,
-	.pr_ops			= &sd_pr_ops,
-};
-
 /**
  *	sd_eh_reset - reset error handling callback
  *	@scmd:		sd-issued command that has failed
@@ -3845,6 +3829,21 @@ static void sd_unlock_native_capacity(struct gendisk *disk)
 		sdev->host->hostt->unlock_native_capacity(sdev);
 }
 
+static const struct block_device_operations sd_fops = {
+	.owner			= THIS_MODULE,
+	.open			= sd_open,
+	.release		= sd_release,
+	.ioctl			= sd_ioctl,
+	.getgeo			= sd_getgeo,
+	.compat_ioctl		= blkdev_compat_ptr_ioctl,
+	.check_events		= sd_check_events,
+	.unlock_native_capacity	= sd_unlock_native_capacity,
+	.report_zones		= sd_zbc_report_zones,
+	.get_unique_id		= sd_get_unique_id,
+	.free_disk		= scsi_disk_free_disk,
+	.pr_ops			= &sd_pr_ops,
+};
+
 /**
  *	sd_format_disk_name - format disk name
  *	@prefix: name prefix - ie. "sd" for SCSI disks

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 6/6] scsi: sd: Do not split error messages
  2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
                   ` (4 preceding siblings ...)
  2024-07-30 21:00 ` [PATCH 5/6] scsi: sd: Move the sd_fops definition Bart Van Assche
@ 2024-07-30 21:00 ` Bart Van Assche
  2024-07-30 23:47   ` Damien Le Moal
  2024-07-31  1:12 ` [PATCH 0/6] SCSI disk source code cleanup Himanshu Madhani
  6 siblings, 1 reply; 15+ messages in thread
From: Bart Van Assche @ 2024-07-30 21:00 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke,
	Bart Van Assche, James E.J. Bottomley

Make it easier to find these error messages with grep. This patch has been
created as follows:
* Delete all occurrences of the following regular expression:
  "[[:blank:]]*\\*\n[[:blank:]]*"
* Split long lines manually where necessary.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/sd.c | 54 ++++++++++++++++++++---------------------------
 1 file changed, 23 insertions(+), 31 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3f4df58f2bbc..304da82fea4f 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1651,8 +1651,9 @@ static int sd_ioctl(struct block_device *bdev, blk_mode_t mode,
 	void __user *p = (void __user *)arg;
 	int error;
     
-	SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, "
-				    "cmd=0x%x\n", disk->disk_name, cmd));
+	SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp,
+				    "sd_ioctl: disk=%s, cmd=0x%x\n",
+				    disk->disk_name, cmd));
 
 	if (bdev_is_partition(bdev) && !capable(CAP_SYS_RAWIO))
 		return -ENOIOCTLCMD;
@@ -2549,8 +2550,8 @@ static int sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer
 	type = ((buffer[12] >> 1) & 7) + 1; /* P_TYPE 0 = Type 1 */
 
 	if (type > T10_PI_TYPE3_PROTECTION) {
-		sd_printk(KERN_ERR, sdkp, "formatted with unsupported"	\
-			  " protection type %u. Disabling disk!\n",
+		sd_printk(KERN_ERR, sdkp,
+			  "formatted with unsupported protection type %u. Disabling disk!\n",
 			  type);
 		sdkp->protection_type = 0;
 		return -ENODEV;
@@ -2829,8 +2830,8 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
 		if ((sizeof(sdkp->capacity) > 4) &&
 		    (sdkp->capacity > 0xffffffffULL)) {
 			int old_sector_size = sector_size;
-			sd_printk(KERN_NOTICE, sdkp, "Very big device. "
-					"Trying to use READ CAPACITY(16).\n");
+			sd_printk(KERN_NOTICE, sdkp,
+				  "Very big device. Trying to use READ CAPACITY(16).\n");
 			sector_size = read_capacity_16(sdkp, sdp, lim, buffer);
 			if (sector_size < 0) {
 				sd_printk(KERN_NOTICE, sdkp,
@@ -2856,8 +2857,8 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
 	 */
 	if (sdp->fix_capacity ||
 	    (sdp->guess_capacity && (sdkp->capacity & 0x01))) {
-		sd_printk(KERN_INFO, sdkp, "Adjusting the sector count "
-				"from its reported value: %llu\n",
+		sd_printk(KERN_INFO, sdkp,
+				"Adjusting the sector count from its reported value: %llu\n",
 				(unsigned long long) sdkp->capacity);
 		--sdkp->capacity;
 	}
@@ -2865,8 +2866,7 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
 got_data:
 	if (sector_size == 0) {
 		sector_size = 512;
-		sd_printk(KERN_NOTICE, sdkp, "Sector size 0 reported, "
-			  "assuming 512.\n");
+		sd_printk(KERN_NOTICE, sdkp, "Sector size 0 reported, assuming 512.\n");
 	}
 
 	if (sector_size != 512 &&
@@ -3071,8 +3071,9 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
 	if (len < 3)
 		goto bad_sense;
 	else if (len > SD_BUF_SIZE) {
-		sd_first_printk(KERN_NOTICE, sdkp, "Truncating mode parameter "
-			  "data from %d to %d bytes\n", len, SD_BUF_SIZE);
+		sd_first_printk(KERN_NOTICE, sdkp,
+				"Truncating mode parameter data from %d to %d bytes\n",
+				len, SD_BUF_SIZE);
 		len = SD_BUF_SIZE;
 	}
 	if (modepage == 0x3F && sdp->use_192_bytes_for_3f)
@@ -3095,8 +3096,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
 				 */
 				if (len - offset <= 2) {
 					sd_first_printk(KERN_ERR, sdkp,
-						"Incomplete mode parameter "
-							"data\n");
+						"Incomplete mode parameter data\n");
 					goto defaults;
 				} else {
 					modepage = page_code;
@@ -3111,8 +3111,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
 					offset += 2 + buffer[offset+1];
 				else {
 					sd_first_printk(KERN_ERR, sdkp,
-							"Incomplete mode "
-							"parameter data\n");
+							"Incomplete mode parameter data\n");
 					goto defaults;
 				}
 			}
@@ -3579,8 +3578,7 @@ static bool sd_validate_min_xfer_size(struct scsi_disk *sdkp)
 
 	if (min_xfer_bytes & (sdkp->physical_block_size - 1)) {
 		sd_first_printk(KERN_WARNING, sdkp,
-				"Preferred minimum I/O size %u bytes not a " \
-				"multiple of physical block size (%u bytes)\n",
+				"Preferred minimum I/O size %u bytes not a multiple of physical block size (%u bytes)\n",
 				min_xfer_bytes, sdkp->physical_block_size);
 		sdkp->min_xfer_blocks = 0;
 		return false;
@@ -3610,41 +3608,35 @@ static bool sd_validate_opt_xfer_size(struct scsi_disk *sdkp,
 
 	if (sdkp->opt_xfer_blocks > dev_max) {
 		sd_first_printk(KERN_WARNING, sdkp,
-				"Optimal transfer size %u logical blocks " \
-				"> dev_max (%u logical blocks)\n",
+				"Optimal transfer size %u logical blocks > dev_max (%u logical blocks)\n",
 				sdkp->opt_xfer_blocks, dev_max);
 		return false;
 	}
 
 	if (sdkp->opt_xfer_blocks > SD_DEF_XFER_BLOCKS) {
 		sd_first_printk(KERN_WARNING, sdkp,
-				"Optimal transfer size %u logical blocks " \
-				"> sd driver limit (%u logical blocks)\n",
+				"Optimal transfer size %u logical blocks > sd driver limit (%u logical blocks)\n",
 				sdkp->opt_xfer_blocks, SD_DEF_XFER_BLOCKS);
 		return false;
 	}
 
 	if (opt_xfer_bytes < PAGE_SIZE) {
 		sd_first_printk(KERN_WARNING, sdkp,
-				"Optimal transfer size %u bytes < " \
-				"PAGE_SIZE (%u bytes)\n",
+				"Optimal transfer size %u bytes < PAGE_SIZE (%u bytes)\n",
 				opt_xfer_bytes, (unsigned int)PAGE_SIZE);
 		return false;
 	}
 
 	if (min_xfer_bytes && opt_xfer_bytes % min_xfer_bytes) {
 		sd_first_printk(KERN_WARNING, sdkp,
-				"Optimal transfer size %u bytes not a " \
-				"multiple of preferred minimum block " \
-				"size (%u bytes)\n",
+				"Optimal transfer size %u bytes not a multiple of preferred minimum block size (%u bytes)\n",
 				opt_xfer_bytes, min_xfer_bytes);
 		return false;
 	}
 
 	if (opt_xfer_bytes & (sdkp->physical_block_size - 1)) {
 		sd_first_printk(KERN_WARNING, sdkp,
-				"Optimal transfer size %u bytes not a " \
-				"multiple of physical block size (%u bytes)\n",
+				"Optimal transfer size %u bytes not a multiple of physical block size (%u bytes)\n",
 				opt_xfer_bytes, sdkp->physical_block_size);
 		return false;
 	}
@@ -3706,8 +3698,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
 
 	buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL);
 	if (!buffer) {
-		sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory "
-			  "allocation failure.\n");
+		sd_printk(KERN_WARNING, sdkp,
+			  "sd_revalidate_disk: Memory allocation failure.\n");
 		goto out;
 	}
 

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/6] scsi: sd: Move the sd_remove() function definition
  2024-07-30 21:00 ` [PATCH 1/6] scsi: sd: Move the sd_remove() function definition Bart Van Assche
@ 2024-07-30 23:41   ` Damien Le Moal
  0 siblings, 0 replies; 15+ messages in thread
From: Damien Le Moal @ 2024-07-30 23:41 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Hannes Reinecke,
	James E.J. Bottomley

On 7/31/24 06:00, Bart Van Assche wrote:
> Move the sd_remove() function definition such that the sd_shutdown()
> forward declaration can be removed.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Looks fine to me.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/6] scsi: sd: Move the sd_config_discard() function definition
  2024-07-30 21:00 ` [PATCH 2/6] scsi: sd: Move the sd_config_discard() " Bart Van Assche
@ 2024-07-30 23:42   ` Damien Le Moal
  0 siblings, 0 replies; 15+ messages in thread
From: Damien Le Moal @ 2024-07-30 23:42 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Hannes Reinecke,
	James E.J. Bottomley

On 7/31/24 06:00, Bart Van Assche wrote:
> Move the sd_config_discard() function definition such that its
> forward declaration can be removed.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 3/6] scsi: sd: Move the sd_config_write_same() function definition
  2024-07-30 21:00 ` [PATCH 3/6] scsi: sd: Move the sd_config_write_same() " Bart Van Assche
@ 2024-07-30 23:43   ` Damien Le Moal
  0 siblings, 0 replies; 15+ messages in thread
From: Damien Le Moal @ 2024-07-30 23:43 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Hannes Reinecke,
	James E.J. Bottomley

On 7/31/24 06:00, Bart Van Assche wrote:
> Move the sd_config_write_same() function definition such that its forward
> declaration can be removed.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 4/6] scsi: sd: Move the scsi_disk_release() function definition
  2024-07-30 21:00 ` [PATCH 4/6] scsi: sd: Move the scsi_disk_release() " Bart Van Assche
@ 2024-07-30 23:43   ` Damien Le Moal
  0 siblings, 0 replies; 15+ messages in thread
From: Damien Le Moal @ 2024-07-30 23:43 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Hannes Reinecke,
	James E.J. Bottomley

On 7/31/24 06:00, Bart Van Assche wrote:
> Move the scsi_disk_release() function definition such that its forward
> declaration can be removed.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 5/6] scsi: sd: Move the sd_fops definition
  2024-07-30 21:00 ` [PATCH 5/6] scsi: sd: Move the sd_fops definition Bart Van Assche
@ 2024-07-30 23:44   ` Damien Le Moal
  0 siblings, 0 replies; 15+ messages in thread
From: Damien Le Moal @ 2024-07-30 23:44 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Hannes Reinecke,
	James E.J. Bottomley

On 7/31/24 06:00, Bart Van Assche wrote:
> Move the sd_fops definition such that the sd_unlock_native_capacity()
> forward declaration can be removed.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/6] scsi: sd: Do not split error messages
  2024-07-30 21:00 ` [PATCH 6/6] scsi: sd: Do not split error messages Bart Van Assche
@ 2024-07-30 23:47   ` Damien Le Moal
  2024-08-05 23:38     ` Bart Van Assche
  0 siblings, 1 reply; 15+ messages in thread
From: Damien Le Moal @ 2024-07-30 23:47 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Hannes Reinecke,
	James E.J. Bottomley

On 7/31/24 06:00, Bart Van Assche wrote:
> Make it easier to find these error messages with grep. This patch has been
> created as follows:
> * Delete all occurrences of the following regular expression:
>   "[[:blank:]]*\\*\n[[:blank:]]*"
> * Split long lines manually where necessary.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

One nit below. With that fixed, feel free to add:

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

> @@ -2856,8 +2857,8 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
>  	 */
>  	if (sdp->fix_capacity ||
>  	    (sdp->guess_capacity && (sdkp->capacity & 0x01))) {
> -		sd_printk(KERN_INFO, sdkp, "Adjusting the sector count "
> -				"from its reported value: %llu\n",
> +		sd_printk(KERN_INFO, sdkp,
> +				"Adjusting the sector count from its reported value: %llu\n",
>  				(unsigned long long) sdkp->capacity);

Can you fix the alignment of the format string while at it ? No need for that
extra tab, removing it will make the line shorter.

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 0/6] SCSI disk source code cleanup
  2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
                   ` (5 preceding siblings ...)
  2024-07-30 21:00 ` [PATCH 6/6] scsi: sd: Do not split error messages Bart Van Assche
@ 2024-07-31  1:12 ` Himanshu Madhani
  6 siblings, 0 replies; 15+ messages in thread
From: Himanshu Madhani @ 2024-07-31  1:12 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Damien Le Moal, Hannes Reinecke



On 7/30/24 14:00, Bart Van Assche wrote:
> Hi Martin,
> 
> This patch series removes multiple forward declarations from the SCSI disk (sd)
> driver and also makes error messages easier to find with grep. Please consider
> this patch series for the next merge window.
> 
> Thanks,
> 
> Bart.
> 
> Bart Van Assche (6):
>    scsi: sd: Move the sd_remove() function definition
>    scsi: sd: Move the sd_config_discard() function definition
>    scsi: sd: Move the sd_config_write_same() function definition
>    scsi: sd: Move the scsi_disk_release() function definition
>    scsi: sd: Move the sd_fops definition
>    scsi: sd: Do not split error messages
> 
>   drivers/scsi/sd.c | 411 ++++++++++++++++++++++------------------------
>   1 file changed, 198 insertions(+), 213 deletions(-)
> 
> 

For the series.

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>

-- 
Himanshu Madhani                                Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 6/6] scsi: sd: Do not split error messages
  2024-07-30 23:47   ` Damien Le Moal
@ 2024-08-05 23:38     ` Bart Van Assche
  0 siblings, 0 replies; 15+ messages in thread
From: Bart Van Assche @ 2024-08-05 23:38 UTC (permalink / raw)
  To: Damien Le Moal, Martin K . Petersen
  Cc: linux-scsi, Christoph Hellwig, Hannes Reinecke,
	James E.J. Bottomley

On 7/30/24 4:47 PM, Damien Le Moal wrote:
> On 7/31/24 06:00, Bart Van Assche wrote:
>> @@ -2856,8 +2857,8 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim,
>>   	 */
>>   	if (sdp->fix_capacity ||
>>   	    (sdp->guess_capacity && (sdkp->capacity & 0x01))) {
>> -		sd_printk(KERN_INFO, sdkp, "Adjusting the sector count "
>> -				"from its reported value: %llu\n",
>> +		sd_printk(KERN_INFO, sdkp,
>> +				"Adjusting the sector count from its reported value: %llu\n",
>>   				(unsigned long long) sdkp->capacity);
> 
> Can you fix the alignment of the format string while at it ? No need for that
> extra tab, removing it will make the line shorter.

Sure, I will fix the alignment of the sd_printk() arguments. Thanks for
the reviews!

Bart.



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-08-05 23:38 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-30 21:00 [PATCH 0/6] SCSI disk source code cleanup Bart Van Assche
2024-07-30 21:00 ` [PATCH 1/6] scsi: sd: Move the sd_remove() function definition Bart Van Assche
2024-07-30 23:41   ` Damien Le Moal
2024-07-30 21:00 ` [PATCH 2/6] scsi: sd: Move the sd_config_discard() " Bart Van Assche
2024-07-30 23:42   ` Damien Le Moal
2024-07-30 21:00 ` [PATCH 3/6] scsi: sd: Move the sd_config_write_same() " Bart Van Assche
2024-07-30 23:43   ` Damien Le Moal
2024-07-30 21:00 ` [PATCH 4/6] scsi: sd: Move the scsi_disk_release() " Bart Van Assche
2024-07-30 23:43   ` Damien Le Moal
2024-07-30 21:00 ` [PATCH 5/6] scsi: sd: Move the sd_fops definition Bart Van Assche
2024-07-30 23:44   ` Damien Le Moal
2024-07-30 21:00 ` [PATCH 6/6] scsi: sd: Do not split error messages Bart Van Assche
2024-07-30 23:47   ` Damien Le Moal
2024-08-05 23:38     ` Bart Van Assche
2024-07-31  1:12 ` [PATCH 0/6] SCSI disk source code cleanup Himanshu Madhani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox