unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 30629@debbugs.gnu.org
Subject: [bug#30629] [PATCH 3/5] linux-initrd: Separate file system module logic.
Date: Tue, 27 Feb 2018 15:22:43 +0100	[thread overview]
Message-ID: <20180227142245.12674-4-ludo@gnu.org> (raw)
In-Reply-To: <20180227142245.12674-1-ludo@gnu.org>

* gnu/system/linux-initrd.scm (vhash, lookup-procedure): New macros.
(file-system-type-modules, file-system-modules): New procedures.
(base-initrd)[cifs-modules, virtio-9p-modules]: Remove.
[file-system-type-predicate]: Remove.
Use 'file-system-modules' instead of 'find' +
'file-system-type-predicate'.
---
 gnu/system/linux-initrd.scm | 60 +++++++++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 330438bce..830445ac8 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -39,6 +39,7 @@
   #:use-module (gnu system mapped-devices)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
+  #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:export (expression->initrd
@@ -242,6 +243,40 @@ FILE-SYSTEMS."
           (list btrfs-progs/static)
           '())))
 
+(define-syntax vhash                              ;TODO: factorize
+  (syntax-rules (=>)
+    "Build a vhash with the given key/value mappings."
+    ((_)
+     vlist-null)
+    ((_ (key others ... => value) rest ...)
+     (vhash-cons key value
+                 (vhash (others ... => value) rest ...)))
+    ((_ (=> value) rest ...)
+     (vhash rest ...))))
+
+(define-syntax lookup-procedure
+  (syntax-rules (else)
+    "Return a procedure that lookups keys in the given dictionary."
+    ((_ mapping ... (else default))
+     (let ((table (vhash mapping ...)))
+       (lambda (key)
+         (match (vhash-assoc key table)
+           (#f    default)
+           (value value)))))))
+
+(define file-system-type-modules
+  ;; Given a file system type, return the list of modules it needs.
+  (lookup-procedure ("cifs" => '("md4" "ecb" "cifs"))
+                    ("9p" => '("9p" "9pnet_virtio"))
+                    ("btrfs" => '("btrfs"))
+                    ("iso9660" => '("isofs"))
+                    (else '())))
+
+(define (file-system-modules file-systems)
+  "Return the list of Linux modules needed to mount FILE-SYSTEMS."
+  (append-map (compose file-system-type-modules file-system-type)
+              file-systems))
+
 (define* (base-initrd file-systems
                       #:key
                       (linux linux-libre)
@@ -272,18 +307,6 @@ loaded at boot time in the order in which they appear."
     '("virtio_pci" "virtio_balloon" "virtio_blk" "virtio_net"
       "virtio_console"))
 
-  (define cifs-modules
-    ;; Modules needed to mount CIFS file systems.
-    '("md4" "ecb" "cifs"))
-
-  (define virtio-9p-modules
-    ;; Modules for the 9p paravirtualized file system.
-    '("9p" "9pnet_virtio"))
-
-  (define (file-system-type-predicate type)
-    (lambda (fs)
-      (string=? (file-system-type fs) type)))
-
   (define linux-modules
     ;; Modules added to the initrd and loaded from the initrd.
     `("ahci"                                  ;for SATA controllers
@@ -298,18 +321,7 @@ loaded at boot time in the order in which they appear."
       ,@(if (or virtio? qemu-networking?)
             virtio-modules
             '())
-      ,@(if (find (file-system-type-predicate "cifs") file-systems)
-            cifs-modules
-            '())
-      ,@(if (find (file-system-type-predicate "9p") file-systems)
-            virtio-9p-modules
-            '())
-      ,@(if (find (file-system-type-predicate "btrfs") file-systems)
-            '("btrfs")
-            '())
-      ,@(if (find (file-system-type-predicate "iso9660") file-systems)
-            '("isofs")
-            '())
+      ,@(file-system-modules file-systems)
       ,@(if volatile-root?
             '("overlay")
             '())
-- 
2.16.2

  parent reply	other threads:[~2018-02-27 14:24 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27 14:17 [bug#30629] [PATCH 0/5] Detect missing modules in the initrd Ludovic Courtès
2018-02-27 14:22 ` Ludovic Courtès
2018-02-27 14:22   ` [bug#30629] [PATCH 1/5] Add (guix glob) Ludovic Courtès
2018-02-27 21:45     ` Marius Bakke
2018-02-28 11:25     ` Danny Milosavljevic
2018-03-01  9:57       ` Ludovic Courtès
2018-03-01 10:11         ` Danny Milosavljevic
2018-03-01 14:29     ` Danny Milosavljevic
2018-02-27 14:22   ` [bug#30629] [PATCH 2/5] linux-modules: Add 'device-module-aliases' and related procedures Ludovic Courtès
2018-02-27 19:33     ` Danny Milosavljevic
2018-02-27 20:55       ` Ludovic Courtès
2018-02-27 21:58         ` Danny Milosavljevic
2018-02-27 21:24           ` Ludovic Courtès
2018-02-27 14:22   ` Ludovic Courtès [this message]
2018-03-01 14:31     ` [bug#30629] [PATCH 3/5] linux-initrd: Separate file system module logic Danny Milosavljevic
2018-02-27 14:22   ` [bug#30629] [PATCH 4/5] system: Add 'initrd-modules' field Ludovic Courtès
2018-03-01 18:39     ` Danny Milosavljevic
2018-02-27 14:22   ` [bug#30629] [PATCH 5/5] guix system: Check for the lack of modules in the initrd Ludovic Courtès
2018-03-02 12:39     ` Danny Milosavljevic
2018-02-27 21:29 ` [bug#30629] [PATCH 0/5] Detect missing " Danny Milosavljevic
2018-02-27 21:15   ` Ludovic Courtès
2018-02-27 22:50     ` Danny Milosavljevic
2018-02-27 23:13       ` [bug#30638] [WIP v2] linux-initrd: Make modprobe pure-Guile Danny Milosavljevic
2018-02-27 23:17         ` Danny Milosavljevic
2018-02-28 11:47         ` [bug#30638] [WIP v3] " Danny Milosavljevic
2018-02-28 12:05           ` [bug#30638] [WIP v4] " Danny Milosavljevic
2018-02-28 11:36       ` [bug#30629] [PATCH 0/5] Detect missing modules in the initrd Danny Milosavljevic
2018-03-01 10:05       ` Ludovic Courtès
2018-03-01 10:11         ` Danny Milosavljevic
2018-03-01 11:46       ` Danny Milosavljevic
2018-03-01 13:39         ` Ludovic Courtès
2018-03-01 13:54           ` Danny Milosavljevic
2018-03-02 12:56             ` bug#30629: " Ludovic Courtès
2018-03-02 17:50               ` [bug#30629] " Danny Milosavljevic
2018-03-02 18:16                 ` Danny Milosavljevic
2018-03-03  8:42                 ` Ludovic Courtès
2018-03-01 13:55           ` Danny Milosavljevic
2018-03-01 21:20             ` Ludovic Courtès
2018-03-02 11:42               ` Danny Milosavljevic
2018-02-28  3:03     ` [bug#30629] Device mapper modalias Danny Milosavljevic
2018-03-01  8:56       ` Danny Milosavljevic
2018-03-01 10:11       ` Ludovic Courtès
2018-03-07 18:56         ` Danny Milosavljevic

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=20180227142245.12674-4-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=30629@debbugs.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).