fix: improve detect kenrel overlay support#1700
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the overlayfs detection logic in OverlayFSDriver by introducing helper functions, adding support for FUSE overlay, and implementing a mode resolution mechanism, along with corresponding unit tests. The review feedback highlights two important improvements: first, avoiding hardcoded paths when searching for the overlay module in dependency files to ensure compatibility across different systems; second, replacing the file I/O and regex parsing of /proc/version with a safer, non-throwing uname and std::sscanf approach to prevent potential crashes in the noexcept function.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| for (const auto &index : { "modules.dep", "modules.builtin" }) { | ||
| std::ifstream modulesIndex(modulesRoot / index); | ||
| if (!modulesIndex.is_open()) { | ||
| continue; | ||
| } | ||
|
|
||
| std::string line; | ||
| while (std::getline(modulesIndex, line)) { | ||
| if (line.find("kernel/fs/overlayfs/overlay.ko") != std::string::npos) { | ||
| return true; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Hardcoding the exact path kernel/fs/overlayfs/overlay.ko when searching in modules.dep or modules.builtin can fail on systems where the overlay module is located in a different directory (e.g., kernel/fs/overlay/overlay.ko, or under updates/ or extra/ when installed via DKMS or backports). Searching for /overlay.ko is much more robust and avoids these issues while still uniquely identifying the overlay module.
| for (const auto &index : { "modules.dep", "modules.builtin" }) { | |
| std::ifstream modulesIndex(modulesRoot / index); | |
| if (!modulesIndex.is_open()) { | |
| continue; | |
| } | |
| std::string line; | |
| while (std::getline(modulesIndex, line)) { | |
| if (line.find("kernel/fs/overlayfs/overlay.ko") != std::string::npos) { | |
| return true; | |
| } | |
| } | |
| } | |
| for (const auto &index : { "modules.dep", "modules.builtin" }) { | |
| std::ifstream modulesIndex(modulesRoot / index); | |
| if (!modulesIndex.is_open()) { | |
| continue; | |
| } | |
| std::string line; | |
| while (std::getline(modulesIndex, line)) { | |
| if (line.find("/overlay.ko") != std::string::npos) { | |
| return true; | |
| } | |
| } | |
| } |
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Detect kenrel overlay support by /proc/filesystems, modinfo and scan module file. Signed-off-by: reddevillg <reddevillg@gmail.com>
deepin pr auto review★ 总体评分:40分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 namespace {
constexpr std::string_view kModinfoPath = "/usr/sbin/modinfo";
constexpr std::string_view kFuseOverlayfsPath = "/usr/bin/fuse-overlayfs";
auto modinfoHasOverlay() noexcept -> bool
{
std::error_code ec;
// 使用绝对路径直接判断文件是否存在,避免 PATH 劫持和 fork/exec 开销
if (!std::filesystem::exists(kModinfoPath, ec) || ec) {
return false;
}
// 若必须执行以获取详细信息,应使用绝对路径初始化 Cmd
auto modinfo = utils::Cmd(std::string(kModinfoPath));
return modinfo.exec({ "overlay" }).has_value();
}
auto canUseFUSEOverlayImpl() noexcept -> bool
{
std::error_code ec;
// 使用绝对路径进行存在性校验
return std::filesystem::exists(kFuseOverlayfsPath, ec) && !ec;
}
} // namespace
auto OverlayFSDriver::canUseFUSEOverlay() noexcept -> bool
{
return canUseFUSEOverlayImpl();
} |
|
@reddevillg: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengbo11, reddevillg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Detect kenrel overlay support by /proc/filesystems, modinfo and scan module file.