Skip to contentSkip to conversation

add a partscan sysfs attribute v2

PATCH In review Christoph Hellwig 3 participants 9 messages May 2, 2024 – May 3, 2024 Block layer

lore
Share & tools
lore
#0 lore raw

Hi all,

this series adds a patscan sysfs attribute so that userspace (e.g. systemd) can check if partition scanning is enabled for a given gendisk.

Changes since v1:
- update the data from the non-existing month of Atorl to May

Diffstat:

 Documentation/ABI/stable/sysfs-block |   10 ++++++++++
 block/genhd.c                        |   15 ++++++++++-----
 block/partitions/core.c              |    5 +----
 include/linux/blkdev.h               |   13 +++++++++++++
 4 files changed, 34 insertions(+), 9 deletions(-)
#1 lore raw

PATCH 1/2 block: add a disk_has_partscan helper

Add a helper to check if partition scanning is enabled instead of open coding the check in a few places. This now always checks for the hidden flag even if all but one of the callers are never reachable for hidden gendisks.

---
 block/genhd.c           |  7 ++-----
 block/partitions/core.c |  5 +----
 include/linux/blkdev.h  | 13 +++++++++++++
 3 files changed, 16 insertions(+), 9 deletions(-)
block/genhd.c +2 -5
index eb893df56d510e..4b85963d09dbb4 100644
@@ -345,9 +345,7 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
 	struct file *file;
 	int ret = 0;
 
-	if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
-		return -EINVAL;
-	if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
+	if (!disk_has_partscan(disk))
 		return -EINVAL;
 	if (disk->open_partitions)
 		return -EBUSY;
@@ -503,8 +501,7 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
 			goto out_unregister_bdi;
 
 		/* Make sure the first partition scan will be proceed */
