libkmod: add weak dependecies

It has been seen that for some network mac drivers (i.e. lan78xx) the
related module for the phy is loaded dynamically depending on the current
hardware. In this case, the associated phy is read using mdio bus and then
the associated phy module is loaded during runtime (kernel function
phy_request_driver_module). However, no software dependency is defined, so
the user tools will no be able to get this dependency. For example, if
dracut is used and the hardware is present, lan78xx will be included but no
phy module will be added, and in the next restart the device will not work
from boot because no related phy will be found during initramfs stage.

In order to solve this, we could define a normal 'pre' software dependency
in lan78xx module with all the possible phy modules (there may be some),
but proceeding in that way, all the possible phy modules would be loaded
while only one is necessary.

The idea is to create a new type of dependency, that we are going to call
'weak' to be used only by the user tools that need to detect this situation.
In that way, for example, dracut could check the 'weak' dependency of the
modules involved in order to install these dependencies in initramfs too.
That is, for the commented lan78xx module, defining the 'weak' dependency
with the possible phy modules list, only the necessary phy would be loaded
on demand keeping the same behavior, but all the possible phy modules would
be available from initramfs.

A new function 'kmod_module_get_weakdeps' in libkmod will be added for
this to avoid breaking the API and maintain backward compatibility. This
general procedure could be useful for other similar cases (not only for
dynamic phy loading).

Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Link: https://lore.kernel.org/r/20240327141116.97587-1-jtornosm@redhat.com
9 files changed
tree: 9834a6dc6e47ff86e91f78557e1caa4e264976e2
  1. libkmod/
  2. m4/
  3. man/
  4. shared/
  5. shell-completion/
  6. testsuite/
  7. tools/
  8. .gitignore
  9. autogen.sh
  10. CODING-STYLE
  11. configure.ac
  12. COPYING
  13. Makefile.am
  14. NEWS
  15. README.md
  16. TODO
README.md

kmod - Linux kernel module handling

Coverity Scan Status

Information

Mailing list: linux-modules@vger.kernel.org (no subscription needed) https://lore.kernel.org/linux-modules/

Signed packages: http://www.kernel.org/pub/linux/utils/kernel/kmod/

Git: git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git http://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git

Gitweb: http://git.kernel.org/?p=utils/kernel/kmod/kmod.git https://github.com/kmod-project/kmod

Irc: #kmod on irc.freenode.org

License: LGPLv2.1+ for libkmod, testsuite and helper libraries GPLv2+ for tools/*

OVERVIEW

kmod is a set of tools to handle common tasks with Linux kernel modules like insert, remove, list, check properties, resolve dependencies and aliases.

These tools are designed on top of libkmod, a library that is shipped with kmod. See libkmod/README for more details on this library and how to use it. The aim is to be compatible with tools, configurations and indexes from module-init-tools project.

Compilation and installation

In order to compiler the source code you need following software packages: - GCC compiler - GNU C library

Optional dependencies: - ZLIB library - LZMA library - ZSTD library - OPENSSL library (signature handling in modinfo)

Typical configuration: ./configure CFLAGS=“-g -O2” --prefix=/usr
--sysconfdir=/etc --libdir=/usr/lib

Configure automatically searches for all required components and packages.

To compile and install run: make && make install

Hacking

Run ‘autogen.sh’ script before configure. If you want to accept the recommended flags, you just need to run ‘autogen.sh c’.

Make sure to read the CODING-STYLE file and the other READMEs: libkmod/README and testsuite/README.

Compatibility with module-init-tools

kmod replaces module-init-tools, which is end-of-life. Most of its tools are rewritten on top of libkmod so it can be used as a drop in replacements. Somethings however were changed. Reasons vary from “the feature was already long deprecated on module-init-tools” to “it would be too much trouble to support it”.

There are several features that are being added in kmod, but we don't keep track of them here.

modprobe

  • ‘modprobe -l’ was marked as deprecated and does not exist anymore

  • ‘modprobe -t’ is gone, together with ‘modprobe -l’

  • modprobe doesn't parse configuration files with names not ending in ‘.alias’ or ‘.conf’. modprobe used to warn about these files.

  • modprobe doesn't parse ‘config’ and ‘include’ commands in configuration files.

  • modprobe from m-i-t does not honour softdeps for install commands. E.g.: config:

      install bli "echo bli"
    

    install bla “echo bla” softdep bla pre: bli

    With m-i-t, the output of ‘modprobe --show-depends bla’ will be: install “echo bla”

    While with kmod: install “echo bli” install “echo bla”

  • kmod doesn‘t dump the configuration as is in the config files. Instead it dumps the configuration as it was parsed. Therefore, comments and file names are not dumped, but on the good side we know what the exact configuration kmod is using. We did this because if we only want to know the entire content of configuration files, it’s enough to use find(1) in modprobe.d directories

depmod

  • there's no ‘depmod -m’ option: legacy modules.*map files are gone

lsmod

  • module-init-tools used /proc/modules to parse module info. kmod uses /sys/module/*, but there‘s a fallback to /proc/modules if the latter isn’t available