]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-util: "partscan" sysattr now directly shows the enabled state
authorMike Yuan <me@yhndnzj.com>
Sun, 26 May 2024 07:54:06 +0000 (15:54 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sun, 26 May 2024 11:52:31 +0000 (13:52 +0200)
See also: https://lore.kernel.org/r/20240502130033.1958492-3-hch@lst.de

src/shared/blockdev-util.c

index 8861cc07ba2715a4b55cf6b6e3b6b63b56b1baeb..9ae66ff2002be91cf157d1e388468046ab018e55 100644 (file)
@@ -375,9 +375,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);
 
@@ -385,6 +389,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