diff --git a/modules/tasks/swraid.nix b/modules/tasks/swraid.nix index c51664d7e32..a662f06c215 100644 --- a/modules/tasks/swraid.nix +++ b/modules/tasks/swraid.nix @@ -15,7 +15,7 @@ let echo "$@" >> ${logFile} case $1 in (NewArray) - initctl emit -n new-devices + initctl emit -n new-raid-array ;; (*) ;; esac @@ -25,33 +25,51 @@ in { - jobs.swraid = - { startOn = [ "startup" "new-devices" ]; - - script = - '' - # Load the necessary RAID personalities. - # !!! hm, doesn't the kernel load these automatically? - for mod in raid0 raid1 raid5; do - ${modprobe}/sbin/modprobe $mod || true - done - - # Scan /proc/partitions for RAID devices. - ${mdadm}/sbin/mdadm --examine --brief --scan -c partitions > ${tempConf} - - if ! test -s ${tempConf}; then exit 0; fi - - # Activate each device found. - ${mdadm}/sbin/mdadm --assemble -c ${tempConf} --scan - ''; + jobs.swraid = { + startOn = [ "new-raid-array" ]; + description = "Assemble RAID arrays."; - task = true; - }; + script = '' + # Load the necessary RAID personalities. + # !!! hm, doesn't the kernel load these automatically? + for mod in raid0 raid1 raid5; do + ${modprobe}/sbin/modprobe $mod || true + done + + # Save previous probe + mv ${tempConf} ${tempConf}.old + + # Scan /proc/partitions for RAID devices. + ${mdadm}/sbin/mdadm --examine --brief --scan -c partitions > ${tempConf} + + if ! diff ${tempConf} ${tempConf}.old > /dev/null; then + # Activate each device found. + ${mdadm}/sbin/mdadm --assemble -c ${tempConf} --scan + + # Send notifications. + initctl emit -n new-devices + fi + + # Remove previous configuration. + rm ${tempConf}.old + ''; + + task = true; + }; jobs.swraidEvents = { name = "swraid-events"; description = "Watch mdadm events."; startOn = [ "startup" ]; + + postStart = '' + echo > ${tempConf} + + # Assemble early raid devices. + initctl emit -n new-raid-array + ''; + + # !!! Someone should ensure that this is indeed doing what the manual says. exec = "${mdadm}/sbin/mdadm --monitor --scan --program ${mdadmEventHandler}"; };