Commit Graph

277 Commits

Author SHA1 Message Date
Johannes Berg c010f02030 modprobe: don't check refcount with remove command
The modprobe.d (5) documentation for the "install" command
states that you could specify

install fred /sbin/modprobe barney; /sbin/modprobe --ignore-install fred

This makes some sense, but then the loading of "barney" is
hidden from the user who did only "modprobe fred". Thus,
it seems it should be possible to be able to unload the
"fred" module with "modprobe -r fred" by configuring the
"barney" module to also be removed:

remove fred /sbin/rmmod barney fred

(or similar.)

Make this possible by not checking the refcount when an
unload command was configured.

Reported-by: David Spinadel <david.spinadel@intel.com>
2013-05-02 23:30:44 -03:00
Lucas De Marchi 1958af88a2 Add format attribute and fix issues
Add __attribute__((format)) to log_filep() and _show() functions, fixing
the bugs they found in the source code.

For functions that receive va_list instead of being variadic functions
we put 0 in the last argument, so at least the string is checked and we
get warnings of -Wformat-nonliteral type. So, it's better than adding a
pragma here to shut up the warning.
2013-04-21 16:17:12 -03:00
Lucas De Marchi 19ac5bd8a0 static-nodes: Fix indentation
kmod uses tab instead of spaces and tries to honour 80chr limit, when
that doesn't worsen the readability.
2013-04-19 19:28:46 -03:00
Tom Gundersen 4905769de7 static-nodes: tmpfiles - also create parents directories of device nodes
Before:

c /dev/cpu/microcode 0600 - - - 10:184
c /dev/fuse 0600 - - - 10:229
c /dev/btrfs-control 0600 - - - 10:234
c /dev/loop-control 0600 - - - 10:237
c /dev/snd/timer 0600 - - - 116:33

After:

d /dev/cpu 0755 - - -
c /dev/cpu/microcode 0600 - - - 10:184
c /dev/fuse 0600 - - - 10:229
c /dev/btrfs-control 0600 - - - 10:234
c /dev/loop-control 0600 - - - 10:237
d /dev/snd 0755 - - -
c /dev/snd/timer 0600 - - - 116:33
2013-04-19 19:03:03 -03:00
Lucas De Marchi 279b177de6 kmod: It's an error not to have modules.devname
This file is created by depmod even if there's no node. In this case it
will be empty.

Previously 'kmod static-nodes' was segfaulting due to passing in==NULL
to fgets.

Also show the error message with %m.
2013-04-17 00:57:11 -03:00
Tom Gundersen db6f2fc7e1 tools: add static-nodes tool
This tool reads modules.devname from the current kernel directory and outputs
the information. By default in a human-readable format, and optionally in
machine-readable formats.

For now only the tmpfiles.d(5) format is supported, but more could easily be
added in the future if there is a need.

This means nothing but kmod needs to reads the private files under
/lib/modules/. In particular systemd-udevd can stop reading modules.devname.

Tools that used to read /lib/modules/`uname -r`/modules.devname directly, can
now move to reading 'kmod static-nodes devname'.
2013-04-16 23:10:36 -03:00
Lucas De Marchi ace742fa9a modprobe: Fix assertion on --show-depends with bogus config file
Putting something like "alias psmouse deadbeef" is a hackish way to
blacklist a module. While I don't encourage doing so, let's not explode
if we fiund such config files.

A small difference from the behavior of module-init-tools: we exit with
0 instead of 1.
2013-03-21 02:33:25 -03:00
Josh Boyer d53abca3be rmmod: Teach rmmod about builtin modules
Currently modprobe -r will fail if a module is built in and report that it
is built in.  rmmod calls the same function to determine state but doesn't
handle the KMOD_MODULE_BUILTIN return code.  This leads to confusing errors
like this:

	libkmod: kmod_module_get_holders: could not open '/sys/module/loop/holders': No such file or directory
	Error: Module loop is in use

Fix this so that it actually reports the correct problem to the user.
2013-03-18 11:16:50 -03:00
Lucas De Marchi e6b0e49b4e Update copyright notices 2013-01-16 11:27:45 -02:00
Andrey Mazo 572a2711e7 depmod: fix builtin symbols resolution when the prefix symbol is set
When the prefix symbol is set, take it into account while adding symbols
from System.map file by skipping it before "__ksymtab_" comparison.

Also, prevent inserted fake symbols (like "__this_module") from being
wrongly truncated from beginning.
2012-12-31 18:23:30 -02:00
Andrey Mazo c02a8e6f9b depmod: --symbol-prefix actually requires an argument
-P requires and uses an argument but its long counterpart --symbol-prefix does not:
depmod: option '--symbol-prefix' doesn't allow an argument
2012-12-13 15:52:42 -02:00
Lucas De Marchi 650f89cd25 depmod: fix checking file extension
In depfile_up_to_date_dir() we need to check if name has a kmod
extension. "path" variable there will be the directory name, which
doesn't contain an extension.

