From 97b3c393bf19e5cc939bbf9c5ea175fd8892bd6c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 24 Sep 2026 13:17:49 +0900 Subject: [PATCH] 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 236e7d8a4c4e872d724431a6f42f6f1725305cdd fails, as io.systemd.Repart.ListCandidateDevices varlink method lists the ramdisks. (cherry picked from commit 77c51f4e9705d17468a0aa47654bd86a3804a512) --- src/repart/repart-list-candidate-devices.c | 2 +- src/repart/repart.c | 2 +- src/shared/blockdev-list.c | 4 ++-- src/shared/blockdev-list.h | 2 +- src/storagetm/storagetm.c | 5 +++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/repart/repart-list-candidate-devices.c b/src/repart/repart-list-candidate-devices.c index 5e5c037ef9..73db5e0971 100644 --- a/src/repart/repart-list-candidate-devices.c +++ b/src/repart/repart-list-candidate-devices.c @@ -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| diff --git a/src/repart/repart.c b/src/repart/repart.c index 388f25c398..cef9de6c32 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -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); diff --git a/src/shared/blockdev-list.c b/src/shared/blockdev-list.c index fe71bd4ccc..262301eda0 100644 --- a/src/shared/blockdev-list.c +++ b/src/shared/blockdev-list.c @@ -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; diff --git a/src/shared/blockdev-list.h b/src/shared/blockdev-list.h index e79ad74a76..faa5accf21 100644 --- a/src/shared/blockdev-list.h +++ b/src/shared/blockdev-list.h @@ -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 */ diff --git a/src/storagetm/storagetm.c b/src/storagetm/storagetm.c index a04d72c042..9323a4a4df 100644 --- a/src/storagetm/storagetm.c +++ b/src/storagetm/storagetm.c @@ -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;