* add a partscan sysfs attribute
@ 2024-04-29 17:48 Christoph Hellwig
2024-04-29 17:49 ` [PATCH 1/2] block: add a disk_has_partscan helper Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Christoph Hellwig @ 2024-04-29 17:48 UTC (permalink / raw)
To: Jens Axboe; +Cc: Lennart Poettering, linux-block
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(-)
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] block: add a disk_has_partscan helper 2024-04-29 17:48 add a partscan sysfs attribute Christoph Hellwig @ 2024-04-29 17:49 ` Christoph Hellwig 2024-04-29 17:49 ` [PATCH 2/2] block: add a partscan sysfs attribute for disks Christoph Hellwig 2024-04-30 14:25 ` add a partscan sysfs attribute Lennart Poettering 2 siblings, 0 replies; 6+ messages in thread From: Christoph Hellwig @ 2024-04-29 17:49 UTC (permalink / raw) To: Jens Axboe; +Cc: Lennart Poettering, linux-block 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. Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/genhd.c | 7 ++----- block/partitions/core.c | 5 +---- include/linux/blkdev.h | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index eb893df56d510e..4b85963d09dbb4 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -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); diff --git a/block/partitions/core.c b/block/partitions/core.c index b11e88c82c8cfa..37b5f92d07fec9 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -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); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 040a22e0eda0ec..3b18a40a1fc109 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -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. -- 2.39.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] block: add a partscan sysfs attribute for disks 2024-04-29 17:48 add a partscan sysfs attribute Christoph Hellwig 2024-04-29 17:49 ` [PATCH 1/2] block: add a disk_has_partscan helper Christoph Hellwig @ 2024-04-29 17:49 ` Christoph Hellwig 2024-04-30 14:10 ` John Garry 2024-04-30 14:25 ` add a partscan sysfs attribute Lennart Poettering 2 siblings, 1 reply; 6+ messages in thread From: Christoph Hellwig @ 2024-04-29 17:49 UTC (permalink / raw) To: Jens Axboe; +Cc: Lennart Poettering, linux-block This attribute reports if partition scanning is enabled for a given disk. Signed-off-by: Christoph Hellwig <hch@lst.de> --- Documentation/ABI/stable/sysfs-block | 10 ++++++++++ block/genhd.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 1fe9a553c37b71..db58fdcdff31b0 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -101,6 +101,16 @@ Description: devices that support receiving integrity metadata. +What: /sys/block/<disk>/partscan +Date: Atorl 2024 +Contact: Christoph Hellwig <hch@lst.de> +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 <martin.petersen@oracle.com> diff --git a/block/genhd.c b/block/genhd.c index 4b85963d09dbb4..dec2ee338fb44a 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -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 -- 2.39.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] block: add a partscan sysfs attribute for disks 2024-04-29 17:49 ` [PATCH 2/2] block: add a partscan sysfs attribute for disks Christoph Hellwig @ 2024-04-30 14:10 ` John Garry 0 siblings, 0 replies; 6+ messages in thread From: John Garry @ 2024-04-30 14:10 UTC (permalink / raw) To: Christoph Hellwig, Jens Axboe; +Cc: Lennart Poettering, linux-block On 29/04/2024 18:49, Christoph Hellwig wrote: > +Date: Atorl 2024 I suppose that this needs to be fixed.. or become May. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: add a partscan sysfs attribute 2024-04-29 17:48 add a partscan sysfs attribute Christoph Hellwig 2024-04-29 17:49 ` [PATCH 1/2] block: add a disk_has_partscan helper Christoph Hellwig 2024-04-29 17:49 ` [PATCH 2/2] block: add a partscan sysfs attribute for disks Christoph Hellwig @ 2024-04-30 14:25 ` Lennart Poettering 2 siblings, 0 replies; 6+ messages in thread From: Lennart Poettering @ 2024-04-30 14:25 UTC (permalink / raw) To: Christoph Hellwig; +Cc: Jens Axboe, linux-block On Mo, 29.04.24 19:48, Christoph Hellwig (hch@lst.de) wrote: > 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* add a partscan sysfs attribute v2 @ 2024-05-02 13:00 Christoph Hellwig 2024-05-02 13:00 ` [PATCH 1/2] block: add a disk_has_partscan helper Christoph Hellwig 0 siblings, 1 reply; 6+ messages in thread From: Christoph Hellwig @ 2024-05-02 13:00 UTC (permalink / raw) To: Jens Axboe; +Cc: Lennart Poettering, linux-block 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(-) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] block: add a disk_has_partscan helper 2024-05-02 13:00 add a partscan sysfs attribute v2 Christoph Hellwig @ 2024-05-02 13:00 ` Christoph Hellwig 0 siblings, 0 replies; 6+ messages in thread From: Christoph Hellwig @ 2024-05-02 13:00 UTC (permalink / raw) To: Jens Axboe; +Cc: Lennart Poettering, linux-block 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. Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/genhd.c | 7 ++----- block/partitions/core.c | 5 +---- include/linux/blkdev.h | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index eb893df56d510e..4b85963d09dbb4 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -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); diff --git a/block/partitions/core.c b/block/partitions/core.c index b11e88c82c8cfa..37b5f92d07fec9 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -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); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 040a22e0eda0ec..3b18a40a1fc109 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -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. -- 2.39.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-02 13:00 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-04-29 17:48 add a partscan sysfs attribute Christoph Hellwig 2024-04-29 17:49 ` [PATCH 1/2] block: add a disk_has_partscan helper Christoph Hellwig 2024-04-29 17:49 ` [PATCH 2/2] block: add a partscan sysfs attribute for disks Christoph Hellwig 2024-04-30 14:10 ` John Garry 2024-04-30 14:25 ` add a partscan sysfs attribute Lennart Poettering -- strict thread matches above, loose matches on Subject: below -- 2024-05-02 13:00 add a partscan sysfs attribute v2 Christoph Hellwig 2024-05-02 13:00 ` [PATCH 1/2] block: add a disk_has_partscan helper Christoph Hellwig
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.