libmodprobe: support parameters in LoadWithAliases

Add support to specify module parameters in LoadWithAliases. These
parameters will be appended to any which are specified for the module in
modules.options.

Change-Id: I9aff1656ea397826f815b658b3b52c1892748601
This commit is contained in:
Steve Muckle 2019-07-31 09:59:48 -07:00
parent bb58b01574
commit 13700a69d3
4 changed files with 18 additions and 9 deletions

View file

@ -25,13 +25,14 @@ class Modprobe {
Modprobe(const std::vector<std::string>&);
bool LoadListedModules();
bool LoadWithAliases(const std::string& module_name, bool strict);
bool LoadWithAliases(const std::string& module_name, bool strict,
const std::string& parameters = "");
bool Remove(const std::string& module_name);
private:
std::string MakeCanonical(const std::string& module_path);
bool InsmodWithDeps(const std::string& module_name);
bool Insmod(const std::string& path_name);
bool InsmodWithDeps(const std::string& module_name, const std::string& parameters);
bool Insmod(const std::string& path_name, const std::string& parameters);
bool Rmmod(const std::string& module_name);
std::vector<std::string> GetDependencies(const std::string& module);
bool ModuleExists(const std::string& module_name);

View file

@ -242,7 +242,7 @@ std::vector<std::string> Modprobe::GetDependencies(const std::string& module) {
return it->second;
}
bool Modprobe::InsmodWithDeps(const std::string& module_name) {
bool Modprobe::InsmodWithDeps(const std::string& module_name, const std::string& parameters) {
if (module_name.empty()) {
LOG(ERROR) << "Need valid module name, given: " << module_name;
return false;
@ -269,7 +269,7 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name) {
}
// load target module itself with args
if (!Insmod(dependencies[0])) {
if (!Insmod(dependencies[0], parameters)) {
return false;
}
@ -283,7 +283,8 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name) {
return true;
}
bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict) {
bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict,
const std::string& parameters) {
std::set<std::string> modules_to_load = {MakeCanonical(module_name)};
bool module_loaded = false;
@ -297,7 +298,7 @@ bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict) {
// attempt to load all modules aliased to this name
for (const auto& module : modules_to_load) {
if (!ModuleExists(module)) continue;
if (InsmodWithDeps(module)) module_loaded = true;
if (InsmodWithDeps(module, parameters)) module_loaded = true;
}
if (strict && !module_loaded) {

View file

@ -22,7 +22,7 @@
#include <modprobe/modprobe.h>
bool Modprobe::Insmod(const std::string& path_name) {
bool Modprobe::Insmod(const std::string& path_name, const std::string& parameters) {
android::base::unique_fd fd(
TEMP_FAILURE_RETRY(open(path_name.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC)));
if (fd == -1) {
@ -35,6 +35,9 @@ bool Modprobe::Insmod(const std::string& path_name) {
if (options_iter != module_options_.end()) {
options = options_iter->second;
}
if (!parameters.empty()) {
options = options + " " + parameters;
}
LOG(INFO) << "Loading module " << path_name << " with args \"" << options << "\"";
int ret = syscall(__NR_finit_module, fd.get(), options.c_str(), 0);

View file

@ -29,7 +29,7 @@
#include "libmodprobe_test.h"
bool Modprobe::Insmod(const std::string& path_name) {
bool Modprobe::Insmod(const std::string& path_name, const std::string& parameters) {
auto deps = GetDependencies(MakeCanonical(path_name));
if (deps.empty()) {
return false;
@ -47,6 +47,10 @@ bool Modprobe::Insmod(const std::string& path_name) {
if (options_iter != module_options_.end()) {
options = " " + options_iter->second;
}
if (!parameters.empty()) {
options = options + " " + parameters;
}
modules_loaded.emplace_back(path_name + options);
return true;
}