Without this, "depmod -A" returns that the modules.dep is up to date,
even if it isn't.

In depmod_modules_search_file() it's pointless to compare the basename,
so pass only the name to be checked.
2012-11-28 14:26:23 -02:00
Aleksey Makarov 6f02b6fa7a fix is_module_filename()
modinfo fails if there is a ".ko" substring in the path to the module
2012-11-28 11:22:00 -02:00
Lucas De Marchi 02c64df3c2 depmod: fix asserting mod->kmod == NULL
If we are replacing a lower priority module (due to its location), we
already created a kmod_module, but didn't open the file for reading its
symbols. This means mod->kmod won't be NULL, and this is just ok. Since
all the functions freeing stuff below the previous assert already takes
NULL into consideration, it's safe to just unref mod->kmod and let the
right thing happens.
2012-11-16 12:05:42 -02:00
Lucas De Marchi 06294621a9 depmod: fix hash lookup by relpath instead of uncrelpath
We index modules in depmod by it's uncompressed relative path, not
relative path. We didn't notice this bug before since this function is
only triggered if we release a module to be replaced by one of higher
priority.

Also fix a leftover log message referring to relpath instead of
uncrelpath.
2012-11-16 11:39:41 -02:00
Lucas De Marchi 7c04aeee40 tools: use program_invocation_short_name provided by libc
Thanks to Dave Reisner for pointing this out.
2012-11-06 19:30:16 -02:00
Lucas De Marchi c841273721 tools: staticize functions that are now only used in log.c 2012-11-06 19:06:11 -02:00
Lucas De Marchi fcb0ce9475 tools: share function for logging 2012-11-06 19:02:23 -02:00
Lucas De Marchi 52a50fe2e5 tools: share setting up libkmod log
This also fixes a bug in "e6996c5 rmmod: route all messages to syslog if
told to" in which "+ verbose" was removed. Instead of letting verbose
add to kmod_get_log_priority(), let it be similar to the other programs
instead.
2012-11-06 18:52:09 -02:00
Lucas De Marchi 92aad74925 tools: use a single function for logging libkmod output 2012-11-06 18:35:17 -02:00
Lucas De Marchi 34e06bfb54 tools: make usage() messages go to stdout rather than stderr
When user supplied --help/-h, program should output to stdout the usage,
not to stderr. It's the expected behavior, what the user asked for,
not something to log or an error.
2012-11-06 17:32:41 -02:00
Lucas De Marchi 84341fbe01 tools: share function to convert prio to string
No change is expected in the final binary since right now only an inline
function is shared. Later we expect to share more code.
2012-11-06 17:10:57 -02:00
Lucas De Marchi 4a2e20dfb3 tools: share getting program name from argv for all tools 2012-11-06 16:55:00 -02:00
Lucas De Marchi e6996c5c30 rmmod: route all messages to syslog if told to 2012-11-05 18:32:05 -02:00
Lucas De Marchi 04c26d28be rmmod: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi 9382dbf7aa modinfo: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi e2f9478faf insmod: prefer ERR over plain fprintf 2012-11-05 17:59:23 -02:00
Lucas De Marchi 96b50d3623 depmod: add depmod prefix to log messages 2012-11-05 02:08:16 -02:00
Lucas De Marchi a3f16ff704 depmod: remove inline from _log 2012-11-05 02:08:16 -02:00
Lucas De Marchi 61c48db360 depmod: prefer ERR and WRN over plain fprintf 2012-11-05 02:01:06 -02:00
Lucas De Marchi d9a2e15504 modprobe: use ERR() instead of fprintf(stderr, ...) 2012-11-01 13:03:02 -02:00
Lucas De Marchi d96ae03bd9 modprobe: prefix log messages to stderr with modprobe 2012-11-01 12:46:12 -02:00
Lucas De Marchi 07df56eb24 modprobe: move log function 2012-11-01 12:46:12 -02:00
Lucas De Marchi 86cc1f2328 modprobe: prefix libkmod messages to stderr with modprobe:
When we are logging to stderr we are previously relying on libkmod
sending it to the default location in case we are not asked to log to
syslog. The problem is that modprobe may be used in scripts that don't
want to log to syslog (since they are not daemons, like scripts to
generate initrd) and then it's difficult to know where the message comes
from.

This patch treats only the messages coming from libkmod.
2012-11-01 12:46:03 -02:00
Lucas De Marchi 1e947e3c87 modprobe: use prio_to_str() helper 2012-10-31 22:00:40 -02:00
Lucas De Marchi 4434d8ba36 modprobe: exit in one place 2012-10-31 21:29:54 -02:00
Lucas De Marchi e4a7352ad3 depmod: unref kmod_module once we don't need it anymore
Once we read all we need from a module, unref it so any resource taken
by it (including the mmap to access the file in libkmod) will be
dropped. This drastically reduces the number of open file descriptors
and also the memory needed, with no performance penalties. Rather,
there's a small speedup of ~2.6%.

