From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:60809) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJz6h-0002Xq-VO for guix-patches@gnu.org; Thu, 02 Apr 2020 08:38:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJz6g-0005Q9-4z for guix-patches@gnu.org; Thu, 02 Apr 2020 08:38:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56032) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJz6g-0005Q2-1w for guix-patches@gnu.org; Thu, 02 Apr 2020 08:38:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jJz6f-0007oa-VD for guix-patches@gnu.org; Thu, 02 Apr 2020 08:38:01 -0400 Subject: [bug#40274] [PATCH v5] gnu: Add kernel-module-loader-service. Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:60709) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJz63-00027l-1Z for guix-patches@gnu.org; Thu, 02 Apr 2020 08:37:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJz60-0004y2-Kq for guix-patches@gnu.org; Thu, 02 Apr 2020 08:37:22 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:35305) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJz60-0004wv-Bb for guix-patches@gnu.org; Thu, 02 Apr 2020 08:37:20 -0400 Received: from localhost (luy13-1-78-237-113-178.fbx.proxad.net [78.237.113.178]) (Authenticated sender: brice@waegenei.re) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 5196C1C0015 for ; Thu, 2 Apr 2020 12:37:15 +0000 (UTC) From: Brice Waegeneire Date: Thu, 2 Apr 2020 14:37:12 +0200 Message-Id: <20200402123712.338-1-brice@waegenei.re> In-Reply-To: <20200328135908.2540-1-brice@waegenei.re> References: <20200328135908.2540-1-brice@waegenei.re> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 40274@debbugs.gnu.org * doc/guix.texi (Linux Services): Add a new subsection and document the new service and its configuration. * gnu/services/linux.scm (kernel-module-loader-service): New procedure. (kernel-module-loader-service-type, kernel-module-loader-configuration): New types. * gnu/tests/linux-modules.scm (module-loader-program): Procedure removed. (modules-loaded?-program): New procedure. (run-loadable-kernel-modules-test): 'module-loader-program' procedure replaced by the new one. New format for last arguments [os]: Use 'kernel-module-loader-service'. (%test-loadable-kernel-modules-0, %test-loadable-kernel-modules-1, %test-loadable-kernel-modules-2): Use the new argument format. --- In this version the typos reported by Mathieu have been fixed and if modprobe fail the error is logged by shepherd. doc/guix.texi | 53 +++++++++++++++++++++++++++ gnu/services/linux.scm | 72 ++++++++++++++++++++++++++++++++++++- gnu/tests/linux-modules.scm | 45 ++++++++++++++--------- 3 files changed, 152 insertions(+), 18 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 8cb85fe62c..ea1d363efc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -76,6 +76,7 @@ Copyright @copyright{} 2020 Damien Cassou@* Copyright @copyright{} 2020 Jakub Kądziołka@* Copyright @copyright{} 2020 Jack Hill@* Copyright @copyright{} 2020 Naga Malleswari@* +Copyright @copyright{} 2020 Brice Waegeneire@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -25383,6 +25384,58 @@ notifications. @end table @end deftp +@cindex modprobe +@cindex kernel module loader +@subsubsection Kernel Module Loader Service + +The @code{kernel-module-loader-service} provides a service to load +kernel modules at boot. This is especially useful for modules that +don't autoload and need to be manually loaded, like it's the case with +@code{ddcci} for example. + +@deffn {Scheme Procedure} kernel-module-loader-service @var{modules} +Return a service that runs @command{modprobe} for each given module. +For example loading the drivers provided by @code{ddci-driver-linux} +with @code{ddcci} in debugging mode can be done as follow: + +@lisp +(use-modules (gnu)) +(use-package-modules linux) +(use-service-modules linux) +(operating-system + ... + (services (cons* (kernel-module-loader-service + '(("ddcci" "dyndbg") + ("ddcci_backlight"))) + %base-services)) + (kernel-loadable-modules (list ddcci-driver-linux))) +@end lisp +@end deffn + +@deffn {Scheme Variable} kernel-module-loader-service-type +The service type for loading kernel modules at boot with +@command{modprobe}, for modules that can't autoload. Its value must be +a @code{kernel-module-loader-configuration} object, described below. +@end deffn + +@deftp {Data Type} kernel-module-loader-configuration +The data type representing the modules to be loaded by +@command{modprobe}. +@end deftp + +@deftp {Data Type} kernel-module-loader-configuration +This is the configuration record for the +@code{kernel-module-loader-service-type}. + +@table @asis +@item @code{modprobe} (default: @code{(file-append kmod "/bin/modprobe"}) +The @command{modprobe} executable to use. + +@item @code{modules} (default: @code{'()}) +A list of list of strings specifying the modules to load with their +optional parameters. +@end table +@end deftp @node Miscellaneous Services @subsection Miscellaneous Services diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm index caa0326c31..e3942f693d 100644 --- a/gnu/services/linux.scm +++ b/gnu/services/linux.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2020 Maxim Cournoyer +;;; Copyright © 2020 Brice Waegeneire ;;; ;;; This file is part of GNU Guix. ;;; @@ -25,6 +26,8 @@ #:use-module (gnu packages linux) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:use-module (ice-9 match) #:export (earlyoom-configuration earlyoom-configuration? @@ -37,7 +40,14 @@ earlyoom-configuration-ignore-positive-oom-score-adj? earlyoom-configuration-show-debug-messages? earlyoom-configuration-send-notification-command - earlyoom-service-type)) + earlyoom-service-type + + kernel-module-loader-configuration + kernel-module-loader-configuration? + kernel-module-loader-configuration-modprobe + kernel-module-loader-configuration-modules + kernel-module-loader-service-type + kernel-module-loader-service)) ;;; @@ -123,3 +133,63 @@ representation." (list (service-extension shepherd-root-service-type (compose list earlyoom-shepherd-service)))) (description "Run @command{earlyoom}, the Early OOM daemon."))) + + +;;; +;;; Kernel module loader. +;;; + +(define-record-type* + kernel-module-loader-configuration make-kernel-module-loader-configuration + kernel-module-loader-configuration? + ;; path of the 'modprobe' command + (modprobe kernel-module-loader-configuration-modprobe + (default (file-append kmod "/bin/modprobe"))) + ;; list of lists of strings + (modules kernel-module-loader-configuration-modules + (default '()))) + +(define kernel-module-loader-shepherd-service + (match-lambda + (($ modprobe kernel-modules) + (list + (shepherd-service + (documentation "Load kernel modules.") + (provision '(kernel-module-loader)) + (respawn? #f) + (one-shot? #t) + (modules `((srfi srfi-34) + (srfi srfi-35) + ,@%default-modules)) + (start + #~(lambda _ + (guard (c ((message-condition? c) + (display (condition-message c)) + #f)) + (map (lambda (module-with-parameters) + (apply invoke/quiet #$modprobe "--" + module-with-parameters)) + '#$kernel-modules))))))))) + +(define kernel-module-loader-service-type + (service-type + (name 'kernel-module-loader) + (description "Load kernel modules.") + (extensions + (list + (service-extension shepherd-root-service-type + kernel-module-loader-shepherd-service))) + (compose concatenate) + (extend (lambda (config modules) + (kernel-module-loader-configuration + (inherit config) + (modules (append + (kernel-module-loader-configuration-modules config) + modules))))) + (default-value (kernel-module-loader-configuration)))) + +(define* (kernel-module-loader-service modules) + "Return a service that loads kernel MODULES." + (service kernel-module-loader-service-type + (kernel-module-loader-configuration + (modules modules)))) diff --git a/gnu/tests/linux-modules.scm b/gnu/tests/linux-modules.scm index 39e11587c6..2532850d34 100644 --- a/gnu/tests/linux-modules.scm +++ b/gnu/tests/linux-modules.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019 Jakob L. Kreuze ;;; Copyright © 2020 Danny Milosavljevic +;;; Copyright © 2020 Brice Waegeneire ;;; ;;; This file is part of GNU Guix. ;;; @@ -19,6 +20,7 @@ (define-module (gnu tests linux-modules) #:use-module (gnu packages linux) + #:use-module (gnu services linux) #:use-module (gnu system) #:use-module (gnu system vm) #:use-module (gnu tests) @@ -37,25 +39,31 @@ ;;; ;;; Code: -(define* (module-loader-program os modules) - "Return an executable store item that, upon being evaluated, will dry-run -load MODULES." +(define* (modules-loaded?-program os modules) + "Return an executable store item that, upon being evaluated, will verify +that MODULES are actually loaded." (program-file "load-kernel-modules.scm" - (with-imported-modules (source-module-closure '((guix build utils))) - #~(begin - (use-modules (guix build utils)) - (for-each (lambda (module) - (invoke (string-append #$kmod "/bin/modprobe") "-n" "--" - module)) - '#$modules))))) + #~(begin + (use-modules (ice-9 rdelim) + (ice-9 popen)) + (let* ((port (open-input-pipe (string-append #$kmod "/bin/lsmod"))) + (output (read-string port)) + (status (close-pipe port))) + (and-map (lambda (module) (string-contains output module)) + '#$modules))))) -(define* (run-loadable-kernel-modules-test module-packages module-names) - "Run a test of an OS having MODULE-PACKAGES, and modprobe MODULE-NAMES." +(define* (run-loadable-kernel-modules-test module-packages + modules-with-parameters) + "Run a test of an OS having MODULE-PACKAGES, and verify that +MODULES-WITH-PARAMETERS are loaded in memory." (define os (marionette-operating-system (operating-system (inherit (simple-operating-system)) + (services (cons (kernel-module-loader-service modules-with-parameters) + (operating-system-user-services + (simple-operating-system)))) (kernel-loadable-modules module-packages)) #:imported-modules '((guix combinators)))) (define vm (virtual-machine os)) @@ -75,7 +83,9 @@ load MODULES." marionette)) (test-end) (exit (= (test-runner-fail-count (test-runner-current)) 0))))) - (gexp->derivation "loadable-kernel-modules" (test (module-loader-program os module-names)))) + (gexp->derivation + "loadable-kernel-modules" + (test (modules-loaded?-program os (map car modules-with-parameters))))) (define %test-loadable-kernel-modules-0 (system-test @@ -88,16 +98,17 @@ with no extra modules.") (system-test (name "loadable-kernel-modules-1") (description "Tests loadable kernel modules facility of -with one extra module.") +with one extra module with some parameters.") (value (run-loadable-kernel-modules-test (list ddcci-driver-linux) - '("ddcci"))))) + '(("ddcci" "dyndbg" "delay=120")))))) (define %test-loadable-kernel-modules-2 (system-test (name "loadable-kernel-modules-2") (description "Tests loadable kernel modules facility of -with two extra modules.") +with two extra modules without any parameters.") (value (run-loadable-kernel-modules-test (list acpi-call-linux-module ddcci-driver-linux) - '("acpi_call" "ddcci"))))) + '(("acpi_call") + ("ddcci")))))) -- 2.25.1