From patchwork Tue Sep 16 12:17:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 45mg <45mg.writes@gmail.com> X-Patchwork-Id: 43427 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9CDE427BC4C; Tue, 16 Sep 2025 13:19:44 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,DMARC_NONE,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 49B2B27BC4A for ; Tue, 16 Sep 2025 13:19:43 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uyUeM-0002Xd-Um; Tue, 16 Sep 2025 08:19:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uyUeH-0002TB-Oc for guix-patches@gnu.org; Tue, 16 Sep 2025 08:19:05 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uyUeH-0007rs-7G; Tue, 16 Sep 2025 08:19:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=Aw0WFCZES8FfsEDTu0rFo1CpmrN8IH9D/x9BHB7jeOw=; b=P2RNq2avXKGNCGPl0zZpUUSsCq0ailz+RkK1RNTCaBlzro1QzyvXZY7CFE4GMwmVb09Jj9ToDXBQF6GGYuQi9w1OqCX0Ayt9oeW/EUx1y9zj8jVhwiw14TBrFAyNYP5Tjt7DOfRKrM1yAZD+bKJypTr0kQJSpso2pvTun2/cbfFxpvNyhBdMmqm3KNCq5KiQ6bZkW8Vm0vFeU92Mfei5O8eECMoEJbL3/xZ8Rzi5V3wrPrqIqc6FhBzkpCpZeensONgKsqdS0qC5mookMAFvpWy7XZftoOJFN9UFNii1XTVK23Rdjpk68bRbH/QT26boXXRfyn4K9eFlGKkvK2g3mg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uyUeE-0007nl-Hb; Tue, 16 Sep 2025 08:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77499] [PATCH v3] mapped-devices/luks: Support extra options. Resent-From: 45mg <45mg.writes@gmail.com> Original-Sender: "Debbugs-submit" Resent-CC: gabriel@erlikon.ch, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Tue, 16 Sep 2025 12:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77499 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxim Cournoyer , 45mg <45mg.writes@gmail.com> Cc: Gabriel Wicki , soeren@soeren-tempel.net, Tadhg McDonald-Jensen , Ludovic =?utf-8?q?Court?= =?utf-8?q?=C3=A8s?= , 77499@debbugs.gnu.org, gmail.com@debbugs.gnu.org, Sisiutl , 70826@debbugs.gnu.org, Hilton Chain , Tomas Volf <~@wolfsden.cz>, Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 77499-submit@debbugs.gnu.org id=B77499.175802512129936 (code B ref 77499); Tue, 16 Sep 2025 12:19:02 +0000 Received: (at 77499) by debbugs.gnu.org; 16 Sep 2025 12:18:41 +0000 Received: from localhost ([127.0.0.1]:47737 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uyUds-0007mm-Jj for submit@debbugs.gnu.org; Tue, 16 Sep 2025 08:18:41 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:43361) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <45mg.writes@gmail.com>) id 1uyUdi-0007lw-W9 for 77499@debbugs.gnu.org; Tue, 16 Sep 2025 08:18:33 -0400 Received: by mail-pj1-x1042.google.com with SMTP id 98e67ed59e1d1-32e74ae0306so1418483a91.1 for <77499@debbugs.gnu.org>; Tue, 16 Sep 2025 05:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758025104; x=1758629904; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Aw0WFCZES8FfsEDTu0rFo1CpmrN8IH9D/x9BHB7jeOw=; b=jBiYouGYwtTy4LnktN4sfZb5UbsCfGDZGAh2e3J0Y86uruLQwzRktlst1g97vkEJ7/ SgFtCCb2b+XrVM0PXgqaho+lpfTZHyjfg4UlsB7n5APfZkfaGsNvSkx9TU4JK+wB4q5M eJVqlVtQP7XHxFOPppCyBDAS2CiZ0klJySjN13L0BKhRidCtvpm4lKtMAihF+GnVP9C/ JGKjIVFcTIYLZ7ral7Wl/hdJOdWY9AhLCt4OpYDdN/lulAhYvYBwZArm5VpH3pXO0UJy BkI3/he7l+FpQiFTbJ8nqRsXSRrZ/W2St4/t4NPooOP4rvPZwG2DLt/jBVieWG3wBEJp o+WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758025104; x=1758629904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Aw0WFCZES8FfsEDTu0rFo1CpmrN8IH9D/x9BHB7jeOw=; b=j2DqRxzwYrKgSj+eEM99oxDEDJR0AHExsgqBUdkJP1jsf/WYgZie11vuMRdcwlVajS lB2BZJtbuk4pbMJ5xoeqjF0Cp7nE8hKICyrnggOhzoRlEnxecNCjcmNXzFYDzzcZ9EGi enNU+ZW5n8fhDbGBpjvVgHZ8HFnz6K+rJ5xjn6Wa1X6HXXGAlFsAMgIXnyfJmKackaw6 gXot4uWyGJXuqQJuTC6hfduHw7H09QAG/zinnPqyp75DEyq+h24uLlnvgHFnebQWwDmy GixjTb8m2RPg8IMnIZJwaVT9z4jEnPuYJoLR+l/fJgqaat8zw+J9+W0k449rI7/GIh37 i+GA== X-Forwarded-Encrypted: i=1; AJvYcCWUpn0NUi/BYowhPv4wh5WL0P6LW4QevNu1lKK9k7+gdaPb03j/JAwQrzvIpkO5oAA5U6XR/Q==@debbugs.gnu.org X-Gm-Message-State: AOJu0YyyFcwu99lUAP5/uZJUFsY2tQoV1MPMa9FslhesDCCeu8AFQy6M jyCIgyV+kFd662K6y6Lm6mB99n8L1uJqaLkzlBrDOOTpy16hDSDX5a7v X-Gm-Gg: ASbGncu8u2HCx5+vVWEA1ld0RLLcPeK0kCvWg8E8OyjGW0ZHxD8YRWYtee1dte/7fwO y+5jpBHMn7UaDX6FmQ+/QzqiR6mnAoNfo/RwkDvXOqjapE0vt1A+x3kQSdF0cSa5B6Afo10gHQ+ QmY86tUj3bXBXL5J/4vT0J542wB2GDdWJ1+QwJrsF4I/z9/gzTOsrjNujiM+VKAtrse7SBGGzbj 08eKq1aUhgUCbNCxsMo4BaaRsd3Y6BObQEXUDo/guUI+KpbpKT3CUnDYOlyEqB95qa/iCOq5WqO pwZ1Gg2dY77tMkfAkkTQTNEvqdk9l/1ZDuQ7lHv+xNeXyISqJsikGR6La0aaT2tpaiQOgc3NCSB IiA/VtaaQI8D3VLsF8NOx X-Google-Smtp-Source: AGHT+IFr8a+xUNR/kust7ULBL4+GuFYlnq6WbaImd4o7Ht3pQKRoQzJCB6eO+SDpNB2Db+n4mV+hQQ== X-Received: by 2002:a17:90b:4b82:b0:32d:fd14:600b with SMTP id 98e67ed59e1d1-32ea60d5664mr2704169a91.7.1758025104259; Tue, 16 Sep 2025 05:18:24 -0700 (PDT) Received: from guix1 ([2401:4900:633e:c23a:e612:db2b:a44b:43bc]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32dfce3c5e0sm11661586a91.9.2025.09.16.05.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Sep 2025 05:18:23 -0700 (PDT) From: 45mg <45mg.writes@gmail.com> Date: Tue, 16 Sep 2025 17:47:43 +0530 Message-ID: X-Mailer: git-send-email 2.50.1 In-Reply-To: <87cy8ypubs.fsf@guixotic.coop> References: <87cy8ypubs.fsf@guixotic.coop> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Allow passing extra options to the 'cryptsetup open' command. * gnu/system/mapped-devices.scm (luks-device-mapping-with-options): [#:extra-options]: New argument. (open-luks-device): Use it. (check-luks-device): Validate it. * doc/guix.texi (Mapped Devices): Document it. * gnu/tests/install.scm (%test-encrypted-root-extra-options-os): New test for it, as well as the previously untested #:allow-discards? option. (%encrypted-root-extra-options-os): New os declaration for the test. Change-Id: Ibbc3cf4f2ee4d49099a3155a015f54d319515663 --- Add default value '() as suggested by Maxim. Also, add the suggested validation in check-luks-device. doc/guix.texi | 21 +++++++++++ gnu/system/mapped-devices.scm | 30 ++++++++++++---- gnu/tests/install.scm | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 6 deletions(-) base-commit: ea4a3af73940e3fd578326510eccb2d5747352b4 diff --git a/doc/guix.texi b/doc/guix.texi index 0924aebf4a..74a6367e43 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -18774,6 +18774,27 @@ Mapped Devices file system level operations visible on the physical device. For more information, refer to the description of the @code{--allow-discards} option in the @code{cryptsetup-open(8)} man page. + +@item #:extra-options +@code{extra-options} may be used to specify a list of additional +command-line options for the @code{cryptsetup open} command. See the +@code{cryptsetup-open(8)} man page for a list of supported options. + +For example, here is how you could specify the +@option{--perf-no_read_workqueue} and @option{--perf-no_write_workqueue} +options, along with @option{--allow-discards}: + +@lisp +(mapped-device +(source "/dev/sdb1") +(target "data") +(type (type luks-device-mapping) + (arguments '(#:allow-discards? #t + #:extra-options + ("--perf-no_read_workqueue" + "--perf-no_write_workqueue"))))) +@end lisp + @end table @end defvar diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm index b0a6beef28..a2d49c55a5 100644 --- a/gnu/system/mapped-devices.scm +++ b/gnu/system/mapped-devices.scm @@ -43,6 +43,7 @@ (define-module (gnu system mapped-devices) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (ice-9 match) + #:use-module (ice-9 optargs) #:use-module (ice-9 format) #:export (%mapped-device mapped-device @@ -200,10 +201,12 @@ (define (check-device-initrd-modules device linux-modules location) ;;; Common device mappings. ;;; -(define* (open-luks-device source targets #:key key-file allow-discards?) +(define* (open-luks-device source targets + #:key key-file allow-discards? (extra-options '())) "Return a gexp that maps SOURCE to TARGET as a LUKS device, using 'cryptsetup'. When ALLOW-DISCARDS? is true, the use of discard (TRIM) -requests is allowed for the underlying device." +requests is allowed for the underlying device. EXTRA-OPTIONS is a list of +additional options to be passed to the 'cryptsetup open' command." (with-imported-modules (source-module-closure '((gnu build file-systems) (guix build utils))) ;; For mkdir-p @@ -244,10 +247,15 @@ (define* (open-luks-device source targets #:key key-file allow-discards?) (let ((cryptsetup #$(file-append cryptsetup-static "/sbin/cryptsetup")) (cryptsetup-flags (cons* - "open" "--type" "luks" partition #$target - (if #$allow-discards? - '("--allow-discards") - '())))) + "open" "--type" "luks" + (append + (if #$allow-discards? + '("--allow-discards") + '()) + (if (pair? '#$extra-options) + '#$extra-options + '()) + (list partition #$target))))) ;; We want to fallback to the password unlock if the keyfile ;; fails. (or (and keyfile @@ -271,6 +279,16 @@ (define* (check-luks-device md #:key "Ensure the source of MD is valid." (let ((source (mapped-device-source md)) (location (mapped-device-location md))) + (let-keywords (mapped-device-arguments md) #t + (key-file allow-discards extra-options) + (unless (pair? extra-options) + (raise (make-compound-condition + (formatted-message (G_ "invalid value ~s for #:extra-options \ +argument of `open-luks-device'") + extra-options) + (condition + (&error-location + (location (source-properties->location location)))))))) (or (not (zero? (getuid))) (if (uuid? source) (match (find-partition-by-luks-uuid (uuid-bytevector source)) diff --git a/gnu/tests/install.scm b/gnu/tests/install.scm index ec31cf2bdf..c6715484cf 100644 --- a/gnu/tests/install.scm +++ b/gnu/tests/install.scm @@ -68,6 +68,7 @@ (define-module (gnu tests install) %test-separate-home-os %test-raid-root-os %test-encrypted-root-os + %test-encrypted-root-extra-options-os %test-encrypted-home-os %test-encrypted-home-os-key-file %test-encrypted-root-not-boot-os @@ -843,6 +844,73 @@ (define %test-encrypted-root-os (run-basic-test %encrypted-root-os command "encrypted-root-os" #:initialization enter-luks-passphrase))))) + +;;; +;;; LUKS-encrypted root with extra options: --allow-discards, +;;; --perf-no_read_workqueue and --perf-no_write_workqueue +;;; + +;; Except for the 'mapped-devices' field, this is exactly the same as +;; %encrypted-root-os. +(define-os-with-source (%encrypted-root-extra-options-os + %encrypted-root-extra-options-os-source) + ;; The OS we want to install. + (use-modules (gnu) (gnu tests) (srfi srfi-1)) + + (operating-system + (host-name "liberigilo") + (timezone "Europe/Paris") + (locale "en_US.UTF-8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (targets '("/dev/vdb")))) + + ;; Note: Do not pass "console=ttyS0" so we can use our passphrase prompt + ;; detection logic in 'enter-luks-passphrase'. + + (mapped-devices (list (mapped-device + (source (uuid "12345678-1234-1234-1234-123456789abc")) + (target "the-root-device") + (type luks-device-mapping) + (arguments '(#:allow-discards? #t + #:extra-options + ("--perf-no_read_workqueue" + "--perf-no_write_workqueue")))))) + (file-systems (cons (file-system + (device "/dev/mapper/the-root-device") + (mount-point "/") + (type "ext4")) + %base-file-systems)) + (users (cons (user-account + (name "charlie") + (group "users") + (supplementary-groups '("wheel" "audio" "video"))) + %base-user-accounts)) + (services (cons (service marionette-service-type + (marionette-configuration + (imported-modules '((gnu services herd) + (guix combinators))))) + %base-services)))) + +(define %test-encrypted-root-extra-options-os + (system-test + (name "encrypted-root-extra-options-os") + (description + "Test basic functionality of an OS installed like one would do by hand, +with an LUKS-encrypted root partition opened with extra options +(--allow-discards, --perf-no_read_workqueue and --perf-no_write_workqueue). +This test is expensive in terms of CPU and storage usage since we need to +build (current-guix) and then store a couple of full system images.") + (value + (mlet* %store-monad ((images (run-install %encrypted-root-extra-options-os + %encrypted-root-extra-options-os-source + #:script + %encrypted-root-installation-script)) + (command (qemu-command* images))) + (run-basic-test %encrypted-root-os command "encrypted-root-extra-options-os" + #:initialization enter-luks-passphrase))))) + ;;; ;;; Separate /home on LVM