Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package mdadm for openSUSE:Factory checked in at 2023-04-28 16:22:05 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/mdadm (Old) and /work/SRC/openSUSE:Factory/.mdadm.new.1533 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "mdadm" Fri Apr 28 16:22:05 2023 rev:142 rq:1083057 version:4.2 Changes: -------- --- /work/SRC/openSUSE:Factory/mdadm/mdadm.changes 2023-04-04 21:16:56.459859387 +0200 +++ /work/SRC/openSUSE:Factory/.mdadm.new.1533/mdadm.changes 2023-04-28 16:22:07.909577187 +0200 @@ -1,0 +2,23 @@ +Mon Apr 24 15:06:42 UTC 2023 - Coly Li <[email protected]> + +- Fixes for mdmon to ensure it run at the right time in the + fight mount namespace. This fixes various problems with + IMSM raid arrays in 15-SP4 (bsc#1205493, bsc#1205830) + - mdmon: fix segfault + 0052-mdmon-fix-segfault.patch + - util: remove obsolete code from get_md_name + 0053-util-remove-obsolete-code-from-get_md_name.patch + - mdmon: don't test both 'all' and 'container_name'. + 0054-mdmon-don-t-test-both-all-and-container_name.patch + - mdmon: change systemd unit file to use --foreground + 0055-mdmon-change-systemd-unit-file-to-use-foreground.patch + - mdmon: Remove need for KillMode=none + 0056-mdmon-Remove-need-for-KillMode-none.patch + - mdmon: Improve switchroot interactions. + 0057-mdmon-Improve-switchroot-interactions.patch + - mdopen: always try create_named_array() + 0058-mdopen-always-try-create_named_array.patch + - Improvements for IMSM_NO_PLATFORM testing + 0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch + +------------------------------------------------------------------- New: ---- 0052-mdmon-fix-segfault.patch 0053-util-remove-obsolete-code-from-get_md_name.patch 0054-mdmon-don-t-test-both-all-and-container_name.patch 0055-mdmon-change-systemd-unit-file-to-use-foreground.patch 0056-mdmon-Remove-need-for-KillMode-none.patch 0057-mdmon-Improve-switchroot-interactions.patch 0058-mdopen-always-try-create_named_array.patch 0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ mdadm.spec ++++++ --- /var/tmp/diff_new_pack.xbVRuQ/_old 2023-04-28 16:22:09.261585079 +0200 +++ /var/tmp/diff_new_pack.xbVRuQ/_new 2023-04-28 16:22:09.269585126 +0200 @@ -92,6 +92,14 @@ Patch49: 0049-ReadMe-fix-command-line-help.patch Patch50: 0050-mdadm-replace-container-level-checking-with-inline.patch Patch51: 0051-Mdmonitor-Omit-non-md-devices.patch +Patch52: 0052-mdmon-fix-segfault.patch +Patch53: 0053-util-remove-obsolete-code-from-get_md_name.patch +Patch54: 0054-mdmon-don-t-test-both-all-and-container_name.patch +Patch55: 0055-mdmon-change-systemd-unit-file-to-use-foreground.patch +Patch56: 0056-mdmon-Remove-need-for-KillMode-none.patch +Patch57: 0057-mdmon-Improve-switchroot-interactions.patch +Patch58: 0058-mdopen-always-try-create_named_array.patch +Patch59: 0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch Patch1001: 1001-display-timeout-status.patch Patch1002: 1002-OnCalendar-format-fix-of-mdcheck_start-timer.patch Patch1003: 1003-mdadm-treat-the-Dell-softraid-array-as-local-array.patch @@ -155,6 +163,14 @@ %patch49 -p1 %patch50 -p1 %patch51 -p1 +%patch52 -p1 +%patch53 -p1 +%patch54 -p1 +%patch55 -p1 +%patch56 -p1 +%patch57 -p1 +%patch58 -p1 +%patch59 -p1 %patch1001 -p1 %patch1002 -p1 %patch1003 -p1 ++++++ 0052-mdmon-fix-segfault.patch ++++++ >From 9b429fc0a4ffd7028b3b336589d38e32fb9045dc Mon Sep 17 00:00:00 2001 From: Mateusz Kusiak <[email protected]> Date: Mon, 2 Jan 2023 09:46:21 +0100 Subject: [PATCH] mdmon: fix segfault Mdmon crashes if stat2devnm returns null. Use open_mddev to check if device is mddevice and get name using fd2devnm. Refactor container name handling. Signed-off-by: Mateusz Kusiak <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> Signed-off-by: Coly Li <[email protected]> --- Makefile | 2 +- mdmon.c | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index ec1f99e..5eac1a4 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ SRCS = $(patsubst %.o,%.c,$(OBJS)) INCL = mdadm.h part.h bitmap.h -MON_OBJS = mdmon.o monitor.o managemon.o uuid.o util.o maps.o mdstat.o sysfs.o \ +MON_OBJS = mdmon.o monitor.o managemon.o uuid.o util.o maps.o mdstat.o sysfs.o config.o mapfile.o mdopen.o\ policy.o lib.o \ Kill.o sg_io.o dlink.o ReadMe.o super-intel.o \ super-mbr.o super-gpt.o \ diff --git a/mdmon.c b/mdmon.c index e9d035e..ecf52dc 100644 --- a/mdmon.c +++ b/mdmon.c @@ -363,14 +363,14 @@ int main(int argc, char *argv[]) } if (all == 0 && container_name == NULL) { - if (argv[optind]) - container_name = argv[optind]; + if (argv[optind]) { + container_name = get_md_name(argv[optind]); + if (!container_name) + container_name = argv[optind]; + } } - if (container_name == NULL) - usage(); - - if (argc - optind > 1) + if (container_name == NULL || argc - optind > 1) usage(); if (strcmp(container_name, "/proc/mdstat") == 0) @@ -402,21 +402,19 @@ int main(int argc, char *argv[]) free_mdstat(mdstat); return status; - } else if (strncmp(container_name, "md", 2) == 0) { - int id = devnm2devid(container_name); - if (id) - devnm = container_name; } else { - struct stat st; + int mdfd = open_mddev(container_name, 1); - if (stat(container_name, &st) == 0) - devnm = xstrdup(stat2devnm(&st)); + if (mdfd < 0) + return 1; + devnm = fd2devnm(mdfd); + close(mdfd); } if (!devnm) { pr_err("%s is not a valid md device name\n", container_name); - exit(1); + return 1; } return mdmon(devnm, dofork && do_fork(), takeover); } -- 2.35.3 ++++++ 0053-util-remove-obsolete-code-from-get_md_name.patch ++++++ >From b938519e7719c992dae2d61c796c45fe49e6b71b Mon Sep 17 00:00:00 2001 From: Mateusz Kusiak <[email protected]> Date: Mon, 2 Jan 2023 09:46:22 +0100 Subject: [PATCH] util: remove obsolete code from get_md_name get_md_name() is used only with mdstat entries. Remove dead code and simplyfy function. Remove redundadnt checks from mdmon.c Signed-off-by: Mateusz Kusiak <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> Signed-off-by: Coly Li <[email protected]> --- mdmon.c | 8 +++----- util.c | 51 +++++++++++++++++---------------------------------- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/mdmon.c b/mdmon.c index ecf52dc..60ba318 100644 --- a/mdmon.c +++ b/mdmon.c @@ -366,7 +366,7 @@ int main(int argc, char *argv[]) if (argv[optind]) { container_name = get_md_name(argv[optind]); if (!container_name) - container_name = argv[optind]; + return 1; } } @@ -403,11 +403,9 @@ int main(int argc, char *argv[]) return status; } else { - int mdfd = open_mddev(container_name, 1); - - if (mdfd < 0) - return 1; + int mdfd = open_mddev(container_name, 0); devnm = fd2devnm(mdfd); + close(mdfd); } diff --git a/util.c b/util.c index 26ffdce..9cd89fa 100644 --- a/util.c +++ b/util.c @@ -968,47 +968,30 @@ dev_t devnm2devid(char *devnm) return 0; } +/** + * get_md_name() - Get main dev node of the md device. + * @devnm: Md device name or path. + * + * Function checks if the full name was passed and returns md name + * if it is the MD device. + * + * Return: Main dev node of the md device or NULL if not found. + */ char *get_md_name(char *devnm) { - /* find /dev/md%d or /dev/md/%d or make a device /dev/.tmp.md%d */ - /* if dev < 0, want /dev/md/d%d or find mdp in /proc/devices ... */ - - static char devname[50]; + static char devname[NAME_MAX]; struct stat stb; - dev_t rdev = devnm2devid(devnm); - char *dn; - if (rdev == 0) - return 0; - if (strncmp(devnm, "md_", 3) == 0) { - snprintf(devname, sizeof(devname), "/dev/md/%s", - devnm + 3); - if (stat(devname, &stb) == 0 && - (S_IFMT&stb.st_mode) == S_IFBLK && (stb.st_rdev == rdev)) - return devname; - } - snprintf(devname, sizeof(devname), "/dev/%s", devnm); - if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK && - (stb.st_rdev == rdev)) - return devname; + if (strncmp(devnm, "/dev/", 5) == 0) + snprintf(devname, sizeof(devname), "%s", devnm); + else + snprintf(devname, sizeof(devname), "/dev/%s", devnm); - snprintf(devname, sizeof(devname), "/dev/md/%s", devnm+2); - if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK && - (stb.st_rdev == rdev)) + if (!is_mddev(devname)) + return NULL; + if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK) return devname; - dn = map_dev(major(rdev), minor(rdev), 0); - if (dn) - return dn; - snprintf(devname, sizeof(devname), "/dev/.tmp.%s", devnm); - if (mknod(devname, S_IFBLK | 0600, rdev) == -1) - if (errno != EEXIST) - return NULL; - - if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK && - (stb.st_rdev == rdev)) - return devname; - unlink(devname); return NULL; } -- 2.35.3 ++++++ 0054-mdmon-don-t-test-both-all-and-container_name.patch ++++++ >From d39fd87e31024804dd7f2c16c03af0379b71f5f1 Mon Sep 17 00:00:00 2001 From: NeilBrown <[email protected]> Date: Mon, 13 Mar 2023 14:42:58 +1100 Subject: [PATCH] mdmon: don't test both 'all' and 'container_name'. If 'all' is not set, then container_name must be NULL, as nothing else can set it. So simplify the test to ignore container_name. This makes the purpose of the code more obvious. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> --- mdmon.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mdmon.c b/mdmon.c index 60ba318..f8fd2f0 100644 --- a/mdmon.c +++ b/mdmon.c @@ -352,7 +352,6 @@ int main(int argc, char *argv[]) } } - if (in_initrd()) { /* * set first char of argv[0] to @. This is used by @@ -362,12 +361,10 @@ int main(int argc, char *argv[]) argv[0][0] = '@'; } - if (all == 0 && container_name == NULL) { - if (argv[optind]) { - container_name = get_md_name(argv[optind]); - if (!container_name) - return 1; - } + if (!all && argv[optind]) { + container_name = get_md_name(argv[optind]); + if (!container_name) + return 1; } if (container_name == NULL || argc - optind > 1) -- 2.35.3 ++++++ 0055-mdmon-change-systemd-unit-file-to-use-foreground.patch ++++++ >From 6660e33edde76329bd3b7f03383856c7efee2aa9 Mon Sep 17 00:00:00 2001 From: NeilBrown <[email protected]> Date: Mon, 13 Mar 2023 14:42:58 +1100 Subject: [PATCH] mdmon: change systemd unit file to use --foreground There is no value in mdmon forking when it is running under systemd - systemd can still track it anyway. So add --foreground option, and remove "Type=forking". Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> --- systemd/[email protected] | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/systemd/[email protected] b/systemd/[email protected] index cb6482d..bba9b0e 100644 --- a/systemd/[email protected] +++ b/systemd/[email protected] @@ -20,8 +20,7 @@ Environment=IMSM_NO_PLATFORM=1 # 'takeover'. As the '--offroot --takeover' don't hurt when # not necessary, are are useful with root-on-md in dracut, # have them always present. -ExecStart=BINDIR/mdmon --offroot --takeover %I -Type=forking +ExecStart=BINDIR/mdmon --foreground --offroot --takeover %I # Don't set the PIDFile. It isn't necessary (systemd can work # it out) and systemd will remove it when transitioning from # initramfs to rootfs. -- 2.35.3 ++++++ 0056-mdmon-Remove-need-for-KillMode-none.patch ++++++ >From 0f9a4b3e11fbe4f8631d20b1f89cf43e9219db55 Mon Sep 17 00:00:00 2001 From: NeilBrown <[email protected]> Date: Mon, 13 Mar 2023 14:42:58 +1100 Subject: [PATCH] mdmon: Remove need for KillMode=none mdmon needs to keep running during the switchroot out of (at boot) and then back into (at shutdown) the initrd. It runs until a new mdmon takes over. Killmode=none is used to achieve this, with the help of --offroot which sets argv[0][0] to '@' which systemd understands. This is needed because mdmon is currently run in system-mdmon.slice which conflicts with shutdown.target so without Killmode=none mdmon would get killed early in shutdown when system.mdmon.slice is removed. As described in systemd.service(5), this conflict with shutdown can be resolved by explicitly requesting system.slice, which is a natural counterpart to DefaultDependencies=no. So add that, and also add IgnoreOnIsolate=true to avoid another possible source of an early death. With these we no longer need KillMode=none which the systemd developers have marked as "deprecated". Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> --- systemd/[email protected] | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/systemd/[email protected] b/systemd/[email protected] index bba9b0e..303ad05 100644 --- a/systemd/[email protected] +++ b/systemd/[email protected] @@ -10,6 +10,9 @@ Description=MD Metadata Monitor on /dev/%I DefaultDependencies=no Before=initrd-switch-root.target Documentation=man:mdmon(8) +# Allow mdmon to keep running after switchroot, until a new +# instance is started. +IgnoreOnIsolate=true [Service] # mdmon should never complain due to lack of a platform, @@ -25,4 +28,6 @@ ExecStart=BINDIR/mdmon --foreground --offroot --takeover %I # it out) and systemd will remove it when transitioning from # initramfs to rootfs. #PIDFile=/run/mdadm/%I.pid -KillMode=none +# The default slice is system-mdmon.slice which Conflicts +# with shutdown, causing mdmon to exit early. So use system.slice. +Slice=system.slice -- 2.35.3 ++++++ 0057-mdmon-Improve-switchroot-interactions.patch ++++++ >From 723d1df4946eb40337bf494f9b2549500c1399b2 Mon Sep 17 00:00:00 2001 From: NeilBrown <[email protected]> Date: Mon, 13 Mar 2023 14:42:58 +1100 Subject: [PATCH] mdmon: Improve switchroot interactions. We need a new mdmon@mdfoo instance to run in the root filesystem after switch root, as /sys and /dev are removed from the initrd. systemd will not start a new unit with the same name running while the old unit is still active, and we want the two mdmon processes to overlap in time to avoid any risk of deadlock, which can happen when a write is attempted with no mdmon running. So we need a different unit name in the initrd than in the root. Apart from the name, everything else should be the same. This is easily achieved using a different instance name as the [email protected] unit file already supports multiple instances (for different arrays). So start "[email protected]" from root, but "[email protected]" from the initrd. udev can tell which circumstance is the case by looking for /etc/initrd-release. continue_from_systemd() is enhanced so that the "initrd-" prefix can be requested. Teach mdmon that a container name like "initrd/foo" should be treated just like "foo". Note that systemd passes the instance name "initrd-foo" as "initrd/foo". We don't need a similar mechanism at shutdown because dracut runs "mdmon --takeover --all" when appropriate. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> --- Grow.c | 4 ++-- mdadm.h | 2 +- mdmon.c | 7 ++++++- systemd/[email protected] | 2 +- udev-md-raid-arrays.rules | 3 ++- util.c | 7 ++++--- 6 files changed, 16 insertions(+), 9 deletions(-) Index: mdadm-4.2/Grow.c =================================================================== --- mdadm-4.2.orig/Grow.c +++ mdadm-4.2/Grow.c @@ -3513,7 +3513,7 @@ started: if (!forked) if (continue_via_systemd(container ?: sra->sys_name, - GROW_SERVICE)) { + GROW_SERVICE, NULL)) { free(fdlist); free(offsets); sysfs_free(sra); @@ -3711,7 +3711,7 @@ int reshape_container(char *container, c ping_monitor(container); if (!forked && !freeze_reshape) - if (continue_via_systemd(container, GROW_SERVICE)) + if (continue_via_systemd(container, GROW_SERVICE, NULL)) return 0; switch (forked ? 0 : fork()) { Index: mdadm-4.2/mdadm.h =================================================================== --- mdadm-4.2.orig/mdadm.h +++ mdadm-4.2/mdadm.h @@ -1550,7 +1550,7 @@ extern int same_dev(char *one, char *two extern int compare_paths (char* path1,char* path2); extern void enable_fds(int devices); extern void manage_fork_fds(int close_all); -extern int continue_via_systemd(char *devnm, char *service_name); +extern int continue_via_systemd(char *devnm, char *service_name, char *prefix); extern int parse_auto(char *str, char *msg, int config); extern struct mddev_ident *conf_get_ident(char *dev); Index: mdadm-4.2/mdmon.c =================================================================== --- mdadm-4.2.orig/mdmon.c +++ mdadm-4.2/mdmon.c @@ -362,7 +362,12 @@ int main(int argc, char *argv[]) } if (!all && argv[optind]) { - container_name = get_md_name(argv[optind]); + static const char prefix[] = "initrd/"; + container_name = argv[optind]; + if (strncmp(container_name, prefix, + sizeof(prefix) - 1) == 0) + container_name += sizeof(prefix)-1; + container_name = get_md_name(container_name); if (!container_name) return 1; } Index: mdadm-4.2/systemd/[email protected] =================================================================== --- mdadm-4.2.orig/systemd/[email protected] +++ mdadm-4.2/systemd/[email protected] @@ -6,7 +6,7 @@ # (at your option) any later version. [Unit] -Description=MD Metadata Monitor on /dev/%I +Description=MD Metadata Monitor on %I DefaultDependencies=no Before=initrd-switch-root.target Documentation=man:mdmon(8) Index: mdadm-4.2/udev-md-raid-arrays.rules =================================================================== --- mdadm-4.2.orig/udev-md-raid-arrays.rules +++ mdadm-4.2/udev-md-raid-arrays.rules @@ -38,7 +38,8 @@ ENV{MD_LEVEL}=="raid[1-9]*", ENV{SYSTEMD # Tell systemd to run mdmon for our container, if we need it. ENV{MD_LEVEL}=="raid[1-9]*", ENV{MD_CONTAINER}=="?*", PROGRAM="/usr/bin/readlink $env{MD_CONTAINER}", ENV{MD_MON_THIS}="%c" -ENV{MD_MON_THIS}=="?*", PROGRAM="/usr/bin/basename $env{MD_MON_THIS}", ENV{SYSTEMD_WANTS}+="mdmon@%c.service" +ENV{MD_MON_THIS}=="?*", TEST=="/etc/initrd-release", PROGRAM="/usr/bin/basename $env{MD_MON_THIS}", ENV{SYSTEMD_WANTS}+="mdmon@initrd-%c.service" +ENV{MD_MON_THIS}=="?*", TEST!="/etc/initrd-release", PROGRAM="/usr/bin/basename $env{MD_MON_THIS}", ENV{SYSTEMD_WANTS}+="mdmon@%c.service" ENV{RESHAPE_ACTIVE}=="yes", PROGRAM="/usr/bin/basename $env{MD_MON_THIS}", ENV{SYSTEMD_WANTS}+="mdadm-grow-continue@%c.service" LABEL="md_end" Index: mdadm-4.2/util.c =================================================================== --- mdadm-4.2.orig/util.c +++ mdadm-4.2/util.c @@ -1906,6 +1906,7 @@ int start_mdmon(char *devnm) int len; pid_t pid; int status; + char *prefix = in_initrd() ? "initrd-" : ""; char pathbuf[1024]; char *paths[4] = { pathbuf, @@ -1916,7 +1917,7 @@ int start_mdmon(char *devnm) if (check_env("MDADM_NO_MDMON")) return 0; - if (continue_via_systemd(devnm, MDMON_SERVICE)) + if (continue_via_systemd(devnm, MDMON_SERVICE, prefix)) return 0; /* That failed, try running mdmon directly */ @@ -2187,7 +2188,7 @@ void manage_fork_fds(int close_all) * 1- if systemd service has been started * 0- otherwise */ -int continue_via_systemd(char *devnm, char *service_name) +int continue_via_systemd(char *devnm, char *service_name, char *prefix) { int pid, status; char pathbuf[1024]; @@ -2199,7 +2200,7 @@ int continue_via_systemd(char *devnm, ch case 0: manage_fork_fds(1); snprintf(pathbuf, sizeof(pathbuf), - "%s@%s.service", service_name, devnm); + "%s@%s%s.service", service_name, prefix ?: "", devnm); status = execl("/usr/bin/systemctl", "systemctl", "restart", pathbuf, NULL); status = execl("/bin/systemctl", "systemctl", "restart", ++++++ 0058-mdopen-always-try-create_named_array.patch ++++++ >From 2e10c46d0906b1a1ec40e8f5005ccb63125dcd9e Mon Sep 17 00:00:00 2001 From: NeilBrown <[email protected]> Date: Tue, 14 Mar 2023 11:06:25 +1100 Subject: [PATCH] mdopen: always try create_named_array() mdopen() will use create_named_array() to ask the kernel to create the given md array, but only if it is given a number or name. If it is NOT given a name and is required to choose one itself using find_free_devnm() it does NOT use create_named_array(). On kernels with CONFIG_BLOCK_LEGACY_AUTOLOAD not set, this can result in failure to assemble an array. This can particularly seen when the "name" of the array begins with a host name different to the name of the host running the command. So add the missing call to create_named_array(). Link: https://bugzilla.kernel.org/show_bug.cgi?id=217074 Signed-off-by: NeilBrown <[email protected]> Acked-by: Mariusz Tkaczyk <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> --- mdopen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mdopen.c b/mdopen.c index d18c931..810f79a 100644 --- a/mdopen.c +++ b/mdopen.c @@ -370,6 +370,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, } if (block_udev) udev_block(devnm); + create_named_array(devnm); } sprintf(devname, "/dev/%s", devnm); -- 2.35.3 ++++++ 0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch ++++++ >From 420dafcd38c5949c2ddb90ad6873e7edd625db30 Mon Sep 17 00:00:00 2001 From: NeilBrown <[email protected]> Date: Mon, 20 Mar 2023 14:43:54 +1100 Subject: [PATCH] Improvements for IMSM_NO_PLATFORM testing. Factor out IMSM_NO_PLATFORM testing into a single function that caches the result. Allow mdmon to explicitly set the result to "1" so that we don't need the ENV var in the unit file Check if the kernel command line contains "mdadm.imsm.test=1" and in that case assert NO_PLATFORM. This simplifies testing in a virtual machine. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Jes Sorensen <[email protected]> --- mdadm.8.in | 5 +++++ mdadm.h | 2 ++ mdmon.c | 6 ++++++ super-intel.c | 45 +++++++++++++++++++++++++++++++++++++++--- systemd/[email protected] | 3 --- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/mdadm.8.in b/mdadm.8.in index 6f0f6c1..b715950 100644 --- a/mdadm.8.in +++ b/mdadm.8.in @@ -3197,6 +3197,11 @@ environment. This can be useful for testing or for disaster recovery. You should be aware that interoperability may be compromised by setting this value. +These change can also be suppressed by adding +.B mdadm.imsm.test=1 +to the kernel command line. This makes it easy to test IMSM +code in a virtual machine that doesn't have IMSM virtual hardware. + .TP .B MDADM_GROW_ALLOW_OLD If an array is stopped while it is performing a reshape and that diff --git a/mdadm.h b/mdadm.h index 1e51827..0d99544 100644 --- a/mdadm.h +++ b/mdadm.h @@ -1263,6 +1263,8 @@ extern struct superswitch super0, super1; extern struct superswitch super_imsm, super_ddf; extern struct superswitch mbr, gpt; +void imsm_set_no_platform(int v); + struct metadata_update { int len; char *buf; diff --git a/mdmon.c b/mdmon.c index 096b4d7..cef5bbc 100644 --- a/mdmon.c +++ b/mdmon.c @@ -318,6 +318,12 @@ int main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; + /* + * mdmon should never complain due to lack of a platform, + * that is mdadm's job if at all. + */ + imsm_set_no_platform(1); + while ((opt = getopt_long(argc, argv, "thaF", options, NULL)) != -1) { switch (opt) { case 'a': diff --git a/super-intel.c b/super-intel.c index e155a8a..a5c86cb 100644 --- a/super-intel.c +++ b/super-intel.c @@ -20,6 +20,7 @@ #define HAVE_STDINT_H 1 #include "mdadm.h" #include "mdmon.h" +#include "dlink.h" #include "sha1.h" #include "platform-intel.h" #include <values.h> @@ -629,6 +630,44 @@ static const char *_sys_dev_type[] = { [SYS_DEV_VMD] = "VMD" }; +static int no_platform = -1; + +static int check_no_platform(void) +{ + static const char search[] = "mdadm.imsm.test=1"; + FILE *fp; + + if (no_platform >= 0) + return no_platform; + + if (check_env("IMSM_NO_PLATFORM")) { + no_platform = 1; + return 1; + } + fp = fopen("/proc/cmdline", "r"); + if (fp) { + char *l = conf_line(fp); + char *w = l; + + do { + if (strcmp(w, search) == 0) + no_platform = 1; + w = dl_next(w); + } while (w != l); + free_line(l); + fclose(fp); + if (no_platform >= 0) + return no_platform; + } + no_platform = 0; + return 0; +} + +void imsm_set_no_platform(int v) +{ + no_platform = v; +} + const char *get_sys_dev_type(enum sys_dev_type type) { if (type >= SYS_DEV_MAX) @@ -2699,7 +2738,7 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle int result=1; if (enumerate_only) { - if (check_env("IMSM_NO_PLATFORM")) + if (check_no_platform()) return 0; list = find_intel_devices(); if (!list) @@ -4722,7 +4761,7 @@ static int find_intel_hba_capability(int fd, struct intel_super *super, char *de devname); return 1; } - if (!is_fd_valid(fd) || check_env("IMSM_NO_PLATFORM")) { + if (!is_fd_valid(fd) || check_no_platform()) { super->orom = NULL; super->hba = NULL; return 0; @@ -10697,7 +10736,7 @@ static int imsm_get_allowed_degradation(int level, int raid_disks, ******************************************************************************/ int validate_container_imsm(struct mdinfo *info) { - if (check_env("IMSM_NO_PLATFORM")) + if (check_no_platform()) return 0; struct sys_dev *idev; diff --git a/systemd/[email protected] b/systemd/[email protected] index 23a375f..020cc7e 100644 --- a/systemd/[email protected] +++ b/systemd/[email protected] @@ -15,9 +15,6 @@ Documentation=man:mdmon(8) IgnoreOnIsolate=true [Service] -# mdmon should never complain due to lack of a platform, -# that is mdadm's job if at all. -Environment=IMSM_NO_PLATFORM=1 # The mdmon starting in the initramfs (with dracut at least) # cannot see sysfs after root is mounted, so we will have to # 'takeover'. As the '--offroot --takeover' don't hurt when -- 2.35.3
