Skip to content

Commit 3ffef55

Browse files
Christoph Hellwiggregkh
authored andcommitted
block: add a partscan sysfs attribute for disks
commit a4217c6 upstream. 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. Cc: stable@vger.kernel.org # 6.3+ Depends-on: 140ce28 ("block: add a disk_has_partscan helper") Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/linux-block/ZhQJf8mzq_wipkBH@gardel-login/ Link: https://lore.kernel.org/r/20240502130033.1958492-3-hch@lst.de [axboe: add links and commit message from Keith] Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d6b6dff commit 3ffef55

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Documentation/ABI/stable/sysfs-block

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ Description:
101101
devices that support receiving integrity metadata.
102102

103103

104+
What: /sys/block/<disk>/partscan
105+
Date: May 2024
106+
Contact: Christoph Hellwig <hch@lst.de>
107+
Description:
108+
The /sys/block/<disk>/partscan files reports if partition
109+
scanning is enabled for the disk. It returns "1" if partition
110+
scanning is enabled, or "0" if not. The value type is a 32-bit
111+
unsigned integer, but only "0" and "1" are valid values.
112+
113+
104114
What: /sys/block/<disk>/<partition>/alignment_offset
105115
Date: April 2009
106116
Contact: Martin K. Petersen <martin.petersen@oracle.com>

block/genhd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,12 @@ static ssize_t diskseq_show(struct device *dev,
10371037
return sprintf(buf, "%llu\n", disk->diskseq);
10381038
}
10391039

1040+
static ssize_t partscan_show(struct device *dev,
1041+
struct device_attribute *attr, char *buf)
1042+
{
1043+
return sprintf(buf, "%u\n", disk_has_partscan(dev_to_disk(dev)));
1044+
}
1045+
10401046
static DEVICE_ATTR(range, 0444, disk_range_show, NULL);
10411047
static DEVICE_ATTR(ext_range, 0444, disk_ext_range_show, NULL);
10421048
static DEVICE_ATTR(removable, 0444, disk_removable_show, NULL);
@@ -1050,6 +1056,7 @@ static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
10501056
static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
10511057
static DEVICE_ATTR(badblocks, 0644, disk_badblocks_show, disk_badblocks_store);
10521058
static DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL);
1059+
static DEVICE_ATTR(partscan, 0444, partscan_show, NULL);
10531060

10541061
#ifdef CONFIG_FAIL_MAKE_REQUEST
10551062
ssize_t part_fail_show(struct device *dev,
@@ -1096,6 +1103,7 @@ static struct attribute *disk_attrs[] = {
10961103
&dev_attr_events_async.attr,
10971104
&dev_attr_events_poll_msecs.attr,
10981105
&dev_attr_diskseq.attr,
1106+
&dev_attr_partscan.attr,
10991107
#ifdef CONFIG_FAIL_MAKE_REQUEST
11001108
&dev_attr_fail.attr,
11011109
#endif

0 commit comments

Comments
 (0)