blockdev-list: split BLOCKDEV_LIST_IGNORE_LOOP out of BLOCKDEV_LIST_IGNORE_VIRTUAL

So far BLOCKDEV_LIST_IGNORE_VIRTUAL filtered out everything below
/sys/devices/virtual/, which includes loopback devices. Loopback devices
are frequently used as stand-ins for real disks though (in tests, and
when installing to disk images), hence it's useful to be able to control
them independently of the other virtual devices (dm, md, zram, …).

Introduce a separate BLOCKDEV_LIST_IGNORE_LOOP flag for loopback
devices, and make BLOCKDEV_LIST_IGNORE_VIRTUAL only cover the non-loop
virtual devices. The only existing user (systemd-report) is updated to
pass both flags, so that its behaviour stays unchanged.
This commit is contained in:
Lennart Poettering
2026-09-23 10:08:36 +02:00
parent 1c168322cf
commit 48a9afb6ec
3 changed files with 28 additions and 12 deletions
+16 -1
View File
@@ -167,7 +167,22 @@ int blockdev_list_one(
goto no_match;
}
if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_VIRTUAL)) {
bool is_loop = false;
if (flags & (BLOCKDEV_LIST_IGNORE_LOOP|BLOCKDEV_LIST_IGNORE_VIRTUAL)) {
r = device_sysname_startswith(dev, "loop");
if (r < 0) {
log_device_warning_errno(dev, r, "Failed to check device name of discovered block device '%s', ignoring: %m", node);
goto skipped;
}
is_loop = r > 0;
if (is_loop && FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_LOOP))
goto no_match;
}
/* Loopback devices are virtual devices too, but they are covered by BLOCKDEV_LIST_IGNORE_LOOP above,
* hence exclude them here. */
if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_VIRTUAL) && !is_loop) {
const char *devpath;
r = sd_device_get_devpath(dev, &devpath);