Commit Graph

75 Commits

Author SHA1 Message Date
Lucas De Marchi 3a92fc6309 libkmod: Allow to ignore log message on module removal
Caller may want to handle retries, in which case the log message is not
appropriate.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:23:46 -07:00
Lucas De Marchi 9becaaea25 libkmod: Add lookup from module name
Slightly different than kmod_module_new_from_lookup(): it doesn't
consider aliases, only module names. This is useful for cases we want to
force a tool to handle something as the module name, without trying to
interpret it as an alias.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20 20:58:11 -08:00
Alexey Gladkov b866b2165a Lookup aliases in the modules.builtin.modinfo
New modules.builtin.modinfo duplicates modules.builtin in the built-in
module name search. If it exists, then we can use this file, but if not,
then we need to fallback to the old file.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2019-12-18 16:56:58 -08:00
Jan Engelhardt 867da6fcfb kmod: build: cure compiler warnings showing up externally
When building a C source file with gcc-7 -Wshift-overflow=2, this warning
springs up:

libkmod.h: warning: result of "1 << 31" requires 33 bits to
represent, but "int" only has 32 bits [-Wshift-overflow=]

Change the two _KMOD_* identifiers to fit into 32 bits.
2018-06-18 09:46:56 -07:00
Laura Abbott b87d01d6ef modprobe: Update error message when path is missing
Currently, modprobe fails with no output by default if the
search paths it tries are missing:

$ modprobe -S notakernel dm-crypt
$
$ modprobe -S notakernel lkjjweiojo
$

This is fairly cryptic and not at all obvious there is a problem
unless the error code is checked or verbose flags are used.
Update the error message to indicate a problem and print out the
directory that failed.
2015-09-30 15:16:59 -03:00
Lucas De Marchi dea2dfee9b Remove FSF mailing address
It has changed in the past, and these days, anyone can get a copy of the
LGPL via the web rather than by post.

Like 657a122 (Remove FSF mailing address) in libabc by Josh Tripplet,
but let the FSF website in which the license can be found.
2014-12-25 23:41:34 -02:00
Lucas De Marchi 7ab8804448 libkmod: always pass O_NONBLOCK to kernel
Not passsing O_NONBLOCK to delete_module() is deprecated since kmod 11
and is being removed from the kernel. Force this flag in libkmod.
2013-09-20 01:37:24 -05:00
Lucas De Marchi e6b0e49b4e Update copyright notices 2013-01-16 11:27:45 -02:00
Lucas De Marchi 6882017f80 libkmod-module: Add KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY flag
With this flag kmod_module_probe_insert_module() check if module is
blacklisted only if it's also an alias. This is needed in order to allow
blacklisting a module by name and effectively blacklisting all its
aliases as module-init-tools was doing.

Before this patch we could load pcspkr module as follows:

	/etc/modprobe.d/test.conf:
		alias yay pcspkr
		blacklist pcspkr

	$ modprobe yay

Now libkmod has support to blacklist "yay" because "pcspkr" is blacklisted.
2012-08-17 09:42:15 -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
Dave Reisner d80b103c63 libkmod/module: add kmod_module_apply_filter method
This is a more generic method of applying filters to module lists. This
deprecates kmod_module_get_filtered_blacklist() which now simply returns
a call to _apply_filter with the extra filter enum arg.
2012-02-24 10:53:42 -05:00
Lucas De Marchi 3805274bf5 kmod-module: lookup: search modules.builtin file too
Search modules.builtin file before saying the module was not found.
Note: these "modules" should not appear as dependencies of other modules
(in modules.dep) even if they appear in modinfo. This fixes the return
code of modprobe with builtin modules.

