From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqgAn-0004jD-H9 for guix-patches@gnu.org; Tue, 27 Feb 2018 09:24:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqgAk-00010y-Kw for guix-patches@gnu.org; Tue, 27 Feb 2018 09:24:05 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:54922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eqgAk-00010u-Gv for guix-patches@gnu.org; Tue, 27 Feb 2018 09:24:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eqgAk-0003PI-Bh for guix-patches@gnu.org; Tue, 27 Feb 2018 09:24:02 -0500 Subject: [bug#30629] [PATCH 3/5] linux-initrd: Separate file system module logic. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 27 Feb 2018 15:22:43 +0100 Message-Id: <20180227142245.12674-4-ludo@gnu.org> In-Reply-To: <20180227142245.12674-1-ludo@gnu.org> References: <20180227142245.12674-1-ludo@gnu.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 30629@debbugs.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