libmodprobe: add verbose mode

Change-Id: I2be18320461cd712a4828400b8f29bb5f07c801f
This commit is contained in:
Steve Muckle 2019-08-01 16:03:02 -07:00
parent 781aa78ee2
commit ded44c06be
3 changed files with 19 additions and 1 deletions

View file

@ -34,6 +34,7 @@ class Modprobe {
std::vector<std::string>* dependencies,
std::vector<std::string>* post_dependencies);
void EnableBlacklist(bool enable);
void EnableVerbose(bool enable);
private:
std::string MakeCanonical(const std::string& module_path);

View file

@ -260,12 +260,22 @@ Modprobe::Modprobe(const std::vector<std::string>& base_paths) {
auto blacklist_callback = std::bind(&Modprobe::ParseBlacklistCallback, this, _1);
ParseCfg(base_path + "/modules.blacklist", blacklist_callback);
}
android::base::SetMinimumLogSeverity(android::base::INFO);
}
void Modprobe::EnableBlacklist(bool enable) {
blacklist_enabled = enable;
}
void Modprobe::EnableVerbose(bool enable) {
if (enable) {
android::base::SetMinimumLogSeverity(android::base::VERBOSE);
} else {
android::base::SetMinimumLogSeverity(android::base::INFO);
}
}
std::vector<std::string> Modprobe::GetDependencies(const std::string& module) {
auto it = module_deps_.find(module);
if (it == module_deps_.end()) {
@ -288,6 +298,7 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name, const std::string&
// load module dependencies in reverse order
for (auto dep = dependencies.rbegin(); dep != dependencies.rend() - 1; ++dep) {
LOG(VERBOSE) << "Loading hard dep for '" << module_name << "': " << *dep;
if (!LoadWithAliases(*dep, true)) {
return false;
}
@ -296,6 +307,7 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name, const std::string&
// try to load soft pre-dependencies
for (const auto& [module, softdep] : module_pre_softdep_) {
if (module_name == module) {
LOG(VERBOSE) << "Loading soft pre-dep for '" << module << "': " << softdep;
LoadWithAliases(softdep, false);
}
}
@ -308,6 +320,7 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name, const std::string&
// try to load soft post-dependencies
for (const auto& [module, softdep] : module_post_softdep_) {
if (module_name == module) {
LOG(VERBOSE) << "Loading soft post-dep for '" << module << "': " << softdep;
LoadWithAliases(softdep, false);
}
}
@ -324,6 +337,7 @@ bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict,
// may alias themselves to the requested name)
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;
modules_to_load.emplace(aliased_module);
}
@ -334,7 +348,7 @@ bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict,
}
if (strict && !module_loaded) {
LOG(ERROR) << "LoadWithAliases did not find a module for " << module_name;
LOG(ERROR) << "LoadWithAliases was unable to load " << module_name;
return false;
}
return true;

View file

@ -66,6 +66,7 @@ bool Modprobe::Rmmod(const std::string& module_name) {
bool Modprobe::ModuleExists(const std::string& module_name) {
struct stat fileStat;
if (blacklist_enabled && module_blacklist_.count(module_name)) {
LOG(INFO) << "module " << module_name << " is blacklisted";
return false;
}
auto deps = GetDependencies(module_name);
@ -74,9 +75,11 @@ bool Modprobe::ModuleExists(const std::string& module_name) {
return false;
}
if (stat(deps.front().c_str(), &fileStat)) {
LOG(INFO) << "module " << module_name << " does not exist";
return false;
}
if (!S_ISREG(fileStat.st_mode)) {
LOG(INFO) << "module " << module_name << " is not a regular file";
return false;
}
return true;