Also fixes a small coding style issue in module_is_inkernel().
2012-02-16 21:18:00 -02:00
Lucas De Marchi 814a57babf libkmod-module: probe: rename flag to be more meaningful 2012-02-06 12:46:39 -02:00
Lucas De Marchi 9226ddad2c libkmod: organize public header 2012-01-31 17:23:35 -02:00
Lucas De Marchi 7aed46088e libkmod-module: probe: remove useless KMOD_PROBE_STOP_ON_COMMAND 2012-01-31 14:08:57 -02:00
Lucas De Marchi 3bc92e8949 libkmod-module: probe: return -EEXIST if told to stop on already loaded 2012-01-31 14:08:57 -02:00
Lucas De Marchi 4c1ffb75d4 libkmod-module: probe: add flag to dry-run 2012-01-31 14:08:57 -02:00
Lucas De Marchi 7c10c69c72 libkmod-module: probe: add flag to ignore loaded modules
We need a way to tell libkmod to ignore loaded modules, so modprobe can
tell it to dry-run and show dependencies. However there's a conflict
with two flags. KMOD_PROBE_STOP_ON_ALREADY_LOADED prevails if passed
together with KMOD_PROBE_IGNORE_LOADED.
2012-01-31 14:08:57 -02:00
Lucas De Marchi 6bd0713deb libkmod-module: probe: add print_action callback
This allows to implement dry-run in modprobe without exporting
kmod_module_get_probe_list().
2012-01-31 14:08:57 -02:00
Lucas De Marchi d851e9a144 libkmod-module: probe: add room in flags for future extension
Breaking flags is one of the reasons next version will need to bump ABI.
In future we don't want to bump it just because of this.
2012-01-30 20:05:34 -02:00
Lucas De Marchi 48b10305cb libkmod-module: probe: ignore-command flag can't be used in return 2012-01-30 20:05:34 -02:00
Lucas De Marchi 79d6c7d764 libkmod-module: probe: remove useless flag to stop on failure
We always want to stop if module failed to loaded due to unknown reason.
2012-01-30 20:05:34 -02:00
Lucas De Marchi 5f3514731e libkmod-module: probe: add flag to stop loading on already loaded
It's not as simple as tell user to check if the module is loaded before
calling this function. Due to race conditions, module might not be
loaded before the function call, but fail later because another process
inserted it.
2012-01-30 20:05:34 -02:00
Lucas De Marchi 89e92487bc libkmod-module: probe: add flag to ignore commands 2012-01-30 20:05:33 -02:00
Lucas De Marchi b1a51256a9 libkmod-module: probe: change insertion to cover more use cases
Split kmod_module_probe_insert_module() in 2:
	1) Get list of modules to be loaded
	2) Iterate the list, loading the module

With this in future we will be able to cover use cases of modprobe,
that has a logic a bit more complicated.

With this we also change the logic to detect dependency loops: instead
of checking the recursion every STEP times, we now keep a field in
kmod_module, marking it as visited. We simply ignore already visited
modules and thus we break loops.
2012-01-30 20:05:33 -02:00
Lucas De Marchi 0224482e62 Add doc to kmod_dump_index 2012-01-16 16:44:25 -02:00
Lucas De Marchi 758428a75f libkmod: dump index files
Provide a function to dump the index files to a certain fd. It could be
more optimized (particularly the functions to dump the index that were
copied and pasted from m-i-t), but it seems like the only user of it is
'modprobe -c', used for debugging purposes. So, keep it as is.
2012-01-16 16:05:46 -02:00
Lucas De Marchi b08314f7b7 libkmod: export enum kmod_index and rename members 2012-01-16 16:05:36 -02:00
Lucas De Marchi 0017862911 config: add exported iterator functions
Config iterators are useful to get each configuration list, remember its
type and how to get their key/value pair.

softdeps don't have the value yet, because they are stored as string
vectors.
2012-01-13 11:12:41 -02:00
Lucas De Marchi 6a82921113 Match param names on header and source code
This is needed by gtk-doc (to be added later) to be able to properly
document the function.
2012-01-09 03:29:48 -02:00
Lucas De Marchi a66a6a999f Update copyright 2012-01-09 00:41:07 -02:00
Lucas De Marchi c4dc3ca8a2 Add call to check if resources are valid 2012-01-01 06:18:16 -02:00
Lucas De Marchi ddbda02286 Add implementation of modprobe's insertion
Treat module insertion as modprobe does: look for (soft-)dependencies, run
install commands, apply blacklist.

The difference with the blacklist is that it's applied to all modules,
including the dependencies. If you want to apply a blacklist only on the
module it's better to call the filter function by yourself.

This implementation detects loops caused by poorly written
soft-dependencies and fail gracefully, printing the loop to the log.
2011-12-27 11:55:22 -02:00
Gustavo Sverzut Barbieri 674f8590e3 elf: implement kmod_module_get_dependency_symbols()
Uses kmod_elf_get_dependency_symbols() that looks into ".symtab" for
UNDEF symbols and matches the name from ".strtab" to "__versions" to
get crc.

