blockdev-list: also ignore ramdisk

This renames BLOCKDEV_LIST_IGNORE_ZRAM to BLOCKDEV_LIST_IGNORE_RAMDISK,
and make it ignores both /dev/ramX and /dev/zramX.

Note, linux-stable by Alpine/postmarketOS has CONFIG_BLK_DEV_RAM=y,
hence the kernel creates /dev/ramX by default. Without this change,
the test case added by 236e7d8a4c fails,
as io.systemd.Repart.ListCandidateDevices varlink method lists the
ramdisks.

(cherry picked from commit 77c51f4e97)
This commit is contained in:
Yu Watanabe
2026-10-16 11:36:32 +01:00
committed by Luca Boccassi
parent b0bac1d35b
commit 97b3c393bf
5 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -160,7 +160,7 @@ int vl_method_list_candidate_devices(
const BlockDevListFlags listflags =
BLOCKDEV_LIST_SHOW_SYMLINKS|
BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING|
BLOCKDEV_LIST_IGNORE_ZRAM|
BLOCKDEV_LIST_IGNORE_RAMDISK|
BLOCKDEV_LIST_IGNORE_READ_ONLY|
BLOCKDEV_LIST_METADATA|
BLOCKDEV_LIST_DISKSEQ|
+1 -1
View File
@@ -10483,7 +10483,7 @@ static int parse_argv(int argc, char *argv[]) {
r = blockdev_list(
BLOCKDEV_LIST_SHOW_SYMLINKS|
BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING|
BLOCKDEV_LIST_IGNORE_ZRAM|
BLOCKDEV_LIST_IGNORE_RAMDISK|
BLOCKDEV_LIST_IGNORE_READ_ONLY,
/* ret_devices= */ NULL,
/* ret_n_devices= */ NULL);
+2 -2
View File
@@ -190,8 +190,8 @@ int blockdev_list_one(
goto no_match;
}
if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ZRAM)) {
r = device_sysname_startswith(dev, "zram");
if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_RAMDISK)) {
r = device_sysname_startswith(dev, "ram", "zram");
if (r < 0) {
log_device_warning_errno(dev, r, "Failed to check device name of discovered block device '%s', ignoring: %m", node);
goto skipped;
+1 -1
View File
@@ -8,7 +8,7 @@ typedef enum BlockDevListFlags {
BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING = 1 << 1, /* Only consider block devices with partition scanning */
BLOCKDEV_LIST_IGNORE_VIRTUAL = 1 << 2, /* Ignore virtual devices (devices under /sys/devices/virtual/) */
BLOCKDEV_LIST_IGNORE_PARTITIONS = 1 << 3, /* Ignore partitions */
BLOCKDEV_LIST_IGNORE_ZRAM = 1 << 4, /* Ignore ZRAM */
BLOCKDEV_LIST_IGNORE_RAMDISK = 1 << 4, /* Ignore RAMDISK (by brd module) and ZRAM (by zram module) */
BLOCKDEV_LIST_IGNORE_ROOT = 1 << 5, /* Ignore the block device we are currently booted from */
BLOCKDEV_LIST_IGNORE_EMPTY = 1 << 6, /* Ignore disks of zero size (usually drives without a medium) */
BLOCKDEV_LIST_IGNORE_READ_ONLY = 1 << 7, /* Ignore read-only block devices */
+3 -2
View File
@@ -88,7 +88,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_LONG("list-devices", NULL,
"List candidate block devices to operate on"):
r = blockdev_list(BLOCKDEV_LIST_SHOW_SYMLINKS|BLOCKDEV_LIST_IGNORE_ZRAM, /* ret_devices= */ NULL, /* ret_n_devices= */ NULL);
r = blockdev_list(BLOCKDEV_LIST_SHOW_SYMLINKS|BLOCKDEV_LIST_IGNORE_RAMDISK,
/* ret_devices= */ NULL, /* ret_n_devices= */ NULL);
if (r < 0)
return r;
@@ -912,7 +913,7 @@ static int device_added(Context *c, sd_device *device) {
log_device_debug(device, "new block device '%s'", sysname);
if (STARTSWITH_SET(sysname, "loop", "zram")) /* Ignore some devices */
if (STARTSWITH_SET(sysname, "loop", "ram", "zram")) /* Ignore some devices */
return 0;
const char *devname;