1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "module-util.h"
7 int module_load_and_warn(struct kmod_ctx
*ctx
, const char *module
, bool verbose
) {
8 const int probe_flags
= KMOD_PROBE_APPLY_BLACKLIST
;
10 _cleanup_(kmod_module_unref_listp
) struct kmod_list
*modlist
= NULL
;
13 /* verbose==true means we should log at non-debug level if we
14 * fail to find or load the module. */
16 log_debug("Loading module: %s", module
);
18 r
= kmod_module_new_from_lookup(ctx
, module
, &modlist
);
20 return log_full_errno(verbose
? LOG_ERR
: LOG_DEBUG
, r
,
21 "Failed to lookup module alias '%s': %m", module
);
24 log_full_errno(verbose
? LOG_ERR
: LOG_DEBUG
, r
,
25 "Failed to find module '%s'", module
);
29 kmod_list_foreach(itr
, modlist
) {
30 _cleanup_(kmod_module_unrefp
) struct kmod_module
*mod
= NULL
;
33 mod
= kmod_module_get_module(itr
);
34 state
= kmod_module_get_initstate(mod
);
37 case KMOD_MODULE_BUILTIN
:
38 log_full(verbose
? LOG_INFO
: LOG_DEBUG
,
39 "Module '%s' is builtin", kmod_module_get_name(mod
));
42 case KMOD_MODULE_LIVE
:
43 log_debug("Module '%s' is already loaded", kmod_module_get_name(mod
));
47 err
= kmod_module_probe_insert_module(mod
, probe_flags
,
48 NULL
, NULL
, NULL
, NULL
);
50 log_full(verbose
? LOG_INFO
: LOG_DEBUG
,
51 "Inserted module '%s'", kmod_module_get_name(mod
));
52 else if (err
== KMOD_PROBE_APPLY_BLACKLIST
)
53 log_full(verbose
? LOG_INFO
: LOG_DEBUG
,
54 "Module '%s' is blacklisted", kmod_module_get_name(mod
));
58 log_full_errno(!verbose
? LOG_DEBUG
:
59 err
== -ENODEV
? LOG_NOTICE
:
60 err
== -ENOENT
? LOG_WARNING
:
63 "Failed to insert module '%s': %m",
64 kmod_module_get_name(mod
));
65 if (!IN_SET(err
, -ENODEV
, -ENOENT
))