Running depmod in a laptop with 2973 modules and comparing the number of
open file descriptors for kmod-10, before and after the last patches to
depmod (caaf438cb6 and HEAD) we have:

	Before:		2980 simultaneously open fds
	After:		7    simultaneously open fds
	kmod-10:	7    simultaneously open fds

So now we have the speedup of caching the file in kmod_module without
the drawback of increasing the number of open file descriptors.
2012-10-30 04:56:59 -02:00
Lucas De Marchi 447eed8c48 depmod: use our copy of modname instead of calling libkmod
In depmod_module_add() we already called kmod_module_get_name() and
copied the string to our struct. Use it instead of calling again and
again the libkmod function.
2012-10-30 04:11:24 -02:00
Lucas De Marchi ec587f298c depmod: cache dependency_symbol list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_get_dependency_symbols(). Calling it earlier, while we
are iterating the modules allows us to free the struct kmod of each
module much sooner. We are still not freeing it since there are other
places that must be refactored first.

There's a performance penalty of ~2.5% from previous commit.
2012-10-30 04:05:53 -02:00
Lucas De Marchi 7062eca38b depmod: cache info_list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_info(). Calling it earlier, while we are iterating the
modules allows us to free the struct kmod of each module much sooner. We
are still not freeing it since there are other places that must be
refactored first.

A nice side effect is that this commit reduces in ~33% the calls to
malloc(), giving a speedup of ~6% for cold caches (reproduced on only 1
laptop).
2012-10-30 03:24:25 -02:00
Lucas De Marchi b51ac407c2 depmod: do not create a hole in struct depmod 2012-10-30 02:33:14 -02:00
Lucas De Marchi cc833644b2 rmmod: Deprecate --wait option
Remove --wait from usage() and give a message + sleep(10) if user is in
fact using it.
2012-10-17 18:43:17 -03:00
Lucas De Marchi 88c247f7f1 depmod: fix parsing of modules.order with compressed modules
We now index the modules by uncompressed-relative-path instead of
relative-path. This is because the file modules.order, coming from
kernel, always comes with uncompressed paths. This fixes the issue of
not sorting the aliases correctly due to paths not matching when using
compressed modules.
2012-10-03 16:29:36 -03:00
Dave Reisner c5b37dba89 build-sys: Remove --with-rootprefix option
This is a broken option that only leads to misery and incompatabilities
with other systems. Kbuild doesn't come close to supporting directories
other than /lib/modules with several targets simply failing without
hacky fixes. Simply remove the option and all traces of it, as it
doesn't make sense in today's world.
2012-10-02 00:27:31 -03:00
Lucas De Marchi 36ddee6562 modprobe: Unconditionally use KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY
This fixes a change in behavior regarding kmod and module-init-tools:
when trying to load a module by alias, we should check if it's
blacklisted, regardless of the command line arguments passed.

This was reported by "Dmitry V. Levin <ldv@altlinux.org>".
2012-08-17 09:42:47 -03:00
Lucas De Marchi e8fd8fec23 Use #pragma once instead of #ifndef
Only the public header maintains #ifndef in the header, together with
pragma. The other ones contain only pragma.

As reported by Shawn Landden on systemd mailing list this is compatible
with all major compilers and gcc has this since version 3.3.
2012-07-18 10:31:50 -03:00
Lucas De Marchi 3f376cd877 depmod: use ferror and fclose to check for error
Thanks to hpa for point this out.
2012-06-15 22:14:00 -03:00
Lucas De Marchi a4fb97a71e depmod: return error when index is truncated due to ENOSPC
Before:
=======
[lucas@vader kmod]$ sudo depmod
[lucas@vader kmod]$ echo $?
0
[lucas@vader kmod]$ ls -l /lib/modules/$(uname -r)
total 12
drwxr-xr-x 8 root root   160 Jun 13 11:05 kernel
-rw-r--r-- 1 root root 12288 Jun 15 21:29 modules.alias
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.alias.bin
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.dep
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.dep.bin
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.devname
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.softdep
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.symbols
-rw-r--r-- 1 root root     0 Jun 15 21:29 modules.symbols.bin

Note that modules.alias is truncated and the other have size == 0

After:
======

