Skip to content

Commit 8cc1fe9

Browse files
yuwatabluca
authored andcommitted
blockdev-util: also check loop/partscan sysattr
With torvalds/linux@b9684a7 (v5.19), we cannot check partition scanning is enabled for a loopback block device without checking the attribute. (cherry picked from commit bab8c85) (cherry picked from commit ae7a07b) (cherry picked from commit e2fe7d8)
1 parent d55fcd8 commit 8cc1fe9

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/shared/blockdev-util.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,27 +394,46 @@ int blockdev_partscan_enabled(int fd) {
394394
* e81cd5a983bb35dabd38ee472cf3fea1c63e0f23, the flag was never used. So, fortunately, we can use
395395
* both the new and old values safely.
396396
*
397+
* With https://github.com/torvalds/linux/commit/b9684a71fca793213378dd410cd11675d973eaa1 (v5.19),
398+
* another flag GD_SUPPRESS_PART_SCAN is introduced for loopback block device, and partition scanning
399+
* is done only when both GENHD_FL_NO_PART and GD_SUPPRESS_PART_SCAN are not set. Before the commit,
400+
* LO_FLAGS_PARTSCAN flag was directly tied with GENHD_FL_NO_PART. But with this change now it is
401+
* tied with GD_SUPPRESS_PART_SCAN. So, LO_FLAGS_PARTSCAN cannot be obtained from 'ext_range'
402+
* sysattr, which corresponds to GENHD_FL_NO_PART, and we need to read 'loop/partscan'. 💣💣💣
403+
*
404+
* With https://github.com/torvalds/linux/commit/73a166d9749230d598320fdae3b687cdc0e2e205 (v6.3),
405+
* the GD_SUPPRESS_PART_SCAN flag is also introduced for userspace block device (ublk). Though, not
406+
* sure if we should support the device...
407+
*
397408
* With https://github.com/torvalds/linux/commit/e81cd5a983bb35dabd38ee472cf3fea1c63e0f23 (v6.3),
398-
* the 'capability' sysfs attribute is deprecated, hence we cannot check the flag from it.
409+
* the 'capability' sysfs attribute is deprecated, hence we cannot check flags from it. 💣💣💣
399410
*
400-
* With https://github.com/torvalds/linux/commit/a4217c6740dc64a3eb6815868a9260825e8c68c6
401-
* (backported to v6.9), the partscan status is directly exposed as 'partscan' sysattr.
411+
* With https://github.com/torvalds/linux/commit/a4217c6740dc64a3eb6815868a9260825e8c68c6 (v6.10,
412+
* backported to v6.9), the partscan status is directly exposed as 'partscan' sysattr.
402413
*
403-
* To support both old and new kernels, we need to do the following: first check 'partscan' attr
404-
* where the information is made directly available; then, fall back to 'ext_range' sysfs attribute,
405-
* and if '1' we can conclude partition scanning is disabled; otherwise check 'capability' sysattr
406-
* for ancient version. */
414+
* To support both old and new kernels, we need to do the following:
415+
* 1) check 'partscan' sysfs attribute where the information is made directly available,
416+
* 2) check 'loop/partscan' sysfs attribute for loopback block devices, and if '0' we can conclude
417+
* partition scanning is disabled,
418+
* 3) check 'ext_range' sysfs attribute, and if '1' we can conclude partition scanning is disabled,
419+
* 4) otherwise check 'capability' sysfs attribute for ancient version. */
407420

408421
assert(fd >= 0);
409422

410423
r = block_device_new_from_fd(fd, 0, &dev);
411424
if (r < 0)
412425
return r;
413426

427+
/* For v6.10 or newer. */
414428
r = device_get_sysattr_bool(dev, "partscan");
415429
if (r != -ENOENT)
416430
return r;
417431

432+
/* For loopback block device, especially for v5.19 or newer. Even if this is enabled, we also need to
433+
* check GENHD_FL_NO_PART flag through 'ext_range' and 'capability' sysfs attributes below. */
434+
if (device_get_sysattr_bool(dev, "loop/partscan") == 0)
435+
return false;
436+
418437
r = device_get_sysattr_int(dev, "ext_range", &ext_range);
419438
if (r == -ENOENT) /* If the ext_range file doesn't exist then we are most likely looking at a
420439
* partition block device, not the whole block device. And that means we have no

0 commit comments

Comments
 (0)