ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag
Subsystems (4)
cover ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag
Hello,
Add UBLK_F_NO_AUTO_PART_SCAN for avoiding to scan partition in start dev command automatically, which is useful for network target.
Also add selftest code to make sure it works as expected.
Ming Lei (2):
ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag
ublk: add selftest for UBLK_F_NO_AUTO_PART_SCAN
drivers/block/ublk_drv.c | 16 ++- include/uapi/linux/ublk_cmd.h | 8 ++ tools/testing/selftests/ublk/Makefile | 1 + tools/testing/selftests/ublk/kublk.c | 6 +- tools/testing/selftests/ublk/kublk.h | 1 + .../testing/selftests/ublk/test_generic_14.sh | 105 ++++++++++++++++++ 6 files changed, 133 insertions(+), 4 deletions(-) create mode 100755 tools/testing/selftests/ublk/test_generic_14.sh
Signature · 1 line
2.47.0
PATCH 1/2 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 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).
---
- 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(-)
drivers/block/ublk_drv.c +13 -3
@@ -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:
include/uapi/linux/ublk_cmd.h +8 -0
@@ -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
Signature · 1 line
2.47.0
Quoted 3 lines · Ming Lei
Add a new feature flag
UBLK_F_NO_AUTO_PART_SCANto 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?
Quoted 10 lines
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 neededUsers can manually trigger partition scanning later when appropriate using standard tools (e.g., partprobe, blockdev --rereadpt).
Quoted 8 lines
Reported-by Yoav Cohen <[email protected]>Link https://lore.kernel.org/linux-block/DM4PR12MB63280C5637917C071C2F0D65A9A8A@DM4PR12MB6328.namprd12.prod.outlook.com/ open hereSigned-off-by Ming Lei <[email protected]>---
- 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.
Quoted 51 lines
drivers/block/ublk_drv.c | 16 +++++++++++++--- include/uapi/linux/ublk_cmd.h | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-)drivers/block/ublk_drv.c +13
-3@@ -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:include/uapi/linux/ublk_cmd.h +0
-0
include/uapi/linux/ublk_cmd.h line 320
Quoted 10 lines
include/uapi/linux/ublk_cmd.h +7
-0@@ -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
Quoted 7 lines
include/uapi/linux/ublk_cmd.h +1
-1+/* device state */ #define UBLK_S_DEV_DEAD 0#define UBLK_S_DEV_LIVE 1 --2.47.0
Quoted 7 lines · Caleb Sander Mateos
Quoted 3 lines · Ming Lei
Add a new feature flag
UBLK_F_NO_AUTO_PART_SCANto 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
Quoted 7 lines · Ming Lei
Quoted 5 lines · Caleb Sander Mateos
Quoted 3 lines · Ming Lei
Add a new feature flag
UBLK_F_NO_AUTO_PART_SCANto allow users to suppress automatic partition scanning when starting a ublk device.
Quoted 6 lines
Quoted 2 lines
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
PATCH 2/2 ublk: add selftest for UBLK_F_NO_AUTO_PART_SCAN
In reply to Ming LeiAdd test_generic_14.sh to test the UBLK_F_NO_AUTO_PART_SCAN feature flag which allows suppressing automatic partition scanning during device startup while still allowing manual partition probing.
The test verifies:
- Normal behavior: partitions are auto-detected without the flag
- With flag: partitions are not auto-detected during START_DEV
- Manual scan: blockdev --rereadpt works with the flag
Also update kublk tool to support --no_auto_part_scan option and recognize the feature flag.
--- tools/testing/selftests/ublk/Makefile | 1 + tools/testing/selftests/ublk/kublk.c | 6 +- tools/testing/selftests/ublk/kublk.h | 1 + .../testing/selftests/ublk/test_generic_14.sh | 105 ++++++++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/ublk/test_generic_14.sh
tools/testing/selftests/ublk/Makefile +1 -0
@@ -21,6 +21,7 @@ TEST_PROGS += test_generic_10.sh TEST_PROGS += test_generic_11.sh TEST_PROGS += test_generic_12.sh TEST_PROGS += test_generic_13.sh +TEST_PROGS += test_generic_14.sh TEST_PROGS += test_null_01.sh TEST_PROGS += test_null_02.sh
tools/testing/selftests/ublk/kublk.c +5 -1
@@ -1415,6 +1415,7 @@ static int cmd_dev_get_features(void)FEAT_NAME (UBLK_F_QUIESCE ),FEAT_NAME (UBLK_F_PER_IO_DAEMON ),FEAT_NAME (UBLK_F_BUF_REG_OFF_DAEMON ), + FEAT_NAME(UBLK_F_NO_AUTO_PART_SCAN), };struct ublk_dev *dev;__u64 features =0 ;
@@ -1509,7 +1510,7 @@ static void __cmd_create_help(char *exe, bool recovery) exe, recovery ? "recover" : "add");printf ("\t[--foreground] [--quiet] [-z] [--auto_zc] [--auto_zc_fallback] [--debug_mask mask] [-r 0|1 ] [-g]\n" );printf ("\t[-e 0|1 ] [-i 0|1] [--no_ublk_fixed_fd]\n" ); -printf ("\t[--nthreads threads] [--per_io_tasks]\n" ); +printf ("\t[--nthreads threads] [--per_io_tasks] [--no_auto_part_scan]\n" );printf ("\t[target options] [backfile1] [backfile2] ...\n" );printf ("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n" );printf ("\tdefault: nthreads=nr_queues" );
@@ -1572,6 +1573,7 @@ int main(int argc, char *argv[]) { "nthreads", 1, NULL, 0 }, { "per_io_tasks", 0, NULL, 0 }, { "no_ublk_fixed_fd", 0, NULL, 0 }, + { "no_auto_part_scan", 0, NULL, 0 }, { 0, 0, 0, 0 } };const struct ublk_tgt_ops *ops =NULL ;
@@ -1653,6 +1655,8 @@ int main(int argc, char *argv[]) ctx.per_io_tasks =1 ;if (!strcmp (longopts[option_idx].name,"no_ublk_fixed_fd" )) ctx.no_ublk_fixed_fd =1 ; +if (!strcmp (longopts[option_idx].name,"no_auto_part_scan" )) + ctx.flags |=UBLK_F_NO_AUTO_PART_SCAN ;break ;case '?' :/*
tools/testing/selftests/ublk/kublk.h +1 -0
@@ -78,6 +78,7 @@ struct dev_ctx { unsigned int auto_zc_fallback:1; unsigned int per_io_tasks:1; unsigned int no_ublk_fixed_fd:1; + unsigned int no_auto_part_scan:1;int _evtfd;int _shmid;
tools/testing/selftests/ublk/test_generic_14.sh new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.47.0