[lucas@vader kmod]$ sudo ./tools/depmod
WARNING: could not open /lib/modules/3.5.0-rc2-demarchi-00028-g94fa83c/modules.order: No such file or directory
ERROR: Could not create index: output truncated: No space left on device
[lucas@vader kmod]$ echo $?
1
2012-06-15 21:31:05 -03:00
Lucas De Marchi 015946da0c depmod: fix coding-style issue in array declaration 2012-06-15 03:04:28 -03:00
Lucas De Marchi 80e49ad988 depmod: fail if any index could not be created 2012-06-15 02:42:39 -03:00
Lucas De Marchi c5db1a3fd2 depmod: don't return error if modules.builtin don't exist 2012-06-15 02:42:25 -03:00
Lucas De Marchi ccd6afa4f2 Remove ifdef for building tools not bundled
Current build system do not support to build separate tools anymore, so
just remove the ifdefs.
2012-06-15 00:40:14 -03:00
Lucas De Marchi ac78e109c3 tools: rename source files
There's no point anymore in having "kmod-" prefix. This is a historical
thing when we started implementation of these tools.
2012-06-14 16:29:28 -03:00
Dave Reisner 819f79a24d depmod: report failures in loading symbols
Previously, depmod would relegate failures of kmod_module_get_symbols()
to debug output, assuming the "error" was simply a lack of symbols.
Leave the ENOENT return to debug output, but report anything else as a
real error.
2012-05-08 10:22:14 -03:00
Lucas De Marchi 20c6e18c37 Return error instead of always 0 2012-04-26 11:40:26 -03:00
Lucas De Marchi 18a492e6f7 Remove dead assignment 2012-04-26 11:39:54 -03:00
Dave Reisner ccb64d1ead modprobe: handle -ENOENT return from init_module
init_module returns -ENOENT when the module failed to load because of a
bad parameter or unknown symbol. Throw a more descriptive error message
than the generic "No such file or directory" to alert the user.

Fixes Debian bug 668216.
2012-04-16 10:37:32 -04:00
Elan Ruusamäe 02629fa02e modprobe: fix typo in config dump: option->options
kmod uses "option MODNAME", not "options MODNAME"

	--- modprobe-sorted.kmod	2012-03-21 22:31:03.751754042 +0200
	+++ modprobe-sorted.module-init-tools	2012-03-21 22:30:49.561753089 +0200
	@@ -1,6 +1,23 @@
	[...]
	-option uvesafb mode_option=1024x786-32 mtrr=4 scroll=ywrap
	+options uvesafb mode_option=1024x786-32 mtrr=4 scroll=ywrap

This breaks scripts that depend in modprobe -c output grepping
2012-03-22 12:00:16 -03:00
Lucas De Marchi ae7ebe8770 modprobe: set log prio to 0 if user passed -q arg 2012-03-15 01:16:54 -03:00
Lucas De Marchi 23ea575014 Merge branch 'master' of git://code.falconindy.com/kmod 2012-03-15 00:31:22 -03:00
Lucas De Marchi c1b84540bb modprobe: always try to remove all modules in command line 2012-03-15 00:27:18 -03:00
Lucas De Marchi 4744ebcef4 modprobe: don't check if module builtin to decide if it's builtin
More or less confusing message, but if module is builtin in the live
system, it doesn't mean it's builtin in the target kernel.

Instead we now check if module has a path. It don't have a path only if
it's builtin in the target or if it doesn't exist at all. The latter
should not be a problem since this code is being called from inside the
library. Anyway, put an assert to make sure we get bug reports if any
case slipped in here.
2012-03-15 00:14:35 -03:00
Dave Reisner f758caf57c modprobe: fix error path in removing modules
We really haven't paid this code much attention, and it's somewhat
evident in our divergence in behavior from module-init-tools. This patch
asserts the following behavior on exit:

* modprobe -r realmod_notloaded => exit zero
* modprobe -r --first-time realmod_notloaded => exit non-zero
* modprobe -r bogusmod => exit non-zero
2012-03-14 22:26:30 -04:00
Dave Reisner aa5da52c3b modprobe: show builtin label on --show-depends
Previously, we didn't handle builtins very well, displaying things like:

$ modprobe -D btrfs
insmod /lib/modules/3.2.6-foo/kernel/crypto/crc32c.ko.gz
insmod (null)
insmod /lib/modules/3.2.6-foo/kernel/lib/libcrc32c.ko.gz
insmod /lib/modules/3.2.6-foo/kernel/lib/zlib_deflate/zlib_deflate.ko.gz
insmod /lib/modules/3.2.6-foo/kernel/fs/btrfs/btrfs.ko.gz

Follow module-init-tools and show builtins with the label 'builtin' and
their name:

$ modprobe -D btrfs
insmod /lib/modules/3.2.6-foo/kernel/crypto/crc32c.ko.gz
builtin intel_crc32c
insmod /lib/modules/3.2.6-foo/kernel/lib/libcrc32c.ko.gz
insmod /lib/modules/3.2.6-foo/kernel/lib/zlib_deflate/zlib_deflate.ko.gz
insmod /lib/modules/3.2.6-foo/kernel/fs/btrfs/btrfs.ko.gz
2012-02-27 18:49:36 -03:00
Dave Reisner 3e4c6af6ad modinfo: use new apply_filter method to avoid builtins 2012-02-24 10:53:42 -05:00
Dan McGee a23f0c9c55 modinfo: handle arguments more carefully
A simple case of breakage before this commit:

    $ touch aes
    $ modinfo aes
    filename:       /tmp/aes
    ERROR: could not get modinfo from 'aes': Invalid argument

