• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/core


コミットメタ情報

リビジョン35a700179b56c2c110c4626e19536bcd3342589a (tree)
日時2019-12-17 14:24:56
作者Michael Goffioul <michael.goffioul@linc...>
コミッターChih-Wei Huang

ログメッセージ

ueventd: auto load modules on uevents

変更サマリ

差分

--- a/init/modalias_handler.cpp
+++ b/init/modalias_handler.cpp
@@ -18,6 +18,8 @@
1818
1919 #include <fnmatch.h>
2020 #include <sys/syscall.h>
21+#include <sys/utsname.h>
22+#include <unistd.h>
2123
2224 #include <algorithm>
2325 #include <functional>
@@ -33,6 +35,13 @@
3335 namespace android {
3436 namespace init {
3537
38+static const std::string base_paths[] = {
39+ "/system/lib/modules/",
40+ "/vendor/lib/modules/",
41+ "/lib/modules/",
42+ "/odm/lib/modules/",
43+};
44+
3645 Result<Success> ModaliasHandler::ParseDepCallback(std::vector<std::string>&& args) {
3746 std::vector<std::string> deps;
3847
@@ -83,26 +92,60 @@ Result<Success> ModaliasHandler::ParseAliasCallback(std::vector<std::string>&& a
8392 ModaliasHandler::ModaliasHandler() {
8493 using namespace std::placeholders;
8594
86- static const std::string base_paths[] = {
87- "/vendor/lib/modules/",
88- "/lib/modules/",
89- "/odm/lib/modules/",
90- };
95+ struct utsname uts;
96+ uname(&uts);
97+ release_ = uts.release;
9198
9299 Parser alias_parser;
93100 auto alias_callback = std::bind(&ModaliasHandler::ParseAliasCallback, this, _1);
94101 alias_parser.AddSingleLineParser("alias", alias_callback);
95- for (const auto& base_path : base_paths) alias_parser.ParseConfig(base_path + "modules.alias");
102+ for (const auto& base_path : base_paths) {
103+ alias_parser.ParseConfig(base_path + release_ + "/modules.alias");
104+ alias_parser.ParseConfig(base_path + "modules.alias");
105+ }
96106
97107 Parser dep_parser;
98108 auto dep_callback = std::bind(&ModaliasHandler::ParseDepCallback, this, _1);
99109 dep_parser.AddSingleLineParser("", dep_callback);
100- for (const auto& base_path : base_paths) dep_parser.ParseConfig(base_path + "modules.dep");
110+ for (const auto& base_path : base_paths) {
111+ dep_parser.ParseConfig(base_path + release_ + "/modules.dep");
112+ dep_parser.ParseConfig(base_path + "modules.dep");
113+ }
114+
115+ auto blacklist_callback = [] (auto args, std::set<std::string>* v_) -> Result<Success> {
116+ if (args.size() < 2) {
117+ return Error() << "blacklist/deferred lines must have 2 entries";
118+ }
119+
120+ v_->emplace(args[1]);
121+ return Success();
122+ };
123+ Parser blacklist_parser;
124+ blacklist_parser.AddSingleLineParser("blacklist", std::bind(blacklist_callback, _1, &this->modules_to_blacklist_));
125+ blacklist_parser.AddSingleLineParser("deferred", std::bind(blacklist_callback, _1, &this->modules_to_defer_));
126+ blacklist_parser.ParseConfig("/system/etc/modules.blacklist");
127+}
128+
129+std::string ModaliasHandler::GetModulePath(const std::string& path_name) {
130+ if (path_name[0] != '/') {
131+ std::string module_path_name;
132+ for (const auto& base_path : base_paths) {
133+ module_path_name = base_path + release_ + "/" + path_name;
134+ if (access(module_path_name.c_str(), F_OK) == 0) {
135+ return module_path_name;
136+ }
137+ module_path_name = base_path + path_name;
138+ if (access(module_path_name.c_str(), F_OK) == 0) {
139+ return module_path_name;
140+ }
141+ }
142+ }
143+ return path_name;
101144 }
102145
103146 Result<Success> ModaliasHandler::Insmod(const std::string& path_name, const std::string& args) {
104147 base::unique_fd fd(
105- TEMP_FAILURE_RETRY(open(path_name.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC)));
148+ TEMP_FAILURE_RETRY(open(GetModulePath(path_name).c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC)));
106149 if (fd == -1) return ErrnoError() << "Could not open module '" << path_name << "'";
107150
108151 int ret = syscall(__NR_finit_module, fd.get(), args.c_str(), 0);
@@ -145,6 +188,17 @@ void ModaliasHandler::HandleUevent(const Uevent& uevent) {
145188 for (const auto& [alias, module] : module_aliases_) {
146189 if (fnmatch(alias.c_str(), uevent.modalias.c_str(), 0) != 0) continue; // Keep looking
147190
191+ if (modules_to_blacklist_.find(module) != modules_to_blacklist_.end()) {
192+ // skip blacklisted module
193+ continue;
194+ }
195+
196+ if (modules_to_defer_.find(module) != modules_to_defer_.end()) {
197+ // defer module load until cold boot phase is done
198+ deferred_modules_.emplace(module);
199+ continue;
200+ }
201+
148202 LOG(DEBUG) << "Loading kernel module '" << module << "' for alias '" << uevent.modalias
149203 << "'";
150204
@@ -155,9 +209,19 @@ void ModaliasHandler::HandleUevent(const Uevent& uevent) {
155209 }
156210
157211 // loading was successful
158- return;
159212 }
160213 }
161214
215+void ModaliasHandler::ColdbootDone() {
216+ for (const auto& module : deferred_modules_) {
217+ LOG(INFO) << "Loading kernel module '" << module << "' [deferred]";
218+ if (auto result = InsmodWithDeps(module, ""); !result) {
219+ LOG(ERROR) << "Cannot load module: " << result.error();
220+ }
221+ }
222+ modules_to_defer_.clear();
223+ deferred_modules_.clear();
224+}
225+
162226 } // namespace init
163227 } // namespace android
--- a/init/modalias_handler.h
+++ b/init/modalias_handler.h
@@ -16,6 +16,7 @@
1616
1717 #pragma once
1818
19+#include <set>
1920 #include <string>
2021 #include <unordered_map>
2122 #include <vector>
@@ -33,6 +34,7 @@ class ModaliasHandler : public UeventHandler {
3334 virtual ~ModaliasHandler() = default;
3435
3536 void HandleUevent(const Uevent& uevent) override;
37+ void ColdbootDone() override;
3638
3739 private:
3840 Result<Success> InsmodWithDeps(const std::string& module_name, const std::string& args);
@@ -41,8 +43,15 @@ class ModaliasHandler : public UeventHandler {
4143 Result<Success> ParseDepCallback(std::vector<std::string>&& args);
4244 Result<Success> ParseAliasCallback(std::vector<std::string>&& args);
4345
46+ std::string GetModulePath(const std::string& path_name);
47+
4448 std::vector<std::pair<std::string, std::string>> module_aliases_;
4549 std::unordered_map<std::string, std::vector<std::string>> module_deps_;
50+ std::set<std::string> modules_to_defer_;
51+ std::set<std::string> modules_to_blacklist_;
52+ std::set<std::string> deferred_modules_;
53+
54+ std::string release_;
4655 };
4756
4857 } // namespace init
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -1,4 +1,5 @@
11 firmware_directories /system/lib/firmware
2+modalias_handling enabled
23 uevent_socket_rcvbuf_size 16M
34
45 subsystem graphics