From 13700a69d382d7b4482f63317b6eaf2e3214e012 Mon Sep 17 00:00:00 2001 From: Steve Muckle Date: Wed, 31 Jul 2019 09:59:48 -0700 Subject: [PATCH] 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 --- libmodprobe/include/modprobe/modprobe.h | 7 ++++--- libmodprobe/libmodprobe.cpp | 9 +++++---- libmodprobe/libmodprobe_ext.cpp | 5 ++++- libmodprobe/libmodprobe_ext_test.cpp | 6 +++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libmodprobe/include/modprobe/modprobe.h b/libmodprobe/include/modprobe/modprobe.h index 5003e6b00..05136bda4 100644 --- a/libmodprobe/include/modprobe/modprobe.h +++ b/libmodprobe/include/modprobe/modprobe.h @@ -25,13 +25,14 @@ class Modprobe { Modprobe(const std::vector&); 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 GetDependencies(const std::string& module); bool ModuleExists(const std::string& module_name); diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp index 4df458ffe..37ac32851 100644 --- a/libmodprobe/libmodprobe.cpp +++ b/libmodprobe/libmodprobe.cpp @@ -242,7 +242,7 @@ std::vector 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 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) { diff --git a/libmodprobe/libmodprobe_ext.cpp b/libmodprobe/libmodprobe_ext.cpp index 8cbd08c5a..52e308fab 100644 --- a/libmodprobe/libmodprobe_ext.cpp +++ b/libmodprobe/libmodprobe_ext.cpp @@ -22,7 +22,7 @@ #include -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); diff --git a/libmodprobe/libmodprobe_ext_test.cpp b/libmodprobe/libmodprobe_ext_test.cpp index ca1c081c8..204809fa5 100644 --- a/libmodprobe/libmodprobe_ext_test.cpp +++ b/libmodprobe/libmodprobe_ext_test.cpp @@ -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; }