GNU bug report logs -
#30604
[PATCH 0/4] Load Linux module only when supported hardware is present.
Previous Next
Full log
View this message in rfc822 format
[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.