Likely the public API should unify the symbol information getters and
list release, they are almost the same.
2011-12-24 01:44:31 -02:00
Gustavo Sverzut Barbieri 45e6db9c01 elf: add get_symbols()
Similar to module-init-tools load_symbols(), it will try .symtab and
.strtab for symbols starting with __crc_, if they are found their crc
is read from ELF's Elf_Sym::st_value.

If not found, then it will fallback to __ksymtab_strings.
2011-12-24 01:44:31 -02:00
Lucas De Marchi f39dc70e4b Removing comments saying flags are not implemented
Both removal and insertion flags are already implemented.
2011-12-20 19:31:14 -02:00
Gustavo Sverzut Barbieri 708624a4eb ELF: initial support for modinfo and strip of modversions and vermagic.
Needs testing, but should work.
2011-12-19 15:06:49 -02:00
Gustavo Sverzut Barbieri d6b55b7d18 introduce kmod_list_foreach_reverse().
walks the list in the reverse order.
2011-12-17 20:03:43 -02:00
Gustavo Sverzut Barbieri d5ec60bc0c introduce kmod_list_last()
This gets the last element in the list, that is, the previous element
of the head.
2011-12-17 19:43:11 -02:00
Gustavo Sverzut Barbieri 1c52260048 implement softdeps. 2011-12-17 19:43:11 -02:00
Lucas De Marchi 5f3429cdad Add comment in public header about flags not implemented 2011-12-15 12:27:45 -02:00
Lucas De Marchi 3e71947c1e Remove flags that likely will not be used 2011-12-15 12:18:00 -02:00
Lucas De Marchi 25c0543ff6 Remove function kmod_resolve_alias_options()
Remove function kmod_resolve_alias_options since it's not needed
anymore. Test is using the following configuration file:

alias blablabla ac
options ac test=1
options blablabla test=2

Lookup test by module name:
	$ ./test/test-lookup ac
	libkmod version 1
	Alias: 'ac'
	Modules matching:
		ac
			options: 'test=1'

Lookup test by alias:
	$ ./test/test-lookup blablabla
	libkmod version 1
	Alias: 'blablabla'
	Modules matching:
		ac
			options: 'test=1 test=2'
2011-12-13 14:28:16 -02:00
Lucas De Marchi cb451f35d9 Change licenses
libkmod is under LGPL 2.1 or later
tools/* are under GPL
2011-12-12 18:24:35 -02:00
Lucas De Marchi a102e262e6 Rename kmod_loaded_get_list() to kmod_module_new_from_loaded()
Be consistent with other similar functions already present and improve
documentation.
2011-12-12 13:50:19 -02:00
Gustavo Sverzut Barbieri cb8d4d3e99 API-BREAK: kmod_new() takes a second parameter for configuration directory.
This is required by modprobe and also to help doing unit tests in future.
2011-12-11 20:58:22 -02:00
Gustavo Sverzut Barbieri 3a721bbcf0 insmod: allows providing option to module. 2011-12-11 20:58:22 -02:00
Gustavo Sverzut Barbieri bd3f553526 export module's options and commands.
This will be required to implement modprobe later. The implementation
follows "man modprobe.conf" and allows options to be specified for
alias as well, thus the need for kmod_resolve_alias_options().

Example mod-a.conf:

    options mod-a a=1 b=2
    options mod-a c=3
    alias mymod-a mod-a
    options mymod-a d=4

Results in:
    options mod-a a=1 b=2 c=3
    options mymod-a a=1 b=2 c=3 d=4

Install commands are being concatenated with ";", but manpage is not
clean about this behavior.
2011-12-11 20:58:21 -02:00
Lucas De Marchi 33bb69b943 Load and unload resources
This call will mmap all the index files and in future some of the work
done in ctx creation can be put here.
2011-12-08 19:51:06 -02:00
Gustavo Sverzut Barbieri 1bdd951ee2 log: give log function its data instead of kmod_ctx.
This will be the most common use case for logging, also changed
log_stderr() to log_filep() with data being stderr to test it.
2011-12-08 14:06:50 -02:00