From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 03 17:48:43 2018 Received: (at 30604) by debbugs.gnu.org; 3 Mar 2018 22:48:43 +0000 Received: from localhost ([127.0.0.1]:43292 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esFxL-0007rb-JY for submit@debbugs.gnu.org; Sat, 03 Mar 2018 17:48:43 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:55216) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esFxJ-0007rS-9F for 30604@debbugs.gnu.org; Sat, 03 Mar 2018 17:48:41 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 72AED11DE2; Sat, 3 Mar 2018 23:48:40 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Siot1ErsUpmx; Sat, 3 Mar 2018 23:48:39 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 3465211D90; Sat, 3 Mar 2018 23:48:39 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Danny Milosavljevic Subject: Re: [bug#30604] [PATCH v8 3/7] linux-boot: Load kernel modules only when the hardware is present. References: <20180302153408.14091-1-dannym@scratchpost.org> <20180303135533.6112-1-dannym@scratchpost.org> <20180303135533.6112-4-dannym@scratchpost.org> Date: Sat, 03 Mar 2018 23:48:38 +0100 In-Reply-To: <20180303135533.6112-4-dannym@scratchpost.org> (Danny Milosavljevic's message of "Sat, 3 Mar 2018 14:55:29 +0100") Message-ID: <87sh9g4vy1.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30604 Cc: 30604@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Danny Milosavljevic skribis: > * gnu/build/linux-boot.scm (boot-system): Load kernel modules only when > the hardware is present. > (lookup-module): Delete procedure. > * gnu/system/linux-initrd.scm (raw-initrd): Add imports. [...] > + (define (load-kernel-modules) > + "Examine /sys/devices to find out which modules to load and load the= m." > + (define enter? > + (const #t)) > + (define (down! directory stat result) > + ;; Note: modprobe mutates the tree starting with DIRECTORY. > + (let ((modalias-name (string-append directory "/modalias"))) > + (if (file-exists? modalias-name) > + (let ((modalias > + (string-trim-right (call-with-input-file modalias-name > + read-string) > + #\newline))) > + (system* "/sbin/modprobe" "-q" "--" modalias)))) If we change =E2=80=98flat-linux-module-directory=E2=80=99 to produce a =E2= =80=98modules.alias=E2=80=99 file, here we could read =E2=80=98modules.aliases=E2=80=99 directly and loa= d the right thing. With the patch below, we get =E2=80=98needed-modules=E2=80=99, and we could= simply do: (for-each (catch-ENOENT load-linux-module*) (needed-modules (known-module-aliases (string-append linux-module-directory "/modules.alias")))) and we can do away with kmod=E2=80=99s modprobe. Thoughts? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index 4a6d4ff08..251095072 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -20,6 +20,7 @@ (define-module (gnu build linux-modules) #:use-module (guix elf) #:use-module (guix glob) + #:use-module (guix build utils) #:use-module (guix build syscalls) #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) @@ -40,7 +41,8 @@ device-module-aliases known-module-aliases - matching-modules)) + matching-modules + needed-modules)) ;;; Commentary: ;;; @@ -370,4 +372,25 @@ ALIAS is a string like \"scsi:t-0x00\" as returned by module))) known-aliases)) +(define (system-device-aliases) + "Browse /sys/devices in search of \"modalias\" files and return the list of +device aliases for the current system." + (let ((files (find-files "/sys/devices" + (lambda (file stat) + (and (eq? 'regular (stat:type stat)) + (string=? "modalias" (basename file))))))) + (filter-map (lambda (file) + (match (string-trim-right + (call-with-input-file file get-string-all)) + ("" #f) + (alias alias))) + files))) + +(define* (needed-modules #:optional (known-aliases (known-module-aliases))) + "Return the list of modules needed by devices on the current system. This +is achieved by browsing /sys/devices and returning the maching modules from +KNOWN-ALIASES." + (append-map (cut matching-modules <> known-aliases) + (system-device-aliases))) + ;;; linux-modules.scm ends here --=-=-=--