From patchwork Mon Sep 22 13:12:04 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: 43430 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 2C85D27BC49; Mon, 22 Sep 2025 14:13:49 +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=unavailable 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 2C48B27BC4A for ; Mon, 22 Sep 2025 14:13:48 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0gMA-0002B9-M6; Mon, 22 Sep 2025 09:13:27 -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 1v0gLr-00029R-9g for guix-patches@gnu.org; Mon, 22 Sep 2025 09:13:07 -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 1v0gLp-0003PA-5P; Mon, 22 Sep 2025 09:13:06 -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=230iwawaz+EiGrO9Fo0a1ZRShUJiaRor4Umq4rGnPEs=; b=WbwIEPitR25aOnWPPVw9cDzAJkRZH0hxBhFZV8C7cYF5eCBk3b/kbqXQraZvFiXEe+7qtC6yW2DzFcT/Q1zPuJLMUvg14MUCWy4gQ+TgOOqAMaMntlCzLILTS6M/N/WpuL7Ik4qjkXUKSSSmt+/GDX282ctyfCFbSMEIDBTZZg05eUt3eaz+NADqGCDItGzQOqu/zwwfzu0pJdxntNOET5UBZuHf+Dqgbra/KPAQX1UjmxDaxx1CBzcgtsAoESXcViebM6iAjNzjTjIi+Gvz3MLRBIYhEldDIsPdqi20rBT2udnX7n3flaZmql80NDVeTvkwIOVtkEmYHl+abKx5Zg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1v0gLm-0005wp-A1; Mon, 22 Sep 2025 09:13:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77499] [PATCH v5] 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: Mon, 22 Sep 2025 13:13: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: 77499@debbugs.gnu.org, soeren@soeren-tempel.net, Tadhg McDonald-Jensen , Ludovic =?utf-8?q?Court?= =?utf-8?q?=C3=A8s?= , Gabriel Wicki , 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.175854676522816 (code B ref 77499); Mon, 22 Sep 2025 13:13:02 +0000 Received: (at 77499) by debbugs.gnu.org; 22 Sep 2025 13:12:45 +0000 Received: from localhost ([127.0.0.1]:33686 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1v0gLT-0005vu-Pf for submit@debbugs.gnu.org; Mon, 22 Sep 2025 09:12:45 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:55362) 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 1v0gLA-0005v3-NA for 77499@debbugs.gnu.org; Mon, 22 Sep 2025 09:12:31 -0400 Received: by mail-pg1-x543.google.com with SMTP id 41be03b00d2f7-b55517e74e3so883728a12.2 for <77499@debbugs.gnu.org>; Mon, 22 Sep 2025 06:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758546737; x=1759151537; 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=230iwawaz+EiGrO9Fo0a1ZRShUJiaRor4Umq4rGnPEs=; b=FqMdxOw5+KTtUgwX6Jr2TLNqhvEqz8JPKRq5EjqiZeSt+MQOdPD4JWFEVHasdbG4ej LNgUfQ8Q9HopCQLnBXuqfQ0qeFovafKWYvoRaHHlRhtAvH7zb7tqjTplsCsLQWYzJKZH bPlzw7UDAM0yaMXFkP+bLc8WoirCiI9J3DYt/+5WBYHcqPFaWpyRgoFf4qpjIDT1UVXg 71cLoWVAr03fw95x5mdkAWIAPoOZv00Dwywuwy0My2G403CL678UQ+PZKL9yR7AyE9/z U6kqAkdv1mdf5sK93kOn42VTyZQNJyyysN2rW2/PoX4RlENXvM3U+eDVScktTJKOCW/X t1Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758546737; x=1759151537; 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=230iwawaz+EiGrO9Fo0a1ZRShUJiaRor4Umq4rGnPEs=; b=e4FpXbf9qiIoJpanoEH0D+2pkgOjpnO1fsx4v6yVZr+8dlNcOfM4k9MklCpWdyr91k ENA8BqkByuE/+KgEPcthy4ssBmtooAt/6ALiNkhGfMJ+0eGPctCFnn3Q4PQmnRwXUAd2 Sck7gpZ7c+2axsHfO07vR/z2nwxtyVz/sWhZWxFjJYS9P0emp178HcHuG8/om4/z+fPZ NmKy/KawrPwEur9HrPZtRGyqIwzDH3cQh3S9MbOWkW9veUdhZjpjcxjKSYhRXKmu1+no cCZ3XbZ7SI7Jva20Dax84qhIx/8ULYikGEj0OCAk7FaDTZCOZlpKUlZGX3+ByTlEsA9E b8GA== X-Forwarded-Encrypted: i=1; AJvYcCWvNAjr5nhPqXtebSjddR8hn4M/v6jGhoZSNnylAXVPhxAe2qa3gFj8kRjrYdVr17GhN9LzQg==@debbugs.gnu.org X-Gm-Message-State: AOJu0YwFD+PV+r/46813XuFOyBg4KGXjBJPKHcyq7nV75VB5PX489BSP e35XV7TToRqqM9aScyq3L9TmBVdyQvBxbB11mBAiWECi8PTTyK3bAcJB X-Gm-Gg: ASbGncv3FJLtALcMZKbyMvR8PHJNdY6B1D1JrItYW2ayvsv/9EKnE8IZ3z94gUhqfnU V9rfiWhIKEgiutslOgl9Ue01wjxqT405cVFZLOw55oExAeNWLGLWKYai3a5LMd3Z3lh46mOL4Lk EAfDhSvSxU5KEsjwHAhDwiM3W2P04DQILf1s/sRFLlO0UxVNoCdcmPWZd4bilzdy5wnC1n2nQ9F VXgM3Cxa4OW9i7DmiqF8OAtNgFTjDqPFexTjDBaFSsq6OrX6TU/Axw1cP4V9R3hYAju2rx4Sb45 R6OuIQamERtv149mhe9mTAcwBo26rUvKdGqo4GnuvidRvKHNHRmXuGWCWg7sqYxbr1MyA6d6/Yc 8/ljJLalmu38kuULUBZI= X-Google-Smtp-Source: AGHT+IHM7B66A7GxyGI8NHvLFWZQYh/NE90MASmFkOeEJbVAP3asX83IGFU6zbvvu33ijib3wsJpnA== X-Received: by 2002:a17:90b:2787:b0:32d:90c7:c63b with SMTP id 98e67ed59e1d1-33098372be8mr13787270a91.30.1758546737434; Mon, 22 Sep 2025 06:12:17 -0700 (PDT) Received: from guix1 ([2401:4900:633e:73ef:743:6f34:7e48:262f]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32eb303158bsm8052629a91.0.2025.09.22.06.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 06:12:16 -0700 (PDT) From: 45mg <45mg.writes@gmail.com> Date: Mon, 22 Sep 2025 18:42:04 +0530 Message-ID: X-Mailer: git-send-email 2.50.1 In-Reply-To: <87zfan757b.fsf_-_@guixotic.coop> References: <87zfan757b.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: I265a431efb0c81ed7cfc984344c6b8a4cc2f1624 --- Specified default value of #:extra-options in check-luks-device; now system tests should work again (ran encrypted-root-os, encrypted-root-extra-options-os and encrypted-home-os-key-file successfully). Fixed indentation of example in doc/guix.texi, per Ludo's input on v3. doc/guix.texi | 21 +++++++++++ gnu/system/mapped-devices.scm | 29 +++++++++++---- gnu/tests/install.scm | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 6 deletions(-) base-commit: ea4a3af73940e3fd578326510eccb2d5747352b4 diff --git a/doc/guix.texi b/doc/guix.texi index 0924aebf4a..c3010119a1 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 +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 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..d568bddc4f 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,13 @@ (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") + '()) + '#$extra-options + (list partition #$target))))) ;; We want to fallback to the password unlock if the keyfile ;; fails. (or (and keyfile @@ -271,6 +277,17 @@ (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 + ((extra-options '()) + key-file allow-discards) + (unless (list? 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