Add a new is_module_filename() function that attempts to do more than
just check if the passed argument is a regular file. We look at the name
for a '.ko' string, and if that is found, ensure it is either at the end
of the string or followed by another '.' (for .gz and .xz modules, for
instance). We don't make this second option conditional on the way the
tools are built with compression support; the file is a module file
regardless and should always be treated that way.

When doing this, and noticed in the test suite output, we open the
system modules index unconditionally, even if it is never going to be
used during the modinfo call, which is the case when passing module
filenames directly. For only one module there's not much advantage in
pre-loading the index, so just remove the call to kmod_load_resources().

With-help-from: Dave Reisner <dreisner@archlinux.org>
[lucas.demarchi@profusion.mobi: remove call to kmod_load_resources()]
2012-02-06 20:29:08 -02:00
Lucas De Marchi 814a57babf libkmod-module: probe: rename flag to be more meaningful 2012-02-06 12:46:39 -02:00
Dan McGee 2ec79834a3 Update .gitignore files
Add kmod-* prefixed tool names, add 'tags' in root directory (for ctags,
matches cscope.out ignore already in there), and prefix tools/ entries
with '/' so they are absolute ignores and don't apply to subdirectories.
2012-02-05 02:15:20 -02:00
Khem Raj 035cbdc763 depmod: Dont use errno unconditionally
fopen() will not reset errno if it succeeds so we should
make sure that we only use errno in error cases.

Also fix the diagnostic messages to not use strerror
when there is no error since strerror will not return
anything useful in this case
2012-02-03 14:52:59 -02:00
Dave Reisner 1505ee9793 modprobe: avoid breaking on insertion failure 2012-02-03 09:10:13 -05:00
Dave Reisner 297a3182e4 modprobe: properly handle errors from init_module
Effectively catch and the zero and non-zero cases and error out
appropriately. Note that -EEXIST will only ever be returned when
KMOD_PROBE_STOP_ON_ALREADY_LOADED is set as a probe_insert_module flag.
2012-01-31 14:08:57 -02:00
Dave Reisner 69a1974347 modprobe: post-remove module deps with 0 refcnt
This commit looks shockingly similar to 0e9bd2d1 because SOMEONE decided
to remove it in a872bba in a glorious frenzy of refactoring.
2012-01-31 14:08:57 -02:00
Lucas De Marchi 2e9dcd742e kmod-modprobe: migrate to kmod_module_probe_insert_module() 2012-01-31 14:08:57 -02:00
Lucas De Marchi 28f32c65ca modprobe: print end of configuration files 2012-01-27 23:56:46 -02:00
Lucas De Marchi 3ef848b28b modprobe: fix build 'cause of excessive number of arguments 2012-01-26 16:03:47 -02:00
Dave Reisner cc98830ca4 modprobe: remove code referring to -t, --type
This was only useful with the --list function, which isn't implemented.
2012-01-26 15:07:09 -02:00
Lucas De Marchi fe8b0671a0 build-sys: do not create symlinks by default
Distro packagers should create them instead. It's too much trouble to
create them in the build system and every distro wants a different path
for them.
2012-01-21 18:01:00 -02:00
Lucas De Marchi 569f1609bd modprobe: kill operations depending on path
It was not on module-init-tools and it doesn't make much sense. It will
deal with dependencies, but looking at modules in the index. This might
not be the module we want if we are loading another from outside of the
tree.

Dealing with paths causes this bug (supposing there's a module names
squashfs):

	# cd /
	# touch squashfs
	# modprobe squashfs

That is because it detects that squashfs exists as a file and it will
try to load it instead of the alias "squashfs".

If you need to load a module from a path, use insmod.

Thanks to Silvan Calarco <silvan.calarco@mambasoft.it> who reported the
bug and helped debugging it.
2012-01-21 02:47:08 -02:00
Lucas De Marchi 411d83c41e Add program to calculate the shortest relative path for symlinks 2012-01-18 19:48:16 -02:00
Thierry Vignaud eff917c0d2 WEXITSTATUS is defined in sys/wait.h
Fix compiling with dietlibc:

