GNU bug report logs - #30604
[PATCH 0/4] Load Linux module only when supported hardware is present.

Previous Next

Package: guix-patches;

Reported by: Danny Milosavljevic <dannym <at> scratchpost.org>

Date: Sun, 25 Feb 2018 11:47:02 UTC

Severity: important

Tags: patch

Full log


Message #209 received at 30604 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 30604 <at> debbugs.gnu.org
Subject: Re: [bug#30604] [PATCH v8 3/7] linux-boot: Load kernel modules only
 when the hardware is present.
Date: Sat, 03 Mar 2018 23:48:38 +0100
[Message part 1 (text/plain, inline)]
Danny Milosavljevic <dannym <at> scratchpost.org> 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 them."
> +    (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 ‘flat-linux-module-directory’ to produce a ‘modules.alias’
file, here we could read ‘modules.aliases’ directly and load the right
thing.

With the patch below, we get ‘needed-modules’, 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’s modprobe.

Thoughts?

Ludo’.

[Message part 2 (text/x-patch, 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

This bug report was last modified 5 years and 305 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.