* [PATCH v4 2/5] scsi: sd: Move the sd_config_discard() function definition
2025-12-16 21:07 [PATCH v4 0/5] Clean up the SCSI disk driver source code Bart Van Assche
2025-12-16 21:07 ` [PATCH v4 1/5] scsi: sd: Move the sd_remove() function definition Bart Van Assche
@ 2025-12-16 21:07 ` Bart Van Assche
2025-12-17 6:56 ` Johannes Thumshirn
2025-12-16 21:07 ` [PATCH v4 3/5] scsi: sd: Move the scsi_disk_release() " Bart Van Assche
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2025-12-16 21:07 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Bart Van Assche, Damien Le Moal, Himanshu Madhani,
James E.J. Bottomley
Move the sd_config_discard() function definition such that its
forward declaration can be removed.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
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 0b479153abb8..d5cb313d1a91 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -102,8 +102,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 void sd_revalidate_disk(struct gendisk *);
@@ -120,6 +118,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)
{
@@ -865,62 +919,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] 11+ messages in thread* [PATCH v4 4/5] scsi: sd: Move the sd_fops definition
2025-12-16 21:07 [PATCH v4 0/5] Clean up the SCSI disk driver source code Bart Van Assche
` (2 preceding siblings ...)
2025-12-16 21:07 ` [PATCH v4 3/5] scsi: sd: Move the scsi_disk_release() " Bart Van Assche
@ 2025-12-16 21:07 ` Bart Van Assche
2025-12-17 6:58 ` Johannes Thumshirn
2025-12-16 21:07 ` [PATCH v4 5/5] scsi: sd: Do not split error messages Bart Van Assche
4 siblings, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2025-12-16 21:07 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Bart Van Assche, Damien Le Moal, Himanshu Madhani,
James E.J. Bottomley
Move the sd_fops definition such that the sd_unlock_native_capacity()
forward declaration can be removed.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
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 58b33e9dad76..f52b435bf398 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -105,7 +105,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
static void sd_config_write_same(struct scsi_disk *sdkp,
struct queue_limits *lim);
static void sd_revalidate_disk(struct gendisk *);
-static void sd_unlock_native_capacity(struct gendisk *disk);
static DEFINE_IDA(sd_index_ida);
@@ -2174,21 +2173,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
@@ -3882,6 +3866,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] 11+ messages in thread* [PATCH v4 5/5] scsi: sd: Do not split error messages
2025-12-16 21:07 [PATCH v4 0/5] Clean up the SCSI disk driver source code Bart Van Assche
` (3 preceding siblings ...)
2025-12-16 21:07 ` [PATCH v4 4/5] scsi: sd: Move the sd_fops definition Bart Van Assche
@ 2025-12-16 21:07 ` Bart Van Assche
2025-12-17 6:59 ` Johannes Thumshirn
4 siblings, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2025-12-16 21:07 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Bart Van Assche, Damien Le Moal, Himanshu Madhani,
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.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
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 f52b435bf398..7bb9e9cf8c00 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1682,9 +1682,10 @@ static int sd_ioctl(struct block_device *bdev, blk_mode_t mode,
struct scsi_device *sdp = sdkp->device;
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;
@@ -2583,8 +2584,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;
@@ -2861,8 +2862,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,
@@ -2888,17 +2889,16 @@ 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",
- (unsigned long long) sdkp->capacity);
+ sd_printk(KERN_INFO, sdkp,
+ "Adjusting the sector count from its reported value: %llu\n",
+ (unsigned long long) sdkp->capacity);
--sdkp->capacity;
}
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 &&
@@ -3103,8 +3103,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)
@@ -3127,8 +3128,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;
@@ -3143,8 +3143,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;
}
}
@@ -3607,8 +3606,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;
@@ -3638,41 +3636,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;
}
^ permalink raw reply related [flat|nested] 11+ messages in thread