Skip to content

refactor(libcgroups): Extract systemd CgroupsPath into its own module - #3935

Merged
saku3 merged 6 commits into
youki-dev:mainfrom
logica0419:refactor-cgroups-path
Nov 24, 2026
Merged

saku3 merged 6 commits into
youki-dev:mainfrom
logica0419:refactor-cgroups-path

Conversation

@logica0419

Copy link
Copy Markdown
Contributor

Description

Moved CgroupsPath out of systemd::manager into systemd::cgroups_path so it can be reused without the D-Bus manager.
Also replaced the in-place name mutation with side-effect-free accessors.

Stacked lower PR for #3564.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test updates
  • CI/CD related changes
  • Other (please describe):

Testing

  • Added new unit tests
  • Added new integration tests
  • Ran existing test suite
  • Tested manually (please provide steps)

Related Issues

Refs #3564

Additional Context

#3564 depends on this PR.

Replace Path::len() (via NixPath) with as_os_str().is_empty() for the
empty-path check.

Signed-off-by: Takuto Nagami <logica0419@gmail.com>
Signed-off-by: Takuto Nagami <logica0419@gmail.com>
Move the CgroupsPath parsing type out of systemd::manager into its
own module so it can be reused without pulling in the D-Bus manager.
No behavior change; register the module in systemd/mod.rs and the
no-systemd stub.

Signed-off-by: Takuto Nagami <logica0419@gmail.com>
Replace the in-place name mutation in Manager::new with
CgroupsPath::sub_cgroup()/unit_name() backed by a free
split_sub_cgroup() function, and simplify construct_cgroups_path()
to read from CgroupsPath instead of taking a separate sub_cgroup
argument. Move the corresponding tests to cgroups_path.

Signed-off-by: Takuto Nagami <logica0419@gmail.com>
@logica0419 logica0419 changed the title refactor(libcgroups): extract systemd CgroupsPath into its own module refactor(libcgroups): Extract systemd CgroupsPath into its own module Nov 24, 2026
@saku3 saku3 added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Nov 24, 2026
@saku3

saku3 commented Nov 24, 2026

Copy link
Copy Markdown
Member

@logica0419
Thanks for the refactoring!

The Basic Checks workflow is currently failing due to formatting issues in cgroups_path.rs. Could you run cargo fmt --all and just lint?

Copilot AI 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.

🟡 Changes recommended

The refactor breaks the public libcgroups::systemd::manager::CgroupsPathError import path, which must be preserved with a public re-export for downstream compatibility.

1 open issue
What changed in this PR

Extracts systemd cgroup-path handling into a reusable module independent of the D-Bus manager, preparing for tenant sub-cgroup support in #3564.

Changes:

  • Moves parsing and unit/sub-cgroup accessors into CgroupsPath.
  • Updates the manager to use side-effect-free accessors and exposes the parser when systemd support is disabled.
  • Adds parser tests and adapts existing path-construction tests.
File Description
crates/​libcgroups/​src/​systemd/​mod.rs Exposes the new cgroup-path module.
crates/​libcgroups/​src/​systemd/​manager.rs Uses the extracted accessors instead of mutating the parsed name.
crates/​libcgroups/​src/​systemd/​cgroups_path.rs Defines the reusable parser, error type, accessors, and unit tests.
crates/​libcgroups/​src/​stub/​systemd/​mod.rs Exposes the same parser without the systemd feature.

Review effort: Balanced

Signed-off-by: Takuto Nagami <logica0419@gmail.com>
@logica0419

Copy link
Copy Markdown
Contributor Author

@saku3
Sorry for bothering you with the formatting issue.
The fix is done.

Signed-off-by: Takuto Nagami <logica0419@gmail.com>

@saku3 saku3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@saku3
saku3 merged commit 3345a20 into youki-dev:main Nov 24, 2026
34 checks passed
@logica0419
logica0419 deleted the refactor-cgroups-path branch November 24, 2026 15:49
@youki-dev-bot youki-dev-bot Bot mentioned this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants