From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evMkL-0008I2-AP for guix-patches@gnu.org; Mon, 12 Mar 2018 08:40:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evMkF-0006o8-9a for guix-patches@gnu.org; Mon, 12 Mar 2018 08:40:09 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:48194) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evMkF-0006nw-6I for guix-patches@gnu.org; Mon, 12 Mar 2018 08:40:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1evMkE-00030C-Vp for guix-patches@gnu.org; Mon, 12 Mar 2018 08:40:02 -0400 Subject: [bug#30604] [PATCH v10 3/6] linux-modules: Add 'load-needed-linux-modules'. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 12 Mar 2018 13:39:15 +0100 Message-Id: <20180312123918.22645-3-ludo@gnu.org> In-Reply-To: <20180312123918.22645-1-ludo@gnu.org> References: <87ina1qxic.fsf@gnu.org> <20180312123918.22645-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: 30604@debbugs.gnu.org Based on a patch by Danny Milosavljevic . * gnu/build/linux-modules.scm (load-needed-linux-modules): New procedure. --- gnu/build/linux-modules.scm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index 1337b5e88..9aabe6d37 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -30,6 +30,7 @@ #:use-module (ice-9 vlist) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) + #:use-module (ice-9 ftw) #:export (dot-ko ensure-dot-ko module-aliases @@ -45,7 +46,8 @@ device-module-aliases known-module-aliases matching-modules - write-module-alias-database)) + write-module-alias-database + load-needed-linux-modules)) ;;; Commentary: ;;; @@ -416,4 +418,34 @@ ALIAS is a string like \"scsi:t-0x00\" as returned by aliases))) aliases)))) +(define (load-needed-linux-modules module-directory) + "Examine /sys/devices to find out which modules are needed and load those we +have in MODULE-DIRECTORY. Return the list of modules loaded, not including +dependencies. + +Note: loading modules leads to the creation of new entries in /sys/devices, +which is why we need traversal and loading to be interleaved. If we walked +/sys/devices and *then* loaded modules, we'd miss the entries added as a +side-effect and would thus need to traverse /sys/devices again." + (define aliases + (known-module-aliases + (string-append module-directory "/modules.alias"))) + + (define (enter? director stat result) result) + (define (down directory stat result) result) + (define (up directory stat result) result) + (define (skip entry stat result) result) + (define (error name stat errno result) result) + (define (leaf file stat result) + (if (string=? (basename file) "modalias") + (let* ((alias (string-trim-right + (call-with-input-file file get-string-all))) + (modules (matching-modules alias aliases))) + (load-linux-modules-from-directory modules + module-directory) + (append modules result)) + result)) + + (file-system-fold enter? leaf down up skip error #t "/sys/devices")) + ;;; linux-modules.scm ends here -- 2.16.2