udev-builtin-kmod: use the generic module_load() function

There should be no functional change.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-07-19 18:28:21 +02:00
parent 3cb9b42af3
commit c3ad978633
4 changed files with 20 additions and 42 deletions
+16 -8
View File
@@ -4,20 +4,25 @@
#include "module-util.h"
int module_load_and_warn(struct kmod_ctx *ctx, const char *module) {
int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose) {
const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
struct kmod_list *itr;
_cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL;
int r = 0;
/* verbose==true means we should log at non-debug level if we
* fail to find or load the module. */
log_debug("Loading module: %s", module);
r = kmod_module_new_from_lookup(ctx, module, &modlist);
if (r < 0)
return log_error_errno(r, "Failed to lookup module alias '%s': %m", module);
return log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
"Failed to lookup module alias '%s': %m", module);
if (!modlist) {
log_error("Failed to find module '%s'", module);
log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
"Failed to find module '%s'", module);
return -ENOENT;
}
@@ -30,7 +35,8 @@ int module_load_and_warn(struct kmod_ctx *ctx, const char *module) {
switch (state) {
case KMOD_MODULE_BUILTIN:
log_info("Module '%s' is builtin", kmod_module_get_name(mod));
log_full(verbose ? LOG_INFO : LOG_DEBUG,
"Module '%s' is builtin", kmod_module_get_name(mod));
break;
case KMOD_MODULE_LIVE:
@@ -40,15 +46,17 @@ int module_load_and_warn(struct kmod_ctx *ctx, const char *module) {
default:
err = kmod_module_probe_insert_module(mod, probe_flags,
NULL, NULL, NULL, NULL);
if (err == 0)
log_info("Inserted module '%s'", kmod_module_get_name(mod));
log_full(verbose ? LOG_INFO : LOG_DEBUG,
"Inserted module '%s'", kmod_module_get_name(mod));
else if (err == KMOD_PROBE_APPLY_BLACKLIST)
log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
log_full(verbose ? LOG_INFO : LOG_DEBUG,
"Module '%s' is blacklisted", kmod_module_get_name(mod));
else {
assert(err < 0);
log_full_errno(err == ENODEV ? LOG_NOTICE :
log_full_errno(!verbose ? LOG_DEBUG :
err == ENODEV ? LOG_NOTICE :
err == ENOENT ? LOG_WARNING :
LOG_ERR,
err,
+1 -1
View File
@@ -9,4 +9,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_ctx*, kmod_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_module*, kmod_module_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_list*, kmod_module_unref_list);
int module_load_and_warn(struct kmod_ctx *ctx, const char *module);
int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose);