* [bug#73654] [PATCH] gnu: luks-device-mapping-with-options: Add allow-discards? argument.
@ 2024-10-06 9:42 Sisiutl
2024-11-06 13:57 ` Hilton Chain via Guix-patches via
2024-12-15 16:31 ` Ludovic Courtès
0 siblings, 2 replies; 3+ messages in thread
From: Sisiutl @ 2024-10-06 9:42 UTC (permalink / raw)
To: 73654; +Cc: Sisiutl
* gnu/system/mapped-devices.scm (luks-device-mapping-with-options): Add allow-discards? argument.
Change-Id: I0a43c13570a223d17698c7fe9ef4607e587bb8d0
---
gnu/system/mapped-devices.scm | 36 +++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm
index 931c371425..674e8708a4 100644
--- a/gnu/system/mapped-devices.scm
+++ b/gnu/system/mapped-devices.scm
@@ -189,12 +189,12 @@ (define missing
(&error-location
(location (source-properties->location location))))))))
-\f
+
;;;
;;; Common device mappings.
;;;
-(define* (open-luks-device source targets #:key key-file)
+(define* (open-luks-device source targets #:key key-file allow-discards?)
"Return a gexp that maps SOURCE to TARGET as a LUKS device, using
'cryptsetup'."
(with-imported-modules (source-module-closure
@@ -234,17 +234,19 @@ (define* (open-luks-device source targets #:key key-file)
(loop (- tries-left 1))))))
(error "LUKS partition not found" source))
source)))
- ;; We want to fallback to the password unlock if the keyfile fails.
- (or (and keyfile
- (zero? (system*/tty
- #$(file-append cryptsetup-static "/sbin/cryptsetup")
- "open" "--type" "luks"
- "--key-file" keyfile
- partition #$target)))
- (zero? (system*/tty
- #$(file-append cryptsetup-static "/sbin/cryptsetup")
- "open" "--type" "luks"
- partition #$target)))))))))
+ (let* ((cryptsetup-flags (list "open" "--type" "luks" partition #$target))
+ (cryptsetup-flags (if allow-discards?
+ (cons "--allow-discards" cryptsetup-flags)
+ cryptsetup-flags)))
+ ;; We want to fallback to the password unlock if the keyfile fails.
+ (or (and keyfile
+ (zero? (apply system*/tty
+ #$(file-append cryptsetup-static "/sbin/cryptsetup")
+ "--key-file" keyfile
+ cryptsetup-flags)))
+ (zero? (apply system*/tty
+ #$(file-append cryptsetup-static "/sbin/cryptsetup")
+ cryptsetup-flags))))))))))
(define (close-luks-device source targets)
"Return a gexp that closes TARGET, a LUKS device."
@@ -286,13 +288,15 @@ (define luks-device-mapping
((gnu build file-systems)
#:select (find-partition-by-luks-uuid system*/tty))))))
-(define* (luks-device-mapping-with-options #:key key-file)
+(define* (luks-device-mapping-with-options #:key key-file allow-discards?)
"Return a luks-device-mapping object with open modified to pass the arguments
into the open-luks-device procedure."
(mapped-device-kind
(inherit luks-device-mapping)
- (open (λ (source targets) (open-luks-device source targets
- #:key-file key-file)))))
+ (open (λ (source targets)
+ (open-luks-device source targets
+ #:key-file key-file
+ #:allow-discards? allow-discards?)))))
(define (open-raid-device sources targets)
"Return a gexp that assembles SOURCES (a list of devices) to the RAID device
--
2.46.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [bug#73654] [PATCH] gnu: luks-device-mapping-with-options: Add allow-discards? argument.
2024-10-06 9:42 [bug#73654] [PATCH] gnu: luks-device-mapping-with-options: Add allow-discards? argument Sisiutl
@ 2024-11-06 13:57 ` Hilton Chain via Guix-patches via
2024-12-15 16:31 ` Ludovic Courtès
1 sibling, 0 replies; 3+ messages in thread
From: Hilton Chain via Guix-patches via @ 2024-11-06 13:57 UTC (permalink / raw)
To: Sisiutl; +Cc: 73654
Hi Sisiutl,
On Sun, 06 Oct 2024 17:42:28 +0800,
Sisiutl wrote:
>
> * gnu/system/mapped-devices.scm (luks-device-mapping-with-options): Add allow-discards? argument.
>
> Change-Id: I0a43c13570a223d17698c7fe9ef4607e587bb8d0
> ---
> gnu/system/mapped-devices.scm | 36 +++++++++++++++++++----------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm
> index 931c371425..674e8708a4 100644
> --- a/gnu/system/mapped-devices.scm
> +++ b/gnu/system/mapped-devices.scm
> @@ -189,12 +189,12 @@ (define missing
> (&error-location
> (location (source-properties->location location))))))))
>
> -\f
> +
This character (‘\f’) is a form feed, please leave it here :)
> ;;;
> ;;; Common device mappings.
> ;;;
>
> -(define* (open-luks-device source targets #:key key-file)
> +(define* (open-luks-device source targets #:key key-file allow-discards?)
> "Return a gexp that maps SOURCE to TARGET as a LUKS device, using
> 'cryptsetup'."
> (with-imported-modules (source-module-closure
> @@ -234,17 +234,19 @@ (define* (open-luks-device source targets #:key key-file)
> (loop (- tries-left 1))))))
> (error "LUKS partition not found" source))
> source)))
> - ;; We want to fallback to the password unlock if the keyfile fails.
> - (or (and keyfile
> - (zero? (system*/tty
> - #$(file-append cryptsetup-static "/sbin/cryptsetup")
> - "open" "--type" "luks"
> - "--key-file" keyfile
> - partition #$target)))
> - (zero? (system*/tty
> - #$(file-append cryptsetup-static "/sbin/cryptsetup")
> - "open" "--type" "luks"
> - partition #$target)))))))))
> + (let* ((cryptsetup-flags (list "open" "--type" "luks" partition #$target))
> + (cryptsetup-flags (if allow-discards?
> + (cons "--allow-discards" cryptsetup-flags)
> + cryptsetup-flags)))
> + ;; We want to fallback to the password unlock if the keyfile fails.
> + (or (and keyfile
> + (zero? (apply system*/tty
> + #$(file-append cryptsetup-static "/sbin/cryptsetup")
> + "--key-file" keyfile
> + cryptsetup-flags)))
> + (zero? (apply system*/tty
> + #$(file-append cryptsetup-static "/sbin/cryptsetup")
> + cryptsetup-flags))))))))))
> (define (close-luks-device source targets)
> "Return a gexp that closes TARGET, a LUKS device."
> @@ -286,13 +288,15 @@ (define luks-device-mapping
> ((gnu build file-systems)
> #:select (find-partition-by-luks-uuid system*/tty))))))
>
> -(define* (luks-device-mapping-with-options #:key key-file)
> +(define* (luks-device-mapping-with-options #:key key-file allow-discards?)
> "Return a luks-device-mapping object with open modified to pass the arguments
> into the open-luks-device procedure."
> (mapped-device-kind
> (inherit luks-device-mapping)
> - (open (λ (source targets) (open-luks-device source targets
> - #:key-file key-file)))))
> + (open (λ (source targets)
> + (open-luks-device source targets
> + #:key-file key-file
> + #:allow-discards? allow-discards?)))))
>
> (define (open-raid-device sources targets)
> "Return a gexp that assembles SOURCES (a list of devices) to the RAID device
> --
> 2.46.0
Can you also add documentation for this option in doc/guix.texi?
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
* [bug#73654] [PATCH] gnu: luks-device-mapping-with-options: Add allow-discards? argument.
2024-10-06 9:42 [bug#73654] [PATCH] gnu: luks-device-mapping-with-options: Add allow-discards? argument Sisiutl
2024-11-06 13:57 ` Hilton Chain via Guix-patches via
@ 2024-12-15 16:31 ` Ludovic Courtès
1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2024-12-15 16:31 UTC (permalink / raw)
To: Sisiutl; +Cc: 73654, Tomas Volf
Hi,
(Cc: Tomas, who I believe initially worked on this.)
Sisiutl <sisiutl@egregore.fun> skribis:
> * gnu/system/mapped-devices.scm (luks-device-mapping-with-options): Add allow-discards? argument.
>
> Change-Id: I0a43c13570a223d17698c7fe9ef4607e587bb8d0
> -\f
> +
This is a linefeed and it facilitates navigation in the file; please
preserve it. :-)
> +(define* (open-luks-device source targets #:key key-file allow-discards?)
> "Return a gexp that maps SOURCE to TARGET as a LUKS device, using
> 'cryptsetup'."
Please briefly document ‘allow-discards?’ in the docstring…
> +(define* (luks-device-mapping-with-options #:key key-file allow-discards?)
> "Return a luks-device-mapping object with open modified to pass the arguments
> into the open-luks-device procedure."
… also here, and also in a bit more detail in the relevant place in
‘doc/guix.texi’.
Thanks in advance!
Ludo’.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-15 16:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-06 9:42 [bug#73654] [PATCH] gnu: luks-device-mapping-with-options: Add allow-discards? argument Sisiutl
2024-11-06 13:57 ` Hilton Chain via Guix-patches via
2024-12-15 16:31 ` Ludovic Courtès
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).