diff --git a/0052-mdmon-fix-segfault.patch b/0052-mdmon-fix-segfault.patch new file mode 100644 index 0000000..306bb61 --- /dev/null +++ b/0052-mdmon-fix-segfault.patch @@ -0,0 +1,87 @@ +From 9b429fc0a4ffd7028b3b336589d38e32fb9045dc Mon Sep 17 00:00:00 2001 +From: Mateusz Kusiak +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 +Signed-off-by: Jes Sorensen +Signed-off-by: Coly Li +--- + 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 + diff --git a/0053-util-remove-obsolete-code-from-get_md_name.patch b/0053-util-remove-obsolete-code-from-get_md_name.patch new file mode 100644 index 0000000..1114b2c --- /dev/null +++ b/0053-util-remove-obsolete-code-from-get_md_name.patch @@ -0,0 +1,117 @@ +From b938519e7719c992dae2d61c796c45fe49e6b71b Mon Sep 17 00:00:00 2001 +From: Mateusz Kusiak +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 +Signed-off-by: Jes Sorensen +Signed-off-by: Coly Li +--- + 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 + diff --git a/0054-mdmon-don-t-test-both-all-and-container_name.patch b/0054-mdmon-don-t-test-both-all-and-container_name.patch new file mode 100644 index 0000000..e714da2 --- /dev/null +++ b/0054-mdmon-don-t-test-both-all-and-container_name.patch @@ -0,0 +1,47 @@ +From d39fd87e31024804dd7f2c16c03af0379b71f5f1 Mon Sep 17 00:00:00 2001 +From: NeilBrown +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 +Signed-off-by: Jes Sorensen +--- + 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 + diff --git a/0055-mdmon-change-systemd-unit-file-to-use-foreground.patch b/0055-mdmon-change-systemd-unit-file-to-use-foreground.patch new file mode 100644 index 0000000..327e56e --- /dev/null +++ b/0055-mdmon-change-systemd-unit-file-to-use-foreground.patch @@ -0,0 +1,33 @@ +From 6660e33edde76329bd3b7f03383856c7efee2aa9 Mon Sep 17 00:00:00 2001 +From: NeilBrown +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 +Signed-off-by: Jes Sorensen +--- + systemd/mdmon@.service | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/systemd/mdmon@.service b/systemd/mdmon@.service +index cb6482d..bba9b0e 100644 +--- a/systemd/mdmon@.service ++++ b/systemd/mdmon@.service +@@ -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 + diff --git a/0056-mdmon-Remove-need-for-KillMode-none.patch b/0056-mdmon-Remove-need-for-KillMode-none.patch new file mode 100644 index 0000000..2845158 --- /dev/null +++ b/0056-mdmon-Remove-need-for-KillMode-none.patch @@ -0,0 +1,55 @@ +From 0f9a4b3e11fbe4f8631d20b1f89cf43e9219db55 Mon Sep 17 00:00:00 2001 +From: NeilBrown +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 +Signed-off-by: Jes Sorensen +--- + systemd/mdmon@.service | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/systemd/mdmon@.service b/systemd/mdmon@.service +index bba9b0e..303ad05 100644 +--- a/systemd/mdmon@.service ++++ b/systemd/mdmon@.service +@@ -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 + diff --git a/0057-mdmon-Improve-switchroot-interactions.patch b/0057-mdmon-Improve-switchroot-interactions.patch new file mode 100644 index 0000000..f01ffaa --- /dev/null +++ b/0057-mdmon-Improve-switchroot-interactions.patch @@ -0,0 +1,163 @@ +From 723d1df4946eb40337bf494f9b2549500c1399b2 Mon Sep 17 00:00:00 2001 +From: NeilBrown +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 +mdmon@.service unit file already supports multiple instances (for +different arrays). + +So start "mdmon@mdfoo.service" from root, but +"mdmon@initrd-mdfoo.service" 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 +Signed-off-by: Jes Sorensen +--- + Grow.c | 4 ++-- + mdadm.h | 2 +- + mdmon.c | 7 ++++++- + systemd/mdmon@.service | 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/mdmon@.service +=================================================================== +--- mdadm-4.2.orig/systemd/mdmon@.service ++++ mdadm-4.2/systemd/mdmon@.service +@@ -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", diff --git a/0058-mdopen-always-try-create_named_array.patch b/0058-mdopen-always-try-create_named_array.patch new file mode 100644 index 0000000..f7f2d31 --- /dev/null +++ b/0058-mdopen-always-try-create_named_array.patch @@ -0,0 +1,40 @@ +From 2e10c46d0906b1a1ec40e8f5005ccb63125dcd9e Mon Sep 17 00:00:00 2001 +From: NeilBrown +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 +Acked-by: Mariusz Tkaczyk +Signed-off-by: Jes Sorensen +--- + 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 + diff --git a/0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch b/0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch new file mode 100644 index 0000000..d7d244a --- /dev/null +++ b/0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch @@ -0,0 +1,172 @@ +From 420dafcd38c5949c2ddb90ad6873e7edd625db30 Mon Sep 17 00:00:00 2001 +From: NeilBrown +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 +Signed-off-by: Jes Sorensen +--- + mdadm.8.in | 5 +++++ + mdadm.h | 2 ++ + mdmon.c | 6 ++++++ + super-intel.c | 45 +++++++++++++++++++++++++++++++++++++++--- + systemd/mdmon@.service | 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 +@@ -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/mdmon@.service b/systemd/mdmon@.service +index 23a375f..020cc7e 100644 +--- a/systemd/mdmon@.service ++++ b/systemd/mdmon@.service +@@ -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 + diff --git a/mdadm.changes b/mdadm.changes index e786e30..f0a816a 100644 --- a/mdadm.changes +++ b/mdadm.changes @@ -1,3 +1,26 @@ +------------------------------------------------------------------- +Mon Apr 24 15:06:42 UTC 2023 - Coly Li + +- 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 + ------------------------------------------------------------------- Sat Apr 1 15:17:58 UTC 2023 - Coly Li diff --git a/mdadm.spec b/mdadm.spec index 392066f..5fd278f 100644 --- a/mdadm.spec +++ b/mdadm.spec @@ -92,6 +92,14 @@ Patch48: 0048-mdadm-Add-Documentation-entries-to-systemd-services.patch 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 @@ mdadm is a program that can be used to control Linux md devices. %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