Commit Graph
23 Commits
Author SHA1 Message Date
Lennart Poettering 48a9afb6ec 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.
2026-09-23 10:08:36 +02:00
Zbigniew Jędrzejewski-Szmek 2e18587872 shared/blockdev-list: allow uninitalized devices
This means we can gather stats without udev running, which can be good
in containers and such.
2026-08-24 21:24:04 +02:00
Zbigniew Jędrzejewski-Szmek 47df51ea40 shared/blockdev-list: add flag to gather read&write stats 2026-08-24 21:24:00 +02:00
Zbigniew Jędrzejewski-Szmek ad997d0630 shared/blockdev-list: add flag to gather diskseq stats
Only one caller ever looks at this field. Let's optimize a bit.
2026-08-21 20:14:43 +02:00
Zbigniew Jędrzejewski-Szmek b298d68dd0 shared/blockdev-list: add flags to ignore virtual devices and partitions 2026-08-21 20:14:42 +02:00
Lennart Poettering 5af1038123 blockdev-list: split per-device filtering into blockdev_list_one()
Subscribers to block-device uevents need to apply the same filter set
blockdev_list() uses over the bulk enumeration, one device at a time.
Pull the per-device body out as blockdev_list_one(), expose
blockdev_list_get_root_devnos() so callers can compute the IGNORE_ROOT
devnos once up-front, and introduce a 4-valued return code so callers
can distinguish:

  MATCH_NO       - fails a static filter (subsystem, ZRAM, IGNORE_ROOT,
                   REQUIRE_PARTITION_SCANNING, REQUIRE_LUKS)
  MATCH_YES      - fully matches
  MATCH_FILTERED - passes static filters but fails a dynamic one
                   (IGNORE_EMPTY, IGNORE_READ_ONLY) - useful to surface
                   as "device just became invisible" transitions when
                   the kernel flips size/ro at runtime
  MATCH_SKIPPED  - soft error during filter evaluation; callers should
                   treat this like MATCH_FILTERED, but the distinct code
                   makes the soft failure visible rather than silently
                   swallowed inside blockdev_list_one()

*ret is initialized on every non-negative return (BLOCK_DEVICE_NULL for
MATCH_NO / MATCH_SKIPPED, fully populated for MATCH_YES / MATCH_FILTERED),
and untouched on negative return. blockdev_list() itself collapses
everything except MATCH_YES back into "skip", so existing callers see
no behavior change.
2026-06-01 11:26:06 +02:00
Lennart Poettering a69f0b8b28 repart: hide read-only block devices from candidates
If they are read-only they are no candidates, since we cannot write to
them.
2026-04-30 08:04:55 +02:00
Christian Brauner 994f016a7f blockdev-list: fix per-element leak in block_device_array_free() (#41869)
FOREACH_ARRAY declares 'i' as the iterator but the body passed 'd' (the
array base) to block_device_done(). Since mfree() leaves the field NULL
after the first call, element 0 is freed repeatedly while elements
1..N-1 leak their node, symlinks strv, model, vendor and subsystem.

The bug predates the sanitizer-instrumented callers. PR #41776's new
systemd-storage-block daemon runs blockdev_list() under ASan/LSan in
TEST-87-AUX-UTILS-VM and exposes it (15 allocs / 804 bytes leaked per
ListVolumes request). The fix also benefits repart and blockdev_list's
internal CLEANUP_ARRAY cleanup.

Follow-up for 9f6b2745ea
2026-04-29 17:28:16 +01:00
Lennart Poettering 71d82cc638 blockdev-list: make BLOCKDEV_LIST_IGNORE_ROOT suppress all definitions of the root disk
There are various definitions of the root disk, let's suppress them all if
the flag is set. So far only the outermost is suppressed, which is a bit
weird, given it's "further away" from the rootfs.
2026-04-26 21:45:28 +02:00
Lennart Poettering 41a8cc281e blockdev-list: pick up read_only property 2026-04-26 21:21:49 +02:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Lennart Poettering 5f076e44fe repart: report vendor/model/subsystem fields in ListCandidateDevices
Prompted by: #39435
2025-11-01 22:01:35 +01:00
Lennart Poettering ea94a05f8a blockdev-list: switch to log_device_xyz() style logging 2025-11-01 22:01:35 +01:00
Luca Boccassi 8240a0942b blockdev-list: add overflow check assert
Fixes coverity warning

CID#1630794
2025-10-17 16:44:15 +01:00
Lennart Poettering ba793df4b9 blockdev-list,repart: optionally hide zero-size block devices
Block devices with removable media (e.g. SD card readers) indicate a
missing medium with a zero size. Optionally ignore such block devices
that carry no medium currently.
2025-09-23 09:25:11 +02:00
Lennart Poettering ed90a0cdc9 blockdev-list,repart: optionally, filter list of candidate block device and remove OS root disk 2025-09-23 09:23:55 +02:00
Lennart Poettering e863e2dbb5 blockdev-list: also pick up block device size 2025-09-23 09:18:21 +02:00
Lennart Poettering 9f6b2745ea blockdev-list: optionally return finds as list instead of writing it to stdout 2025-09-23 09:13:13 +02:00
Daan De Meyer 69a283c5f2 shared: Clean up includes
Split out of #37344.
2025-05-24 14:00:44 +02:00
Yu Watanabe ab1bd9daed device-util: introduce several more helper functions
This also makes device_in_subsystem() and device_is_devtype() return
negative error on critical error
2025-05-14 02:06:02 +09:00
Daan De Meyer e548ca38b9 device-util: Reduce transitive includes 2025-05-07 22:04:46 +09:00
Lennart Poettering b7120388f8 terminal-util: split out color macros/helpers into its own header
This is a lot of stuff, and sometimes quite wild, let's turn this into
its own header.

All stuff color-related that just generates sequences is now in
ansi-color.h (no .c file!), and everything more complex that
probes/ineracts with terminals remains in termina-util.[ch]
2024-07-19 11:44:04 +02:00
Lennart Poettering 68ff31fa0a util: add generic block device listener helper
Various of our tools operate on block devices, and it's not always
obvious to know which block devices are actually appropriate for use.
Hence, let's add a helper that allows to list block devices, and
supports some limited filtering.
2024-07-01 16:39:40 +02:00