public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] ublk: rework partition handling
@ 2026-02-27 14:57 Alexander Atanasov
  2026-02-27 14:57 ` [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS Alexander Atanasov
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Alexander Atanasov @ 2026-02-27 14:57 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 fully disable partitions on device.

For privileged device partitions are enabled by default -
they can be disabled by new UBLK_F_NO_PARTITIONS flag.
Auto partition scan can be disabled by UBLK_F_NO_AUTO_PART_SCAN.

Update related tests and documentation.

-v1->v2:
  - remove code duplication and extra flag settings
  - switch from out-in to out-out to preserve backwards compatibility

Alexander Atanasov (4):
  ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS
  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                      | 25 +++++++++----------
 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, 64 insertions(+), 38 deletions(-)


base-commit: 72f4d6fca699a1e35b39c5e5dacac2926d254135
-- 
2.43.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS
  2026-02-27 14:57 [PATCH v2 0/4] ublk: rework partition handling Alexander Atanasov
@ 2026-02-27 14:57 ` Alexander Atanasov
  2026-02-27 18:29   ` Caleb Sander Mateos
  2026-02-27 14:57 ` [PATCH v2 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Alexander Atanasov @ 2026-02-27 14:57 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.

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 enabled,
automatic initial scan can be disabled via UBLK_F_NO_AUTO_PART_SCAN flag.
Partitions can be disabled via UBLK_F_NO_PARTITIONS 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_NO_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      | 23 +++++++++--------------
 include/uapi/linux/ublk_cmd.h |  3 +++
 2 files changed, 12 insertions(+), 14 deletions(-)

-v1->v2:
  - remove code duplication and extra flag settings
  - switch from out-in to out-out to preserve backwards compatibility


diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 3c918db4905c..36da63ba2a57 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -81,6 +81,7 @@
 		| (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
 		| UBLK_F_SAFE_STOP_DEV \
 		| UBLK_F_BATCH_IO \
+		| UBLK_F_NO_PARTITIONS \
 		| UBLK_F_NO_AUTO_PART_SCAN)
 
 #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
@@ -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,10 +4405,10 @@ 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.
 	 */
-	set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
+	disk->flags |= GENHD_FL_NO_PART;
 
 	ublk_get_device(ub);
 	ub->dev_info.state = UBLK_S_DEV_LIVE;
@@ -4429,12 +4425,11 @@ 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)
+	if (!ub->unprivileged_daemons && !(ub->dev_info.flags & UBLK_F_NO_PARTITIONS)) {
+		/* Enable partitions on device */
+		disk->flags &= ~GENHD_FL_NO_PART;
+		/* Disable auto partition scan if requested */
+		if (!(ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN))
 			schedule_work(&ub->partition_scan_work);
 	}
 
diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
index a88876756805..bfd2adfb3d8d 100644
--- a/include/uapi/linux/ublk_cmd.h
+++ b/include/uapi/linux/ublk_cmd.h
@@ -370,6 +370,9 @@
 /* Disable automatic partition scanning when device is started */
 #define UBLK_F_NO_AUTO_PART_SCAN (1ULL << 18)
 
+/* Disable partitions on the device */
+#define UBLK_F_NO_PARTITIONS (1ULL << 19)
+
 /* device state */
 #define UBLK_S_DEV_DEAD	0
 #define UBLK_S_DEV_LIVE	1

