From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evVke-0004gu-3h for guix-patches@gnu.org; Mon, 12 Mar 2018 18:17:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evVkd-0004pv-5B for guix-patches@gnu.org; Mon, 12 Mar 2018 18:17:04 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:49888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evVkd-0004pq-1a for guix-patches@gnu.org; Mon, 12 Mar 2018 18:17:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1evVkc-0005WJ-SN for guix-patches@gnu.org; Mon, 12 Mar 2018 18:17:02 -0400 Subject: [bug#30604] [PATCH v11 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 23:15:38 +0100 Message-Id: <20180312221541.1886-3-ludo@gnu.org> In-Reply-To: <20180312221541.1886-1-ludo@gnu.org> References: <87h8plkkkc.fsf@gnu.org> <20180312221541.1886-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 0084f972b..55161e026 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: ;;; @@ -413,4 +415,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