all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Danny Milosavljevic <dannym@scratchpost.org>
Cc: 34902@debbugs.gnu.org
Subject: bug#34902: guix cannot find a module on boot
Date: Fri, 22 Mar 2019 21:27:42 +0100	[thread overview]
Message-ID: <87wokq4ptt.fsf@gnu.org> (raw)
In-Reply-To: <20190318231359.217af9f4@scratchpost.org> (Danny Milosavljevic's message of "Mon, 18 Mar 2019 23:40:28 +0100")

[-- Attachment #1: Type: text/plain, Size: 887 bytes --]

Hi Danny,

Thanks for the explanation, I was unaware of all these subtleties…

Danny Milosavljevic <dannym@scratchpost.org> skribis:

> Every time we want to lookup a module by modname, check a hashtable that
> is built from modules.dep by:
>  
> * let x-path be the first value of each modules.dep line.
> * Then the key for the hashtable entry is (underscore (stop-at-dot (basename x-path)))
> * And the value for the hashtable entry is x-path.
>
> In this way we would look up modules in a way similar to them.

Instead of guessing, we could also store a mapping from module name to
file name.  I had that in a previous patch series that we discussed some
time ago (see below.)

This a custom format, not used by kmod or any other tool, but the
advantage is that it solves the module/file name mapping without ugly
guess-hacks.

WDYT?

Thanks,
Ludo’.


[-- Attachment #2: Type: text/x-patch, Size: 5404 bytes --]

commit 370c4426aa94d99f8faafd3992d54169ff918fb1
Author: Ludovic Courtès <ludo@gnu.org>
Date:   Wed Mar 14 23:11:01 2018 +0100

    linux-modules: Define and use a module name database.
    
    * gnu/build/linux-modules.scm (module-formal-name): New procedure.
    (load-linux-modules-from-directory)[lookup-module]: Remove.
    [module-name->file-name]: New variable.  Use it.
    (module-name->file-name/guess, module-name-lookup)
    (write-module-name-database): New procedures.
    * gnu/system/linux-initrd.scm (flat-linux-module-directory): Call
    'write-module-name-database'.

diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index 615e9e1d07..7e99f62941 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -31,8 +31,10 @@
   #:use-module (ice-9 match)
   #:use-module (ice-9 rdelim)
   #:use-module (ice-9 ftw)
+  #:autoload   (ice-9 pretty-print) (pretty-print)
   #:export (dot-ko
             ensure-dot-ko
+            module-formal-name
             module-aliases
             module-dependencies
             recursive-module-dependencies
@@ -46,6 +48,7 @@
             device-module-aliases
             known-module-aliases
             matching-modules
+            write-module-name-database
             write-module-alias-database
             write-module-device-database
             load-needed-linux-modules))
@@ -95,6 +98,14 @@ key/value pairs.."
 (define %not-comma
   (char-set-complement (char-set #\,)))
 
+(define (module-formal-name file)
+  "Return the module name of FILE as it appears in its info section.  Usually
+the module name is the same as the base name of FILE, modulo hyphens and minus
+the \".ko\" extension."
+  (match (assq 'name (modinfo-section-contents file))
+    (('name . name) name)
+    (#f #f)))
+
 (define (module-dependencies file)
   "Return the list of modules that FILE depends on.  The returned list
 contains module names, not actual file names."
@@ -240,12 +251,13 @@ appears in BLACK-LIST are not loaded."
   "Load MODULES and their dependencies from DIRECTORY, a directory containing
 the '.ko' files.  The '.ko' suffix is automatically added to MODULES if
 needed."
-  (define (lookup-module name)
-    (string-append directory "/" (ensure-dot-ko name)))
+  (define module-name->file-name
+    (module-name-lookup directory))
 
-  (for-each (cut load-linux-module* <>
-                 #:lookup-module lookup-module)
-            (map lookup-module modules)))
+  (for-each (lambda (module)
+              (load-linux-module* (module-name->file-name module)
+                                  #:lookup-module module-name->file-name))
+            modules))
 
 \f
 ;;;
@@ -401,6 +413,47 @@ ALIAS is a string like \"scsi:t-0x00\" as returned by
                       module)))
               known-aliases))
 
+(define (module-name->file-name/guess directory name)
+  "Guess the file name corresponding to NAME, a module name.  That doesn't
+always work because sometimes underscores in NAME map to hyphens (e.g.,
+\"input-leds.ko\"), sometimes not (e.g., \"mac_hid.ko\")."
+  (string-append directory "/" (ensure-dot-ko name)))
+
+(define (module-name-lookup directory)
+  "Return a one argument procedure that takes a module name (e.g.,
+\"input_leds\") and returns its absolute file name (e.g.,
+\"/.../input-leds.ko\")."
+  (catch 'system-error
+    (lambda ()
+      (define mapping
+        (call-with-input-file (string-append directory "/modules.name")
+          read))
+
+      (lambda (name)
+        (or (assoc-ref mapping name)
+            (module-name->file-name/guess directory name))))
+    (lambda args
+      (if (= ENOENT (system-error-errno args))
+          (cut module-name->file-name/guess directory <>)
+          (apply throw args)))))
+
+(define (write-module-name-database directory)
+  "Write a database that maps \"module names\" as they appear in the relevant
+ELF section of '.ko' files, to actual file names.  This format is
+Guix-specific.  It aims to deal with inconsistent naming, in particular
+hyphens vs. underscores."
+  (define mapping
+    (map (lambda (file)
+           (match (module-formal-name file)
+             (#f   (cons (basename file ".ko") file))
+             (name (cons name file))))
+         (find-files directory "\\.ko$")))
+
+  (call-with-output-file (string-append directory "/modules.name")
+    (lambda (port)
+      (display ";; Module name to file name mapping.\n" port)
+      (pretty-print mapping port))))
+
 (define (write-module-alias-database directory)
   "Traverse the '.ko' files in DIRECTORY and create the corresponding
 'modules.alias' file."
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 4379fb461e..9160d94847 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -242,6 +242,9 @@ MODULES and taken from LINUX."
           (write-module-alias-database #$output)
           (write-module-device-database #$output)
 
+          ;; Hyphen or underscore?  This database tells us.
+          (write-module-name-database #$output)
+
           ;; Copy "modules.builtin", which we need to determine whether a
           ;; module needs to be loaded.
           (match (find-files #$linux (string->regexp "modules.builtin"))

  reply	other threads:[~2019-03-22 20:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18  9:17 bug#34902: guix cannot find a module on boot Julien Lepiller
2019-03-18 20:42 ` Ludovic Courtès
2019-03-18 21:34   ` Julien Lepiller
2019-03-18 22:40   ` Danny Milosavljevic
2019-03-22 20:27     ` Ludovic Courtès [this message]
2019-04-04 20:42       ` Danny Milosavljevic
2019-08-16 21:10         ` Ludovic Courtès
2019-08-16 21:10           ` [bug#30604] " Ludovic Courtès
2019-08-01  9:49 ` bug#34902: Guix " Julien Lepiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wokq4ptt.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=34902@debbugs.gnu.org \
    --cc=dannym@scratchpost.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.