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 network-backed devices where partition scanning can cause issues: - Partition scan triggers synchronous I/O during device startup - If userspace server crashes during scan, recovery is problematic - For remotely-managed devices, partition probing may not be needed
Users 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@D... Cc: stable@vger.kernel.org Signed-off-by: Ming Lei ming.lei@redhat.com ---
- suggest to backport to stable, which is useful for avoiding problematic recovery, also the change is simple enough
drivers/block/ublk_drv.c | 16 +++++++++++++--- include/uapi/linux/ublk_cmd.h | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 78f3e22151b9..ca6ec8ed443f 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -73,7 +73,8 @@ | UBLK_F_AUTO_BUF_REG \ | UBLK_F_QUIESCE \ | UBLK_F_PER_IO_DAEMON \ - | UBLK_F_BUF_REG_OFF_DAEMON) + | UBLK_F_BUF_REG_OFF_DAEMON \ + | UBLK_F_NO_AUTO_PART_SCAN)
#define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \ | UBLK_F_USER_RECOVERY_REISSUE \ @@ -2930,8 +2931,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
ublk_apply_params(ub);
- /* don't probe partitions if any daemon task is un-trusted */ - if (ub->unprivileged_daemons) + /* + * Don't probe partitions if: + * - any daemon task is un-trusted, or + * - user explicitly requested to suppress partition scan + */ + if (ub->unprivileged_daemons || + (ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN)) set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
ublk_get_device(ub); @@ -2947,6 +2953,10 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, if (ret) goto out_put_cdev;
+ /* allow user to probe partitions from userspace */ + if (!ub->unprivileged_daemons && + (ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN)) + clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state); set_bit(UB_STATE_USED, &ub->state);
out_put_cdev: diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index ec77dabba45b..0827db14a215 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -311,6 +311,14 @@ */ #define UBLK_F_BUF_REG_OFF_DAEMON (1ULL << 14)
+/* + * If this feature is set, the kernel will not automatically scan for partitions + * when the device is started. This is useful for network-backed devices where + * partition scanning can cause deadlocks if the userspace server crashes during + * the scan. Users can manually trigger partition scanning later when appropriate. + */ +#define UBLK_F_NO_AUTO_PART_SCAN (1ULL << 15) + /* device state */ #define UBLK_S_DEV_DEAD 0 #define UBLK_S_DEV_LIVE 1
On Sat, Dec 20, 2025 at 4:53 AM Ming Lei ming.lei@redhat.com wrote:
Add a new feature flag UBLK_F_NO_AUTO_PART_SCAN to allow users to suppress automatic partition scanning when starting a ublk device.
Is this approach superseded by your patch series "ublk: scan partition in async way", or are you expecting both to coexist?
This is useful for network-backed devices where partition scanning can cause issues:
- Partition scan triggers synchronous I/O during device startup
- If userspace server crashes during scan, recovery is problematic
- For remotely-managed devices, partition probing may not be needed
Users 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@D... Cc: stable@vger.kernel.org Signed-off-by: Ming Lei ming.lei@redhat.com
- suggest to backport to stable, which is useful for avoiding problematic recovery, also the change is simple enough
Not sure backporting to stable makes sense. It's a new feature that requires the ublk server to opt in, so any existing ublk server being used on a stable kernel won't be able to make use of it.
drivers/block/ublk_drv.c | 16 +++++++++++++--- include/uapi/linux/ublk_cmd.h | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 78f3e22151b9..ca6ec8ed443f 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -73,7 +73,8 @@ | UBLK_F_AUTO_BUF_REG \ | UBLK_F_QUIESCE \ | UBLK_F_PER_IO_DAEMON \
| UBLK_F_BUF_REG_OFF_DAEMON)
| UBLK_F_BUF_REG_OFF_DAEMON \| UBLK_F_NO_AUTO_PART_SCAN)#define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \ | UBLK_F_USER_RECOVERY_REISSUE \ @@ -2930,8 +2931,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
ublk_apply_params(ub);
/* don't probe partitions if any daemon task is un-trusted */if (ub->unprivileged_daemons)
/** Don't probe partitions if:* - any daemon task is un-trusted, or* - user explicitly requested to suppress partition scan*/if (ub->unprivileged_daemons ||(ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN)) set_bit(GD_SUPPRESS_PART_SCAN, &disk->state); ublk_get_device(ub);@@ -2947,6 +2953,10 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, if (ret) goto out_put_cdev;
/* allow user to probe partitions from userspace */if (!ub->unprivileged_daemons &&(ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN))clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state); set_bit(UB_STATE_USED, &ub->state);out_put_cdev: diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index ec77dabba45b..0827db14a215 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -311,6 +311,14 @@ */ #define UBLK_F_BUF_REG_OFF_DAEMON (1ULL << 14)
+/*
- If this feature is set, the kernel will not automatically scan for partitions
- when the device is started. This is useful for network-backed devices where
- partition scanning can cause deadlocks if the userspace server crashes during
- the scan. Users can manually trigger partition scanning later when appropriate.
- */
+#define UBLK_F_NO_AUTO_PART_SCAN (1ULL << 15)
This is the same bit you've used for UBLK_F_BATCH_IO in your other patch series. Are you planning to change that one?
Best, Caleb
/* device state */ #define UBLK_S_DEV_DEAD 0
#define UBLK_S_DEV_LIVE 1
2.47.0
On Mon, Dec 22, 2025 at 12:11:03PM -0500, Caleb Sander Mateos wrote:
On Sat, Dec 20, 2025 at 4:53 AM Ming Lei ming.lei@redhat.com wrote:
Add a new feature flag UBLK_F_NO_AUTO_PART_SCAN to allow users to suppress automatic partition scanning when starting a ublk device.
Is this approach superseded by your patch series "ublk: scan partition in async way", or are you expecting both to coexist?
This one probably is useful too, but it should belong to v6.20 because "ublk: scan partition in async way" can fix the issue now, and backport to stable isn't needed any more.
Thanks, Ming
On Mon, Dec 22, 2025 at 9:32 PM Ming Lei ming.lei@redhat.com wrote:
On Mon, Dec 22, 2025 at 12:11:03PM -0500, Caleb Sander Mateos wrote:
On Sat, Dec 20, 2025 at 4:53 AM Ming Lei ming.lei@redhat.com wrote:
Add a new feature flag UBLK_F_NO_AUTO_PART_SCAN to allow users to suppress automatic partition scanning when starting a ublk device.
Is this approach superseded by your patch series "ublk: scan partition in async way", or are you expecting both to coexist?
This one probably is useful too, but it should belong to v6.20 because "ublk: scan partition in async way" can fix the issue now, and backport to stable isn't needed any more.
Sure, I think it could be useful for other ublk servers too that know the block devices they expose won't be partitioned or want to more finely control when/whether the partition scan happens.
Best, Caleb
linux-stable-mirror@lists.linaro.org