Merge "libmodprobe: Do not reload modules previously instantiated"
This commit is contained in:
commit
33eecb8f82
3 changed files with 16 additions and 3 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
class Modprobe {
|
||||
|
@ -59,5 +60,6 @@ class Modprobe {
|
|||
std::vector<std::string> module_load_;
|
||||
std::unordered_map<std::string, std::string> module_options_;
|
||||
std::set<std::string> module_blacklist_;
|
||||
std::unordered_set<std::string> module_loaded_;
|
||||
bool blacklist_enabled = false;
|
||||
};
|
||||
|
|
|
@ -330,7 +330,12 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name, const std::string&
|
|||
|
||||
bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict,
|
||||
const std::string& parameters) {
|
||||
std::set<std::string> modules_to_load = {MakeCanonical(module_name)};
|
||||
auto canonical_name = MakeCanonical(module_name);
|
||||
if (module_loaded_.count(canonical_name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::set<std::string> modules_to_load = {canonical_name};
|
||||
bool module_loaded = false;
|
||||
|
||||
// use aliases to expand list of modules to load (multiple modules
|
||||
|
@ -338,6 +343,7 @@ bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict,
|
|||
for (const auto& [alias, aliased_module] : module_aliases_) {
|
||||
if (fnmatch(alias.c_str(), module_name.c_str(), 0) != 0) continue;
|
||||
LOG(VERBOSE) << "Found alias for '" << module_name << "': '" << aliased_module;
|
||||
if (module_loaded_.count(MakeCanonical(aliased_module))) continue;
|
||||
modules_to_load.emplace(aliased_module);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,9 @@ bool Modprobe::Insmod(const std::string& path_name, const std::string& parameter
|
|||
return false;
|
||||
}
|
||||
|
||||
auto canonical_name = MakeCanonical(path_name);
|
||||
std::string options = "";
|
||||
auto options_iter = module_options_.find(MakeCanonical(path_name));
|
||||
auto options_iter = module_options_.find(canonical_name);
|
||||
if (options_iter != module_options_.end()) {
|
||||
options = options_iter->second;
|
||||
}
|
||||
|
@ -44,6 +45,7 @@ bool Modprobe::Insmod(const std::string& path_name, const std::string& parameter
|
|||
if (ret != 0) {
|
||||
if (errno == EEXIST) {
|
||||
// Module already loaded
|
||||
module_loaded_.emplace(canonical_name);
|
||||
return true;
|
||||
}
|
||||
LOG(ERROR) << "Failed to insmod '" << path_name << "' with args '" << options << "'";
|
||||
|
@ -51,15 +53,18 @@ bool Modprobe::Insmod(const std::string& path_name, const std::string& parameter
|
|||
}
|
||||
|
||||
LOG(INFO) << "Loaded kernel module " << path_name;
|
||||
module_loaded_.emplace(canonical_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Modprobe::Rmmod(const std::string& module_name) {
|
||||
int ret = syscall(__NR_delete_module, MakeCanonical(module_name).c_str(), O_NONBLOCK);
|
||||
auto canonical_name = MakeCanonical(module_name);
|
||||
int ret = syscall(__NR_delete_module, canonical_name.c_str(), O_NONBLOCK);
|
||||
if (ret != 0) {
|
||||
PLOG(ERROR) << "Failed to remove module '" << module_name << "'";
|
||||
return false;
|
||||
}
|
||||
module_loaded_.erase(canonical_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue