* [PATCH 0/4] ublk: rework partition handling
@ 2026-02-23 12:15 Alexander Atanasov
2026-02-23 12:15 ` [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
` (3 more replies)
0 siblings, 4 replies; 16+ messages in thread
From: Alexander Atanasov @ 2026-02-23 12:15 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov
Rework how partitions are handled for ublk devices.
Disable partitions on unprivileged devices completely -
GD_SUPPRESS_PART_SCAN is used but partitions still can
be created by userspace scan.
Use GENHD_FL_NO_PART to truly disable partitions on device.
For privileged device partitions are optional - disabled
by default.
They can be enabled with UBLK_F_PARTITIONS flag.
Auto partition scan is performed only when explicitly requested
by user.
Update related tests and documentation.
Alexander Atanasov (4):
ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
selftests: ublk: rework partitions tests for new flags
ublk: document partition flags, kublk and update external links
selftests: ublk: cleanup kublk.h
Documentation/block/ublk.rst | 22 ++++++++++--
drivers/block/ublk_drv.c | 34 +++++++++++--------
include/uapi/linux/ublk_cmd.h | 7 ++--
tools/testing/selftests/ublk/kublk.c | 18 ++++++----
tools/testing/selftests/ublk/kublk.h | 1 -
.../selftests/ublk/test_integrity_01.sh | 9 ++---
tools/testing/selftests/ublk/test_part_01.sh | 14 ++++----
tools/testing/selftests/ublk/test_part_02.sh | 6 ++--
8 files changed, 71 insertions(+), 40 deletions(-)
base-commit: 72f4d6fca699a1e35b39c5e5dacac2926d254135
--
2.43.0
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 12:15 [PATCH 0/4] ublk: rework partition handling Alexander Atanasov
@ 2026-02-23 12:15 ` Alexander Atanasov
2026-02-23 12:29 ` Hannes Reinecke
` (2 more replies)
2026-02-23 12:15 ` [PATCH 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
` (2 subsequent siblings)
3 siblings, 3 replies; 16+ messages in thread
From: Alexander Atanasov @ 2026-02-23 12:15 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov
Currently the code misuse GD_SUPPRESS_PART_SCAN flag
as it tries to use it as a switch for the auto partition scan.
To fully disable creation of partitions GENHD_FL_NO_PART must
be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
Using the new flags rules for partitions become:
- Unprivileged daemons - never scan partitions, they have
GENHD_FL_NO_PART always set - they are devices without partitions.
- Trusted daemons - by default have partitions disabled.
Partitions can be enabled via UBLK_F_PARTITIONS flag and
automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
Rework the code to work as described above:
- remove checks in ublk_partition_scan_work and rely on
the caller to schedule the work only if it has to be done.
- set GENHD_FL_NO_PART on unprivileged devices
- set GENHD_FL_NO_PART depending on UBLK_F_PARTITIONS on trusted
devices.
Fixes: 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag")
Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
---
drivers/block/ublk_drv.c | 34 +++++++++++++++++++---------------
include/uapi/linux/ublk_cmd.h | 7 +++++--
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 3c918db4905c..d0c646eb9435 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -81,7 +81,8 @@
| (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
| UBLK_F_SAFE_STOP_DEV \
| UBLK_F_BATCH_IO \
- | UBLK_F_NO_AUTO_PART_SCAN)
+ | UBLK_F_PARTITIONS \
+ | UBLK_F_AUTO_PART_SCAN)
#define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
| UBLK_F_USER_RECOVERY_REISSUE \
@@ -2361,14 +2362,9 @@ static void ublk_partition_scan_work(struct work_struct *work)
if (!disk)
return;
- if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
- &disk->state)))
- goto out;
-
mutex_lock(&disk->open_mutex);
bdev_disk_changed(disk, false);
mutex_unlock(&disk->open_mutex);
-out:
ublk_put_disk(disk);
}
@@ -4409,9 +4405,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
* wait while holding ub->mutex, which can deadlock with other
* operations that need the mutex. Defer partition scan to async
* work.
- * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
- * permanently.
+ * For unprivileged daemons, set GENHD_FL_NO_PART to
+ * disable partitions.
*/
+ if (ub->unprivileged_daemons)
+ disk->flags |= GENHD_FL_NO_PART;
+
+ /* Disable partition scans */
set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
ublk_get_device(ub);
@@ -4429,13 +4429,17 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
set_bit(UB_STATE_USED, &ub->state);
- /* 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);
+ if (!ub->unprivileged_daemons) {
+ if (!(ub->dev_info.flags & UBLK_F_PARTITIONS)) {
+ /* disable partitions on trusted device */
+ disk->flags |= GENHD_FL_NO_PART;
+ } else {
+ /* Enable partition scan on device */
+ clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
+ /* Schedule auto partition scan if requested */
+ if (ub->dev_info.flags & UBLK_F_AUTO_PART_SCAN)
+ schedule_work(&ub->partition_scan_work);
+ }
}
out_put_cdev:
diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
index a88876756805..467ecaa20ac1 100644
--- a/include/uapi/linux/ublk_cmd.h
+++ b/include/uapi/linux/ublk_cmd.h
@@ -367,8 +367,11 @@
*/
#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)
+/* Enable partitions on the device */
+#define UBLK_F_PARTITIONS (1ULL << 18)
+
+/* Perform automatic partition scanning when device is started */
+#define UBLK_F_AUTO_PART_SCAN (1ULL << 19)
/* device state */
#define UBLK_S_DEV_DEAD 0
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 2/4] selftests: ublk: rework partitions tests for new flags
2026-02-23 12:15 [PATCH 0/4] ublk: rework partition handling Alexander Atanasov
2026-02-23 12:15 ` [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
@ 2026-02-23 12:15 ` Alexander Atanasov
2026-02-23 12:29 ` Hannes Reinecke
2026-02-23 12:15 ` [PATCH 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
2026-02-23 12:15 ` [PATCH 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
3 siblings, 1 reply; 16+ messages in thread
From: Alexander Atanasov @ 2026-02-23 12:15 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov
To support reworked flags - UBLK_F_PARTITIONS and UBLK_F_AUTO_PART_SCAN
update kublk.
Remove old argument --no_auto_part_scan
Add arguments:
-p, --with-partitions - enable partitions on trusted devices
-P, --auto_part_scan - enable partitions and perform auto scan
Update test cases to use the new arguments
Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
---
tools/testing/selftests/ublk/kublk.c | 18 ++++++++++++------
.../selftests/ublk/test_integrity_01.sh | 9 +++++----
tools/testing/selftests/ublk/test_part_01.sh | 14 +++++++-------
tools/testing/selftests/ublk/test_part_02.sh | 6 ++++--
4 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
index e8279c4acc40..8a4b7c49f788 100644
--- a/tools/testing/selftests/ublk/kublk.c
+++ b/tools/testing/selftests/ublk/kublk.c
@@ -1615,7 +1615,8 @@ static int cmd_dev_get_features(void)
FEAT_NAME(UBLK_F_INTEGRITY),
FEAT_NAME(UBLK_F_SAFE_STOP_DEV),
FEAT_NAME(UBLK_F_BATCH_IO),
- FEAT_NAME(UBLK_F_NO_AUTO_PART_SCAN),
+ FEAT_NAME(UBLK_F_PARTITIONS),
+ FEAT_NAME(UBLK_F_AUTO_PART_SCAN),
};
struct ublk_dev *dev;
__u64 features = 0;
@@ -1713,7 +1714,7 @@ static void __cmd_create_help(char *exe, bool recovery)
printf("\t[--nthreads threads] [--per_io_tasks]\n");
printf("\t[--integrity_capable] [--integrity_reftag] [--metadata_size SIZE] "
"[--pi_offset OFFSET] [--csum_type ip|t10dif|nvme] [--tag_size SIZE]\n");
- printf("\t[--batch|-b] [--no_auto_part_scan]\n");
+ printf("\t[--batch|-b] [-p,--with_partitions] [-P,--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");
@@ -1783,11 +1784,12 @@ int main(int argc, char *argv[])
{ "integrity_reftag", 0, NULL, 0 },
{ "metadata_size", 1, NULL, 0 },
{ "pi_offset", 1, NULL, 0 },
+ { "with_partitions", 0, NULL, 'p' },
+ { "auto_part_scan", 0, NULL, 'P' },
{ "csum_type", 1, NULL, 0 },
{ "tag_size", 1, NULL, 0 },
{ "safe", 0, NULL, 0 },
{ "batch", 0, NULL, 'b'},
- { "no_auto_part_scan", 0, NULL, 0 },
{ 0, 0, 0, 0 }
};
const struct ublk_tgt_ops *ops = NULL;
@@ -1810,7 +1812,7 @@ int main(int argc, char *argv[])
opterr = 0;
optind = 2;
- while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:s:gazub",
+ while ((opt = getopt_long(argc, argv, "t:n:d:q:r:e:i:s:gazubpP",
longopts, &option_idx)) != -1) {
switch (opt) {
case 'a':
@@ -1856,6 +1858,12 @@ int main(int argc, char *argv[])
case 'u':
ctx.flags |= UBLK_F_USER_COPY;
break;
+ case 'p':
+ ctx.flags |= UBLK_F_PARTITIONS;
+ break;
+ case 'P':
+ ctx.flags |= UBLK_F_PARTITIONS|UBLK_F_AUTO_PART_SCAN;
+ break;
case 's':
ctx.size = strtoull(optarg, NULL, 10);
break;
@@ -1900,8 +1908,6 @@ int main(int argc, char *argv[])
ctx.tag_size = strtoul(optarg, NULL, 0);
if (!strcmp(longopts[option_idx].name, "safe"))
ctx.safe_stop = 1;
- if (!strcmp(longopts[option_idx].name, "no_auto_part_scan"))
- ctx.flags |= UBLK_F_NO_AUTO_PART_SCAN;
break;
case '?':
/*
diff --git a/tools/testing/selftests/ublk/test_integrity_01.sh b/tools/testing/selftests/ublk/test_integrity_01.sh
index 6713b280a6ff..454a846b9a8f 100755
--- a/tools/testing/selftests/ublk/test_integrity_01.sh
+++ b/tools/testing/selftests/ublk/test_integrity_01.sh
@@ -21,7 +21,7 @@ _check_value() {
_test_metadata_only() {
local dev_id
- dev_id=$(_add_ublk_dev -t null -u --no_auto_part_scan --metadata_size 8)
+ dev_id=$(_add_ublk_dev -t null -u --metadata_size 8)
_check_add_dev "$TID" $?
_check_value "metadata_size" "$(_get_metadata_size "$dev_id" metadata_size)" 8 &&
@@ -40,7 +40,8 @@ _test_metadata_only() {
_test_integrity_capable_ip() {
local dev_id
- dev_id=$(_add_ublk_dev -t null -u --no_auto_part_scan --integrity_capable --metadata_size 64 --pi_offset 56 --csum_type ip)
+ dev_id=$(_add_ublk_dev -t null -u --integrity_capable --metadata_size 64 \
+ --pi_offset 56 --csum_type ip)
_check_add_dev "$TID" $?
_check_value "metadata_size" "$(_get_metadata_size "$dev_id" metadata_size)" 64 &&
@@ -59,7 +60,7 @@ _test_integrity_capable_ip() {
_test_integrity_reftag_t10dif() {
local dev_id
- dev_id=$(_add_ublk_dev -t null -u --no_auto_part_scan --integrity_reftag --metadata_size 8 --csum_type t10dif)
+ dev_id=$(_add_ublk_dev -t null -u --integrity_reftag --metadata_size 8 --csum_type t10dif)
_check_add_dev "$TID" $?
_check_value "metadata_size" "$(_get_metadata_size "$dev_id" metadata_size)" 8 &&
@@ -78,7 +79,7 @@ _test_integrity_reftag_t10dif() {
_test_nvme_csum() {
local dev_id
- dev_id=$(_add_ublk_dev -t null -u --no_auto_part_scan --metadata_size 16 --csum_type nvme --tag_size 8)
+ dev_id=$(_add_ublk_dev -t null -u --metadata_size 16 --csum_type nvme --tag_size 8)
_check_add_dev "$TID" $?
_check_value "metadata_size" "$(_get_metadata_size "$dev_id" metadata_size)" 16 &&
diff --git a/tools/testing/selftests/ublk/test_part_01.sh b/tools/testing/selftests/ublk/test_part_01.sh
index 8028f6e4b3a5..b6bd3eb16ac5 100755
--- a/tools/testing/selftests/ublk/test_part_01.sh
+++ b/tools/testing/selftests/ublk/test_part_01.sh
@@ -10,7 +10,7 @@ format_backing_file()
local backing_file=$1
# Create ublk device to write partition table
- local tmp_dev=$(_add_ublk_dev -t loop "${backing_file}")
+ local tmp_dev=$(_add_ublk_dev -t loop "${backing_file}" -p)
[ $? -ne 0 ] && return 1
# Write partition table with sfdisk
@@ -30,8 +30,8 @@ test_auto_part_scan()
{
local backing_file=$1
- # Create device WITHOUT --no_auto_part_scan
- local dev_id=$(_add_ublk_dev -t loop "${backing_file}")
+ # Create device WITH automatic partition scan
+ local dev_id=$(_add_ublk_dev -t loop "${backing_file}" -P)
[ $? -ne 0 ] && return 1
udevadm settle
@@ -50,8 +50,8 @@ test_no_auto_part_scan()
{
local backing_file=$1
- # Create device WITH --no_auto_part_scan
- local dev_id=$(_add_ublk_dev -t loop --no_auto_part_scan "${backing_file}")
+ # Create device WITHOUT automatic partition scan
+ local dev_id=$(_add_ublk_dev -t loop "${backing_file}" -p)
[ $? -ne 0 ] && return 1
udevadm settle
@@ -79,9 +79,9 @@ if ! _have_program sfdisk || ! _have_program blockdev; then
exit "$UBLK_SKIP_CODE"
fi
-_prep_test "generic" "test UBLK_F_NO_AUTO_PART_SCAN"
+_prep_test "generic" "test UBLK_F_PARTITIONS"
-if ! _have_feature "UBLK_F_NO_AUTO_PART_SCAN"; then
+if ! _have_feature "UBLK_F_PARTITIONS"; then
_cleanup_test "generic"
exit "$UBLK_SKIP_CODE"
fi
diff --git a/tools/testing/selftests/ublk/test_part_02.sh b/tools/testing/selftests/ublk/test_part_02.sh
index 7d42ab4d6e83..f0a8637714c1 100755
--- a/tools/testing/selftests/ublk/test_part_02.sh
+++ b/tools/testing/selftests/ublk/test_part_02.sh
@@ -22,10 +22,12 @@ _test_partition_scan_no_hang()
# for partition scan events to complete
if [ "$recovery_flag" = "yes" ]; then
echo "Testing partition scan with recovery support..."
- dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000 -r 1)
+ dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 \
+ --delay_us 60000000 -r 1 -P)
else
echo "Testing partition scan without recovery..."
- dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 --delay_us 60000000)
+ dev_id=$(_add_ublk_dev_no_settle -t fault_inject -q 1 -d 1 \
+ --delay_us 60000000 -P)
fi
_check_add_dev "$TID" $?
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 3/4] ublk: document partition flags, kublk and update external links
2026-02-23 12:15 [PATCH 0/4] ublk: rework partition handling Alexander Atanasov
2026-02-23 12:15 ` [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
2026-02-23 12:15 ` [PATCH 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
@ 2026-02-23 12:15 ` Alexander Atanasov
2026-02-23 12:30 ` Hannes Reinecke
2026-02-23 12:15 ` [PATCH 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
3 siblings, 1 reply; 16+ messages in thread
From: Alexander Atanasov @ 2026-02-23 12:15 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov
Add section about partition handling on ublk devices.
Document UBLK_F_PARTITIONS and UBLK_F_AUTO_PART_SCAN.
Add section for kublk to be used as reference.
Update extenal github links - repos have moved to ublk-org
and README is renamed to README.rst
Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
---
Documentation/block/ublk.rst | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/Documentation/block/ublk.rst b/Documentation/block/ublk.rst
index 6ad28039663d..168b61098d4a 100644
--- a/Documentation/block/ublk.rst
+++ b/Documentation/block/ublk.rst
@@ -88,6 +88,14 @@ Below is example of using ``ublksrv`` to provide ublk-based loop device.
See usage details in README of ``ublksrv`` [#userspace_readme]_.
+Using kublk from ublk test suite
+================================
+
+ublk selftests contain utility(``kublk``) which can be used for reference
+and as a simple server. It is a stripped down version of ublk.
+
+See ``tools/testing/selftests/ublk/kublk.c``
+
Design
======
@@ -238,6 +246,14 @@ be provided in these commands' payload from ublk server. With this way,
ublk device becomes container-ware, and device created in one container
can be controlled/accessed just inside this container.
+Partitions
+----------
+
+By default partitions are disabled on ublk devices.
+
+They can be enabled *only on trusted* devices with ``UBLK_F_PARTITIONS`` flag.
+Automatic partition scan can be requested with ``UBLK_F_AUTO_PART_SCAN`` flag.
+
Data plane
----------
@@ -488,10 +504,10 @@ Limitations
References
==========
-.. [#userspace] https://github.com/ming1/ubdsrv
+.. [#userspace] https://github.com/ublk-org/ublksrv
-.. [#userspace_lib] https://github.com/ming1/ubdsrv/tree/master/lib
+.. [#userspace_lib] https://github.com/ublk-org/ublksrv/tree/master/lib
.. [#userspace_nbdublk] https://gitlab.com/rwmjones/libnbd/-/tree/nbdublk
-.. [#userspace_readme] https://github.com/ming1/ubdsrv/blob/master/README
+.. [#userspace_readme] https://github.com/ublk-org/ublksrv/blob/master/README.rst
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 4/4] selftests: ublk: cleanup kublk.h
2026-02-23 12:15 [PATCH 0/4] ublk: rework partition handling Alexander Atanasov
` (2 preceding siblings ...)
2026-02-23 12:15 ` [PATCH 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
@ 2026-02-23 12:15 ` Alexander Atanasov
2026-02-23 12:30 ` Hannes Reinecke
3 siblings, 1 reply; 16+ messages in thread
From: Alexander Atanasov @ 2026-02-23 12:15 UTC (permalink / raw)
To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov
Arguments are handled via flags so
remove unused no_auto_part_scan bitfield.
Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
---
tools/testing/selftests/ublk/kublk.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/tools/testing/selftests/ublk/kublk.h b/tools/testing/selftests/ublk/kublk.h
index 1faeccaaecae..3379e49449b4 100644
--- a/tools/testing/selftests/ublk/kublk.h
+++ b/tools/testing/selftests/ublk/kublk.h
@@ -79,7 +79,6 @@ struct dev_ctx {
unsigned int per_io_tasks:1;
unsigned int no_ublk_fixed_fd:1;
unsigned int safe_stop:1;
- unsigned int no_auto_part_scan:1;
__u32 integrity_flags;
__u8 metadata_size;
__u8 pi_offset;
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 12:15 ` [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
@ 2026-02-23 12:29 ` Hannes Reinecke
2026-02-23 15:59 ` Caleb Sander Mateos
2026-02-24 9:34 ` Ming Lei
2 siblings, 0 replies; 16+ messages in thread
From: Hannes Reinecke @ 2026-02-23 12:29 UTC (permalink / raw)
To: Alexander Atanasov, Ming Lei, Jens Axboe; +Cc: linux-block
On 2/23/26 13:15, Alexander Atanasov wrote:
> Currently the code misuse GD_SUPPRESS_PART_SCAN flag
> as it tries to use it as a switch for the auto partition scan.
> To fully disable creation of partitions GENHD_FL_NO_PART must
> be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
>
> Using the new flags rules for partitions become:
> - Unprivileged daemons - never scan partitions, they have
> GENHD_FL_NO_PART always set - they are devices without partitions.
>
> - Trusted daemons - by default have partitions disabled.
> Partitions can be enabled via UBLK_F_PARTITIONS flag and
> automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
>
> Rework the code to work as described above:
> - remove checks in ublk_partition_scan_work and rely on
> the caller to schedule the work only if it has to be done.
> - set GENHD_FL_NO_PART on unprivileged devices
> - set GENHD_FL_NO_PART depending on UBLK_F_PARTITIONS on trusted
> devices.
>
> Fixes: 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag")
> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> ---
> drivers/block/ublk_drv.c | 34 +++++++++++++++++++---------------
> include/uapi/linux/ublk_cmd.h | 7 +++++--
> 2 files changed, 24 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3c918db4905c..d0c646eb9435 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -81,7 +81,8 @@
> | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
> | UBLK_F_SAFE_STOP_DEV \
> | UBLK_F_BATCH_IO \
> - | UBLK_F_NO_AUTO_PART_SCAN)
> + | UBLK_F_PARTITIONS \
> + | UBLK_F_AUTO_PART_SCAN)
>
> #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> | UBLK_F_USER_RECOVERY_REISSUE \
> @@ -2361,14 +2362,9 @@ static void ublk_partition_scan_work(struct work_struct *work)
> if (!disk)
> return;
>
> - if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
> - &disk->state)))
> - goto out;
> -
> mutex_lock(&disk->open_mutex);
> bdev_disk_changed(disk, false);
> mutex_unlock(&disk->open_mutex);
> -out:
> ublk_put_disk(disk);
> }
>
> @@ -4409,9 +4405,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
> * wait while holding ub->mutex, which can deadlock with other
> * operations that need the mutex. Defer partition scan to async
> * work.
> - * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
> - * permanently.
> + * For unprivileged daemons, set GENHD_FL_NO_PART to
> + * disable partitions.
> */
> + if (ub->unprivileged_daemons)
> + disk->flags |= GENHD_FL_NO_PART;
> +
> + /* Disable partition scans */
> set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
>
> ublk_get_device(ub);
> @@ -4429,13 +4429,17 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
>
> set_bit(UB_STATE_USED, &ub->state);
>
> - /* 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);
> + if (!ub->unprivileged_daemons) {
> + if (!(ub->dev_info.flags & UBLK_F_PARTITIONS)) {
> + /* disable partitions on trusted device */
> + disk->flags |= GENHD_FL_NO_PART;
> + } else {
> + /* Enable partition scan on device */
> + clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> + /* Schedule auto partition scan if requested */
> + if (ub->dev_info.flags & UBLK_F_AUTO_PART_SCAN)
> + schedule_work(&ub->partition_scan_work);
> + }
> }
>
> out_put_cdev:
Why is this done in two different locations?
Wouldn't it be better to keep them both together to make the code
more readable?
> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
> index a88876756805..467ecaa20ac1 100644
> --- a/include/uapi/linux/ublk_cmd.h
> +++ b/include/uapi/linux/ublk_cmd.h
> @@ -367,8 +367,11 @@
> */
> #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)
> +/* Enable partitions on the device */
> +#define UBLK_F_PARTITIONS (1ULL << 18)
> +
> +/* Perform automatic partition scanning when device is started */
> +#define UBLK_F_AUTO_PART_SCAN (1ULL << 19)
>
> /* device state */
> #define UBLK_S_DEV_DEAD 0
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/4] selftests: ublk: rework partitions tests for new flags
2026-02-23 12:15 ` [PATCH 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
@ 2026-02-23 12:29 ` Hannes Reinecke
0 siblings, 0 replies; 16+ messages in thread
From: Hannes Reinecke @ 2026-02-23 12:29 UTC (permalink / raw)
To: Alexander Atanasov, Ming Lei, Jens Axboe; +Cc: linux-block
On 2/23/26 13:15, Alexander Atanasov wrote:
> To support reworked flags - UBLK_F_PARTITIONS and UBLK_F_AUTO_PART_SCAN
> update kublk.
> Remove old argument --no_auto_part_scan
> Add arguments:
> -p, --with-partitions - enable partitions on trusted devices
> -P, --auto_part_scan - enable partitions and perform auto scan
>
> Update test cases to use the new arguments
>
> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> ---
> tools/testing/selftests/ublk/kublk.c | 18 ++++++++++++------
> .../selftests/ublk/test_integrity_01.sh | 9 +++++----
> tools/testing/selftests/ublk/test_part_01.sh | 14 +++++++-------
> tools/testing/selftests/ublk/test_part_02.sh | 6 ++++--
> 4 files changed, 28 insertions(+), 19 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/4] ublk: document partition flags, kublk and update external links
2026-02-23 12:15 ` [PATCH 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
@ 2026-02-23 12:30 ` Hannes Reinecke
0 siblings, 0 replies; 16+ messages in thread
From: Hannes Reinecke @ 2026-02-23 12:30 UTC (permalink / raw)
To: Alexander Atanasov, Ming Lei, Jens Axboe; +Cc: linux-block
On 2/23/26 13:15, Alexander Atanasov wrote:
> Add section about partition handling on ublk devices.
> Document UBLK_F_PARTITIONS and UBLK_F_AUTO_PART_SCAN.
>
> Add section for kublk to be used as reference.
>
> Update extenal github links - repos have moved to ublk-org
> and README is renamed to README.rst
>
> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> ---
> Documentation/block/ublk.rst | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 4/4] selftests: ublk: cleanup kublk.h
2026-02-23 12:15 ` [PATCH 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
@ 2026-02-23 12:30 ` Hannes Reinecke
0 siblings, 0 replies; 16+ messages in thread
From: Hannes Reinecke @ 2026-02-23 12:30 UTC (permalink / raw)
To: Alexander Atanasov, Ming Lei, Jens Axboe; +Cc: linux-block
On 2/23/26 13:15, Alexander Atanasov wrote:
> Arguments are handled via flags so
> remove unused no_auto_part_scan bitfield.
>
> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> ---
> tools/testing/selftests/ublk/kublk.h | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/tools/testing/selftests/ublk/kublk.h b/tools/testing/selftests/ublk/kublk.h
> index 1faeccaaecae..3379e49449b4 100644
> --- a/tools/testing/selftests/ublk/kublk.h
> +++ b/tools/testing/selftests/ublk/kublk.h
> @@ -79,7 +79,6 @@ struct dev_ctx {
> unsigned int per_io_tasks:1;
> unsigned int no_ublk_fixed_fd:1;
> unsigned int safe_stop:1;
> - unsigned int no_auto_part_scan:1;
> __u32 integrity_flags;
> __u8 metadata_size;
> __u8 pi_offset;
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 12:15 ` [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
2026-02-23 12:29 ` Hannes Reinecke
@ 2026-02-23 15:59 ` Caleb Sander Mateos
2026-02-23 16:23 ` Alexander Atanasov
2026-02-24 9:31 ` Ming Lei
2026-02-24 9:34 ` Ming Lei
2 siblings, 2 replies; 16+ messages in thread
From: Caleb Sander Mateos @ 2026-02-23 15:59 UTC (permalink / raw)
To: Alexander Atanasov; +Cc: Ming Lei, Jens Axboe, linux-block
On Mon, Feb 23, 2026 at 4:17 AM Alexander Atanasov <alex@zazolabs.com> wrote:
>
> Currently the code misuse GD_SUPPRESS_PART_SCAN flag
> as it tries to use it as a switch for the auto partition scan.
> To fully disable creation of partitions GENHD_FL_NO_PART must
> be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
>
> Using the new flags rules for partitions become:
> - Unprivileged daemons - never scan partitions, they have
> GENHD_FL_NO_PART always set - they are devices without partitions.
>
> - Trusted daemons - by default have partitions disabled.
> Partitions can be enabled via UBLK_F_PARTITIONS flag and
> automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
>
> Rework the code to work as described above:
> - remove checks in ublk_partition_scan_work and rely on
> the caller to schedule the work only if it has to be done.
> - set GENHD_FL_NO_PART on unprivileged devices
> - set GENHD_FL_NO_PART depending on UBLK_F_PARTITIONS on trusted
> devices.
>
> Fixes: 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag")
> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> ---
> drivers/block/ublk_drv.c | 34 +++++++++++++++++++---------------
> include/uapi/linux/ublk_cmd.h | 7 +++++--
> 2 files changed, 24 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3c918db4905c..d0c646eb9435 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -81,7 +81,8 @@
> | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
> | UBLK_F_SAFE_STOP_DEV \
> | UBLK_F_BATCH_IO \
> - | UBLK_F_NO_AUTO_PART_SCAN)
> + | UBLK_F_PARTITIONS \
> + | UBLK_F_AUTO_PART_SCAN)
>
> #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> | UBLK_F_USER_RECOVERY_REISSUE \
> @@ -2361,14 +2362,9 @@ static void ublk_partition_scan_work(struct work_struct *work)
> if (!disk)
> return;
>
> - if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
> - &disk->state)))
> - goto out;
> -
> mutex_lock(&disk->open_mutex);
> bdev_disk_changed(disk, false);
> mutex_unlock(&disk->open_mutex);
> -out:
> ublk_put_disk(disk);
> }
>
> @@ -4409,9 +4405,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
> * wait while holding ub->mutex, which can deadlock with other
> * operations that need the mutex. Defer partition scan to async
> * work.
> - * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
> - * permanently.
> + * For unprivileged daemons, set GENHD_FL_NO_PART to
> + * disable partitions.
> */
> + if (ub->unprivileged_daemons)
> + disk->flags |= GENHD_FL_NO_PART;
> +
> + /* Disable partition scans */
> set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
>
> ublk_get_device(ub);
> @@ -4429,13 +4429,17 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
>
> set_bit(UB_STATE_USED, &ub->state);
>
> - /* 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);
> + if (!ub->unprivileged_daemons) {
> + if (!(ub->dev_info.flags & UBLK_F_PARTITIONS)) {
> + /* disable partitions on trusted device */
> + disk->flags |= GENHD_FL_NO_PART;
> + } else {
> + /* Enable partition scan on device */
> + clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> + /* Schedule auto partition scan if requested */
> + if (ub->dev_info.flags & UBLK_F_AUTO_PART_SCAN)
> + schedule_work(&ub->partition_scan_work);
> + }
> }
>
> out_put_cdev:
> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
> index a88876756805..467ecaa20ac1 100644
> --- a/include/uapi/linux/ublk_cmd.h
> +++ b/include/uapi/linux/ublk_cmd.h
> @@ -367,8 +367,11 @@
> */
> #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)
> +/* Enable partitions on the device */
> +#define UBLK_F_PARTITIONS (1ULL << 18)
This is not backwards compatible. Existing ublk servers expect their
devices to support partitioning. If you want to introduce a feature
flag to control this, it needs to be opt-out rather than opt-in.
UBLK_F_AUTO_PART_SCAN probably also needs to remain as
UBLK_F_NO_AUTO_PART_SCAN.
Best,
Caleb
> +
> +/* Perform automatic partition scanning when device is started */
> +#define UBLK_F_AUTO_PART_SCAN (1ULL << 19)
>
> /* device state */
> #define UBLK_S_DEV_DEAD 0
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 15:59 ` Caleb Sander Mateos
@ 2026-02-23 16:23 ` Alexander Atanasov
2026-02-23 16:42 ` Caleb Sander Mateos
2026-02-24 9:31 ` Ming Lei
1 sibling, 1 reply; 16+ messages in thread
From: Alexander Atanasov @ 2026-02-23 16:23 UTC (permalink / raw)
To: Caleb Sander Mateos; +Cc: Ming Lei, Jens Axboe, linux-block
> On 23 Feb 2026, at 17:59, Caleb Sander Mateos <csander@purestorage.com> wrote:
>
> On Mon, Feb 23, 2026 at 4:17 AM Alexander Atanasov <alex@zazolabs.com> wrote:
>>
>> Currently the code misuse GD_SUPPRESS_PART_SCAN flag
>> as it tries to use it as a switch for the auto partition scan.
>> To fully disable creation of partitions GENHD_FL_NO_PART must
>> be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
>>
>> Using the new flags rules for partitions become:
>> - Unprivileged daemons - never scan partitions, they have
>> GENHD_FL_NO_PART always set - they are devices without partitions.
>>
>> - Trusted daemons - by default have partitions disabled.
>> Partitions can be enabled via UBLK_F_PARTITIONS flag and
>> automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
>>
[snip]
>> Rework the code to work as described above:
>> - remove checks in ublk_partition_scan_work and rely on
>> the caller to schedule the work only if it has to be done.
>> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
>> index a88876756805..467ecaa20ac1 100644
>> --- a/include/uapi/linux/ublk_cmd.h
>> +++ b/include/uapi/linux/ublk_cmd.h
>> @@ -367,8 +367,11 @@
>> */
>> #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)
>> +/* Enable partitions on the device */
>> +#define UBLK_F_PARTITIONS (1ULL << 18)
>
> This is not backwards compatible. Existing ublk servers expect their
> devices to support partitioning. If you want to introduce a feature
> flag to control this, it needs to be opt-out rather than opt-in.
> UBLK_F_AUTO_PART_SCAN probably also needs to remain as
> UBLK_F_NO_AUTO_PART_SCAN.
It is easy to turn both to opt-out - it will just get double negatives here and there,
which I tried to avoid. I got the impression that the API can be changed in current stage
and people in general do not want to have partitions at all, so not having them by default
is better. But looks like I am wrong here.
UBLK_F_NO_AUTO_PART_SCAN(old) -> UBLK_F_NO_PARTITIONS on by default
UBLK_F_NO_AUTO_PART_SCAN(new) -> disable auto scan on by default
Also for backward compatibility moving to GENHD_FL_NO_PART can also break
users who did a user space partition scan. But I have no idea what to do here (yet),
especially with regard to unprivileged devices.
>
> Best,
> Caleb
>
>> +
>> +/* Perform automatic partition scanning when device is started */
>> +#define UBLK_F_AUTO_PART_SCAN (1ULL << 19)
>>
>> /* device state */
>> #define UBLK_S_DEV_DEAD 0
>> --
>> 2.43.0
Regards,
Alexander Atanasov
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 16:23 ` Alexander Atanasov
@ 2026-02-23 16:42 ` Caleb Sander Mateos
2026-02-23 17:19 ` Alexander Atanasov
0 siblings, 1 reply; 16+ messages in thread
From: Caleb Sander Mateos @ 2026-02-23 16:42 UTC (permalink / raw)
To: Alexander Atanasov; +Cc: Ming Lei, Jens Axboe, linux-block
On Mon, Feb 23, 2026 at 8:23 AM Alexander Atanasov <alex@zazolabs.com> wrote:
>
>
>
> > On 23 Feb 2026, at 17:59, Caleb Sander Mateos <csander@purestorage.com> wrote:
> >
> > On Mon, Feb 23, 2026 at 4:17 AM Alexander Atanasov <alex@zazolabs.com> wrote:
> >>
> >> Currently the code misuse GD_SUPPRESS_PART_SCAN flag
> >> as it tries to use it as a switch for the auto partition scan.
> >> To fully disable creation of partitions GENHD_FL_NO_PART must
> >> be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
> >>
> >> Using the new flags rules for partitions become:
> >> - Unprivileged daemons - never scan partitions, they have
> >> GENHD_FL_NO_PART always set - they are devices without partitions.
> >>
> >> - Trusted daemons - by default have partitions disabled.
> >> Partitions can be enabled via UBLK_F_PARTITIONS flag and
> >> automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
> >>
>
> [snip]
>
> >> Rework the code to work as described above:
> >> - remove checks in ublk_partition_scan_work and rely on
> >> the caller to schedule the work only if it has to be done.
> >> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
> >> index a88876756805..467ecaa20ac1 100644
> >> --- a/include/uapi/linux/ublk_cmd.h
> >> +++ b/include/uapi/linux/ublk_cmd.h
> >> @@ -367,8 +367,11 @@
> >> */
> >> #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)
> >> +/* Enable partitions on the device */
> >> +#define UBLK_F_PARTITIONS (1ULL << 18)
> >
> > This is not backwards compatible. Existing ublk servers expect their
> > devices to support partitioning. If you want to introduce a feature
> > flag to control this, it needs to be opt-out rather than opt-in.
> > UBLK_F_AUTO_PART_SCAN probably also needs to remain as
> > UBLK_F_NO_AUTO_PART_SCAN.
>
> It is easy to turn both to opt-out - it will just get double negatives here and there,
> which I tried to avoid. I got the impression that the API can be changed in current stage
> and people in general do not want to have partitions at all, so not having them by default
> is better. But looks like I am wrong here.
I agree it's probably more typical to use ublk devices without
partitions. If we were designing the ublk UAPI from scratch, it might
make sense to require a feature flag to opt in to partitioning. But
ublk has been around since kernel 6.0 and has always implicitly
allowed ublk devices to be partitioned. So we can't change that now
without breaking existing ublk servers. UBLK_F_NO_AUTO_PART_SCAN, on
the other hand, was just merged in the 7.0 merge window, so there
likely aren't many ublk servers using it yet. It's reasonable to
change its behavior before 7.0 is released.
>
> UBLK_F_NO_AUTO_PART_SCAN(old) -> UBLK_F_NO_PARTITIONS on by default
> UBLK_F_NO_AUTO_PART_SCAN(new) -> disable auto scan on by default
>
> Also for backward compatibility moving to GENHD_FL_NO_PART can also break
> users who did a user space partition scan. But I have no idea what to do here (yet),
> especially with regard to unprivileged devices.
I'm not familiar enough with how partition scanning works, but if a
userspace-initiated partition scan can block any kernel threads, I
think it would be reasonable to prevent it for ublk devices with
unprivileged daemons. I agree it's a behavior change, but it could be
considered a bug fix.
Best,
Caleb
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 16:42 ` Caleb Sander Mateos
@ 2026-02-23 17:19 ` Alexander Atanasov
0 siblings, 0 replies; 16+ messages in thread
From: Alexander Atanasov @ 2026-02-23 17:19 UTC (permalink / raw)
To: Caleb Sander Mateos; +Cc: Ming Lei, Jens Axboe, linux-block
> On 23 Feb 2026, at 18:42, Caleb Sander Mateos <csander@purestorage.com> wrote:
>
> On Mon, Feb 23, 2026 at 8:23 AM Alexander Atanasov <alex@zazolabs.com> wrote:
>>
>>
>>
>>> On 23 Feb 2026, at 17:59, Caleb Sander Mateos <csander@purestorage.com> wrote:
>>>
>>> On Mon, Feb 23, 2026 at 4:17 AM Alexander Atanasov <alex@zazolabs.com> wrote:
>>>>
>>>> Currently the code misuse GD_SUPPRESS_PART_SCAN flag
>>>> as it tries to use it as a switch for the auto partition scan.
>>>> To fully disable creation of partitions GENHD_FL_NO_PART must
>>>> be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
>>>>
>>>> Using the new flags rules for partitions become:
>>>> - Unprivileged daemons - never scan partitions, they have
>>>> GENHD_FL_NO_PART always set - they are devices without partitions.
>>>>
>>>> - Trusted daemons - by default have partitions disabled.
>>>> Partitions can be enabled via UBLK_F_PARTITIONS flag and
>>>> automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
>>>>
>>
>> [snip]
>>
>>>> Rework the code to work as described above:
>>>> - remove checks in ublk_partition_scan_work and rely on
>>>> the caller to schedule the work only if it has to be done.
>>>> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
>>>> index a88876756805..467ecaa20ac1 100644
>>>> --- a/include/uapi/linux/ublk_cmd.h
>>>> +++ b/include/uapi/linux/ublk_cmd.h
>>>> @@ -367,8 +367,11 @@
>>>> */
>>>> #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)
>>>> +/* Enable partitions on the device */
>>>> +#define UBLK_F_PARTITIONS (1ULL << 18)
>>>
>>> This is not backwards compatible. Existing ublk servers expect their
>>> devices to support partitioning. If you want to introduce a feature
>>> flag to control this, it needs to be opt-out rather than opt-in.
>>> UBLK_F_AUTO_PART_SCAN probably also needs to remain as
>>> UBLK_F_NO_AUTO_PART_SCAN.
>>
>> It is easy to turn both to opt-out - it will just get double negatives here and there,
>> which I tried to avoid. I got the impression that the API can be changed in current stage
>> and people in general do not want to have partitions at all, so not having them by default
>> is better. But looks like I am wrong here.
>
> I agree it's probably more typical to use ublk devices without
> partitions. If we were designing the ublk UAPI from scratch, it might
> make sense to require a feature flag to opt in to partitioning. But
> ublk has been around since kernel 6.0 and has always implicitly
> allowed ublk devices to be partitioned. So we can't change that now
> without breaking existing ublk servers. UBLK_F_NO_AUTO_PART_SCAN, on
> the other hand, was just merged in the 7.0 merge window, so there
> likely aren't many ublk servers using it yet. It's reasonable to
> change its behavior before 7.0 is released.
Well, may be we can spend on flags bit and just keep
UBLK_F_NO_AUTO_PART_SCAN (1ULL << 18)
as it is for backward compatibility and mark it as deprecated.
and add the two opt-in flags for new users.
>
>>
>> UBLK_F_NO_AUTO_PART_SCAN(old) -> UBLK_F_NO_PARTITIONS on by default
>> UBLK_F_NO_AUTO_PART_SCAN(new) -> disable auto scan on by default
>>
>> Also for backward compatibility moving to GENHD_FL_NO_PART can also break
>> users who did a user space partition scan. But I have no idea what to do here (yet),
>> especially with regard to unprivileged devices.
>
> I'm not familiar enough with how partition scanning works, but if a
> userspace-initiated partition scan can block any kernel threads, I
> think it would be reasonable to prevent it for ublk devices with
> unprivileged daemons. I agree it's a behavior change, but it could be
> considered a bug fix.
GD_SUPPRESS_PART_SCAN is protection against bugs in kernel partition
scanning code, i.e. it can be feed with bad data and cause a crash.
But it does not prevent using BLKPG* family ioctls to manage partitions,
partscan uses them for example.
The intent was to disable partitions on untrusted devices as they
might be used in containers and potentially with untrusted data.
But the right flag to do so is GENHD_FL_NO_PART, which disables partitions completely.
Yes it is both a bug fix and a behavior change. But since the original
intent is to not have partitions I think it is okay to count it as a bug fix only.
Regards,
Alexander Atanasov
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 15:59 ` Caleb Sander Mateos
2026-02-23 16:23 ` Alexander Atanasov
@ 2026-02-24 9:31 ` Ming Lei
1 sibling, 0 replies; 16+ messages in thread
From: Ming Lei @ 2026-02-24 9:31 UTC (permalink / raw)
To: Caleb Sander Mateos; +Cc: Alexander Atanasov, Jens Axboe, linux-block
On Mon, Feb 23, 2026 at 07:59:54AM -0800, Caleb Sander Mateos wrote:
> On Mon, Feb 23, 2026 at 4:17 AM Alexander Atanasov <alex@zazolabs.com> wrote:
> >
> > Currently the code misuse GD_SUPPRESS_PART_SCAN flag
> > as it tries to use it as a switch for the auto partition scan.
> > To fully disable creation of partitions GENHD_FL_NO_PART must
> > be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
> >
> > Using the new flags rules for partitions become:
> > - Unprivileged daemons - never scan partitions, they have
> > GENHD_FL_NO_PART always set - they are devices without partitions.
> >
> > - Trusted daemons - by default have partitions disabled.
> > Partitions can be enabled via UBLK_F_PARTITIONS flag and
> > automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
> >
> > Rework the code to work as described above:
> > - remove checks in ublk_partition_scan_work and rely on
> > the caller to schedule the work only if it has to be done.
> > - set GENHD_FL_NO_PART on unprivileged devices
> > - set GENHD_FL_NO_PART depending on UBLK_F_PARTITIONS on trusted
> > devices.
> >
> > Fixes: 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag")
> > Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> > ---
> > drivers/block/ublk_drv.c | 34 +++++++++++++++++++---------------
> > include/uapi/linux/ublk_cmd.h | 7 +++++--
> > 2 files changed, 24 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 3c918db4905c..d0c646eb9435 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -81,7 +81,8 @@
> > | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
> > | UBLK_F_SAFE_STOP_DEV \
> > | UBLK_F_BATCH_IO \
> > - | UBLK_F_NO_AUTO_PART_SCAN)
> > + | UBLK_F_PARTITIONS \
> > + | UBLK_F_AUTO_PART_SCAN)
> >
> > #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> > | UBLK_F_USER_RECOVERY_REISSUE \
> > @@ -2361,14 +2362,9 @@ static void ublk_partition_scan_work(struct work_struct *work)
> > if (!disk)
> > return;
> >
> > - if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
> > - &disk->state)))
> > - goto out;
> > -
> > mutex_lock(&disk->open_mutex);
> > bdev_disk_changed(disk, false);
> > mutex_unlock(&disk->open_mutex);
> > -out:
> > ublk_put_disk(disk);
> > }
> >
> > @@ -4409,9 +4405,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
> > * wait while holding ub->mutex, which can deadlock with other
> > * operations that need the mutex. Defer partition scan to async
> > * work.
> > - * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
> > - * permanently.
> > + * For unprivileged daemons, set GENHD_FL_NO_PART to
> > + * disable partitions.
> > */
> > + if (ub->unprivileged_daemons)
> > + disk->flags |= GENHD_FL_NO_PART;
> > +
> > + /* Disable partition scans */
> > set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> >
> > ublk_get_device(ub);
> > @@ -4429,13 +4429,17 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
> >
> > set_bit(UB_STATE_USED, &ub->state);
> >
> > - /* 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);
> > + if (!ub->unprivileged_daemons) {
> > + if (!(ub->dev_info.flags & UBLK_F_PARTITIONS)) {
> > + /* disable partitions on trusted device */
> > + disk->flags |= GENHD_FL_NO_PART;
> > + } else {
> > + /* Enable partition scan on device */
> > + clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> > + /* Schedule auto partition scan if requested */
> > + if (ub->dev_info.flags & UBLK_F_AUTO_PART_SCAN)
> > + schedule_work(&ub->partition_scan_work);
> > + }
> > }
> >
> > out_put_cdev:
> > diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
> > index a88876756805..467ecaa20ac1 100644
> > --- a/include/uapi/linux/ublk_cmd.h
> > +++ b/include/uapi/linux/ublk_cmd.h
> > @@ -367,8 +367,11 @@
> > */
> > #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)
> > +/* Enable partitions on the device */
> > +#define UBLK_F_PARTITIONS (1ULL << 18)
>
> This is not backwards compatible. Existing ublk servers expect their
> devices to support partitioning. If you want to introduce a feature
> flag to control this, it needs to be opt-out rather than opt-in.
> UBLK_F_AUTO_PART_SCAN probably also needs to remain as
> UBLK_F_NO_AUTO_PART_SCAN.
UBLK_F_AUTO_PART_SCAN is just merged in 7.0-rc, which isn't released yet,
so it is fine to change it before 7.0 formal release, IMO.
Thanks,
Ming
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
2026-02-23 12:15 ` [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
2026-02-23 12:29 ` Hannes Reinecke
2026-02-23 15:59 ` Caleb Sander Mateos
@ 2026-02-24 9:34 ` Ming Lei
[not found] ` <182C75BB-3CBC-4627-9F15-AE8FE675260C@zazolabs.com>
2 siblings, 1 reply; 16+ messages in thread
From: Ming Lei @ 2026-02-24 9:34 UTC (permalink / raw)
To: Alexander Atanasov; +Cc: Jens Axboe, linux-block
On Mon, Feb 23, 2026 at 12:15:11PM +0000, Alexander Atanasov wrote:
> Currently the code misuse GD_SUPPRESS_PART_SCAN flag
> as it tries to use it as a switch for the auto partition scan.
> To fully disable creation of partitions GENHD_FL_NO_PART must
> be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
>
> Using the new flags rules for partitions become:
> - Unprivileged daemons - never scan partitions, they have
> GENHD_FL_NO_PART always set - they are devices without partitions.
>
> - Trusted daemons - by default have partitions disabled.
> Partitions can be enabled via UBLK_F_PARTITIONS flag and
> automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
>
> Rework the code to work as described above:
> - remove checks in ublk_partition_scan_work and rely on
> the caller to schedule the work only if it has to be done.
> - set GENHD_FL_NO_PART on unprivileged devices
> - set GENHD_FL_NO_PART depending on UBLK_F_PARTITIONS on trusted
> devices.
>
> Fixes: 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag")
> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> ---
> drivers/block/ublk_drv.c | 34 +++++++++++++++++++---------------
> include/uapi/linux/ublk_cmd.h | 7 +++++--
> 2 files changed, 24 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3c918db4905c..d0c646eb9435 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -81,7 +81,8 @@
> | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
> | UBLK_F_SAFE_STOP_DEV \
> | UBLK_F_BATCH_IO \
> - | UBLK_F_NO_AUTO_PART_SCAN)
> + | UBLK_F_PARTITIONS \
> + | UBLK_F_AUTO_PART_SCAN)
>
> #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> | UBLK_F_USER_RECOVERY_REISSUE \
> @@ -2361,14 +2362,9 @@ static void ublk_partition_scan_work(struct work_struct *work)
> if (!disk)
> return;
>
> - if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
> - &disk->state)))
> - goto out;
> -
> mutex_lock(&disk->open_mutex);
> bdev_disk_changed(disk, false);
> mutex_unlock(&disk->open_mutex);
> -out:
> ublk_put_disk(disk);
> }
>
> @@ -4409,9 +4405,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
> * wait while holding ub->mutex, which can deadlock with other
> * operations that need the mutex. Defer partition scan to async
> * work.
> - * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
> - * permanently.
> + * For unprivileged daemons, set GENHD_FL_NO_PART to
> + * disable partitions.
> */
> + if (ub->unprivileged_daemons)
> + disk->flags |= GENHD_FL_NO_PART;
The above code block can cover UBLK_F_PARTITIONS too.
> +
> + /* Disable partition scans */
> set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
>
> ublk_get_device(ub);
> @@ -4429,13 +4429,17 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
>
> set_bit(UB_STATE_USED, &ub->state);
>
> - /* 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);
> + if (!ub->unprivileged_daemons) {
> + if (!(ub->dev_info.flags & UBLK_F_PARTITIONS)) {
> + /* disable partitions on trusted device */
> + disk->flags |= GENHD_FL_NO_PART;
> + } else {
> + /* Enable partition scan on device */
> + clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> + /* Schedule auto partition scan if requested */
> + if (ub->dev_info.flags & UBLK_F_AUTO_PART_SCAN)
> + schedule_work(&ub->partition_scan_work);
> + }
> }
>
> out_put_cdev:
> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
> index a88876756805..467ecaa20ac1 100644
> --- a/include/uapi/linux/ublk_cmd.h
> +++ b/include/uapi/linux/ublk_cmd.h
> @@ -367,8 +367,11 @@
> */
> #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)
> +/* Enable partitions on the device */
> +#define UBLK_F_PARTITIONS (1ULL << 18)
> +
> +/* Perform automatic partition scanning when device is started */
> +#define UBLK_F_AUTO_PART_SCAN (1ULL << 19)
I think it isn't necessary to add UBLK_F_AUTO_PART_SCAN, and the default
behavior is to scan partitions automatically just like other block device.
Thanks,
Ming
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
[not found] ` <182C75BB-3CBC-4627-9F15-AE8FE675260C@zazolabs.com>
@ 2026-02-24 11:04 ` Ming Lei
0 siblings, 0 replies; 16+ messages in thread
From: Ming Lei @ 2026-02-24 11:04 UTC (permalink / raw)
To: Alexander Atanasov; +Cc: Jens Axboe, linux-block
On Tue, Feb 24, 2026 at 12:54:49PM +0200, Alexander Atanasov wrote:
>
>
> > On 24 Feb 2026, at 11:34, Ming Lei <ming.lei@redhat.com> wrote:
> >
> > On Mon, Feb 23, 2026 at 12:15:11PM +0000, Alexander Atanasov wrote:
> >> Currently the code misuse GD_SUPPRESS_PART_SCAN flag
> >> as it tries to use it as a switch for the auto partition scan.
> >> To fully disable creation of partitions GENHD_FL_NO_PART must
> >> be used, switch code to use it instead GD_SUPPRESS_PART_SCAN.
> >>
> >> Using the new flags rules for partitions become:
> >> - Unprivileged daemons - never scan partitions, they have
> >> GENHD_FL_NO_PART always set - they are devices without partitions.
> >>
> >> - Trusted daemons - by default have partitions disabled.
> >> Partitions can be enabled via UBLK_F_PARTITIONS flag and
> >> automatic initial scan can be requested via UBLK_F_AUTO_PART_SCAN flag.
> >>
> >> Rework the code to work as described above:
> >> - remove checks in ublk_partition_scan_work and rely on
> >> the caller to schedule the work only if it has to be done.
> >> - set GENHD_FL_NO_PART on unprivileged devices
> >> - set GENHD_FL_NO_PART depending on UBLK_F_PARTITIONS on trusted
> >> devices.
> >>
> >> Fixes: 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag")
> >> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> >> ---
> >> drivers/block/ublk_drv.c | 34 +++++++++++++++++++---------------
> >> include/uapi/linux/ublk_cmd.h | 7 +++++--
> >> 2 files changed, 24 insertions(+), 17 deletions(-)
> >>
> >> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> >> index 3c918db4905c..d0c646eb9435 100644
> >> --- a/drivers/block/ublk_drv.c
> >> +++ b/drivers/block/ublk_drv.c
> >> @@ -81,7 +81,8 @@
> >> | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
> >> | UBLK_F_SAFE_STOP_DEV \
> >> | UBLK_F_BATCH_IO \
> >> - | UBLK_F_NO_AUTO_PART_SCAN)
> >> + | UBLK_F_PARTITIONS \
> >> + | UBLK_F_AUTO_PART_SCAN)
> >>
> >> #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> >> | UBLK_F_USER_RECOVERY_REISSUE \
> >> @@ -2361,14 +2362,9 @@ static void ublk_partition_scan_work(struct work_struct *work)
> >> if (!disk)
> >> return;
> >>
> >> - if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
> >> - &disk->state)))
> >> - goto out;
> >> -
> >> mutex_lock(&disk->open_mutex);
> >> bdev_disk_changed(disk, false);
> >> mutex_unlock(&disk->open_mutex);
> >> -out:
> >> ublk_put_disk(disk);
> >> }
> >>
> >> @@ -4409,9 +4405,13 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
> >> * wait while holding ub->mutex, which can deadlock with other
> >> * operations that need the mutex. Defer partition scan to async
> >> * work.
> >> - * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
> >> - * permanently.
> >> + * For unprivileged daemons, set GENHD_FL_NO_PART to
> >> + * disable partitions.
> >> */
> >> + if (ub->unprivileged_daemons)
> >> + disk->flags |= GENHD_FL_NO_PART;
> >
> > The above code block can cover UBLK_F_PARTITIONS too.
>
> Yes, as Hannes noted. I will merge flag update fragments in one place where possible.
> Only clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state); needs to be after add_disk(disk);
> which will trigger partition scan that we want to do manually when ready.
>
>
> >> +
> >> + /* Disable partition scans */
> >> set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> >>
> >> ublk_get_device(ub);
> >> @@ -4429,13 +4429,17 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
> >>
> >> set_bit(UB_STATE_USED, &ub->state);
> >>
> >> - /* 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);
> >> + if (!ub->unprivileged_daemons) {
> >> + if (!(ub->dev_info.flags & UBLK_F_PARTITIONS)) {
> >> + /* disable partitions on trusted device */
> >> + disk->flags |= GENHD_FL_NO_PART;
> >> + } else {
> >> + /* Enable partition scan on device */
> >> + clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> >> + /* Schedule auto partition scan if requested */
> >> + if (ub->dev_info.flags & UBLK_F_AUTO_PART_SCAN)
> >> + schedule_work(&ub->partition_scan_work);
> >> + }
> >> }
> >>
> >> out_put_cdev:
> >> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
> >> index a88876756805..467ecaa20ac1 100644
> >> --- a/include/uapi/linux/ublk_cmd.h
> >> +++ b/include/uapi/linux/ublk_cmd.h
> >> @@ -367,8 +367,11 @@
> >> */
> >> #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)
> >> +/* Enable partitions on the device */
> >> +#define UBLK_F_PARTITIONS (1ULL << 18)
> >> +
> >> +/* Perform automatic partition scanning when device is started */
> >> +#define UBLK_F_AUTO_PART_SCAN (1ULL << 19)
> >
> > I think it isn't necessary to add UBLK_F_AUTO_PART_SCAN, and the default
> > behavior is to scan partitions automatically just like other block device.
>
>
> If we want by default to scan there should be UBLK_F_NO_AUTO_PART_SCAN to disable
> scanning when desired - are you ok with it?
I am fine with either way:
- keep UBLK_F_NO_AUTO_PART_SCAN as it is, which just disallow partition
scan during add disk; meantime add UBLK_F_NO_PART_SCAN, which disables part
scan permanently
- remove UBLK_F_NO_AUTO_PART_SCAN, as no one requires it, meantime add
UBLK_F_NO_PART_SCAN, which disables part scan permanently
But looks Hannes prefers to the latter, which is cleaner from UAPI
viewpoint.
Thanks,
Ming
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-02-24 11:05 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 12:15 [PATCH 0/4] ublk: rework partition handling Alexander Atanasov
2026-02-23 12:15 ` [PATCH 1/4] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
2026-02-23 12:29 ` Hannes Reinecke
2026-02-23 15:59 ` Caleb Sander Mateos
2026-02-23 16:23 ` Alexander Atanasov
2026-02-23 16:42 ` Caleb Sander Mateos
2026-02-23 17:19 ` Alexander Atanasov
2026-02-24 9:31 ` Ming Lei
2026-02-24 9:34 ` Ming Lei
[not found] ` <182C75BB-3CBC-4627-9F15-AE8FE675260C@zazolabs.com>
2026-02-24 11:04 ` Ming Lei
2026-02-23 12:15 ` [PATCH 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
2026-02-23 12:29 ` Hannes Reinecke
2026-02-23 12:15 ` [PATCH 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
2026-02-23 12:30 ` Hannes Reinecke
2026-02-23 12:15 ` [PATCH 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
2026-02-23 12:30 ` Hannes Reinecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox