From 289c679c80bd248130b2b19602d49c177ffcf4f2 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 26 May 2024 15:54:06 +0800 Subject: [PATCH] blockdev-util: "partscan" sysattr now directly shows the enabled state See also: https://lore.kernel.org/r/20240502130033.1958492-3-hch@lst.de (cherry picked from commit 100bed702b73414161d57adff71e07329c1016ac) --- src/shared/blockdev-util.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index 7a2dd1c5d0..a5fe05e5c7 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -386,9 +386,13 @@ int blockdev_partscan_enabled(int fd) { * With https://github.com/torvalds/linux/commit/e81cd5a983bb35dabd38ee472cf3fea1c63e0f23 (v6.3), * the 'capability' sysfs attribute is deprecated, hence we cannot check the flag from it. * - * To support both old and new kernels, we need to do the following: first check 'ext_range' sysfs - * attribute, and if '1' we can conclude partition scanning is disabled, otherwise check 'capability' - * sysattr for older version. */ + * With https://github.com/torvalds/linux/commit/a4217c6740dc64a3eb6815868a9260825e8c68c6 + * (backported to v6.9), the partscan status is directly exposed as 'partscan' sysattr. + * + * To support both old and new kernels, we need to do the following: first check 'partscan' attr + * where the information is made directly available; then, fall back to 'ext_range' sysfs attribute, + * and if '1' we can conclude partition scanning is disabled; otherwise check 'capability' sysattr + * for ancient version. */ assert(fd >= 0); @@ -396,6 +400,10 @@ int blockdev_partscan_enabled(int fd) { if (r < 0) return r; + r = device_get_sysattr_bool(dev, "partscan"); + if (r != -ENOENT) + return r; + r = device_get_sysattr_int(dev, "ext_range", &ext_range); if (r == -ENOENT) /* If the ext_range file doesn't exist then we are most likely looking at a * partition block device, not the whole block device. And that means we have no