[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#30604] [PATCH v10 6/6] linux-modules: Add "modules.devname" writer.
From: |
Ludovic Courtès |
Subject: |
[bug#30604] [PATCH v10 6/6] linux-modules: Add "modules.devname" writer. |
Date: |
Mon, 12 Mar 2018 13:39:18 +0100 |
* gnu/build/linux-modules.scm (aliases->device-tuple)
(write-module-device-database): New procedures.
Co-authored-by: Danny Milosavljevic <address@hidden>.
---
gnu/build/linux-modules.scm | 48 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index 9aabe6d37..2ed04e5b4 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -47,6 +47,8 @@
known-module-aliases
matching-modules
write-module-alias-database
+ write-module-device-database
+
load-needed-linux-modules))
;;; Commentary:
@@ -418,6 +420,52 @@ ALIAS is a string like \"scsi:t-0x00\" as returned by
aliases)))
aliases))))
+(define (aliases->device-tuple aliases)
+ "Traverse ALIASES, a list of module aliases, and search for
+\"char-major-M-N\", \"block-major-M-N\", or \"devname:\" aliases. When they
+are found, return a tuple (DEVNAME TYPE MAJOR MINOR), otherwise return #f."
+ (define (char/block-major? alias)
+ (or (string-prefix? "char-major-" alias)
+ (string-prefix? "block-major-" alias)))
+
+ (define (char/block-major->tuple alias)
+ (match (string-tokenize alias %not-dash)
+ ((type "major" (= string->number major) (= string->number minor))
+ (list (match type
+ ("char" "c")
+ ("block" "b"))
+ major minor))))
+
+ (let* ((devname (any (lambda (alias)
+ (and (string-prefix? "devname:" alias)
+ (string-drop alias 8)))
+ aliases))
+ (major/minor (match (find char/block-major? aliases)
+ (#f #f)
+ (str (char/block-major->tuple str)))))
+ (and devname major/minor
+ (cons devname major/minor))))
+
+(define (write-module-device-database directory)
+ "Traverse the '.ko' files in DIRECTORY and create the corresponding
+'modules.devname' file. This file contains information about modules that can
+be loaded on-demand, such as file system modules."
+ (define aliases
+ (filter-map (lambda (file)
+ (match (aliases->device-tuple (module-aliases file))
+ (#f #f)
+ (tuple (cons (file-name->module-name file) tuple))))
+ (find-files directory "\\.ko$")))
+
+ (call-with-output-file (string-append "/tmp" "/modules.devname")
+ (lambda (port)
+ (display "# Device nodes to trigger on-demand module loading.\n" port)
+ (for-each (match-lambda
+ ((module devname type major minor)
+ (format port "~a ~a ~a~a:~a~%"
+ module devname type major minor)))
+ 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
--
2.16.2
- [bug#30604] [PATCH v10 5/6] linux-initrd: Provide our own 'modprobe' program., (continued)
- [bug#30604] [PATCH v10 4/6] vm: Make the virtio-blk uniquely identifiable in /sys., Ludovic Courtès, 2018/03/12
- [bug#30604] [PATCH v10 2/6] linux-modules: Add 'load-linux-modules-from-directory'., Ludovic Courtès, 2018/03/12
- [bug#30604] [PATCH v10 2/6] linux-modules: Add 'load-linux-modules-from-directory'., Danny Milosavljevic, 2018/03/12
- [bug#30604] [PATCH v10 3/6] linux-modules: Add 'load-needed-linux-modules'., Ludovic Courtès, 2018/03/12
- [bug#30604] [PATCH v10 3/6] linux-modules: Add 'load-needed-linux-modules'., Danny Milosavljevic, 2018/03/12
- [bug#30604] [PATCH v10 3/6] linux-modules: Add 'load-needed-linux-modules'., Ludovic Courtès, 2018/03/12
- [bug#30604] [PATCH v10 6/6] linux-modules: Add "modules.devname" writer.,
Ludovic Courtès <=
- [bug#30604] [PATCH v10 1/6] linux-modules: Add "modules.alias" writer., Danny Milosavljevic, 2018/03/12
- [bug#30604] [PATCH v10 1/6] linux-modules: Add "modules.alias" writer., Ludovic Courtès, 2018/03/12
- [bug#30604] [PATCH v8 3/7] linux-boot: Load kernel modules only when the hardware is present., Danny Milosavljevic, 2018/03/09
- [bug#30604] [PATCH v9 0/7] Load Linux module only when supported hardware is present., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 7/7] linux-initrd: Use module-aliases->module-file-names, too., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 7/7] linux-initrd: Use module-aliases->module-file-names, too., Danny Milosavljevic, 2018/03/09
- [bug#30604] [PATCH v9 5/7] vm: Allow qemu-image builder to load Linux kernel modules., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 3/7] linux-initrd: Provide pure-Guile modprobe., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 3/7] linux-initrd: Provide pure-Guile modprobe., Danny Milosavljevic, 2018/03/11
- [bug#30604] [PATCH v9 3/7] linux-initrd: Provide pure-Guile modprobe., Ludovic Courtès, 2018/03/12