Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag

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>

authored by

Ming Lei and committed by
Jens Axboe
8443e208 66d3af8d

+13 -4
+10 -4
drivers/block/ublk_drv.c
··· 80 80 | UBLK_F_BUF_REG_OFF_DAEMON \ 81 81 | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \ 82 82 | UBLK_F_SAFE_STOP_DEV \ 83 - | UBLK_F_BATCH_IO) 83 + | UBLK_F_BATCH_IO \ 84 + | UBLK_F_NO_AUTO_PART_SCAN) 84 85 85 86 #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \ 86 87 | UBLK_F_USER_RECOVERY_REISSUE \ ··· 4431 4430 4432 4431 set_bit(UB_STATE_USED, &ub->state); 4433 4432 4434 - /* Schedule async partition scan for trusted daemons */ 4435 - if (!ub->unprivileged_daemons) 4436 - schedule_work(&ub->partition_scan_work); 4433 + /* Skip partition scan if disabled by user */ 4434 + if (ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN) { 4435 + clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state); 4436 + } else { 4437 + /* Schedule async partition scan for trusted daemons */ 4438 + if (!ub->unprivileged_daemons) 4439 + schedule_work(&ub->partition_scan_work); 4440 + } 4437 4441 4438 4442 out_put_cdev: 4439 4443 if (ret) {
+3
include/uapi/linux/ublk_cmd.h
··· 367 367 */ 368 368 #define UBLK_F_SAFE_STOP_DEV (1ULL << 17) 369 369 370 + /* Disable automatic partition scanning when device is started */ 371 + #define UBLK_F_NO_AUTO_PART_SCAN (1ULL << 18) 372 + 370 373 /* device state */ 371 374 #define UBLK_S_DEV_DEAD 0 372 375 #define UBLK_S_DEV_LIVE 1