summary refs log tree commit diff
path: root/gnu/system
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/system')
-rw-r--r--gnu/system/mapped-devices.scm49
1 files changed, 29 insertions, 20 deletions
diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm
index d0a9f0288f..7b91fcfc41 100644
--- a/gnu/system/mapped-devices.scm
+++ b/gnu/system/mapped-devices.scm
@@ -81,14 +81,7 @@
        (documentation "Map a device node using Linux's device mapper.")
        (start #~(lambda () #$(open source target)))
        (stop #~(lambda _ (not #$(close source target))))
-       (respawn? #f)
-
-       ;; Add the modules needed by LUKS-DEVICE-MAPPING.
-       ;; FIXME: This info should be propagated via gexps.
-       (modules `((rnrs bytevectors)              ;bytevector?
-                  ((gnu build file-systems)
-                   #:select (find-partition-by-luks-uuid))
-                  ,@%default-modules)))))))
+       (respawn? #f))))))
 
 (define (device-mapping-service mapped-device)
   "Return a service that sets up @var{mapped-device}."
@@ -105,6 +98,11 @@
   (with-imported-modules '((gnu build file-systems)
                            (guix build bournish))
     #~(let ((source #$source))
+        ;; XXX: 'use-modules' should be at the top level.
+        (use-modules (rnrs bytevectors)           ;bytevector?
+                     ((gnu build file-systems)
+                      #:select (find-partition-by-luks-uuid)))
+
         (zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
                         "open" "--type" "luks"
 
@@ -130,20 +128,31 @@
    (open open-luks-device)
    (close close-luks-device)))
 
-(define (open-raid-device source target)
-  "Return a gexp that assembles SOURCE (a list of devices) to the RAID device
-TARGET, using 'mdadm'."
-  #~(let ((every (@ (srfi srfi-1) every)))
-      (let loop ()
-        (unless (every file-exists? '#$source)
-          (format #t "waiting a bit...~%")
+(define (open-raid-device sources target)
+  "Return a gexp that assembles SOURCES (a list of devices) to the RAID device
+TARGET (e.g., \"/dev/md0\"), using 'mdadm'."
+  #~(let ((sources '#$sources)
+
+          ;; XXX: We're not at the top level here.  We could use a
+          ;; non-top-level 'use-modules' form but that doesn't work when the
+          ;; code is eval'd, like the Shepherd does.
+          (every   (@ (srfi srfi-1) every))
+          (format  (@ (ice-9 format) format)))
+      (let loop ((attempts 0))
+        (unless (every file-exists? sources)
+          (when (> attempts 20)
+            (error "RAID devices did not show up; bailing out"
+                   sources))
+
+          (format #t "waiting for RAID source devices~{ ~a~}...~%"
+                  sources)
           (sleep 1)
-          (loop)))
-       (zero? (system* (string-append #$mdadm "/sbin/mdadm")
-                                      "--assemble" #$target
-                                      #$@source))))
+          (loop (+ 1 attempts))))
+
+      (zero? (system* (string-append #$mdadm "/sbin/mdadm")
+                      "--assemble" #$target sources))))
 
-(define (close-raid-device source target)
+(define (close-raid-device sources target)
   "Return a gexp that stops the RAID device TARGET."
   #~(zero? (system* (string-append #$mdadm "/sbin/mdadm")
                     "--stop" #$target)))