diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2014-09-11 23:39:15 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2014-09-12 00:14:52 +0200 |
| commit | 5dae0186dea1e72e73bf223161620cfeddef5a63 (patch) | |
| tree | 7f8d7ef58c4a7eb35c0ae90b12d8e71ec51eabd2 | |
| parent | ee7bae3bbd2030d5f2cdb88e484e1c67a063e2a3 (diff) | |
system: Add support for Linux-style mapped devices.
* gnu/system/file-systems.scm (<mapped-device>): New record type.
* gnu/system.scm (<operating-system>)[mapped-devices]: New field.
(luks-device-mapping): New procedure.
(other-file-system-services)[device-mappings, requirements]: New
procedures. Pass #:requirements to 'file-system-service'.
(device-mapping-services): New procedure.
(essential-services): Use it. Append its result to the return value.
(operating-system-initrd-file): Add comment.
* gnu/services/base.scm (file-system-service): Add #:requirements
parameter and honor it.
(device-mapping-service): New procedure.
* gnu/system/linux-initrd.scm (base-initrd): Add comment.
| -rw-r--r-- | gnu/services/base.scm | 24 | ||||
| -rw-r--r-- | gnu/system.scm | 67 | ||||
| -rw-r--r-- | gnu/system/file-systems.scm | 21 | ||||
| -rw-r--r-- | gnu/system/linux-initrd.scm | 1 |
4 files changed, 97 insertions, 16 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm index bf5af8369e0..014eef053ba 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm | |||
| @@ -38,6 +38,7 @@ | |||
| 38 | #:use-module (ice-9 format) | 38 | #:use-module (ice-9 format) |
| 39 | #:export (root-file-system-service | 39 | #:export (root-file-system-service |
| 40 | file-system-service | 40 | file-system-service |
| 41 | device-mapping-service | ||
| 41 | user-processes-service | 42 | user-processes-service |
| 42 | host-name-service | 43 | host-name-service |
| 43 | console-font-service | 44 | console-font-service |
| @@ -99,18 +100,20 @@ This service must be the root of the service dependency graph so that its | |||
| 99 | 100 | ||
| 100 | (define* (file-system-service device target type | 101 | (define* (file-system-service device target type |
| 101 | #:key (flags '()) (check? #t) | 102 | #:key (flags '()) (check? #t) |
| 102 | create-mount-point? options (title 'any)) | 103 | create-mount-point? options (title 'any) |
| 104 | (requirements '())) | ||
| 103 | "Return a service that mounts DEVICE on TARGET as a file system TYPE with | 105 | "Return a service that mounts DEVICE on TARGET as a file system TYPE with |
| 104 | OPTIONS. TITLE is a symbol specifying what kind of name DEVICE is: 'label for | 106 | OPTIONS. TITLE is a symbol specifying what kind of name DEVICE is: 'label for |
| 105 | a partition label, 'device for a device file name, or 'any. When CHECK? is | 107 | a partition label, 'device for a device file name, or 'any. When CHECK? is |
| 106 | true, check the file system before mounting it. When CREATE-MOUNT-POINT? is | 108 | true, check the file system before mounting it. When CREATE-MOUNT-POINT? is |
| 107 | true, create TARGET if it does not exist yet. FLAGS is a list of symbols, | 109 | true, create TARGET if it does not exist yet. FLAGS is a list of symbols, |
| 108 | such as 'read-only' etc." | 110 | such as 'read-only' etc. Optionally, REQUIREMENTS may be a list of service |
| 111 | names such as device-mapping services." | ||
| 109 | (with-monad %store-monad | 112 | (with-monad %store-monad |
| 110 | (return | 113 | (return |
| 111 | (service | 114 | (service |
| 112 | (provision (list (symbol-append 'file-system- (string->symbol target)))) | 115 | (provision (list (symbol-append 'file-system- (string->symbol target)))) |
| 113 | (requirement '(root-file-system)) | 116 | (requirement `(root-file-system ,@requirements)) |
| 114 | (documentation "Check, mount, and unmount the given file system.") | 117 | (documentation "Check, mount, and unmount the given file system.") |
| 115 | (start #~(lambda args | 118 | (start #~(lambda args |
| 116 | (let ((device (canonicalize-device-spec #$device '#$title))) | 119 | (let ((device (canonicalize-device-spec #$device '#$title))) |
| @@ -567,6 +570,21 @@ extra rules from the packages listed in @var{rules}." | |||
| 567 | pid))))) | 570 | pid))))) |
| 568 | (stop #~(make-kill-destructor)))))) | 571 | (stop #~(make-kill-destructor)))))) |
| 569 | 572 | ||
| 573 | (define (device-mapping-service target command) | ||
| 574 | "Return a service that maps device @var{target}, a string such as | ||
| 575 | @code{\"home\"} (meaning @code{/dev/mapper/home}), by executing @var{command}, | ||
| 576 | a gexp." | ||
| 577 | (with-monad %store-monad | ||
| 578 | (return (service | ||
| 579 | (provision (list (symbol-append 'device-mapping- | ||
| 580 | (string->symbol target)))) | ||
| 581 | (requirement '(udev)) | ||
| 582 | (documentation "Map a device node using Linux's device mapper.") | ||
| 583 | (start #~(lambda () | ||
| 584 | #$command)) | ||
| 585 | (stop #~(const #f)) | ||
| 586 | (respawn? #f))))) | ||
| 587 | |||
| 570 | (define %base-services | 588 | (define %base-services |
| 571 | ;; Convenience variable holding the basic services. | 589 | ;; Convenience variable holding the basic services. |
| 572 | (let ((motd (text-file "motd" " | 590 | (let ((motd (text-file "motd" " |
diff --git a/gnu/system.scm b/gnu/system.scm index 8a3f4f6ba88..9bdf227eca3 100644 --- a/gnu/system.scm +++ b/gnu/system.scm | |||
| @@ -44,6 +44,7 @@ | |||
| 44 | #:use-module (gnu system linux) | 44 | #:use-module (gnu system linux) |
| 45 | #:use-module (gnu system linux-initrd) | 45 | #:use-module (gnu system linux-initrd) |
| 46 | #:use-module (gnu system file-systems) | 46 | #:use-module (gnu system file-systems) |
| 47 | #:autoload (gnu packages cryptsetup) (cryptsetup) | ||
| 47 | #:use-module (ice-9 match) | 48 | #:use-module (ice-9 match) |
| 48 | #:use-module (srfi srfi-1) | 49 | #:use-module (srfi srfi-1) |
| 49 | #:use-module (srfi srfi-26) | 50 | #:use-module (srfi srfi-26) |
| @@ -64,6 +65,7 @@ | |||
| 64 | operating-system-packages | 65 | operating-system-packages |
| 65 | operating-system-timezone | 66 | operating-system-timezone |
| 66 | operating-system-locale | 67 | operating-system-locale |
| 68 | operating-system-mapped-devices | ||
| 67 | operating-system-file-systems | 69 | operating-system-file-systems |
| 68 | operating-system-activation-script | 70 | operating-system-activation-script |
| 69 | 71 | ||
| @@ -72,7 +74,9 @@ | |||
| 72 | operating-system-grub.cfg | 74 | operating-system-grub.cfg |
| 73 | 75 | ||
| 74 | %setuid-programs | 76 | %setuid-programs |
| 75 | %base-packages)) | 77 | %base-packages |
| 78 | |||
| 79 | luks-device-mapping)) | ||
| 76 | 80 | ||
| 77 | ;;; Commentary: | 81 | ;;; Commentary: |
| 78 | ;;; | 82 | ;;; |
| @@ -96,6 +100,8 @@ | |||
| 96 | (hosts-file operating-system-hosts-file ; M item | #f | 100 | (hosts-file operating-system-hosts-file ; M item | #f |
| 97 | (default #f)) | 101 | (default #f)) |
| 98 | 102 | ||
| 103 | (mapped-devices operating-system-mapped-devices ; list of <mapped-device> | ||
| 104 | (default '())) | ||
| 99 | (file-systems operating-system-file-systems) ; list of fs | 105 | (file-systems operating-system-file-systems) ; list of fs |
| 100 | 106 | ||
| 101 | (users operating-system-users ; list of user accounts | 107 | (users operating-system-users ; list of user accounts |
| @@ -152,6 +158,13 @@ file." | |||
| 152 | ;;; Services. | 158 | ;;; Services. |
| 153 | ;;; | 159 | ;;; |
| 154 | 160 | ||
| 161 | (define (luks-device-mapping source target) | ||
| 162 | "Return a gexp that maps SOURCE to TARGET as a LUKS device, using | ||
| 163 | 'cryptsetup'." | ||
| 164 | #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup") | ||
| 165 | "open" "--type" "luks" | ||
| 166 | #$source #$target))) | ||
| 167 | |||
| 155 | (define (other-file-system-services os) | 168 | (define (other-file-system-services os) |
| 156 | "Return file system services for the file systems of OS that are not marked | 169 | "Return file system services for the file systems of OS that are not marked |
| 157 | as 'needed-for-boot'." | 170 | as 'needed-for-boot'." |
| @@ -161,30 +174,58 @@ as 'needed-for-boot'." | |||
| 161 | (string=? "/" (file-system-mount-point fs)))) | 174 | (string=? "/" (file-system-mount-point fs)))) |
| 162 | (operating-system-file-systems os))) | 175 | (operating-system-file-systems os))) |
| 163 | 176 | ||
| 177 | (define (device-mappings fs) | ||
| 178 | (filter (lambda (md) | ||
| 179 | (string=? (string-append "/dev/mapper/" | ||
| 180 | (mapped-device-target md)) | ||
| 181 | (file-system-device fs))) | ||
| 182 | (operating-system-mapped-devices os))) | ||
| 183 | |||
| 184 | (define (requirements fs) | ||
| 185 | (map (lambda (md) | ||
| 186 | (symbol-append 'device-mapping- | ||
| 187 | (string->symbol (mapped-device-target md)))) | ||
| 188 | (device-mappings fs))) | ||
| 189 | |||
| 164 | (sequence %store-monad | 190 | (sequence %store-monad |
| 165 | (map (match-lambda | 191 | (map (lambda (fs) |
| 166 | (($ <file-system> device title target type flags opts | 192 | (match fs |
| 167 | #f check? create?) | 193 | (($ <file-system> device title target type flags opts |
| 168 | (file-system-service device target type | 194 | #f check? create?) |
| 169 | #:title title | 195 | (file-system-service device target type |
| 170 | #:check? check? | 196 | #:title title |
| 171 | #:create-mount-point? create? | 197 | #:requirements (requirements fs) |
| 172 | #:options opts | 198 | #:check? check? |
| 173 | #:flags flags))) | 199 | #:create-mount-point? create? |
| 200 | #:options opts | ||
| 201 | #:flags flags)))) | ||
| 174 | file-systems))) | 202 | file-systems))) |
| 175 | 203 | ||
| 204 | (define (device-mapping-services os) | ||
| 205 | "Return the list of device-mapping services for OS as a monadic list." | ||
| 206 | (sequence %store-monad | ||
| 207 | (map (lambda (md) | ||
| 208 | (let ((source (mapped-device-source md)) | ||
| 209 | (target (mapped-device-target md)) | ||
| 210 | (command (mapped-device-command md))) | ||
| 211 | (device-mapping-service target | ||
| 212 | (command source target)))) | ||
| 213 | (operating-system-mapped-devices os)))) | ||
| 214 | |||
| 176 | (define (essential-services os) | 215 | (define (essential-services os) |
| 177 | "Return the list of essential services for OS. These are special services | 216 | "Return the list of essential services for OS. These are special services |
| 178 | that implement part of what's declared in OS are responsible for low-level | 217 | that implement part of what's declared in OS are responsible for low-level |
| 179 | bookkeeping." | 218 | bookkeeping." |
| 180 | (mlet* %store-monad ((root-fs (root-file-system-service)) | 219 | (mlet* %store-monad ((mappings (device-mapping-services os)) |
| 220 | (root-fs (root-file-system-service)) | ||
| 181 | (other-fs (other-file-system-services os)) | 221 | (other-fs (other-file-system-services os)) |
| 182 | (procs (user-processes-service | 222 | (procs (user-processes-service |
| 183 | (map (compose first service-provision) | 223 | (map (compose first service-provision) |
| 184 | other-fs))) | 224 | other-fs))) |
| 185 | (host-name (host-name-service | 225 | (host-name (host-name-service |
| 186 | (operating-system-host-name os)))) | 226 | (operating-system-host-name os)))) |
| 187 | (return (cons* host-name procs root-fs other-fs)))) | 227 | (return (cons* host-name procs root-fs |
| 228 | (append other-fs mappings))))) | ||
| 188 | 229 | ||
| 189 | (define (operating-system-services os) | 230 | (define (operating-system-services os) |
| 190 | "Return all the services of OS, including \"internal\" services that do not | 231 | "Return all the services of OS, including \"internal\" services that do not |
| @@ -490,6 +531,8 @@ we're running in the final root." | |||
| 490 | boot?)) | 531 | boot?)) |
| 491 | (operating-system-file-systems os))) | 532 | (operating-system-file-systems os))) |
| 492 | 533 | ||
| 534 | ;; TODO: Pass the mapped devices required by boot-time file systems to the | ||
| 535 | ;; initrd. | ||
| 493 | (mlet %store-monad | 536 | (mlet %store-monad |
| 494 | ((initrd ((operating-system-initrd os) boot-file-systems))) | 537 | ((initrd ((operating-system-initrd os) boot-file-systems))) |
| 495 | (return #~(string-append #$initrd "/initrd")))) | 538 | (return #~(string-append #$initrd "/initrd")))) |
diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm index 48c4fc7e773..90e2b0c796a 100644 --- a/gnu/system/file-systems.scm +++ b/gnu/system/file-systems.scm | |||
| @@ -37,7 +37,13 @@ | |||
| 37 | %pseudo-terminal-file-system | 37 | %pseudo-terminal-file-system |
| 38 | %devtmpfs-file-system | 38 | %devtmpfs-file-system |
| 39 | 39 | ||
| 40 | %base-file-systems)) | 40 | %base-file-systems |
| 41 | |||
| 42 | mapped-device | ||
| 43 | mapped-device? | ||
| 44 | mapped-device-source | ||
| 45 | mapped-device-target | ||
| 46 | mapped-device-command)) | ||
| 41 | 47 | ||
| 42 | ;;; Commentary: | 48 | ;;; Commentary: |
| 43 | ;;; | 49 | ;;; |
| @@ -128,4 +134,17 @@ | |||
| 128 | %pseudo-terminal-file-system | 134 | %pseudo-terminal-file-system |
| 129 | %shared-memory-file-system)) | 135 | %shared-memory-file-system)) |
| 130 | 136 | ||
| 137 | |||
| 138 | |||
| 139 | ;;; | ||
| 140 | ;;; Mapped devices, for Linux's device-mapper. | ||
| 141 | ;;; | ||
| 142 | |||
| 143 | (define-record-type* <mapped-device> mapped-device | ||
| 144 | make-mapped-device | ||
| 145 | mapped-device? | ||
| 146 | (source mapped-device-source) ;string | ||
| 147 | (target mapped-device-target) ;string | ||
| 148 | (command mapped-device-command)) ;source target -> gexp | ||
| 149 | |||
| 131 | ;;; file-systems.scm ends here | 150 | ;;; file-systems.scm ends here |
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm index e83a9a5b23f..93f751b7571 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm | |||
| @@ -131,6 +131,7 @@ initrd code." | |||
| 131 | volatile-root? | 131 | volatile-root? |
| 132 | (extra-modules '()) | 132 | (extra-modules '()) |
| 133 | guile-modules-in-chroot?) | 133 | guile-modules-in-chroot?) |
| 134 | ;; TODO: Support boot-time device mappings. | ||
| 134 | "Return a monadic derivation that builds a generic initrd. FILE-SYSTEMS is | 135 | "Return a monadic derivation that builds a generic initrd. FILE-SYSTEMS is |
| 135 | a list of file-systems to be mounted by the initrd, possibly in addition to | 136 | a list of file-systems to be mounted by the initrd, possibly in addition to |
| 136 | the root file system specified on the kernel command line via '--root'. | 137 | the root file system specified on the kernel command line via '--root'. |
