Commit Graph

65 Commits

Author SHA1 Message Date
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
Gustavo Sverzut Barbieri 1487a64ffa add kmod_module_get_filtered_blacklist()
This function will filter the given list against the known blacklist,
returning a new list with remaining modules with the reference
incremented.
2011-12-08 11:17:16 -02:00
Lucas De Marchi f1cd799fb0 kmod_module: return a new list and increase ref of dependencies
kmod_module_get_dependency is renamed to kmod_module_get_dependencies
since it's returning a list. To match other APIs, now it returns a new
list that user must free with kmod_module_unref_list().
2011-12-06 02:48:03 -02:00
Lucas De Marchi 49b741d0b0 Add padding to enum to make sure it's an int 2011-12-05 11:42:12 -02:00
Gustavo Sverzut Barbieri 69f9dd4369 no more kmod_loaded and kmod_loaded_module.
kmod_loaded_get_list() now returns a regular list of kmod_modules, use
kmod_module_get_module(), kmod_module_unref() and
kmod_module_unref_list() to operate on it.
2011-12-04 17:24:08 -02:00
Gustavo Sverzut Barbieri f12ae3c438 kmod_module: extended information gathering.
provide means to get:
 * refcount
 * initstate
 * holders
 * sections

this can be used to individually query properties from modules,
similar to /proc/modules (kmod_loaded / kmod_loaded_module).
2011-12-04 17:24:08 -02:00
Gustavo Sverzut Barbieri ad4d1ae565 kmod_module_get_module: safety against NULL pointers 2011-12-04 17:24:08 -02:00
Gustavo Sverzut Barbieri 1ce08a563e improve "const" keyword usage.
functions that do not modify their parameters get them as const pointers.

special cases:
 * kmod_get_userdata/kmod_set_userdata: return as void* for user convenience.
 * kmod_list_append/kmod_list_prepend: take const void* for user convenience.
2011-12-03 03:51:55 -02:00
Lucas De Marchi 0835fc3bf9 Add fucntion to API to get dependencies 2011-12-01 20:06:08 -02:00
Lucas De Marchi 79d77111dc Add kmod_list_prev to exported functions 2011-12-01 14:47:44 -02:00
Lucas De Marchi 7f3eb0cced Add lookup to create modules list from alias
We return a kmod_list when searching for an alias. Right now, it only
search for aliases in config files.

To use it, we create a list:
	list = NULL;
	kmod_module_new_from_lookup(..., &list);

And iterate over it to get the modules and their details:

	kmod_list_foreach(l, list) {
		struct kmod_mod *mod = kmod_module_get_module(l);
		...
		... kmod_module_get_name(mod);
		... kmod_module_get_path(mod);
	}

Aliases might contain globs and are match by using fnmatch().
2011-11-30 19:03:41 -02:00