LCOV - code coverage report
Current view: top level - shared - module-util.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 0 33 0.0 %
Date: 2019-08-22 15:41:25 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <errno.h>
       4             : 
       5             : #include "module-util.h"
       6             : 
       7           0 : int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose) {
       8           0 :         const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
       9             :         struct kmod_list *itr;
      10           0 :         _cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL;
      11           0 :         int r = 0;
      12             : 
      13             :         /* verbose==true means we should log at non-debug level if we
      14             :          * fail to find or load the module. */
      15             : 
      16           0 :         log_debug("Loading module: %s", module);
      17             : 
      18           0 :         r = kmod_module_new_from_lookup(ctx, module, &modlist);
      19           0 :         if (r < 0)
      20           0 :                 return log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
      21             :                                       "Failed to lookup module alias '%s': %m", module);
      22             : 
      23           0 :         if (!modlist) {
      24           0 :                 log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
      25             :                                "Failed to find module '%s'", module);
      26           0 :                 return -ENOENT;
      27             :         }
      28             : 
      29           0 :         kmod_list_foreach(itr, modlist) {
      30           0 :                 _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
      31             :                 int state, err;
      32             : 
      33           0 :                 mod = kmod_module_get_module(itr);
      34           0 :                 state = kmod_module_get_initstate(mod);
      35             : 
      36           0 :                 switch (state) {
      37           0 :                 case KMOD_MODULE_BUILTIN:
      38           0 :                         log_full(verbose ? LOG_INFO : LOG_DEBUG,
      39             :                                  "Module '%s' is builtin", kmod_module_get_name(mod));
      40           0 :                         break;
      41             : 
      42           0 :                 case KMOD_MODULE_LIVE:
      43           0 :                         log_debug("Module '%s' is already loaded", kmod_module_get_name(mod));
      44           0 :                         break;
      45             : 
      46           0 :                 default:
      47           0 :                         err = kmod_module_probe_insert_module(mod, probe_flags,
      48             :                                                               NULL, NULL, NULL, NULL);
      49           0 :                         if (err == 0)
      50           0 :                                 log_full(verbose ? LOG_INFO : LOG_DEBUG,
      51             :                                          "Inserted module '%s'", kmod_module_get_name(mod));
      52           0 :                         else if (err == KMOD_PROBE_APPLY_BLACKLIST)
      53           0 :                                 log_full(verbose ? LOG_INFO : LOG_DEBUG,
      54             :                                          "Module '%s' is blacklisted", kmod_module_get_name(mod));
      55             :                         else {
      56           0 :                                 assert(err < 0);
      57             : 
      58           0 :                                 log_full_errno(!verbose ? LOG_DEBUG :
      59             :                                                err == -ENODEV ? LOG_NOTICE :
      60             :                                                err == -ENOENT ? LOG_WARNING :
      61             :                                                                 LOG_ERR,
      62             :                                                err,
      63             :                                                "Failed to insert module '%s': %m",
      64             :                                                kmod_module_get_name(mod));
      65           0 :                                 if (!IN_SET(err, -ENODEV, -ENOENT))
      66           0 :                                         r = err;
      67             :                         }
      68             :                 }
      69             :         }
      70             : 
      71           0 :         return r;
      72             : }

Generated by: LCOV version 1.14