Skip to contentSkip to conversation

scsi: Fix discard_granularity for -drive if=scsi

PATCH In review Kevin Wolf 2 participants 5 messages Apr 10 – May 13

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

cover scsi: Fix discard_granularity for -drive if=scsi

This fixes the default for discard_granularity with -drive if=scsi, which was unintentionally 0 (disable discard) instead of sharing the default with the qdev property used for -device scsi-hd (usually 4096). This was a regression in QEMU 9.0.

Kevin Wolf (2):
block: Create DEFAULT_BLOCK_CONF macro
block: Add more defaults to DEFAULT_BLOCK_CONF

 include/hw/block/block.h | 12 ++++++++++++
 hw/scsi/scsi-bus.c       |  7 +------
 2 files changed, 13 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/2 block: Create DEFAULT_BLOCK_CONF macro

The property default values from include/hw/block/block.h were duplicated in scsi_bus_legacy_handle_cmdline(), allowing them to go out of sync easily. There doesn't seem a good way to avoid the duplication, but moving them next to each other in the header file should help to avoid this problem in the future.

---
 include/hw/block/block.h | 7 +++++++
 hw/scsi/scsi-bus.c       | 7 +------
 2 files changed, 8 insertions(+), 6 deletions(-)
include/hw/block/block.h +7 -0
index 7dc19d8a453..e0a427039ee 100644
@@ -51,6 +51,13 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
     return exp;
 }
 
+#define DEFAULT_BLOCK_CONF (BlockConf) {                                \
+    .bootindex = -1,                                                    \
+    .share_rw = false,                                                  \
+    .rerror = BLOCKDEV_ON_ERROR_AUTO,                                   \
+    .werror = BLOCKDEV_ON_ERROR_AUTO,                                   \
+}
+
 #define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf)                     \
     DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state,                 \
                             _conf.backend_defaults, ON_OFF_AUTO_AUTO),  \
hw/scsi/scsi-bus.c +1 -6
index 1a6b181b9d6..dccb2f25b2a 100644
@@ -485,12 +485,7 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
     Location loc;
     DriveInfo *dinfo;
     int unit;
-    BlockConf conf = {
-        .bootindex = -1,
-        .share_rw = false,
-        .rerror = BLOCKDEV_ON_ERROR_AUTO,
-        .werror = BLOCKDEV_ON_ERROR_AUTO,
-    };
+    BlockConf conf = DEFAULT_BLOCK_CONF;
 
     loc_push_none(&loc);
     for (unit = 0; unit <= bus->info->max_target; unit++) {
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH 2/2 block: Add more defaults to DEFAULT_BLOCK_CONF

In reply to Kevin Wolf

discard_granularity was missing from this, which means that SCSI disks created with -drive if=scsi would default to 0 (i.e. disabling discards) instead of -1, which makes scsi-hd automatically pick a granularity and is the default of the corresponding qdev property for -device scsi-hd.

This was broken in QEMU 9.0 with commit 3089637.

Also set other fields whose default isn't an obvious 0. These are not actual bug fixes because ON_OFF_AUTO_AUTO in fact happens to be 0, but it's better not to rely on the order of enums.

Fixes 308963746169 ('scsi: Don't ignore most usb-storage properties')
---
 include/hw/block/block.h | 5 +++++
 1 file changed, 5 insertions(+)
include/hw/block/block.h +5 -0
index e0a427039ee..df941df19f2 100644
@@ -53,7 +53,12 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
 
 #define DEFAULT_BLOCK_CONF (BlockConf) {                                \
     .bootindex = -1,                                                    \
+    .backend_defaults = ON_OFF_AUTO_AUTO,                               \
+    .discard_granularity = -1,                                          \
+    .wce = ON_OFF_AUTO_AUTO,                                            \
     .share_rw = false,                                                  \
+    .account_invalid = ON_OFF_AUTO_AUTO,                                \
+    .account_failed = ON_OFF_AUTO_AUTO,                                 \
     .rerror = BLOCKDEV_ON_ERROR_AUTO,                                   \
     .werror = BLOCKDEV_ON_ERROR_AUTO,                                   \
 }
Signature · 1 line
2.53.0
#3 lore raw
In reply to Kevin Wolf
Quoted 4 lines · Kevin Wolf

This fixes the default for discard_granularity with -drive if=scsi, which was unintentionally 0 (disable discard) instead of sharing the default with the qdev property used for -device scsi-hd (usually 4096). This was a regression in QEMU 9.0.

Hi!

Has this patchset been forgotten, or is it not needed anymore?

If it's needed, it would be nice if it lands in the master branch in the next 10 days, to be included in the next stable series.

Thanks,

/mjt

Quoted 8 lines

Kevin Wolf (2):
block: Create DEFAULT_BLOCK_CONF macro
block: Add more defaults to DEFAULT_BLOCK_CONF

  include/hw/block/block.h | 12 ++++++++++++
  hw/scsi/scsi-bus.c       |  7 +------
  2 files changed, 13 insertions(+), 6 deletions(-)
author
#4 lore raw

Am 13.05.2026 um 08:36 hat Michael Tokarev geschrieben:

Quoted 6 lines · Kevin Wolf
Quoted 4 lines

This fixes the default for discard_granularity with -drive if=scsi, which was unintentionally 0 (disable discard) instead of sharing the default with the qdev property used for -device scsi-hd (usually 4096). This was a regression in QEMU 9.0.

Quoted 6 lines

Hi!

Has this patchset been forgotten, or is it not needed anymore?

If it's needed, it would be nice if it lands in the master branch in the next 10 days, to be included in the next stable series.

I was hoping for review, but I'll include it in my next pull request either way. (And to be honest, yes, I had forgotten about it, but after rebasing my local development branch on top of the next pull request, I would probably have noticed that it's still missing.)

Kevin