../libkmod/libkmod-module.c:858:2: warning: implicit declaration of function 'WEXITSTATUS' [-Wimplicit-function-declaration]
../libkmod/libkmod-module.c:858:2: warning: nested extern declaration of 'WEXITSTATUS' [-Wnested-externs]
(...)
kmod-modprobe.c:(.text.command_do+0x157): undefined reference to `WEXITSTATUS'
2012-01-17 17:33:07 -02:00
Lucas De Marchi 09e9ae58b6 modprobe: flush stdout before dumping indexes
Index dump doesn't use stdio.h function and instead call write()
directly on STDOUT_FILENO file descriptor. Therefore we need to flush
stdio buffers before calling it, to be sure the configuration dump will
appear before index's.
2012-01-17 10:11:03 -02:00
Lucas De Marchi b8542a82b7 Fix common misspelling with codespell
-------8<-------
SUMMARY:
ommitted      1
2012-01-16 23:03:33 -02:00
Lucas De Marchi 49a163759d modprobe: dump indexes as well 2012-01-16 16:05:47 -02:00
Lucas De Marchi e15a56af85 depmod: deal with relative root dir
module paths coming from libkmod are absolute. Make sure we store the
absolute dirname to compare later.
2012-01-14 02:46:58 -02:00
Lucas De Marchi 33557e8d69 depmod: fix idx calculation after postponed array creation
We need to set up each module's idx when the array is created. So,
postpone its initialization as well.
2012-01-14 02:07:14 -02:00
Lucas De Marchi 31f1d0d306 Reduce scope of counter variable 2012-01-14 02:04:31 -02:00
Lucas De Marchi f6b838e1ba depmod: adhere to coding style 2012-01-14 02:03:21 -02:00
Lucas De Marchi bc43496a87 modprobe: dump configuration 2012-01-13 11:12:41 -02:00
Lucas De Marchi 8b01376742 modprobe: abort on dependency loop that cannot be broken 2012-01-12 17:14:30 -02:00
Lucas De Marchi e4e1e64ab0 modprobe: fix leak on error path 2012-01-12 15:37:57 -02:00
Lucas De Marchi a872bba22d modprobe: rework module removal without tree traversing
Just like the module insertion, module removal is remade.

The dependencies line that comes from modules.dep already contains all
the dependencies necessary to remove that module. Therefore modprobe
doesn't have to do the recursion between the modules in order to remove
it. All we have to do is to remove in order:

For the module being removed:
----------------------------

1. softdeps (in reverse order)
2. deps (in reverse order)
3. module
4. postdeps (in reverse order)

For any of the dependencies:
----------------------------

1. softdeps (in reverse order)
2. module
3. softdeps (in reverse order)
2012-01-12 15:23:51 -02:00
Lucas De Marchi 0cf2832a31 modprobe: rework module insertion without tree traversing
The dependencies line that comes from modules.dep already contains all
the dependencies necessary to insert that module. Therefore modprobe
doesn't have to do the recursion between the modules in order to load a
module. All we have to do is to load in order:

For the module being loaded:
----------------------------

1. softdeps
2. deps
3. module
4. postdeps

For any of the dependencies:
----------------------------

1. softdeps
2. module
3. softdeps
2012-01-12 14:34:19 -02:00
Lucas De Marchi 92122614b2 modprobe: show if module is in kernel
Now with './tools/modprobe --show-depends ahci' (ahci is builtin) we have the following
output:

$ ./tools/modprobe --show-depends ahci
builtin ahci

Just like modprobe from m-i-t. Previously we had:

$ ./tools/modprobe --show-depends ahci
FATAL: Module ahci not found.
2012-01-11 21:54:25 -02:00
Jan Alexander Steffens (heftig) 00bd319113 depmod: Postpone creation of module array
Deleting modules (we have found replacements) invalidates the indices
because the array collapses removed elements, hitting the assertion.

Since we don't make use of the array until the sorting step, build it from
the modules_by_name hash instead.
2012-01-11 20:35:18 -02:00
Lucas De Marchi af0ff2f22a modprobe: break dependency loop by checking if module is loaded
modprobe doesn't have support for handling dependency loop. That happens
with poorly written softdeps that can introduce a loop. We must deal
with them like it's being done in libkmod.

However, we can break a dependency loop when the dependency was already
inserted. This commit fixes this issue, that happens in the following
scenario:

dependencies:
-------------

modA:
modB: modA
modC: modA

config:

softdep modA post: modB modC

This creates the following loop:

modA
    inserted ok
    handle post-soft-deps of modA -> modB modC
        modB
            handle dependencies of modB -> modA
                modA is already inserted
                    handle post-soft-deps of modA -> modB modC

And so on and so forth.

Now we break the loop by checking if module is already inserted, before
handling it. Thus this gives us:

modA
    inserted ok
    handle post-soft-deps of modA -> modB modC
        modB
            handle dependencies of modB -> modA
                modA is already inserted
            inserted ok
        modC
            handle dependencies of modC -> modA
                modA is already inserted
            inserted ok
2012-01-11 18:29:55 -02:00
Lucas De Marchi 8f1922101e modprobe: adhere do coding style 2012-01-11 15:48:20 -02:00
Dave Reisner 6da9cdf1f7 rmmod: behavior more like m-i-t's rmmod
In line with m-i-t's behavior, we should check to see if each module is:

- loaded
- has any holders
- has a 0 refcnt

Detecting any of these lets us provide a more useful message than the
kernel's EPERM response to delete_module(2).

Additionally, alter the main loop behavior to avoid exiting early on the
first error.
2012-01-10 22:35:18 -05:00
Dave Reisner b54f1bf06a modprobe: check for EPERM on insertion
Throw an appropriate error when an unprivileged user attempts to load a
module.
2012-01-10 22:33:05 -05:00
Lucas De Marchi 0b22179acd build-sys: workaround libtool issue with argv[0]
Symlinking tools to kmod doesn't work because argv[0] is not the name of
the symlink, but rather 'kmod' (since libtool's wrapper script calls the
tools/.libs/kmod directly)

Now we create another binary kmod-nolib that is statically linked to
libkmod so we can call the binary directly and do not worry about
LD_LIBRARY_PATH.
2012-01-10 15:31:58 -02:00
Lucas De Marchi 00fc926cd8 build-sys: create symlinks instead of building separate tools 2012-01-10 15:31:58 -02:00
Lucas De Marchi a66a6a999f Update copyright 2012-01-09 00:41:07 -02:00
Lucas De Marchi cb0d0b7212 modprobe: fix error path when loading dependencies
demarchi> scenario is the following:
demarchi> modA depends on modB and modC
demarchi> if there's a race when trying to insert a dependency of a module, say
          modB, it will stop loading all the modules
demarchi> it should check by "module already loaded error"
demarchi> like it does for modA
2012-01-08 18:08:05 -02:00
Gustavo Sverzut Barbieri 525fa07b8f modprobe: show is independent from verbose level.
"modprobe --quiet --show-depends" now works.
2012-01-08 14:32:23 -02:00
Lucas De Marchi 6daceb2f1f Replace NAME_MAX with PATH_MAX for module aliases
Module aliases can be bigger than NAME_MAX. So, replace with PATH_MAX
that is bigger enough to hold them.

Technically in some places NAME_MAX would be sufficient (those using
module names only), but they use functions that can be called with
alias. So increase the buffers in these cases to PATH_MAX too.
2012-01-08 01:02:29 -02:00
Rolf Eike Beer 55021bed20 tools/kmod-depmod: fix aliasing warning 2012-01-06 10:47:47 -02:00
Lucas De Marchi 3f1e970b5a Revert "tools/kmod-depmod: fix aliasing warning"
This reverts commit f63fc9e606. Wrong
author name. I'll apply it again later.
2012-01-06 10:44:45 -02:00
root f63fc9e606 tools/kmod-depmod: fix aliasing warning 2012-01-06 10:39:39 -02:00
Dave Reisner 7f37491375 tools/modprobe: exit non-zero on module not found with --all 2012-01-06 02:33:58 -02:00
Dave Reisner 5f85a133f8 tools/modinfo: exit non-zero on module not found 2012-01-06 02:32:28 -02:00
Lucas De Marchi aa156c9860 tools: use basename in help message 2012-01-05 08:16:28 -02:00
Lucas De Marchi 56406fdb0a kmod-depmod: demote messages to WRN when non-critical files are missing 2012-01-04 21:02:20 -02:00
Dave Reisner 6369837707 tools: unify error verbiage and casing
Fix a typo and ensure that we always use "could not" instead of "Could
not" or the conjunction "couldn't".
2012-01-04 10:59:03 -05:00
Gustavo Sverzut Barbieri 3db5bf9d38 kmod-depmod: fix replacement of existing modules.
We cannot create a kmod_module for existing module name, it will fail
due existing in the hash table "modules_by_name".

To avoid it, we first delete the existing module, if lower priority,
then add the new one.

kmod_module_new_from_path() is called only when the former module was
deleted or does not exist.
2012-01-03 16:14:57 -02:00
Gustavo Sverzut Barbieri 026c7b448d kmod-depmod: fix comparison of module priority.
This code was never tested, my bad!

 * the prefix should be ignored, as it is not stored in cfg_search/override.

 * baselen should not include '/'.

 * search length should not include '\0'.

 * override path should not include cfg->dirname prefix.
2012-01-03 16:10:17 -02:00
Gustavo Sverzut Barbieri 8ea02fe056 kmod-depmod: fix incorrect math finding out end of dirname. 2012-01-03 15:11:58 -02:00
Gustavo Sverzut Barbieri 5988652597 kmod-depmod: document --config/-C in help output. 2012-01-03 15:06:08 -02:00
Gustavo Sverzut Barbieri b0bcadd0ae kmod-depmod: add missing trailing \n to log messages. 2012-01-03 15:04:34 -02:00
Lucas De Marchi d8a6c0ccb8 kmod-modprobe: mimic modprobe when removing deps with usecount=0 2012-01-01 06:13:09 -02:00
Lucas De Marchi c9a144481d Fix leak of kmod_module and fix code style 2012-01-01 06:12:59 -02:00
Dave Reisner 0e9bd2d1ca kmodprobe: post-remove module deps with 0 refcnt 2011-12-31 18:21:00 -05:00
Dave Reisner d98880ad5c modprobe: use lighter access call instead of stat 2011-12-31 18:02:30 -05:00
Dave Reisner b09668cf64 modprobe: remove --list option
This was marked as deprecated in m-i-t's modprobe in favor of find and
basename.
2011-12-31 16:51:40 -05:00
Lucas De Marchi 0c010fae10 Move libkmod-util.c to convenience util lib
Share more code between tools and libkmod. underscores() in kmod-depmod
can not use the same function as in the lib, so rename it.
2011-12-28 13:33:26 -02:00
Lucas De Marchi 6670c63344 Move array implementation from depmode to libkmod-util 2011-12-28 12:58:47 -02:00
Lucas De Marchi f6cf14ce13 tools: kmod: bundle depmod together with the others 2011-12-27 19:56:33 -02:00
Lucas De Marchi bcb812275e Fix header guard 2011-12-27 19:53:38 -02:00
Leandro Pereira 4783d69e48 kmod tool: don't keep iterating when command has been executed 2011-12-27 19:46:44 -02:00
Lucas De Marchi 5cd13064ec kmod-depmod: use hash implementation from util lib 2011-12-27 18:11:58 -02:00
Lucas De Marchi ea1b8c3702 kmod-depmod: Fix leak of dependency vector 2011-12-27 15:21:31 -02:00
Gustavo Sverzut Barbieri a627c3f31a kmod-depmod: refactor extension matching array, support XZ.
move the extensions array match to global, conditionally add GZ and XZ
if the support is enabled.
2011-12-27 12:09:17 -02:00
Gustavo Sverzut Barbieri 18cd9da303 kmod-depmod: implement -A (--quick) 2011-12-27 12:09:17 -02:00
Gustavo Sverzut Barbieri 4a0e46dac2 kmod-depmod: implement -F and -E options.
Read System.map and Module.symvers from kernel built, then be able to
report unknown symbols.
2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 7436788ca0 kmod-depmod: dump modules.dep.bin 2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri ec77abb918 kmod-depmod: dump modules.alias.bin 2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 75a9723bb2 kmod-depmod: dump modules.symbols.bin 2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 4b144e5fb4 kmod-depmod: dump modules.builtin.bin 2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 92df661697 kmod-depmod: add utility functions to be used by binary dumps.
Binary dumps will use functions to convert alias to underscores and
paths to module names.
2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 0de40463ba kmod-depmod: copy code from module-init-tools/index.c
Copy code from module-init-tools/index.c, the following copyright applies:

    Copyright (C) 2008  Alan Jenkins <alan-jenkins@tuffmail.co.uk>.
2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 8e3505c504 kmod-depmod: dump deps. 2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 0d13174578 kmod-depmod: dump aliases 2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 8bc830efc5 kmod-depmod: dump softdeps. 2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 9a14d0e989 kmod-depmod: dump modules.symbols
note that the hash algorithm is different thus the output order will
be different as well.

to compare the outputs, sort the files:

   depmod -n | grep '^alias symbol:' | sort > /tmp/orig
   kmod-depmod -n | grep '^alias symbol:' | sort > /tmp/new
   diff /tmp/orig /tmp/new
2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 25c4151203 kmod-depmod: dump devname
first try to dump files: modules.devname.
2011-12-27 12:09:16 -02:00
Gustavo Sverzut Barbieri 64b8b586eb kmod-depmod: initial code (no files generated, untested)
this is the initial code for depmod, it should:
 * use configuration from /run/depmod.d, /etc/depmod.d, /lib/depmod.d
 * respect overrides and searches
 * resolve symbols and dependencies
 * break circular dependencies (dependency loops)
 * --errsyms: print out modules with unresolved symbols and incorrect crc
 * --symbol-prefix: respect architecture symbol prefix

it will not:
 * --quick: does not do quick mode
 * --warn: does not warn on duplicates
 * --filesyms: does not load symbols from map file
 * --symvers: does not load symbol versions from map file
 * dump files: does not dump any files at the moment.

it is highly untested, then I appreciate your help with real world
scenarios using overrides and searches. To get output run with -vvvvvv.

next version should fill in the gaps and at least generate the files
2011-12-27 12:09:16 -02:00
Lucas De Marchi 9b966da87e tools: kmod: show wrong command in err message 2011-12-23 11:44:28 -02:00
Lucas De Marchi a458e36738 tools: kmod: print help message when no commands given 2011-12-23 11:35:48 -02:00
Lucas De Marchi 252c51a996 tools: kmod: add list command
It's the same of lsmod since there's not much to change on its format.
2011-12-23 11:33:02 -02:00
Lucas De Marchi fa29c0ee96 tools: kmod: Add handling of compat modprobe 2011-12-23 03:09:05 -02:00
Lucas De Marchi 769becb5db tools: kmod: Add handling of compat modinfo 2011-12-23 03:09:05 -02:00
Lucas De Marchi ad6026965f tools: kmod: Add handling of compat insmod 2011-12-23 03:09:05 -02:00