mdadm: 3.3 -> 3.3.4

Okay, this update is a bit more tricky and the patch I've included is
not very nice to be honest.

So the patch causes "mdadm --udev-rules" to search for the right store
path using /proc/self/exec. This has the disadvantage that we could end
up having /run/current-system/bin/mdadm in the rule file.

But on the other hand, when we're on NixOS, we don't need to use that
command *at*all*, so we should be safe.

The patch also sets BINDIR to /sbin, which causes the included rule and
systemd files to not work out of the box on NixOS. But we have a
substituteInPlace where we do rewrite /sbin/mdadm to the right store
path in our udev rule generator, so that shouldn't be an issue.

I've tested this using the mdraid installer test and it succeeded.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>

aszlig bcd31d0a 48fad440

+136 -4
+6 -4
pkgs/os-specific/linux/mdadm/default.nix
··· 1 1 { stdenv, fetchurl, groff }: 2 2 3 3 stdenv.mkDerivation rec { 4 - name = "mdadm-3.3"; 4 + name = "mdadm-3.3.4"; 5 5 6 6 # WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING 7 7 # Do NOT update this if you're not ABSOLUTELY certain that it will work. ··· 13 13 # https://github.com/NixOS/nixpkgs/pull/6006 14 14 # WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING -- WARNING 15 15 src = fetchurl { 16 - url = "mirror://kernel/linux/utils/raid/mdadm/${name}.tar.bz2"; 17 - sha256 = "0igdqflihiq1dp5qlypzw0xfl44f4n3bckl7r2x2wfgkplcfa1ww"; 16 + url = "mirror://kernel/linux/utils/raid/mdadm/${name}.tar.xz"; 17 + sha256 = "0s6a4bq7v7zxiqzv6wn06fv9f6g502dp047lj471jwxq0r9z9rca"; 18 18 }; 19 + 20 + patches = [ ./no-self-references.patch ]; 19 21 20 22 nativeBuildInputs = [ groff ]; 21 23 ··· 28 30 # /dev/.mdadm/map as a fallback). 29 31 preBuild = 30 32 '' 31 - makeFlagsArray=(INSTALL=install BINDIR=$out/sbin MANDIR=$out/share/man RUN_DIR=/dev/.mdadm) 33 + makeFlagsArray=(NIXOS=1 INSTALL=install INSTALL_BINDIR=$out/sbin MANDIR=$out/share/man RUN_DIR=/dev/.mdadm) 32 34 if [[ -n "$crossConfig" ]]; then 33 35 makeFlagsArray+=(CROSS_COMPILE=$crossConfig-) 34 36 fi
+130
pkgs/os-specific/linux/mdadm/no-self-references.patch
··· 1 + diff --git a/Makefile b/Makefile 2 + index d82e30f..d231cf9 100644 3 + --- a/Makefile 4 + +++ b/Makefile 5 + @@ -51,6 +51,9 @@ endif 6 + ifdef DEBIAN 7 + CPPFLAGS += -DDEBIAN 8 + endif 9 + +ifdef NIXOS 10 + +CPPFLAGS += -DNIXOS 11 + +endif 12 + ifdef DEFAULT_OLD_METADATA 13 + CPPFLAGS += -DDEFAULT_OLD_METADATA 14 + DEFAULT_METADATA=0.90 15 + @@ -105,6 +108,7 @@ endif 16 + INSTALL = /usr/bin/install 17 + DESTDIR = 18 + BINDIR = /sbin 19 + +INSTALL_BINDIR = ${BINDIR} 20 + MANDIR = /usr/share/man 21 + MAN4DIR = $(MANDIR)/man4 22 + MAN5DIR = $(MANDIR)/man5 23 + @@ -259,20 +263,20 @@ sha1.o : sha1.c sha1.h md5.h 24 + $(CC) $(CFLAGS) -DHAVE_STDINT_H -o sha1.o -c sha1.c 25 + 26 + install : mdadm mdmon install-man install-udev 27 + - $(INSTALL) -D $(STRIP) -m 755 mdadm $(DESTDIR)$(BINDIR)/mdadm 28 + - $(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(BINDIR)/mdmon 29 + + $(INSTALL) -D $(STRIP) -m 755 mdadm $(DESTDIR)$(INSTALL_BINDIR)/mdadm 30 + + $(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(INSTALL_BINDIR)/mdmon 31 + 32 + install-static : mdadm.static install-man 33 + - $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm 34 + + $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(INSTALL_BINDIR)/mdadm 35 + 36 + install-tcc : mdadm.tcc install-man 37 + - $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm 38 + + $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(INSTALL_BINDIR)/mdadm 39 + 40 + install-uclibc : mdadm.uclibc install-man 41 + - $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm 42 + + $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm 43 + 44 + install-klibc : mdadm.klibc install-man 45 + - $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm 46 + + $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm 47 + 48 + install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8 49 + $(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8 50 + @@ -305,7 +309,7 @@ install-systemd: systemd/mdmon@.service 51 + if [ -f /etc/SuSE-release -o -n "$(SUSE)" ] ;then $(INSTALL) -D -m 755 systemd/SUSE-mdadm_env.sh $(DESTDIR)$(SYSTEMD_DIR)/../scripts/mdadm_env.sh ;fi 52 + 53 + uninstall: 54 + - rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm 55 + + rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(INSTALL_BINDIR)/mdadm 56 + 57 + test: mdadm mdmon test_stripe swap_super raid6check 58 + @echo "Please run './test' as root" 59 + diff --git a/policy.c b/policy.c 60 + index 064d349..6b2f2b1 100644 61 + --- a/policy.c 62 + +++ b/policy.c 63 + @@ -796,12 +796,39 @@ char *find_rule(struct rule *rule, char *rule_type) 64 + #define UDEV_RULE_FORMAT \ 65 + "ACTION==\"add\", SUBSYSTEM==\"block\", " \ 66 + "ENV{DEVTYPE}==\"%s\", ENV{ID_PATH}==\"%s\", " \ 67 + -"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n" 68 + +"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n" 69 + 70 + #define UDEV_RULE_FORMAT_NOTYPE \ 71 + "ACTION==\"add\", SUBSYSTEM==\"block\", " \ 72 + "ENV{ID_PATH}==\"%s\", " \ 73 + -"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n" 74 + +"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n" 75 + + 76 + +#ifdef NIXOS 77 + +const char *get_mdadm_bindir(void) 78 + +{ 79 + + static char *bindir = NULL; 80 + + if (bindir != NULL) { 81 + + return bindir; 82 + + } else { 83 + + int len; 84 + + bindir = xmalloc(1025); 85 + + len = readlink("/proc/self/exe", bindir, 1024); 86 + + if (len > 0) { 87 + + char *basename; 88 + + if ((basename = strrchr(bindir, '/')) != NULL) 89 + + *basename = '\0'; 90 + + else 91 + + *(bindir + len) = '\0'; 92 + + } else { 93 + + *bindir = '\0'; 94 + + } 95 + + return bindir; 96 + + } 97 + +} 98 + +#define SELF get_mdadm_bindir() 99 + +#else 100 + +#define SELF BINDIR 101 + +#endif 102 + 103 + /* Write rule in the rule file. Use format from UDEV_RULE_FORMAT */ 104 + int write_rule(struct rule *rule, int fd, int force_part) 105 + @@ -815,9 +842,9 @@ int write_rule(struct rule *rule, int fd, int force_part) 106 + if (force_part) 107 + typ = type_part; 108 + if (typ) 109 + - snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth); 110 + + snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth, SELF); 111 + else 112 + - snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth); 113 + + snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth, SELF); 114 + return write(fd, line, strlen(line)) == (int)strlen(line); 115 + } 116 + 117 + diff --git a/util.c b/util.c 118 + index cc98d3b..1ada2f4 100644 119 + --- a/util.c 120 + +++ b/util.c 121 + @@ -1700,7 +1700,9 @@ int start_mdmon(char *devnm) 122 + char pathbuf[1024]; 123 + char *paths[4] = { 124 + pathbuf, 125 + +#ifndef NIXOS 126 + BINDIR "/mdmon", 127 + +#endif 128 + "./mdmon", 129 + NULL 130 + };