diff options
author | alk3pInjection <webmaster@raspii.tech> | 2022-10-30 13:40:08 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2022-10-30 13:40:08 +0800 |
commit | f0103ea35d56ccebbae16a43cac19ac38b11a9a2 (patch) | |
tree | ea6bc2da8206628d3480e372b4b31c9149cb62dc | |
parent | 491533ef38e2495a74ba5af7ddd6a8df1644514a (diff) | |
parent | 903f0313b7844379e8d5a024971c30f4d1308e9a (diff) |
Merge tag 'LA.QSSI.13.0.r1-07200.02-qssi.0' into tachibana
"LA.QSSI.13.0.r1-07200.02-qssi.0"
Change-Id: I0491e905744539a17349b1ce931736461f5290cc
-rw-r--r-- | libmodprobe/libmodprobe.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp index 3054d2b43..e071c96d9 100644 --- a/libmodprobe/libmodprobe.cpp +++ b/libmodprobe/libmodprobe.cpp @@ -440,12 +440,12 @@ bool Modprobe::IsBlocklisted(const std::string& module_name) { } // Another option to load kernel modules. load in independent modules in parallel -// and then load modules which only have soft dependency, third update dependency list of other -// remaining modules, repeat these steps until all modules are loaded. +// and then update dependency list of other remaining modules, repeat these steps +// until all modules are loaded. bool Modprobe::LoadModulesParallel(int num_threads) { bool ret = true; + int count = -1; std::map<std::string, std::set<std::string>> mod_with_deps; - std::map<std::string, std::set<std::string>> mod_with_softdeps; // Get dependencies for (const auto& module : module_load_) { @@ -458,26 +458,36 @@ bool Modprobe::LoadModulesParallel(int num_threads) { // Get soft dependencies for (const auto& [it_mod, it_softdep] : module_pre_softdep_) { - mod_with_softdeps[MakeCanonical(it_mod)].emplace(it_softdep); + if (mod_with_deps.find(MakeCanonical(it_softdep)) != mod_with_deps.end()) { + mod_with_deps[MakeCanonical(it_mod)].emplace( + GetDependencies(MakeCanonical(it_softdep))[0]); + } } // Get soft post dependencies for (const auto& [it_mod, it_softdep] : module_post_softdep_) { - mod_with_softdeps[MakeCanonical(it_mod)].emplace(it_softdep); + if (mod_with_deps.find(MakeCanonical(it_softdep)) != mod_with_deps.end()) { + mod_with_deps[MakeCanonical(it_softdep)].emplace( + GetDependencies(MakeCanonical(it_mod))[0]); + } } - while (!mod_with_deps.empty()) { + while (!mod_with_deps.empty() && count != module_loaded_.size()) { std::vector<std::thread> threads; std::vector<std::string> mods_path_to_load; - std::vector<std::string> mods_with_softdep_to_load; std::mutex vector_lock; + count = module_loaded_.size(); - // Find independent modules and modules only having soft dependencies + // Find independent modules for (const auto& [it_mod, it_dep] : mod_with_deps) { - if (it_dep.size() == 1 && mod_with_softdeps[it_mod].empty()) { - mods_path_to_load.emplace_back(*(it_dep.begin())); - } else if (it_dep.size() == 1) { - mods_with_softdep_to_load.emplace_back(it_mod); + if (it_dep.size() == 1) { + if (module_options_[it_mod].find("load_sequential=1") != std::string::npos) { + if (!LoadWithAliases(it_mod, true) && !IsBlocklisted(it_mod)) { + return false; + } + } else { + mods_path_to_load.emplace_back(it_mod); + } } } @@ -485,12 +495,16 @@ bool Modprobe::LoadModulesParallel(int num_threads) { auto thread_function = [&] { std::unique_lock lk(vector_lock); while (!mods_path_to_load.empty()) { - auto mod_path_to_load = std::move(mods_path_to_load.back()); + auto ret_load = true; + auto mod_to_load = std::move(mods_path_to_load.back()); mods_path_to_load.pop_back(); lk.unlock(); - ret &= Insmod(mod_path_to_load, ""); + ret_load &= LoadWithAliases(mod_to_load, true); lk.lock(); + if (!ret_load && !IsBlocklisted(mod_to_load)) { + ret &= ret_load; + } } }; @@ -502,21 +516,12 @@ bool Modprobe::LoadModulesParallel(int num_threads) { thread.join(); } - // Since we cannot assure if these soft dependencies tree are overlap, - // we loaded these modules one by one. - for (auto dep = mods_with_softdep_to_load.rbegin(); dep != mods_with_softdep_to_load.rend(); - dep++) { - ret &= LoadWithAliases(*dep, true); - } + if (!ret) return ret; std::lock_guard guard(module_loaded_lock_); // Remove loaded module form mod_with_deps and soft dependencies of other modules for (const auto& module_loaded : module_loaded_) { mod_with_deps.erase(module_loaded); - - for (auto& [mod, softdeps] : mod_with_softdeps) { - softdeps.erase(module_loaded); - } } // Remove loaded module form dependencies of other modules which are not loaded yet |