add a partscan sysfs attribute
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.
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(-)
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
@@ -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
@@ -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
@@ -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
PATCH 2/2 block: add a partscan sysfs attribute for disks
In reply to Christoph HellwigThis 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
@@ -101,6 +101,16 @@ Description: devices that support receiving integrity metadata. +What: /sys/block/<disk>/partscan +Date: Atorl 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
@@ -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
Re: [PATCH 2/2] block: add a partscan sysfs attribute for disks
Quoted 1 line · Christoph Hellwig
+Date: Atorl 2024
I suppose that this needs to be fixed.. or become May.
Quoted 5 lines · Christoph Hellwig
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.
thanks!
lgtm for our uses!
Lennart
--
Lennart Poettering, Berlin