From 34a5e47508e117dda4bd02abad7b2110e987110a Mon Sep 17 00:00:00 2001 From: Eduard Shishkin Date: Wed, 16 Apr 2025 19:30:25 +0200 Subject: [PATCH] zipl_helper.device-mapper: Fix imprecise is_device_mapper() predicate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix is_device_mapper() predicate to not base on checking a hardcoded major number (253), which not always correct, since on some systems dm-devices have different majors". Reviewed-by: Stefan Haberland Signed-off-by: Eduard Shishkin Signed-off-by: Jan Höppner --- include/lib/util_proc.h | 1 + zipl/include/misc.h | 1 + zipl/src/disk.c | 5 +---- zipl/src/misc.c | 13 ++++++++++++- zipl/src/zipl_helper.device-mapper.c | 17 +++++++++++++---- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/lib/util_proc.h b/include/lib/util_proc.h index 2f544f65..8ab4be1e 100644 --- a/include/lib/util_proc.h +++ b/include/lib/util_proc.h @@ -31,6 +31,7 @@ struct util_proc_dev_entry { #define UTIL_PROC_DEV_ENTRY_SD "sd" #define UTIL_PROC_DEV_ENTRY_BLKEXT "blkext" #define UTIL_PROC_DEV_ENTRY_MD "md" +#define UTIL_PROC_DEV_ENTRY_DM "device-mapper" int util_proc_part_get_entry(dev_t device, struct util_proc_part_entry *entry); void util_proc_part_free_entry(struct util_proc_part_entry *entry); diff --git a/zipl/include/misc.h b/zipl/include/misc.h index 572dd1b8..01f3a323 100644 --- a/zipl/include/misc.h +++ b/zipl/include/misc.h @@ -58,6 +58,7 @@ int misc_check_writable_device(const char* devno, int blockdev, int chardev); void misc_ebcdic_to_ascii(unsigned char *from, unsigned char *to); void misc_ascii_to_ebcdic(unsigned char *from, unsigned char *to); unsigned int misc_check_secure_boot(void); +void misc_warn_on_failed_pdge(dev_t device); #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) #endif /* not MISC_H */ diff --git a/zipl/src/disk.c b/zipl/src/disk.c index a9318463..7d4fe853 100644 --- a/zipl/src/disk.c +++ b/zipl/src/disk.c @@ -509,10 +509,7 @@ static void set_driver_name(int fd, struct disk_info *info, dev_t device) info->drv_name = misc_strdup(dev_entry.name); util_proc_dev_free_entry(&dev_entry); } else { - fprintf(stderr, "Warning: Could not determine driver name for " - "major %d from /proc/devices\n", major(device)); - fprintf(stderr, "Warning: Preparing a logical device for boot " - "might fail\n"); + misc_warn_on_failed_pdge(device); } } diff --git a/zipl/src/misc.c b/zipl/src/misc.c index 236f55af..b2d7fa29 100644 --- a/zipl/src/misc.c +++ b/zipl/src/misc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "error.h" @@ -662,4 +663,14 @@ void misc_ascii_to_ebcdic(unsigned char *from, unsigned char *to) *from = ascebc[*from]; } - +/** + * zipl-specific response on failed util_proc_dev_get_entry() + */ +void misc_warn_on_failed_pdge(dev_t device) +{ + fprintf(stderr, + "Warning: Could not determine driver name for major %d from /proc/devices\n", + major(device)); + fprintf(stderr, + "Warning: Preparing a logical device for boot might fail\n"); +} diff --git a/zipl/src/zipl_helper.device-mapper.c b/zipl/src/zipl_helper.device-mapper.c index 0da35c7e..f189848d 100644 --- a/zipl/src/zipl_helper.device-mapper.c +++ b/zipl/src/zipl_helper.device-mapper.c @@ -180,7 +180,6 @@ struct helper { #define SCSI_PARTN_MASK 0x0f #define MD_MAJOR 9 -#define DEVICE_MAPPER_MAJOR 253 /* Internal constants */ enum dev_type { @@ -231,9 +230,19 @@ static int error_on(const char *state, const char *this, const char *fixup, return 0; } -static int is_device_mapper(unsigned int major) +static int is_device_mapper(dev_t device) { - return major == DEVICE_MAPPER_MAJOR; + struct util_proc_dev_entry pde; + int result = 0; + + if (util_proc_dev_get_entry(device, 1, &pde) == 0) { + if (strcmp(pde.name, UTIL_PROC_DEV_ENTRY_DM) == 0) + result = 1; + util_proc_dev_free_entry(&pde); + } else { + misc_warn_on_failed_pdge(device); + } + return result; } static void get_type_name(char *name, unsigned short type) @@ -1705,7 +1714,7 @@ static int md_mirror_to_params(unsigned int major, unsigned int minor, ERR("Unsupported configuration: nested md devices\n"); return -1; } - if (is_device_mapper(major)) { + if (is_device_mapper(dev)) { struct ext_dev xdev = {dev, data_start_md + fs_start_md}; char *name;