From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id qLlaNIV4mV99SgAA0tVLHw (envelope-from ) for ; Wed, 28 Oct 2020 13:56:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id mCQxMIV4mV83BAAAB5/wlQ (envelope-from ) for ; Wed, 28 Oct 2020 13:56:21 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 948E2940149 for ; Wed, 28 Oct 2020 13:56:21 +0000 (UTC) Received: from localhost ([::1]:40622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlw4-0000hg-JR for larch@yhetil.org; Wed, 28 Oct 2020 09:56:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXlvn-0000g0-IF for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38433) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kXlvm-0003XY-Ia for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kXlvm-0006gV-FI for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#44169] [PATCH v2 2/3] services: swap: Allow for UUIDs and file system labels. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 28 Oct 2020 13:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44169@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 44169-submit@debbugs.gnu.org id=B44169.160389335025676 (code B ref 44169); Wed, 28 Oct 2020 13:56:02 +0000 Received: (at 44169) by debbugs.gnu.org; 28 Oct 2020 13:55:50 +0000 Received: from localhost ([127.0.0.1]:49976 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlva-0006g3-Cr for submit@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlvU-0006f5-Uk for 44169@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:45 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:44164) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlvP-0003VA-NY; Wed, 28 Oct 2020 09:55:39 -0400 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:38634 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kXlvO-0001bF-Lo; Wed, 28 Oct 2020 09:55:39 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 28 Oct 2020 14:54:56 +0100 Message-Id: <20201028135457.23335-2-ludo@gnu.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201028135457.23335-1-ludo@gnu.org> References: <87imaxdwv5.fsf@gnu.org> <20201028135457.23335-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 3.49 X-TUID: hHC1EyIZmwtd * gnu/services/base.scm (swap-service-type)[device-lookup, device-name]: New variables. Add 'modules' field to 'shepherd-service'. In 'start' and 'stop', use 'device-lookup' to resolve UUIDs and labels. * doc/guix.texi (operating-system Reference): Adjust accordingly. --- doc/guix.texi | 34 +++++++++++++++++++++++---- gnu/services/base.scm | 54 +++++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 17 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index efb4ea1c47..feb5760129 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13043,14 +13043,38 @@ A list of mapped devices. @xref{Mapped Devices}. @item @code{file-systems} A list of file systems. @xref{File Systems}. -@item @code{swap-devices} (default: @code{'()}) @cindex swap devices -A list of strings identifying devices or files to be used for ``swap +@cindex swap space +@item @code{swap-devices} (default: @code{'()}) +A list of UUIDs, file system labels, or strings identifying devices or +files to be used for ``swap space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference -Manual}). For example, @code{'("/dev/sda3")} or @code{'("/swapfile")}. +Manual}). Here are some examples: + +@table @code +@item (list (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")) +Use the swap partition with the given UUID. You can learn the UUID of a +Linux swap partition by running @command{swaplabel @var{device}}, where +@var{device} is the @file{/dev} file name of that partition. + +@item (list (file-system-label "swap")) +Use the partition with label @code{swap}. Again, the +@command{swaplabel} command allows you to view and change the label of a +Linux swap partition. + +@item (list "/swapfile") +Use the file @file{/swapfile} as swap space. + +@item (list "/dev/sda3" "/dev/sdb2") +Use the @file{/dev/sda3} and @file{/dev/sdb2} partitions as swap space. +We recommend referring to swap devices by UUIDs or labels as shown above +instead. +@end table + It is possible to specify a swap file in a file system on a mapped -device, provided that the necessary device mapping and file system are -also specified. @xref{Mapped Devices} and @ref{File Systems}. +device (under @file{/dev/mapper}), provided that the necessary device +mapping and file system are also specified. @xref{Mapped Devices} and +@ref{File Systems}. @item @code{users} (default: @code{%base-user-accounts}) @itemx @code{groups} (default: @code{%base-groups}) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 37b0a13ea7..07d9089b0a 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -2104,22 +2104,52 @@ instance." 'swap (lambda (device) (define requirement - (if (string-prefix? "/dev/mapper/" device) + (if (and (string? device) + (string-prefix? "/dev/mapper/" device)) (list (symbol-append 'device-mapping- (string->symbol (basename device)))) '())) - (shepherd-service - (provision (list (symbol-append 'swap- (string->symbol device)))) - (requirement `(udev ,@requirement)) - (documentation "Enable the given swap device.") - (start #~(lambda () - (restart-on-EINTR (swapon #$device)) - #t)) - (stop #~(lambda _ - (restart-on-EINTR (swapoff #$device)) - #f)) - (respawn? #f))))) + (define (device-lookup device) + ;; The generic 'find-partition' procedures could return a partition + ;; that's not swap space, but that's unlikely. + (cond ((uuid? device) + #~(find-partition-by-uuid #$(uuid-bytevector device))) + ((file-system-label? device) + #~(find-partition-by-label + #$(file-system-label->string device))) + (else + device))) + + (define service-name + (symbol-append 'swap- + (string->symbol + (cond ((uuid? device) + (string-take (uuid->string device) 6)) + ((file-system-label? device) + (file-system-label->string device)) + (else + device))))) + + (with-imported-modules (source-module-closure '((gnu build file-systems))) + (shepherd-service + (provision (list service-name)) + (requirement `(udev ,@requirement)) + (documentation "Enable the given swap device.") + (modules `((gnu build file-systems) + ,@%default-modules)) + (start #~(lambda () + (let ((device #$(device-lookup device))) + (and device + (begin + (restart-on-EINTR (swapon device)) + #t))))) + (stop #~(lambda _ + (let ((device #$(device-lookup device))) + (when device + (restart-on-EINTR (swapoff device))) + #f))) + (respawn? #f)))))) (define (swap-service device) "Return a service that uses @var{device} as a swap device." -- 2.28.0