base-commit: 72f4d6fca699a1e35b39c5e5dacac2926d254135
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/4] selftests: ublk: rework partitions tests for new flags
  2026-02-27 14:57 [PATCH v2 0/4] ublk: rework partition handling Alexander Atanasov
  2026-02-27 14:57 ` [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS Alexander Atanasov
@ 2026-02-27 14:57 ` Alexander Atanasov
  2026-02-28 10:06   ` Ming Lei
  2026-02-27 14:57 ` [PATCH v2 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
  2026-02-27 14:57 ` [PATCH v2 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
  3 siblings, 1 reply; 12+ messages in thread
From: Alexander Atanasov @ 2026-02-27 14:57 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov

To support new flag - UBLK_F_NO_PARTITIONS
add kublk argument:
-m, --no_partitions - disable partitions on trusted devices
Add short argument for  UBLK_F_NO_AUTO_PART_SCAN
-p, --no_auto_part_scan - disable initial partition scan

Update test cases to use the new arguments

Fix long lines while at it.

Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
---
 tools/testing/selftests/ublk/kublk.c             | 16 +++++++++++-----
 .../testing/selftests/ublk/test_integrity_01.sh  |  8 +++++---
 tools/testing/selftests/ublk/test_part_01.sh     |  6 +++---
 tools/testing/selftests/ublk/test_part_02.sh     |  6 ++++--
 4 files changed, 23 insertions(+), 13 deletions(-)

v1->v2:
  - switch from opt-in to opt-out flags

diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
index e8279c4acc40..c0dacdc12ebe 100644
--- a/tools/testing/selftests/ublk/kublk.c
+++ b/tools/testing/selftests/ublk/kublk.c
@@ -1615,6 +1615,7 @@ 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_PARTITIONS),
 		FEAT_NAME(UBLK_F_NO_AUTO_PART_SCAN),
 	};
 	struct ublk_dev *dev;
@@ -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] [-m,--no_partitions] [-p,--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");
@@ -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 },
+		{ "no_partitions",	0,	NULL, 'm' },
+		{ "no_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:gazubmp",
 				  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 'm':
+			ctx.flags |= UBLK_F_NO_PARTITIONS;
+			break;
+		case 'p':
+			ctx.flags |= UBLK_F_NO_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..b7ffc6212d24 100755
--- a/tools/testing/selftests/ublk/test_integrity_01.sh
+++ b/tools/testing/selftests/ublk/test_integrity_01.sh
@@ -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 --no_auto_part_scan --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,8 @@ _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 --no_auto_part_scan --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 +80,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..0a7ca6b8450d 100755
--- a/tools/testing/selftests/ublk/test_part_01.sh
+++ b/tools/testing/selftests/ublk/test_part_01.sh
@@ -30,7 +30,7 @@ test_auto_part_scan()
 {
 	local backing_file=$1
 
-	# Create device WITHOUT --no_auto_part_scan
+	# Create device WITH automatic partition scan
 	local dev_id=$(_add_ublk_dev -t loop "${backing_file}")
 	[ $? -ne 0 ] && return 1
 
@@ -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
diff --git a/tools/testing/selftests/ublk/test_part_02.sh b/tools/testing/selftests/ublk/test_part_02.sh
index 7d42ab4d6e83..a046ff13856c 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)
 	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)
 	fi
 
 	_check_add_dev "$TID" $?
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/4] ublk: document partition flags, kublk and update external links
  2026-02-27 14:57 [PATCH v2 0/4] ublk: rework partition handling Alexander Atanasov
  2026-02-27 14:57 ` [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS Alexander Atanasov
  2026-02-27 14:57 ` [PATCH v2 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
@ 2026-02-27 14:57 ` Alexander Atanasov
  2026-02-28 10:07   ` Ming Lei
  2026-02-27 14:57 ` [PATCH v2 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
  3 siblings, 1 reply; 12+ messages in thread
From: Alexander Atanasov @ 2026-02-27 14:57 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov

Add section about partition handling on ublk devices.
Document UBLK_F_NO_PARTITIONS and UBLK_F_NO_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 | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

v1->v2:
   - switch fromn opt-in to opt-out flags

diff --git a/Documentation/block/ublk.rst b/Documentation/block/ublk.rst
index 6ad28039663d..4219b6f51260 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,15 @@ 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
+----------
+
+Partitions are enabled on ublk trusted devices and disabled on
+unprivileged devices by default.
+
+They can be disabled *only on trusted* devices with ``UBLK_F_NO_PARTITIONS`` flag.
+Automatic partition scan can be disabled with ``UBLK_F_NO_AUTO_PART_SCAN`` flag.
+
 Data plane
 ----------
 
@@ -488,10 +505,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] 12+ messages in thread

* [PATCH v2 4/4] selftests: ublk: cleanup kublk.h
  2026-02-27 14:57 [PATCH v2 0/4] ublk: rework partition handling Alexander Atanasov
                   ` (2 preceding siblings ...)
  2026-02-27 14:57 ` [PATCH v2 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
@ 2026-02-27 14:57 ` Alexander Atanasov
  2026-02-28 10:07   ` Ming Lei
  3 siblings, 1 reply; 12+ messages in thread
From: Alexander Atanasov @ 2026-02-27 14:57 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] 12+ messages in thread

* Re: [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS
  2026-02-27 14:57 ` [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS Alexander Atanasov
@ 2026-02-27 18:29   ` Caleb Sander Mateos
  2026-02-28  2:06     ` Ming Lei
  0 siblings, 1 reply; 12+ messages in thread
From: Caleb Sander Mateos @ 2026-02-27 18:29 UTC (permalink / raw)
  To: Alexander Atanasov; +Cc: Ming Lei, Jens Axboe, linux-block

On Fri, Feb 27, 2026 at 7:07 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.
>
> 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 enabled,
> automatic initial scan can be disabled via UBLK_F_NO_AUTO_PART_SCAN flag.
> Partitions can be disabled via UBLK_F_NO_PARTITIONS 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_NO_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      | 23 +++++++++--------------
>  include/uapi/linux/ublk_cmd.h |  3 +++
>  2 files changed, 12 insertions(+), 14 deletions(-)
>
> -v1->v2:
>   - remove code duplication and extra flag settings
>   - switch from out-in to out-out to preserve backwards compatibility
>
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3c918db4905c..36da63ba2a57 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -81,6 +81,7 @@
>                 | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
>                 | UBLK_F_SAFE_STOP_DEV \
>                 | UBLK_F_BATCH_IO \
> +               | UBLK_F_NO_PARTITIONS \
>                 | UBLK_F_NO_AUTO_PART_SCAN)
>
>  #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> @@ -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,10 +4405,10 @@ 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.
>          */
> -       set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> +       disk->flags |= GENHD_FL_NO_PART;
>
>         ublk_get_device(ub);
>         ub->dev_info.state = UBLK_S_DEV_LIVE;
> @@ -4429,12 +4425,11 @@ 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)
> +       if (!ub->unprivileged_daemons && !(ub->dev_info.flags & UBLK_F_NO_PARTITIONS)) {
> +               /* Enable partitions on device */
> +               disk->flags &= ~GENHD_FL_NO_PART;

Is it safe to modify disk->flags after the disk has been added? This looks racy.

Best,
Caleb


> +               /* Disable auto partition scan if requested */
> +               if (!(ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN))
>                         schedule_work(&ub->partition_scan_work);
>         }
>
> diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
> index a88876756805..bfd2adfb3d8d 100644
> --- a/include/uapi/linux/ublk_cmd.h
> +++ b/include/uapi/linux/ublk_cmd.h
> @@ -370,6 +370,9 @@
>  /* Disable automatic partition scanning when device is started */
>  #define UBLK_F_NO_AUTO_PART_SCAN (1ULL << 18)
>
> +/* Disable partitions on the device */
> +#define UBLK_F_NO_PARTITIONS (1ULL << 19)
> +
>  /* device state */
>  #define UBLK_S_DEV_DEAD        0
>  #define UBLK_S_DEV_LIVE        1
>
> base-commit: 72f4d6fca699a1e35b39c5e5dacac2926d254135
> --
> 2.43.0
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS
  2026-02-27 18:29   ` Caleb Sander Mateos
@ 2026-02-28  2:06     ` Ming Lei
  2026-02-28  5:30       ` Alexander Atanasov
  0 siblings, 1 reply; 12+ messages in thread
From: Ming Lei @ 2026-02-28  2:06 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Alexander Atanasov, Jens Axboe, linux-block

On Fri, Feb 27, 2026 at 10:29:56AM -0800, Caleb Sander Mateos wrote:
> On Fri, Feb 27, 2026 at 7:07 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.
> >
> > 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 enabled,
> > automatic initial scan can be disabled via UBLK_F_NO_AUTO_PART_SCAN flag.
> > Partitions can be disabled via UBLK_F_NO_PARTITIONS 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_NO_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      | 23 +++++++++--------------
> >  include/uapi/linux/ublk_cmd.h |  3 +++
> >  2 files changed, 12 insertions(+), 14 deletions(-)
> >
> > -v1->v2:
> >   - remove code duplication and extra flag settings
> >   - switch from out-in to out-out to preserve backwards compatibility
> >
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 3c918db4905c..36da63ba2a57 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -81,6 +81,7 @@
> >                 | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
> >                 | UBLK_F_SAFE_STOP_DEV \
> >                 | UBLK_F_BATCH_IO \
> > +               | UBLK_F_NO_PARTITIONS \
> >                 | UBLK_F_NO_AUTO_PART_SCAN)
> >
> >  #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> > @@ -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,10 +4405,10 @@ 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.
> >          */
> > -       set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> > +       disk->flags |= GENHD_FL_NO_PART;
> >
> >         ublk_get_device(ub);
> >         ub->dev_info.state = UBLK_S_DEV_LIVE;
> > @@ -4429,12 +4425,11 @@ 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)
> > +       if (!ub->unprivileged_daemons && !(ub->dev_info.flags & UBLK_F_NO_PARTITIONS)) {
> > +               /* Enable partitions on device */
> > +               disk->flags &= ~GENHD_FL_NO_PART;
> 
> Is it safe to modify disk->flags after the disk has been added? This looks racy.

Yeah, GENHD_FL_NO_PART should cover unprivileged_daemons & UBLK_F_NO_PARTITIONS only
in static way.

Normal partition scanning still need GD_SUPPRESS_PART_SCAN.


Thanks,
Ming


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS
  2026-02-28  2:06     ` Ming Lei
@ 2026-02-28  5:30       ` Alexander Atanasov
  2026-02-28  7:19         ` Ming Lei
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Atanasov @ 2026-02-28  5:30 UTC (permalink / raw)
  To: Ming Lei; +Cc: Caleb Sander Mateos, Jens Axboe, linux-block



> On 28 Feb 2026, at 4:06, Ming Lei <ming.lei@redhat.com> wrote:
> 
> On Fri, Feb 27, 2026 at 10:29:56AM -0800, Caleb Sander Mateos wrote:
>> On Fri, Feb 27, 2026 at 7:07 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.
>>> 
>>> 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 enabled,
>>> automatic initial scan can be disabled via UBLK_F_NO_AUTO_PART_SCAN flag.
>>> Partitions can be disabled via UBLK_F_NO_PARTITIONS 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_NO_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      | 23 +++++++++--------------
>>> include/uapi/linux/ublk_cmd.h |  3 +++
>>> 2 files changed, 12 insertions(+), 14 deletions(-)
>>> 
>>> -v1->v2:
>>>  - remove code duplication and extra flag settings
>>>  - switch from out-in to out-out to preserve backwards compatibility
>>> 
>>> 
>>> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
>>> index 3c918db4905c..36da63ba2a57 100644
>>> --- a/drivers/block/ublk_drv.c
>>> +++ b/drivers/block/ublk_drv.c
>>> @@ -81,6 +81,7 @@
>>>                | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
>>>                | UBLK_F_SAFE_STOP_DEV \
>>>                | UBLK_F_BATCH_IO \
>>> +               | UBLK_F_NO_PARTITIONS \
>>>                | UBLK_F_NO_AUTO_PART_SCAN)
>>> 
>>> #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
>>> @@ -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,10 +4405,10 @@ 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.
>>>         */
>>> -       set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
>>> +       disk->flags |= GENHD_FL_NO_PART;
>>> 
>>>        ublk_get_device(ub);
>>>        ub->dev_info.state = UBLK_S_DEV_LIVE;
>>> @@ -4429,12 +4425,11 @@ 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)
>>> +       if (!ub->unprivileged_daemons && !(ub->dev_info.flags & UBLK_F_NO_PARTITIONS)) {
>>> +               /* Enable partitions on device */
>>> +               disk->flags &= ~GENHD_FL_NO_PART;
>> 
>> Is it safe to modify disk->flags after the disk has been added? This looks racy.
> 
> Yeah, GENHD_FL_NO_PART should cover unprivileged_daemons & UBLK_F_NO_PARTITIONS only
> in static way.


Once set disk->flags are not modified anywhere. Where modifications are required then there is a disk->state.
No one inside the driver can touch the disk since the mutex is held.
Outside the driver flags are only checked.
add_disk(..) does not start any asynchronous operations, that’s the reason there is a work queue.
So where do you see a race ?


> Normal partition scanning still need GD_SUPPRESS_PART_SCAN.
> 


static inline bool disk_has_partscan(struct gendisk *disk)
{
        return !(disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN)) &&
                !test_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
}


GD_SUPPRESS_PART_SCAN is a state.
GENHD_FL_NO_PART is permanent disable.

It is enough to prevent partition scanning triggered from add_disk(…) and
that is the goal. I can’t see a reason to manage both as they effectively 
do the same.



Regards,
Alexander Atanasov




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS
  2026-02-28  5:30       ` Alexander Atanasov
@ 2026-02-28  7:19         ` Ming Lei
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Lei @ 2026-02-28  7:19 UTC (permalink / raw)
  To: Alexander Atanasov; +Cc: Caleb Sander Mateos, Jens Axboe, linux-block

On Sat, Feb 28, 2026 at 07:30:06AM +0200, Alexander Atanasov wrote:
> 
> 
> > On 28 Feb 2026, at 4:06, Ming Lei <ming.lei@redhat.com> wrote:
> > 
> > On Fri, Feb 27, 2026 at 10:29:56AM -0800, Caleb Sander Mateos wrote:
> >> On Fri, Feb 27, 2026 at 7:07 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.
> >>> 
> >>> 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 enabled,
> >>> automatic initial scan can be disabled via UBLK_F_NO_AUTO_PART_SCAN flag.
> >>> Partitions can be disabled via UBLK_F_NO_PARTITIONS 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_NO_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      | 23 +++++++++--------------
> >>> include/uapi/linux/ublk_cmd.h |  3 +++
> >>> 2 files changed, 12 insertions(+), 14 deletions(-)
> >>> 
> >>> -v1->v2:
> >>>  - remove code duplication and extra flag settings
> >>>  - switch from out-in to out-out to preserve backwards compatibility
> >>> 
> >>> 
> >>> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> >>> index 3c918db4905c..36da63ba2a57 100644
> >>> --- a/drivers/block/ublk_drv.c
> >>> +++ b/drivers/block/ublk_drv.c
> >>> @@ -81,6 +81,7 @@
> >>>                | (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) ? UBLK_F_INTEGRITY : 0) \
> >>>                | UBLK_F_SAFE_STOP_DEV \
> >>>                | UBLK_F_BATCH_IO \
> >>> +               | UBLK_F_NO_PARTITIONS \
> >>>                | UBLK_F_NO_AUTO_PART_SCAN)
> >>> 
> >>> #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> >>> @@ -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,10 +4405,10 @@ 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.
> >>>         */
> >>> -       set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> >>> +       disk->flags |= GENHD_FL_NO_PART;
> >>> 
> >>>        ublk_get_device(ub);
> >>>        ub->dev_info.state = UBLK_S_DEV_LIVE;
> >>> @@ -4429,12 +4425,11 @@ 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)
> >>> +       if (!ub->unprivileged_daemons && !(ub->dev_info.flags & UBLK_F_NO_PARTITIONS)) {
> >>> +               /* Enable partitions on device */
> >>> +               disk->flags &= ~GENHD_FL_NO_PART;
> >> 
> >> Is it safe to modify disk->flags after the disk has been added? This looks racy.
> > 
> > Yeah, GENHD_FL_NO_PART should cover unprivileged_daemons & UBLK_F_NO_PARTITIONS only
> > in static way.
> 
> 
> Once set disk->flags are not modified anywhere. Where modifications are required then there is a disk->state.
> No one inside the driver can touch the disk since the mutex is held.
> Outside the driver flags are only checked.
> add_disk(..) does not start any asynchronous operations, that’s the reason there is a work queue.
> So where do you see a race ?

The block layer has a clear two-tier design for partition control:

1. disk->flags (e.g. GENHD_FL_NO_PART) — set before add_disk(), meant to be
static/permanent. These are regular integers, not atomic.

2. disk->state (e.g. GD_SUPPRESS_PART_SCAN) — atomic bit operations
(set_bit/clear_bit/test_and_clear_bit), designed for runtime toggling.

This distinction is intentional — disk->flags uses non-atomic read-modify-write (&=, |=),
so concurrent modification is genuinely unsafe. Similar change may not even
compile in memory safety language, such as Rust.

Also the ublk mutex can't protect concurrent partition scanning from ioctl(BLKRRPART).

BTW, the patch title has typo in `UBLK_F_NO_PARTITONS`.

Thanks, 
Ming


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/4] selftests: ublk: rework partitions tests for new flags
  2026-02-27 14:57 ` [PATCH v2 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
@ 2026-02-28 10:06   ` Ming Lei
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Lei @ 2026-02-28 10:06 UTC (permalink / raw)
  To: Alexander Atanasov; +Cc: Jens Axboe, linux-block

On Fri, Feb 27, 2026 at 02:57:54PM +0000, Alexander Atanasov wrote:
> To support new flag - UBLK_F_NO_PARTITIONS
> add kublk argument:
> -m, --no_partitions - disable partitions on trusted devices
> Add short argument for  UBLK_F_NO_AUTO_PART_SCAN
> -p, --no_auto_part_scan - disable initial partition scan
> 
> Update test cases to use the new arguments
> 
> Fix long lines while at it.
> 
> Signed-off-by: Alexander Atanasov <alex@zazolabs.com>
> ---
>  tools/testing/selftests/ublk/kublk.c             | 16 +++++++++++-----
>  .../testing/selftests/ublk/test_integrity_01.sh  |  8 +++++---
>  tools/testing/selftests/ublk/test_part_01.sh     |  6 +++---
>  tools/testing/selftests/ublk/test_part_02.sh     |  6 ++++--
>  4 files changed, 23 insertions(+), 13 deletions(-)
> 
> v1->v2:
>   - switch from opt-in to opt-out flags
> 
> diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
> index e8279c4acc40..c0dacdc12ebe 100644
> --- a/tools/testing/selftests/ublk/kublk.c
> +++ b/tools/testing/selftests/ublk/kublk.c
> @@ -1615,6 +1615,7 @@ 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_PARTITIONS),
>  		FEAT_NAME(UBLK_F_NO_AUTO_PART_SCAN),
>  	};
>  	struct ublk_dev *dev;
> @@ -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] [-m,--no_partitions] [-p,--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");
> @@ -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 },
> +		{ "no_partitions",	0,	NULL, 'm' },
> +		{ "no_auto_part_scan",	0,	NULL, 'p' },

IMO, both two short options('m' and 'p') are not readable, I'd suggest to
not add short option if better name can't be figured out.

Otherwise, this patch looks fine.


thanks,
Ming


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/4] ublk: document partition flags, kublk and update external links
  2026-02-27 14:57 ` [PATCH v2 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
@ 2026-02-28 10:07   ` Ming Lei
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Lei @ 2026-02-28 10:07 UTC (permalink / raw)
  To: Alexander Atanasov; +Cc: Jens Axboe, linux-block

On Fri, Feb 27, 2026 at 02:57:55PM +0000, Alexander Atanasov wrote:
> Add section about partition handling on ublk devices.
> Document UBLK_F_NO_PARTITIONS and UBLK_F_NO_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>

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 4/4] selftests: ublk: cleanup kublk.h
  2026-02-27 14:57 ` [PATCH v2 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
@ 2026-02-28 10:07   ` Ming Lei
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Lei @ 2026-02-28 10:07 UTC (permalink / raw)
  To: Alexander Atanasov; +Cc: Jens Axboe, linux-block

On Fri, Feb 27, 2026 at 02:57:56PM +0000, 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: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-02-28 10:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 14:57 [PATCH v2 0/4] ublk: rework partition handling Alexander Atanasov
2026-02-27 14:57 ` [PATCH v2 1/4] ublk: cleanup partition flags handling and introduce UBLK_F_NO_PARTITONS Alexander Atanasov
2026-02-27 18:29   ` Caleb Sander Mateos
2026-02-28  2:06     ` Ming Lei
2026-02-28  5:30       ` Alexander Atanasov
2026-02-28  7:19         ` Ming Lei
2026-02-27 14:57 ` [PATCH v2 2/4] selftests: ublk: rework partitions tests for new flags Alexander Atanasov
2026-02-28 10:06   ` Ming Lei
2026-02-27 14:57 ` [PATCH v2 3/4] ublk: document partition flags, kublk and update external links Alexander Atanasov
2026-02-28 10:07   ` Ming Lei
2026-02-27 14:57 ` [PATCH v2 4/4] selftests: ublk: cleanup kublk.h Alexander Atanasov
2026-02-28 10:07   ` Ming Lei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox