Skip to content

Revert "fix: fix rootfs propagation"#1639

Merged
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
dengbo11:revert-code
Apr 20, 2026
Merged

Revert "fix: fix rootfs propagation"#1639
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
dengbo11:revert-code

Conversation

@dengbo11

Copy link
Copy Markdown
Collaborator

This reverts commit 65b19c1.

@dengbo11 dengbo11 requested a review from reddevillg April 20, 2026 07:25
@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

deepin pr auto review

这段代码修改主要是在 OCI (Open Container Initiative) 容器配置的构建过程中,为 Linux 特定的配置添加了 rootfsPropagation 属性。以下是对这段代码的详细审查和改进建议:

1. 代码审查

修改内容分析:

auto linux_ = ocppi::runtime::config::types::Linux{};
+   linux_.rootfsPropagation = RootfsPropagation::Slave;

这行代码将容器的根文件系统传播类型设置为 Slave

2. 逻辑与功能分析

  • 功能目的rootfsPropagation 控制挂载事件的传播方向。设置为 Slave 意味着:
    • 主机(父挂载命名空间)中的挂载事件会传播到容器(子挂载命名空间)中。
    • 容器中的挂载事件不会传播回主机。
  • 适用场景:这是一个非常安全的默认设置。它防止了容器内部对挂载点的修改意外影响到宿主机,同时允许容器感知到宿主机的挂载变化(例如,如果宿主机动态挂载了设备到容器内)。

3. 改进意见

A. 代码质量与可维护性

建议:使用常量或配置项
目前 "linglong"RootfsPropagation::Slave 都是硬编码的。如果未来需要根据不同的场景调整配置,修改源代码会比较麻烦。

改进示例:

// 建议在类定义或配置文件中定义默认值
static constexpr const char* DEFAULT_HOSTNAME = "linglong";
static constexpr auto DEFAULT_ROOTFS_PROPAGATION = RootfsPropagation::Slave;

// 在函数中使用
config.hostname = DEFAULT_HOSTNAME;
auto linux_ = ocppi::runtime::config::types::Linux{};
linux_.rootfsPropagation = DEFAULT_ROOTFS_PROPAGATION;

B. 代码安全

评价:安全

  • 使用 Slave 而不是 Shared 是正确的安全实践。Shared 允许双向传播,存在容器污染宿主机挂载命名空间的风险。
  • 这符合容器隔离的最佳实践。

C. 代码性能

评价:无影响

  • 这是一个简单的枚举赋值操作,对性能几乎没有影响。

4. 潜在风险与注意事项

  1. 挂载传播的依赖性:要使 Slave 传播生效,宿主机上对应的挂载点本身必须被标记为 Shared。如果宿主机的挂载点是 Private,那么设置为 Slave 可能不会产生预期的效果(容器可能无法感知宿主机的挂载变化,或者行为取决于具体运行时的实现)。建议在文档或注释中说明这一前提条件。

  2. 特定场景需求:某些极度依赖隔离性的场景可能更倾向于使用 Private(完全隔离)。如果 linglong 框架允许用户自定义 OCI 配置,应确保用户有权覆盖此默认值。

5. 综合建议

在代码中添加注释,解释为什么选择 Slave 以及其工作原理,这有助于后续维护。

最终建议代码:

    config.hostname = "linglong";

    auto linux_ = ocppi::runtime::config::types::Linux{};
    
    // 设置为 Slave 以允许宿主机的挂载事件传播到容器,
    // 但阻止容器内的挂载事件传播回宿主机,增强安全性。
    // 注意:这要求宿主机上的挂载源必须是 Shared 的。
    linux_.rootfsPropagation = RootfsPropagation::Slave;
    
    linux_.namespaces = std::vector<NamespaceReference>{
        NamespaceReference{ .type = NamespaceType::Pid },
        NamespaceReference{ .type = NamespaceType::Mount },

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the container configuration builder to set the root filesystem propagation to Slave. I have no feedback to provide.

@codecov

codecov Bot commented Apr 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...glong/oci-cfg-generators/container_cfg_builder.cpp 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
...glong/oci-cfg-generators/container_cfg_builder.cpp 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dengbo11 dengbo11 merged commit 3644cbb into OpenAtom-Linyaps:master Apr 20, 2026
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants