From patchwork Sun Sep 21 09:14:02 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: 43428 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 7336527BC4B; Sun, 21 Sep 2025 10:16:21 +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 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 7E9B327BC49 for ; Sun, 21 Sep 2025 10:16:20 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0GAx-00067f-Gi; Sun, 21 Sep 2025 05:16:07 -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 1v0GAt-00067B-DO for guix-patches@gnu.org; Sun, 21 Sep 2025 05:16:03 -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 1v0GAt-0002dg-2W; Sun, 21 Sep 2025 05:16:03 -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=BxnrmAuSUeemRyi7GD6tET3gkhkxDpXCBKq8XLRKoG4=; b=o8a0+jpK+hC5K2mWPC/20uVwhsJHKqEGxyHMZDboeVce5Wdfwo1QJ+zdcC8xXKZnE7Efrr8PzHXmRPPIKWVLIyEuGb1gHfZhfKK2/aTrj1UJCUBqfx+PYDMwCMcmo/Ebs5Gksigkrc4e3cAwSC4rE+kY4slEaR8fUSXJoUgUoUD8Oo7/35B165+Ceu/SohUQMR6rYCTVYIhvxuNENA5LToaZvvp2ti3vuYfjuBjOOBVmLz0gnD0Czy149meKtPhIcYyhgE/HK2WMO5Sed14P5RAmm3VhkmbGf1wyq22/9qBrn37hNo4bYdpAqFyOMtCIgBlqasJ0INJThkT5alBghA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1v0GAs-00083l-RD; Sun, 21 Sep 2025 05:16:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77499] [PATCH v4] 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: Sun, 21 Sep 2025 09:16: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: 45mg <45mg.writes@gmail.com>, Maxim Cournoyer 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.175844610630667 (code B ref 77499); Sun, 21 Sep 2025 09:16:02 +0000 Received: (at 77499) by debbugs.gnu.org; 21 Sep 2025 09:15:06 +0000 Received: from localhost ([127.0.0.1]:52776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1v0G9x-0007xF-Dn for submit@debbugs.gnu.org; Sun, 21 Sep 2025 05:15:06 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:58382) 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 1v0G9t-0007v1-Rq for 77499@debbugs.gnu.org; Sun, 21 Sep 2025 05:15:02 -0400 Received: by mail-pj1-x1042.google.com with SMTP id 98e67ed59e1d1-323266d6f57so3548114a91.0 for <77499@debbugs.gnu.org>; Sun, 21 Sep 2025 02:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758446095; x=1759050895; 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=BxnrmAuSUeemRyi7GD6tET3gkhkxDpXCBKq8XLRKoG4=; b=boCWpBOWiP6QNi/2VHK3Dt4G8T3NEMSANVdsbppoAAGfx9JEwTHC0QNq9EDjg8BmR+ gAM5C1tTYforbGcmdXyNhrPtsvvwAGG94aW/k5RYDZ06+I2dw4/fMyIDeNBCgsqcSwrD 4Nc7I2YQxUNmTdoJjsOcCvSuxmzgy0O+wqu0akCNYrMbjBdmqxbWHLQXd/1mzjsBzbn7 SIPjCHaGoTO7dlvM0L1fjhIQ+0oKAv8wgpYFYHAFDu7W8YkS+s2TUH0favYKVtpQkBjo iRgbKhwOZGVNF8NR9fxyJLhXRGHdHac8qxXkCxCfhFgwfNyEnyo54Gtt3fxFRudSlwns qIzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758446095; x=1759050895; 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=BxnrmAuSUeemRyi7GD6tET3gkhkxDpXCBKq8XLRKoG4=; b=ChkigVA58fTb6R2hdomeIVSfq1CQfRdhC3nkQX06nwPsUoCmKUV1HbQR2uQByDv4E3 bxISSXt1PUMvjuEhJ19srW8PKauxAZSM2+kjkGirjybw4LFnhBu3qvsrQMBgUmAQNDDU zCzQg230vP+mKb0NzzDNmF21nXuBMVg4F42Sx96fW5+dYQQBvYmZf6FSzw9+M6y0Pr8A 0wWBkYOKK8f4WbpVDcdYoY0g3B8r7weVLAke/6eb/CznfLBGOhx333HOZ3Rp7ggfIIza 5TxX7kNrKX94clrkjqDKfF2Nk2KvGTA06ts+BH4vrCBtXcAsGPtvwCbz5p5ary6ApyWw C5nA== X-Forwarded-Encrypted: i=1; AJvYcCV5E9RLirkXBsC8deWkJLTAjoPIk8dL9/JlUA7T5GWrxU8VkBCjL4lN4BhlCn1NRE1WV4/WUA==@debbugs.gnu.org X-Gm-Message-State: AOJu0YxGzQPj1UYVWakkYO+mOe+L74p0EUPGhWz1mHWlLKtdPSHrfdRo M/yfBdBZ53EHSw2uODNmXbBUCQ9VXvp0cDkhcu9QEYtLJ/FCPXcYSvC3 X-Gm-Gg: ASbGncs2gu350fyoVi/5RZDsdr5kTWxwq9dvQEY1x5ybDJyqDkzdTZ/d8GJYhoiXymS uB/mYW2h98+5idXK3aGVYk25Ooi3dNka+5UInplyKvi3yNYq4VdnBomuigjZuP4bb0KkRrqq3X7 abyly/4sr/yH9z5AnDlkygwC4njSPMPNYJFB6YKJLjEFdxwfd5/fteKVHESyz4n+thOu0VFiV8f q6/5gPZUT9ZjbedvE7rrnEErBpBh94MpiVRmQ/1nAyqC64v86j3cYjjUaBdUsZZ7TbsoUxuiTr1 xLzhjhd1e9LqmP5f3cRtCMhL5Gnf07A35bfjlblN7X76MQysUDyGJsm8WndMGGtv/FPC/A1wdG6 RMXGFTLdw83Iyq5Ec8Q1CNn+s1A== X-Google-Smtp-Source: AGHT+IEUtmhr3xmBE3ZMfdDnMUb+xuaGLWH4UXm6wRZgVbNWXdgce4LeTmv/s70CnO9vpSJNWJt2VA== X-Received: by 2002:a17:90b:4cd2:b0:32e:7270:949c with SMTP id 98e67ed59e1d1-3309838d098mr12627066a91.35.1758446095310; Sun, 21 Sep 2025 02:14:55 -0700 (PDT) Received: from guix1 (utm.nitt.edu. [203.129.195.130]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-77f2d414457sm1275601b3a.30.2025.09.21.02.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Sep 2025 02:14:54 -0700 (PDT) From: 45mg <45mg.writes@gmail.com> Date: Sun, 21 Sep 2025 14:44:02 +0530 Message-ID: X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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: I1bd8d2dcdfc50f4790a9fe0629ac7c25cbbce83d --- Changed wording in doc/guix.texi as per Ludo's suggestion. Removed superfluous validation from open-luks-device; it was already done in check-luks-device. doc/guix.texi | 21 +++++++++++ gnu/system/mapped-devices.scm | 28 +++++++++++---- gnu/tests/install.scm | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 6 deletions(-) base-commit: ea4a3af73940e3fd578326510eccb2d5747352b4 diff --git a/doc/guix.texi b/doc/guix.texi index 0924aebf4a..066143a35a 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 (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..a97bcc26b8 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,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