Loading libmodprobe/libmodprobe.cpp +15 −5 Original line number Diff line number Diff line Loading @@ -444,6 +444,7 @@ bool Modprobe::IsBlocklisted(const std::string& module_name) { // 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; // Get dependencies Loading Loading @@ -471,18 +472,21 @@ bool Modprobe::LoadModulesParallel(int num_threads) { } } 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::mutex vector_lock; count = module_loaded_.size(); // Find independent modules for (const auto& [it_mod, it_dep] : mod_with_deps) { if (it_dep.size() == 1) { if (module_options_[it_mod].find("load_sequential=1") != std::string::npos) { LoadWithAliases(it_mod, true); if (!LoadWithAliases(it_mod, true) && !IsBlocklisted(it_mod)) { return false; } } else { mods_path_to_load.emplace_back(*(it_dep.begin())); mods_path_to_load.emplace_back(it_mod); } } } Loading @@ -491,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; } } }; Loading @@ -508,6 +516,8 @@ bool Modprobe::LoadModulesParallel(int num_threads) { thread.join(); } 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_) { Loading Loading
libmodprobe/libmodprobe.cpp +15 −5 Original line number Diff line number Diff line Loading @@ -444,6 +444,7 @@ bool Modprobe::IsBlocklisted(const std::string& module_name) { // 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; // Get dependencies Loading Loading @@ -471,18 +472,21 @@ bool Modprobe::LoadModulesParallel(int num_threads) { } } 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::mutex vector_lock; count = module_loaded_.size(); // Find independent modules for (const auto& [it_mod, it_dep] : mod_with_deps) { if (it_dep.size() == 1) { if (module_options_[it_mod].find("load_sequential=1") != std::string::npos) { LoadWithAliases(it_mod, true); if (!LoadWithAliases(it_mod, true) && !IsBlocklisted(it_mod)) { return false; } } else { mods_path_to_load.emplace_back(*(it_dep.begin())); mods_path_to_load.emplace_back(it_mod); } } } Loading @@ -491,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; } } }; Loading @@ -508,6 +516,8 @@ bool Modprobe::LoadModulesParallel(int num_threads) { thread.join(); } 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_) { Loading