public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN
@ 2026-02-12 15:25 Alexander Atanasov
  2026-02-13  3:48 ` Ming Lei
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Atanasov @ 2026-02-12 15:25 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: linux-block, Alexander Atanasov, Yoav Cohen

Currently the code misuse GD_SUPPRESS_PART_SCAN flag
as it tries to use it as a switch for the auto partition scan.
When UBLK_F_NO_AUTO_PART_SCAN is not passed a proper
auto partition scanning is not done because the first
call to ublk_partition_scan_work will clear the bit
GD_SUPPRESS_PART_SCAN but not actually load the partitions.

How it should work:
Unprivileged daemons - never scan partitions, they have
GD_SUPPRESS_PART_SCAN always set - they are marked as devices
without partitions. While ioctl(BLKRRPART) does require
CAP_SYS_ADMIN, block layer have its own a check in
disk_has_partscan(...) if partitions are supported.

Trusted daemons - auto scan partitions by default
and they do not have the bit set, so they do have partitions.

For trusted daemons auto partitions scan is performed but it can
be skipped if user have set UBLK_F_NO_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.
- keep GD_SUPPRESS_PART_SCAN always set on unprivileged
- keep GD_SUPPRESS_PART_SCAN always clear on trusted
- Properly handle user request to skip auto partitioning scanning

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 | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Cc: Yoav Cohen <yoav@nvidia.com>

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 3c918db4905c..e662c6e8e722 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2361,14 +2361,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);
 }
 
@@ -4429,12 +4424,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) {
+	if (!ub->unprivileged_daemons) {
+		/* Enable partition scanning for trusted daemons */
 		clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
-	} else {
-		/* Schedule async partition scan for trusted daemons */
-		if (!ub->unprivileged_daemons)
+		/* Skip auto partition scan if requested by user */
+		if (!(ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN))
 			schedule_work(&ub->partition_scan_work);
 	}
 

base-commit: 72f4d6fca699a1e35b39c5e5dacac2926d254135
-- 
2.43.0


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

end of thread, other threads:[~2026-02-21 13:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-12 15:25 [PATCH] ublk: cleanup flag handling and fix UBLK_F_NO_AUTO_PART_SCAN Alexander Atanasov
2026-02-13  3:48 ` Ming Lei
2026-02-13  6:56   ` Hannes Reinecke
2026-02-13 11:05   ` Alexander Atanasov
2026-02-20  3:58     ` Ming Lei
2026-02-21 13:00       ` Alexander Atanasov

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