-		if (get_capacity(disk) && !(disk->flags & GENHD_FL_NO_PART) &&
-		    !test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
+		if (get_capacity(disk) && disk_has_partscan(disk))
 			set_bit(GD_NEED_PART_SCAN, &disk->state);
 
 		bdev_add(disk->part0, ddev->devt);
block/partitions/core.c +1 -4
index b11e88c82c8cfa..37b5f92d07fec9 100644
@@ -573,10 +573,7 @@ static int blk_add_partitions(struct gendisk *disk)
 	struct parsed_partitions *state;
 	int ret = -EAGAIN, p;
 
-	if (disk->flags & GENHD_FL_NO_PART)
-		return 0;
-
-	if (test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
+	if (!disk_has_partscan(disk))
 		return 0;
 
 	state = check_partition(disk);
include/linux/blkdev.h +13 -0
index 040a22e0eda0ec..3b18a40a1fc109 100644
@@ -230,6 +230,19 @@ static inline unsigned int disk_openers(struct gendisk *disk)
 	return atomic_read(&disk->part0->bd_openers);
 }
 
+/**
+ * disk_has_partscan - return %true if partition scanning is enabled on a disk
+ * @disk: disk to check
+ *
+ * Returns %true if partitions scanning is enabled for @disk, or %false if
+ * partition scanning is disabled either permanently or temporarily.
+ */
+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);
+}
+
 /*
  * The gendisk is refcounted by the part0 block_device, and the bd_device
  * therein is also used for device model presentation in sysfs.
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/2 block: add a partscan sysfs attribute for disks

In reply to Christoph Hellwig

This attribute reports if partition scanning is enabled for a given disk.

---
 Documentation/ABI/stable/sysfs-block | 10 ++++++++++
 block/genhd.c                        |  8 ++++++++
 2 files changed, 18 insertions(+)
Documentation/ABI/stable/sysfs-block +10 -0
index 1fe9a553c37b71..f0025d1c3d5acd 100644
@@ -101,6 +101,16 @@ Description:
 		devices that support receiving integrity metadata.
 
 
+What:		/sys/block/<disk>/partscan
+Date:		May 2024
+Contact:	Christoph Hellwig <[email protected]>
+Description:
+		The /sys/block/<disk>/partscan files reports if partition
+		scanning is enabled for the disk.  It returns "1" if partition
+		scanning is enabled, or "0" if not.  The value type is a 32-bit
+		unsigned integer, but only "0" and "1" are valid values.
+
+
 What:		/sys/block/<disk>/<partition>/alignment_offset
 Date:		April 2009
 Contact:	Martin K. Petersen <[email protected]>
block/genhd.c +8 -0
index 4b85963d09dbb4..dec2ee338fb44a 100644
@@ -1044,6 +1044,12 @@ static ssize_t diskseq_show(struct device *dev,
 	return sprintf(buf, "%llu\n", disk->diskseq);
 }
 
+static ssize_t partscan_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%u\n", disk_has_partscan(dev_to_disk(dev)));
+}
+
 static DEVICE_ATTR(range, 0444, disk_range_show, NULL);
 static DEVICE_ATTR(ext_range, 0444, disk_ext_range_show, NULL);
 static DEVICE_ATTR(removable, 0444, disk_removable_show, NULL);
@@ -1057,6 +1063,7 @@ static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
 static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
 static DEVICE_ATTR(badblocks, 0644, disk_badblocks_show, disk_badblocks_store);
 static DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL);
+static DEVICE_ATTR(partscan, 0444, partscan_show, NULL);
 
 #ifdef CONFIG_FAIL_MAKE_REQUEST
 ssize_t part_fail_show(struct device *dev,
@@ -1103,6 +1110,7 @@ static struct attribute *disk_attrs[] = {
 	&dev_attr_events_async.attr,
 	&dev_attr_events_poll_msecs.attr,
 	&dev_attr_diskseq.attr,
+	&dev_attr_partscan.attr,
 #ifdef CONFIG_FAIL_MAKE_REQUEST
 	&dev_attr_fail.attr,
 #endif
Signature · 1 line
2.39.2
maintainer
#3 lore raw

Re: [PATCH 2/2] block: add a partscan sysfs attribute for disks

Quoted 1 line · Christoph Hellwig

This attribute reports if partition scanning is enabled for a given disk.

This should, at least, have a reference to Lennart's posting, and honestly a much better commit message as well. There's no reasoning given here at all.

Maybe even a fixes tag and stable notation?

Signature · 1 line
Jens Axboe
#4 lore raw

Re: [PATCH 2/2] block: add a partscan sysfs attribute for disks

Quoted 6 lines · Jens Axboe
Quoted 1 line · Christoph Hellwig

This attribute reports if partition scanning is enabled for a given disk.

This should, at least, have a reference to Lennart's posting, and honestly a much better commit message as well. There's no reasoning given here at all.

I'm not sure I can come up with something much better, feel free to throw in what you prefer.

Quoted 1 line

Maybe even a fixes tag and stable notation?

This is definitively not a Fixes as nothing it doesn't actually fix any code. It provides a proper interfaces for what was an abuse of leaking internal bits out.

#5 lore raw

Re: [PATCH 2/2] block: add a partscan sysfs attribute for disks

Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Jens Axboe
Quoted 1 line · Christoph Hellwig

This attribute reports if partition scanning is enabled for a given disk.

This should, at least, have a reference to Lennart's posting, and honestly a much better commit message as well. There's no reasoning given here at all.

I'm not sure I can come up with something much better, feel free to throw in what you prefer.

I think just explaining the "why" would be usesful for the git history. How about this:

Userspace had been unknowingly relying on a non-stable interface of kernel internals to determine if partition scanning is enabled for a given disk. Provide a stable interface for this purpose instead.

Quoted 5 lines
Quoted 1 line

Maybe even a fixes tag and stable notation?

This is definitively not a Fixes as nothing it doesn't actually fix any code. It provides a proper interfaces for what was an abuse of leaking internal bits out.

I kind of agree it's not a "Fixes:" in the traditional sense, but at a "Cc: <stable>" sounds appropriate given the fallout.

maintainer
#6 lore raw

Re: [PATCH 2/2] block: add a partscan sysfs attribute for disks

Quoted 12 lines · Keith Busch
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Jens Axboe
Quoted 1 line · Christoph Hellwig

This attribute reports if partition scanning is enabled for a given disk.

This should, at least, have a reference to Lennart's posting, and honestly a much better commit message as well. There's no reasoning given here at all.

I'm not sure I can come up with something much better, feel free to throw in what you prefer.

Quoted 8 lines

I think just explaining the "why" would be usesful for the git history. How about this:

Userspace had been unknowingly relying on a non-stable interface of kernel internals to determine if partition scanning is enabled for a given disk. Provide a stable interface for this purpose instead.

Yep this looks good, I can grab that.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Maybe even a fixes tag and stable notation?

This is definitively not a Fixes as nothing it doesn't actually fix any code. It provides a proper interfaces for what was an abuse of leaking internal bits out.

I kind of agree it's not a "Fixes:" in the traditional sense, but at a "Cc: <stable>" sounds appropriate given the fallout.

It's definitely not a traditional kind of fixes, even a made-up tag might be fine for this.

But probably just a Cc: [email protected] # version

and the added link would be good enough.

Signature · 1 line
Jens Axboe
maintainer
#7 lore raw

Re: [PATCH 2/2] block: add a partscan sysfs attribute for disks

In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Jens Axboe
Quoted 1 line · Christoph Hellwig

This attribute reports if partition scanning is enabled for a given disk.

This should, at least, have a reference to Lennart's posting, and honestly a much better commit message as well. There's no reasoning given here at all.

I'm not sure I can come up with something much better, feel free to throw in what you prefer.

Really? You have literally nothing in there! It's good practice to include reasoning for why the change is being done, particularly in this case where there's quite strong reasonings for the addition.

Quoted 5 lines
Quoted 1 line

Maybe even a fixes tag and stable notation?

This is definitively not a Fixes as nothing it doesn't actually fix any code. It provides a proper interfaces for what was an abuse of leaking internal bits out.

I'm looking to bridge the gap between when we yanked the old garbage interface and now added this one. So yeah it's not a pure fixes, but I think we should still tie them together somehow so we can do a proper stable backport of this.

Signature · 1 line
Jens Axboe
maintainer Applied
#8 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

this series adds a patscan sysfs attribute so that userspace (e.g. systemd) can check if partition scanning is enabled for a given gendisk.

Changes since v1:
- update the data from the non-existing month of Atorl to May

[...]

Applied, thanks!

[1/2] block: add a disk_has_partscan helper

      commit: 140ce28dd3bee8e53acc27f123ae474d69ef66f0
[2/2] block: add a partscan sysfs attribute for disks
      commit: a4217c6740dc64a3eb6815868a9260825e8c68c6

Best regards,

Signature · 1 line
Jens Axboe