system: Define 'device-mapping-kind', and add a 'close' procedure.

* gnu/system/file-systems.scm (<mapped-device-type>): New record type.
  (<mapped-device>)[command]: Remove field.
  [type]: New field.
* gnu/services/base.scm (device-mapping-service): Rename 'command'
  parameter to 'open'.  Add 'close' parameter and honor it.
* gnu/system.scm (luks-device-mapping): Rename to...
  (open-luks-device): ... this.
  (close-luks-device): New procedure.
  (luks-device-mapping): New variable.
  (device-mapping-services): Get the type of MD, and pass its 'open' and
  'close' fields to 'device-mapping-service'.
This commit is contained in:
Ludovic Courtès 2014-09-18 19:18:39 +02:00
parent cb823dd279
commit 722554a306
3 changed files with 39 additions and 13 deletions

View File

@ -600,19 +600,18 @@ extra rules from the packages listed in @var{rules}."
;; called. Thus, make sure it is not respawned. ;; called. Thus, make sure it is not respawned.
(respawn? #f))))) (respawn? #f)))))
(define (device-mapping-service target command) (define (device-mapping-service target open close)
"Return a service that maps device @var{target}, a string such as "Return a service that maps device @var{target}, a string such as
@code{\"home\"} (meaning @code{/dev/mapper/home}), by executing @var{command}, @code{\"home\"} (meaning @code{/dev/mapper/home}). Evaluate @var{open}, a
a gexp." gexp, to open it, and evaluate @var{close} to close it."
(with-monad %store-monad (with-monad %store-monad
(return (service (return (service
(provision (list (symbol-append 'device-mapping- (provision (list (symbol-append 'device-mapping-
(string->symbol target)))) (string->symbol target))))
(requirement '(udev)) (requirement '(udev))
(documentation "Map a device node using Linux's device mapper.") (documentation "Map a device node using Linux's device mapper.")
(start #~(lambda () (start #~(lambda () #$open))
#$command)) (stop #~(lambda _ (not #$close)))
(stop #~(const #f))
(respawn? #f))))) (respawn? #f)))))
(define %base-services (define %base-services

View File

@ -160,13 +160,24 @@ file."
;;; Services. ;;; Services.
;;; ;;;
(define (luks-device-mapping source target) (define (open-luks-device source target)
"Return a gexp that maps SOURCE to TARGET as a LUKS device, using "Return a gexp that maps SOURCE to TARGET as a LUKS device, using
'cryptsetup'." 'cryptsetup'."
#~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup") #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
"open" "--type" "luks" "open" "--type" "luks"
#$source #$target))) #$source #$target)))
(define (close-luks-device source target)
"Return a gexp that closes TARGET, a LUKS device."
#~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
"close" #$target)))
(define luks-device-mapping
;; The type of LUKS mapped devices.
(mapped-device-kind
(open open-luks-device)
(close close-luks-device)))
(define (other-file-system-services os) (define (other-file-system-services os)
"Return file system services for the file systems of OS that are not marked "Return file system services for the file systems of OS that are not marked
as 'needed-for-boot'." as 'needed-for-boot'."
@ -207,11 +218,14 @@ as 'needed-for-boot'."
"Return the list of device-mapping services for OS as a monadic list." "Return the list of device-mapping services for OS as a monadic list."
(sequence %store-monad (sequence %store-monad
(map (lambda (md) (map (lambda (md)
(let ((source (mapped-device-source md)) (let* ((source (mapped-device-source md))
(target (mapped-device-target md)) (target (mapped-device-target md))
(command (mapped-device-command md))) (type (mapped-device-type md))
(open (mapped-device-kind-open type))
(close (mapped-device-kind-close type)))
(device-mapping-service target (device-mapping-service target
(command source target)))) (open source target)
(close source target))))
(operating-system-mapped-devices os)))) (operating-system-mapped-devices os))))
(define (essential-services os) (define (essential-services os)

View File

@ -17,6 +17,7 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu system file-systems) (define-module (gnu system file-systems)
#:use-module (guix gexp)
#:use-module (guix records) #:use-module (guix records)
#:export (<file-system> #:export (<file-system>
file-system file-system
@ -43,7 +44,12 @@
mapped-device? mapped-device?
mapped-device-source mapped-device-source
mapped-device-target mapped-device-target
mapped-device-command)) mapped-device-type
mapped-device-kind
mapped-device-kind?
mapped-device-kind-open
mapped-device-kind-close))
;;; Commentary: ;;; Commentary:
;;; ;;;
@ -145,6 +151,13 @@
mapped-device? mapped-device?
(source mapped-device-source) ;string (source mapped-device-source) ;string
(target mapped-device-target) ;string (target mapped-device-target) ;string
(command mapped-device-command)) ;source target -> gexp (type mapped-device-type)) ;<mapped-device-kind>
(define-record-type* <mapped-device-type> mapped-device-kind
make-mapped-device-kind
mapped-device-kind?
(open mapped-device-kind-open) ;source target -> gexp
(close mapped-device-kind-close ;source target -> gexp
(default (const #~(const #f)))))
;;; file-systems.scm ends here ;;; file-systems.scm ends here