unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 37305@debbugs.gnu.org
Subject: [bug#37305] [PATCH] Allow booting from a Btrfs subvolume.
Date: Wed, 12 Feb 2020 03:47:40 -0500	[thread overview]
Message-ID: <87k14sfaz7.fsf@gmail.com> (raw)
In-Reply-To: <87y2yg3t3s.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sun, 22 Sep 2019 23:43:03 +0200")

[-- Attachment #1: Type: text/plain, Size: 212 bytes --]

Hello Ludovic!

My much delayed answer to your review are the attached, much improved
patches.

The new test passes and I'm already using this on one of my system successfully.

Thanks for your patience,

Maxim


[-- Attachment #2: 0001-gnu-tests-Reduce-the-time-required-to-run-the-system.patch --]
[-- Type: text/x-patch, Size: 6105 bytes --]

From 3640bea548826e1c1ec9b766da1fdfe4791d7452 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sun, 17 Nov 2019 06:01:00 +0900
Subject: [PATCH 1/8] gnu: tests: Reduce the time required to run the system
 tests.

When setting the GUIX_DEV_HACKS environment variable, the Guix package used
inside the instrumented VMs recycles the binaries already found in the Guix
checkout of the developer instead of rebuilding Guix from scratch.  This
brings the time required for this component from 20+ minutes down to 2-3
minutes on an X200 machine.

* gnu/packages/package-management.scm (current-guix/pre-built): New procedure.
* build-aux/run-system-tests.scm (tests-for-channel-instance): Use it, when
GUIX_DEV_HACKS is defined.
---
 build-aux/run-system-tests.scm      | 11 ++++-
 gnu/packages/package-management.scm | 66 +++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/build-aux/run-system-tests.scm b/build-aux/run-system-tests.scm
index b0cb3bd2bf..04b6fa29c3 100644
--- a/build-aux/run-system-tests.scm
+++ b/build-aux/run-system-tests.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2016, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -58,8 +59,16 @@ instance."
   ;; of tests to run in the usual way:
   ;;
   ;;   make check-system TESTS=installed-os
+
+  ;; When the GUIX_DEV_HACKS environment variable is defined, override the
+  ;; package returned by `current-guix' with a flavor that saves recompiling
+  ;; Guix from scratch and reuse the developer's checkout binaries.  The
+  ;; override "builds" about 20 times faster than the regular `current-guix'
+  ;; package, which can help speed iterative development.
   (parameterize ((current-guix-package
-                  (channel-instance->package instance)))
+                  (if (getenv "GUIX_DEV_HACKS")
+                      (current-guix/pre-built)
+                      (channel-instance->package instance))))
     (match (getenv "TESTS")
       (#f
        (all-system-tests))
diff --git a/gnu/packages/package-management.scm b/gnu/packages/package-management.scm
index 422d4f1959..bd2ed85189 100644
--- a/gnu/packages/package-management.scm
+++ b/gnu/packages/package-management.scm
@@ -468,6 +468,72 @@ out) and returning a package that uses that as its 'source'."
                                 #:recursive? #t
                                 #:select? (force select?))))))))
 
+(define-public (current-guix/pre-built)
+  "Similar to `current-guix', but with a modified build procedure that
+reuses the existing byte compiled artifacts to save recompilation time."
+
+  (let* ( ;; The `current-source-directory' macro doesn't work from the REPL.
+         ;; For testing, you can replace it with a static string pointing to
+         ;; your Guix checkout directory.
+         (repository-root (delay (canonicalize-path
+                                  (string-append (current-source-directory)
+                                                 "/../.."))))
+         (select? (lambda (file stat)
+                    (match (basename file)
+                      ((or ".git"
+                           "configure" "autom4te.cache"
+                           "config.log" "config.status"
+                           "stamp-1" "stamp-2" "stamp-3" "stamp-4" "stamp-5"
+                           "stamp-h1" "stamp-vti"
+                           "Makefile" "Makefile.in" ".libs"
+                           ".deps" ".dirstamp"
+                           "test-tmp"
+                           ) #f)
+                      (_ #t)))))
+    (package
+      (inherit guix)
+      (version (string-append (package-version guix) "+"))
+      (source (local-file (force repository-root) "guix-current"
+                          #:recursive? #t
+                          #:select? select?))
+      (arguments
+       (substitute-keyword-arguments (package-arguments guix)
+         ((#:phases phases)
+          `(modify-phases ,phases
+             ;; XXX: References to tools such as 'mkdir' and 'install' are
+             ;; captured in Makefile.in when 'autoconf' is run.  It'd be nicer
+             ;; to find those at configuration time.
+             (delete 'copy-bootstrap-guile)
+             (delete 'check)
+             (delete 'disable-failing-tests)
+             (delete 'strip)            ;can't strip .go files anyway
+             (replace 'build
+               (lambda _
+                 ;; Set the write permission bit on some files that need to be
+                 ;; touched.
+                 (chmod "nix" #o777)
+                 (for-each (lambda (f)
+                             (chmod f #o666))
+                           (cons* "guix-daemon"
+                                  (find-files "." ".*\\.(a|o)$")))
+
+                 ;; The following prevent 'make install' from rebuilding the
+                 ;; daemon and the documentation.
+                 (invoke "make" "--touch" "info"
+                         ;; TODO: Currently we must rebuild the daemon as it
+                         ;; was linked against external dependencies that
+                         ;; depend on the provenance of the profile (or
+                         ;; environment) that was used to build it.
+
+                         ;; If we could query the provenance of any profile,
+                         ;; we could make this package inherit from the guix
+                         ;; inferior that was used to provide such
+                         ;; dependencies.  The most reliable way would
+                         ;; probably be to record that provenance at build
+                         ;; time (as a make target).
+                         ;"guix-daemon"
+                         ))))))))))
+
 \f
 ;;;
 ;;; Other tools.
-- 
2.25.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-gnu-linux-boot-Ensure-volatile-root-is-mounted-read-.patch --]
[-- Type: text/x-patch, Size: 1299 bytes --]

From 97d8a635eba34c7cf0708e99bf77ef9bad1344bf Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 11 Feb 2020 12:57:29 -0500
Subject: [PATCH 2/8] gnu: linux-boot: Ensure volatile root is mounted
 read-only.

* gnu/build/linux-boot.scm (mount-root-file-system): Ensure MS_RDONLY is
present among the root file system flags when VOLATILE-ROOT? is #t.
---
 gnu/build/linux-boot.scm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 3d40a7d05d..4fb711b8f2 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -362,12 +362,12 @@ the last argument of `mknod'."
   "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? is
 true, mount ROOT read-only and make it an overlay with a writable tmpfs using
 the kernel built-in overlayfs. FLAGS and OPTIONS indicates the options to use
-to mount ROOT."
+to mount ROOT, and behave the same as for the `mount' procedure."
 
   (if volatile-root?
       (begin
         (mkdir-p "/real-root")
-        (mount root "/real-root" type MS_RDONLY options)
+        (mount root "/real-root" type (logior MS_RDONLY flags) options)
         (mkdir-p "/rw-root")
         (mount "none" "/rw-root" "tmpfs")
 
-- 
2.25.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-file-systems-Add-a-file-system-device-string-procedu.patch --]
[-- Type: text/x-patch, Size: 4738 bytes --]

From 870277ade6c20546566161adbe3e6f4a5c4368a8 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 11 Feb 2020 23:56:45 -0500
Subject: [PATCH 3/8] file-systems: Add a 'file-system-device->string'
 procedure.

* gnu/system/file-systems.scm (file-system-device->string): New procedure.
* gnu/system.scm (bootable-kernel-arguments): Use it.
* gnu/system/vm.scm (operating-system-uuid): Likewise.
* guix/scripts/system.scm (display-system-generation): Likewise.
---
 gnu/system.scm              | 15 +++++----------
 gnu/system/file-systems.scm | 13 +++++++++++++
 gnu/system/vm.scm           |  8 +-------
 guix/scripts/system.scm     |  7 +------
 4 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/gnu/system.scm b/gnu/system.scm
index 01baa248a2..2e6d03272d 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -142,16 +142,11 @@
 (define (bootable-kernel-arguments system root-device)
   "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVICE."
   (list (string-append "--root="
-                       (cond ((uuid? root-device)
-
-                              ;; Note: Always use the DCE format because that's
-                              ;; what (gnu build linux-boot) expects for the
-                              ;; '--root' kernel command-line option.
-                              (uuid->string (uuid-bytevector root-device)
-                                            'dce))
-                             ((file-system-label? root-device)
-                              (file-system-label->string root-device))
-                             (else root-device)))
+                       ;; Note: Always use the DCE format because that's what
+                       ;; (gnu build linux-boot) expects for the '--root'
+                       ;; kernel command-line option.
+                       (file-system-device->string root-device
+                                                   #:uuid-type 'dce))
         #~(string-append "--system=" #$system)
         #~(string-append "--load=" #$system "/boot")))
 
diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm
index d47a514b66..70a6febe3d 100644
--- a/gnu/system/file-systems.scm
+++ b/gnu/system/file-systems.scm
@@ -30,6 +30,7 @@
   #:export (file-system
             file-system?
             file-system-device
+            file-system-device->string
             file-system-title                     ;deprecated
             file-system-mount-point
             file-system-type
@@ -235,6 +236,18 @@ where both FILE1 and FILE2 are absolute file name.  For example:
               (()
                #f)))))))
 
+(define* (file-system-device->string device #:key (uuid-type 'dce))
+  "Return the string representations of the DEVICE field of a <file-system>
+record.  When the device is a UUID, its representation is chosen depening on
+UUID-TYPE, a symbol such as 'dce or 'iso9660."
+  (match device
+    ((? file-system-label?)
+     (file-system-label->string device))
+    ((? uuid?)
+     (uuid->string device))
+    ((? string?)
+     device)))
+
 (define (file-system-needed-for-boot? fs)
   "Return true if FS has the 'needed-for-boot?' flag set, or if it holds the
 store--e.g., if FS is the root file system."
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 81b2e06ba2..03a511cdde 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -609,13 +609,7 @@ TYPE (one of 'iso9660 or 'dce).  Return a UUID object."
     (let ((device (file-system-device fs)))
       (list (file-system-mount-point fs)
             (file-system-type fs)
-            (cond ((file-system-label? device)
-                   (file-system-label->string device))
-                  ((uuid? device)
-                   (uuid->string device))
-                  ((string? device)
-                   device)
-                  (else #f))
+            (file-system-device->string device)
             (file-system-options fs))))
 
   (if (eq? type 'iso9660)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index e69a3b6c97..b0386a1392 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -517,12 +517,7 @@ list of services."
               (cond ((uuid? root-device) 0)
                     ((file-system-label? root-device) 1)
                     (else 2))
-              (cond ((uuid? root-device)
-                     (uuid->string root-device))
-                    ((file-system-label? root-device)
-                     (file-system-label->string root-device))
-                    (else
-                     root-device)))
+              (file-system-device->string root-device))
 
       (format #t (G_ "  kernel: ~a~%") kernel)
 
-- 
2.25.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-gnu-linux-boot-Refactor-boot-system.patch --]
[-- Type: text/x-patch, Size: 4408 bytes --]

From 347cccca292119104383aa7116b5eb7473d8a51b Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 11 Feb 2020 14:00:06 -0500
Subject: [PATCH 4/8] gnu: linux-boot: Refactor boot-system.

The --root option can now be omitted, and inferred from the root file system
declaration instead.

* gnu/build/linux-boot.scm (boot-system): Remove nested definitions for
root-fs-type, root-fs-flags and root-fs-options, and bind those inside the
let* instead.  Make "--root" take precendence over the device field string
representation of the root file system.
* doc/guix.texi (Initial RAM Disk): Document that "--root" can be left
unspecified.
---
 doc/guix.texi            |  7 ++++---
 gnu/build/linux-boot.scm | 42 +++++++++++++++++++---------------------
 2 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 42d7cfa2e8..85cfabc2f3 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -25917,9 +25917,10 @@ service activation programs and then spawns the GNU@tie{}Shepherd, the
 initialization system.
 
 @item --root=@var{root}
-Mount @var{root} as the root file system.  @var{root} can be a
-device name like @code{/dev/sda1}, a file system label, or a file system
-UUID.
+Mount @var{root} as the root file system.  @var{root} can be a device
+name like @code{/dev/sda1}, a file system label, or a file system UUID.
+When unspecified, the device name from the root file system of the
+operating system declaration is used.
 
 @item --system=@var{system}
 Have @file{/run/booted-system} and @file{/run/current-system} point to
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 4fb711b8f2..28697e7bbf 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -467,26 +467,6 @@ upon error."
   (define (root-mount-point? fs)
     (string=? (file-system-mount-point fs) "/"))
 
-  (define root-fs-type
-    (or (any (lambda (fs)
-               (and (root-mount-point? fs)
-                    (file-system-type fs)))
-             mounts)
-        "ext4"))
-
-  (define root-fs-flags
-    (mount-flags->bit-mask (or (any (lambda (fs)
-                                      (and (root-mount-point? fs)
-                                           (file-system-flags fs)))
-                                    mounts)
-                               '())))
-
-  (define root-fs-options
-    (any (lambda (fs)
-           (and (root-mount-point? fs)
-                (file-system-options fs)))
-         mounts))
-
   (display "Welcome, this is GNU's early boot Guile.\n")
   (display "Use '--repl' for an initrd REPL.\n\n")
 
@@ -495,7 +475,25 @@ upon error."
       (mount-essential-file-systems)
       (let* ((args    (linux-command-line))
              (to-load (find-long-option "--load" args))
-             (root    (find-long-option "--root" args)))
+             (root-fs (find root-mount-point? mounts))
+             (root-fs-type (or (and=> root-fs file-system-type)
+                               "ext4"))
+             (root-device (and=> root-fs file-system-device))
+             (root-device-str (and=> root-device file-system-device->string))
+             ;; --root takes precedence over the 'device' field of the root
+             ;; <file-system> record.
+             (root (or (find-long-option "--root" args)
+                       root-device-str))
+             (root-fs-flags (mount-flags->bit-mask
+                             (or (and=> root-fs file-system-flags)
+                                 '())))
+             (root-fs-options (if root-fs
+                                  (file-system-options root-fs)
+                                  '()))
+             (root-options (if (null? root-fs-options)
+                               #f
+                               (file-system-options->str
+                                root-fs-options))))
 
         (when (member "--repl" args)
           (start-repl))
@@ -541,7 +539,7 @@ upon error."
                                       root-fs-type
                                       #:volatile-root? volatile-root?
                                       #:flags root-fs-flags
-                                      #:options root-fs-options))
+                                      #:options root-options))
             (mount "none" "/root" "tmpfs"))
 
         ;; Mount the specified file systems.
-- 
2.25.0


[-- Attachment #6: 0005-file-systems-Represent-the-file-system-options-as-an.patch --]
[-- Type: text/x-patch, Size: 9844 bytes --]

From 38286c910480a7102f9ae52c731eeea363f567f2 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Wed, 25 Sep 2019 22:43:41 +0900
Subject: [PATCH 5/8] file-systems: Represent the file system options as an
 alist.

This allows accessing the parameter values easily, without having to parse a
string.

* gnu/system/file-systems.scm (<file-system>): Update the default value of the
OPTIONS field, doc.
(%file-system-options): Field accessor renamed from `file-system-options'.
(file-system-options, file-system-options->string): New procedures.
* gnu/build/file-systems.scm (mount-file-system): Adapt.
* gnu/services/base.scm (file-system->fstab-entry): Likewise.
* tests/file-systems.scm: New tests.
* doc/guix.texi (File Systems): Document the modified default value of the
'file-system-options' field.
---
 doc/guix.texi               | 11 ++++++-----
 gnu/build/file-systems.scm  | 15 +++++++++------
 gnu/services/base.scm       | 35 +++++++++++++++++++----------------
 gnu/system/file-systems.scm | 35 +++++++++++++++++++++++++++++++++--
 tests/file-systems.scm      | 24 ++++++++++++++++++++++++
 5 files changed, 91 insertions(+), 29 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 85cfabc2f3..5d526b1aee 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -11405,11 +11405,12 @@ update time on the in-memory version of the file inode), and
 @xref{Mount-Unmount-Remount,,, libc, The GNU C Library Reference
 Manual}, for more information on these flags.
 
-@item @code{options} (default: @code{#f})
-This is either @code{#f}, or a string denoting mount options passed to the
-file system driver.  @xref{Mount-Unmount-Remount,,, libc, The GNU C Library
-Reference Manual}, for details and run @command{man 8 mount} for options for
-various file systems.
+@item @code{options} (default: @code{'()})
+A list of parameters and/or of pairs of parameter name and values, as
+strings.  Those represent the mount options that are passed to the file
+system driver.  @xref{Mount-Unmount-Remount,,, libc, The GNU C Library
+Reference Manual}, for details and run @command{man 8 mount} for options
+for various file systems.
 
 @item @code{mount?} (default: @code{#t})
 This value indicates whether to automatically mount the file system when
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index ee6375515f..cfa3898f83 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -662,12 +662,15 @@ corresponds to the symbols listed in FLAGS."
                             (if options
                                 (string-append "," options)
                                 "")))))
-  (let ((type        (file-system-type fs))
-        (options     (file-system-options fs))
-        (source      (canonicalize-device-spec (file-system-device fs)))
-        (mount-point (string-append root "/"
-                                    (file-system-mount-point fs)))
-        (flags       (mount-flags->bit-mask (file-system-flags fs))))
+  (let* ((type        (file-system-type fs))
+         (fs-options (file-system-options fs))
+         (options (if (null? fs-options)
+                      #f
+                      (file-system-options->string fs-options)))
+         (source      (canonicalize-device-spec (file-system-device fs)))
+         (mount-point (string-append root "/"
+                                     (file-system-mount-point fs)))
+         (flags       (mount-flags->bit-mask (file-system-flags fs))))
     (when (file-system-check? fs)
       (check-file-system source type))
 
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 0c154d1c4e..6104b47870 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -313,22 +313,25 @@ seconds after @code{SIGTERM} has been sent are terminated with
 
 (define (file-system->fstab-entry file-system)
   "Return a @file{/etc/fstab} entry for @var{file-system}."
-  (string-append (match (file-system-device file-system)
-                   ((? file-system-label? label)
-                    (string-append "LABEL="
-                                   (file-system-label->string label)))
-                   ((? uuid? uuid)
-                    (string-append "UUID=" (uuid->string uuid)))
-                   ((? string? device)
-                    device))
-                 "\t"
-                 (file-system-mount-point file-system) "\t"
-                 (file-system-type file-system) "\t"
-                 (or (file-system-options file-system) "defaults") "\t"
-
-                 ;; XXX: Omit the 'fs_freq' and 'fs_passno' fields because we
-                 ;; don't have anything sensible to put in there.
-                 ))
+  (let ((options (file-system-options file-system)))
+    (string-append (match (file-system-device file-system)
+                     ((? file-system-label? label)
+                      (string-append "LABEL="
+                                     (file-system-label->string label)))
+                     ((? uuid? uuid)
+                      (string-append "UUID=" (uuid->string uuid)))
+                     ((? string? device)
+                      device))
+                   "\t"
+                   (file-system-mount-point file-system) "\t"
+                   (file-system-type file-system) "\t"
+                   (if (null? options)
+                       "defaults"
+                       (file-system-options->string options)) "\t"
+
+                   ;; XXX: Omit the 'fs_freq' and 'fs_passno' fields because we
+                   ;; don't have anything sensible to put in there.
+                   )))
 
 (define (file-systems->fstab file-systems)
   "Return a @file{/etc} entry for an @file{fstab} describing
diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm
index 70a6febe3d..eff89f146c 100644
--- a/gnu/system/file-systems.scm
+++ b/gnu/system/file-systems.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -37,6 +38,7 @@
             file-system-needed-for-boot?
             file-system-flags
             file-system-options
+            file-system-options->string
             file-system-mount?
             file-system-check?
             file-system-create-mount-point?
@@ -97,8 +99,8 @@
   (type             file-system-type)             ; string
   (flags            file-system-flags             ; list of symbols
                     (default '()))
-  (options          file-system-options           ; string or #f
-                    (default #f))
+  (options          %file-system-options          ; list of strings and/or
+                    (default '()))                ; pair of strings
   (mount?           file-system-mount?            ; Boolean
                     (default #t))
   (needed-for-boot? %file-system-needed-for-boot? ; Boolean
@@ -248,6 +250,35 @@ UUID-TYPE, a symbol such as 'dce or 'iso9660."
     ((? string?)
      device)))
 
+(define (file-system-options fs)
+  "Return the options of a <file-system> record, as a list of options or
+option/value pairs."
+
+  ;; Support the deprecated options format (a string).
+  (define (options-string->options-list str)
+    (let ((option-list (string-split str #\,)))
+      (map (lambda (param)
+             (if (string-contains param "=")
+                 (apply cons (string-split param #\=))
+                 param))
+           option-list)))
+
+  (let ((fs-options (%file-system-options fs)))
+    (if (string? fs-options)
+        (options-string->options-list fs-options)
+        fs-options)))
+
+(define (file-system-options->string options)
+  "Return the string representation of the OPTIONS field of a <file-system>
+record"
+  (string-join (map (match-lambda
+                      ((key . value)
+                       (string-append key "=" value))
+                      (key
+                       key))
+                    options)
+               ","))
+
 (define (file-system-needed-for-boot? fs)
   "Return true if FS has the 'needed-for-boot?' flag set, or if it holds the
 store--e.g., if FS is the root file system."
diff --git a/tests/file-systems.scm b/tests/file-systems.scm
index 4c28d0ebc5..b9f4f50aad 100644
--- a/tests/file-systems.scm
+++ b/tests/file-systems.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015, 2017 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -64,4 +65,27 @@
           (_ #f))
         (source-module-closure '((gnu system file-systems)))))
 
+(define %fs-with-deprecated-options-string
+  (file-system
+    (device (file-system-label "btrfs-pool"))
+    (mount-point "/home")
+    (type "btrfs")
+    (options "autodefrag,subvol=home,compress=lzo")))
+
+(define %fs
+  (file-system
+    (device (file-system-label "btrfs-pool"))
+    (mount-point "/root")
+    (type "btrfs")
+    (options '("autodefrag" ("subvol" . "root") ("compress" . "lzo")))))
+
+(test-equal "<file-system> options given as a string (deprecated)"
+  '("autodefrag" ("subvol" . "home") ("compress" . "lzo"))
+  (file-system-options %fs-with-deprecated-options-string))
+
+(test-equal "<file-system> options conversion to string"
+  "autodefrag,subvol=root,compress=lzo"
+  (file-system-options->string
+   (file-system-options %fs)))
+
 (test-end)
-- 
2.25.0


[-- Attachment #7: 0006-gnu-linux-boot-Honor-the-root-options-kernel-argumen.patch --]
[-- Type: text/x-patch, Size: 3618 bytes --]

From de7043998f2a2877f47e7952a435b711a0cbe9b5 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 11 Feb 2020 14:14:36 -0500
Subject: [PATCH 6/8] gnu: linux-boot: Honor the "--root-options" kernel
 argument.

* gnu/build/linux-boot.scm (boot-system): Parse the "--root-options" kernel
argument, and use it when calling `mount-root-file-system'.  Update doc.
* doc/guix.texi (Initial RAM Disk): Document the use of the "--root-options"
argument.
---
 doc/guix.texi            | 10 ++++++++++
 gnu/build/linux-boot.scm | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 5d526b1aee..d6bfbd7b55 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -25935,6 +25935,16 @@ Instruct the initial RAM disk as well as the @command{modprobe} command
 must be a comma-separated list of module names---e.g.,
 @code{usbkbd,9pnet}.
 
+@item --root-options=@var{options}@dots{}
+@cindex mount options for the root file system, passed to initrd
+@cindex rootflags, initrd
+@cindex root-options, initrd
+This argument allows passing one or multiple file system specific mount
+options used by the initrd to mount the root file system.  @var{options}
+must be a comma-separated list of option names or option-value pairs.
+When unspecified, the value of the options field of the root file system
+of the operating system declaration is used.
+
 @item --repl
 Start a read-eval-print loop (REPL) from the initial RAM disk before it
 tries to load kernel modules and to mount the root file system.  Our
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 28697e7bbf..f65e942ebc 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
+;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -452,7 +453,8 @@ LINUX-MODULE-DIRECTORY, then installing KEYMAP-FILE with 'loadkeys' (if
 KEYMAP-FILE is true), then setting up QEMU guest networking if
 QEMU-GUEST-NETWORKING? is true, calling PRE-MOUNT, mounting the file systems
 specified in MOUNTS, and finally booting into the new root if any.  The initrd
-supports kernel command-line options '--load', '--root', and '--repl'.
+supports kernel command-line options '--load', '--root', '--root-options' and
+'--repl'.
 
 Mount the root file system, specified by the '--root' command-line argument,
 if any.
@@ -490,10 +492,13 @@ upon error."
              (root-fs-options (if root-fs
                                   (file-system-options root-fs)
                                   '()))
-             (root-options (if (null? root-fs-options)
-                               #f
-                               (file-system-options->str
-                                root-fs-options))))
+             ;; --root-options takes precedence over the 'options' field of the
+             ;; root <file-system> record.
+             (root-options (or (find-long-option "--root-options" args)
+                               (if (null? root-fs-options)
+                                   #f
+                                   (file-system-options->string
+                                    root-fs-options)))))
 
         (when (member "--repl" args)
           (start-repl))
-- 
2.25.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: 0007-gnu-linux-boot-Filter-out-file-system-independent-op.patch --]
[-- Type: text/x-patch, Size: 2969 bytes --]

From 549d585266e32cf413ae0511edd315f615f0c3a9 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 11 Feb 2020 14:27:19 -0500
Subject: [PATCH 7/8] gnu: linux-boot: Filter out file system independent
 options.

This fixes an issue where options such as "defaults", which are understood by
the command line program "mount", are not understood by the system call of the
same name, which is used in the initial RAM disk.

* gnu/system/file-systems.scm (%file-system-independent-mount-options): New variable.
(file-system-independent-mount-option?): New predicate.
* gnu/build/linux-boot.scm (boot-system): Use the above predicate to filter
out system independent mount options.
---
 gnu/build/linux-boot.scm    |  3 ++-
 gnu/system/file-systems.scm | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index f65e942ebc..8e55797549 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -490,7 +490,8 @@ upon error."
                              (or (and=> root-fs file-system-flags)
                                  '())))
              (root-fs-options (if root-fs
-                                  (file-system-options root-fs)
+                                  (remove file-system-independent-mount-option?
+                                          (file-system-options root-fs))
                                   '()))
              ;; --root-options takes precedence over the 'options' field of the
              ;; root <file-system> record.
diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm
index eff89f146c..2dcf41ba57 100644
--- a/gnu/system/file-systems.scm
+++ b/gnu/system/file-systems.scm
@@ -46,6 +46,7 @@
             file-system-location
 
             file-system-type-predicate
+            file-system-independent-mount-option?
 
             file-system-label
             file-system-label?
@@ -563,4 +564,20 @@ system has the given TYPE."
   (lambda (fs)
     (string=? (file-system-type fs) type)))
 
+(define %file-system-independent-mount-options
+  ;; Taken from 'man 8 mount'.
+  '("async" "atime" "auto" "noatime" "noauto" "context" "defaults" "dev" "nodev"
+    "diratime" "nodiratime" "dirsync" "exec" "noexec" "group" "iversion"
+    "noiversion" "mand" "nomand" "_netdev" "nofail" "relatime" "norelatime"
+    "strictatime" "nostrictatime" "lazytime" "nolazytime" "suid" "nosuid"
+    "silent" "loud" "owner" "remount" "ro" "rw" "sync" "user" "nouser" "users"))
+
+(define (file-system-independent-mount-option? option)
+  "Predicate to check if a <file-system> option is file system independent."
+  (let ((option-name (if (pair? option)
+                         (car option)
+                         option)))
+    (or (string-prefix-ci? "x-" option-name)
+        (member option-name %file-system-independent-mount-options))))
+
 ;;; file-systems.scm ends here
-- 
2.25.0


  reply	other threads:[~2020-02-12  8:48 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05  0:20 [bug#37305] [PATCH] Allow booting from a Btrfs subvolume Maxim Cournoyer
2019-09-08 16:10 ` Christopher Baines
2019-09-22 21:43 ` Ludovic Courtès
2020-02-12  8:47   ` Maxim Cournoyer [this message]
2020-02-13 20:27     ` [bug#37305] [PATCH V2] " Maxim Cournoyer
2020-02-14 17:22       ` Ludovic Courtès
2020-02-16  5:36         ` Maxim Cournoyer
2020-02-16 11:11           ` [bug#37305] Making system installation tests faster Ludovic Courtès
2020-02-18 13:37             ` Maxim Cournoyer
2020-02-18 21:27               ` Maxim Cournoyer
2020-03-07  4:01                 ` Maxim Cournoyer
2020-02-24 16:02           ` [bug#37305] [PATCH V2] Allow booting from a Btrfs subvolume Ludovic Courtès
2020-03-03  5:00             ` Maxim Cournoyer
2020-02-24 14:23         ` [bug#37305] [PATCH V3] " Maxim Cournoyer
2020-02-19  2:52 ` [bug#37305] Allow booting from a Btrfs subvolume [review part 2] Maxim Cournoyer
2020-02-20  9:55   ` Ludovic Courtès
2020-03-18 15:27     ` maxim.cournoyer
2020-05-17 13:29       ` Pierre Neidhardt
2020-05-17 16:13         ` [bug#37305] [PATCH v3] Allow booting from a Btrfs subvolume Maxim Cournoyer
2020-05-17 16:37           ` Pierre Neidhardt
2020-05-17 19:05             ` Pierre Neidhardt
2020-05-17 19:09               ` Pierre Neidhardt
2020-05-17 19:48                 ` Pierre Neidhardt
2020-05-18  1:16                   ` Maxim Cournoyer
2020-05-18  8:54                     ` Pierre Neidhardt
2020-05-17 20:22                 ` Pierre Neidhardt
2020-05-18  0:49                   ` Maxim Cournoyer
2020-05-18 21:55           ` Ludovic Courtès
2020-05-20 12:44             ` Maxim Cournoyer
2020-05-20 12:44             ` bug#37305: " Maxim Cournoyer
2020-05-20 13:29               ` [bug#37305] " Pierre Neidhardt
2020-05-20 22:03               ` Ludovic Courtès
2020-05-21  6:58                 ` Pierre Neidhardt
2020-05-28  4:30                   ` Maxim Cournoyer
2020-05-28  8:26                     ` Pierre Neidhardt
2020-05-29 21:14                       ` Maxim Cournoyer
2020-05-28 12:30                     ` Ludovic Courtès
2020-05-30  2:00                       ` Maxim Cournoyer
2020-05-30  7:32                         ` Pierre Neidhardt
2020-05-30  7:32                         ` Pierre Neidhardt
2020-05-31  2:44                           ` Maxim Cournoyer
2020-05-31  7:32                             ` Pierre Neidhardt
2020-05-17 14:03       ` [bug#37305] Allow booting from a Btrfs subvolume [review part 2] Pierre Neidhardt
2020-05-17 16:16         ` Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k14sfaz7.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=37305@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).