]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag
authorMing Lei <ming.lei@redhat.com>
Thu, 29 Jan 2026 16:19:51 +0000 (00:19 +0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 31 Jan 2026 13:36:41 +0000 (06:36 -0700)
Add a new feature flag UBLK_F_NO_AUTO_PART_SCAN to allow users to suppress
automatic partition scanning when starting a ublk device.

This is useful for some cases in which user don't want to scan
partitions.

Users still can manually trigger partition scanning later when appropriate
using standard tools (e.g., partprobe, blockdev --rereadpt).

Reported-by: Yoav Cohen <yoav@nvidia.com>
Link: https://lore.kernel.org/linux-block/DM4PR12MB63280C5637917C071C2F0D65A9A8A@DM4PR12MB6328.namprd12.prod.outlook.com/
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c
include/uapi/linux/ublk_cmd.h

index 92bd2351e3ad2192314b2f2bbdc269f8c8d7d44f..4fe754e7d1e8b6fd2339209cebe289ff4dfeed48 100644 (file)
@@ -80,7 +80,8 @@
                | UBLK_F_BUF_REG_OFF_DAEMON \
                | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
                | UBLK_F_SAFE_STOP_DEV \
-               | UBLK_F_BATCH_IO)
+               | UBLK_F_BATCH_IO \
+               | UBLK_F_NO_AUTO_PART_SCAN)
 
 #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
                | UBLK_F_USER_RECOVERY_REISSUE \
@@ -4430,9 +4431,14 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
 
        set_bit(UB_STATE_USED, &ub->state);
 
-       /* Schedule async partition scan for trusted daemons */
-       if (!ub->unprivileged_daemons)
-               schedule_work(&ub->partition_scan_work);
+       /* Skip partition scan if disabled by user */
+       if (ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN) {
+               clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
+       } else {
+               /* Schedule async partition scan for trusted daemons */
+               if (!ub->unprivileged_daemons)
+                       schedule_work(&ub->partition_scan_work);
+       }
 
 out_put_cdev:
        if (ret) {
index 743d314913875a1b1da37fcc13872202d053c875..a88876756805502493dd5b9fefe5edfe1457842c 100644 (file)
  */
 #define UBLK_F_SAFE_STOP_DEV   (1ULL << 17)
 
+/* Disable automatic partition scanning when device is started */
+#define UBLK_F_NO_AUTO_PART_SCAN (1ULL << 18)
+
 /* device state */
 #define UBLK_S_DEV_DEAD        0
 #define UBLK_S_DEV_LIVE        1