Skip to content

btrfs: Add bd_btrfs_delete_subvolume_recursive function#1193

Merged
vojtechtrefny merged 1 commit intostoraged-project:masterfrom
vojtechtrefny:master_btrfs-subvolume-recursive-remove
Apr 24, 2026
Merged

btrfs: Add bd_btrfs_delete_subvolume_recursive function#1193
vojtechtrefny merged 1 commit intostoraged-project:masterfrom
vojtechtrefny:master_btrfs-subvolume-recursive-remove

Conversation

@vojtechtrefny
Copy link
Copy Markdown
Member

@vojtechtrefny vojtechtrefny commented Apr 21, 2026

Add a new function for deleting btrfs subvolumes with an option for recursive deletion using the --recursive flag (requires btrfs-progs

= 6.12). The existing bd_btrfs_delete_subvolume now delegates to
the new function with recursive=FALSE.

A new BD_BTRFS_TECH_MODE_DELETE_RECURSIVE tech mode is added and checked in bd_btrfs_is_tech_avail for the SUBVOL tech.

Fixes: #1107

Summary by CodeRabbit

  • New Features

    • Added recursive subvolume deletion support for btrfs. The new function allows deleting subvolume hierarchies in a single operation. Requires btrfs-progs version 6.12 or later.
  • Tests

    • Added test coverage for recursive subvolume deletion, including version compatibility validation.

Add a new function for deleting btrfs subvolumes with an option for
recursive deletion using the --recursive flag (requires btrfs-progs
>= 6.12). The existing bd_btrfs_delete_subvolume now delegates to
the new function with recursive=FALSE.

A new BD_BTRFS_TECH_MODE_DELETE_RECURSIVE tech mode is added and
checked in bd_btrfs_is_tech_avail for the SUBVOL tech.

Fixes: storaged-project#1107

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

This pull request adds support for recursive deletion of btrfs subvolumes by introducing a new function bd_btrfs_delete_subvolume_recursive with version requirement checking for btrfs-progs 6.12 or higher, alongside corresponding API declarations, implementation, and test coverage.

Changes

Cohort / File(s) Summary
API Declarations
src/lib/plugin_apis/btrfs.api, src/plugins/btrfs.h, docs/libblockdev-sections.txt
Added new public function bd_btrfs_delete_subvolume_recursive declaration and new mode flag BD_BTRFS_TECH_MODE_DELETE_RECURSIVE = 1 << 4 to the BDBtrfsTechMode enum; exported symbol added to documentation.
Core Implementation
src/plugins/btrfs.c
Implemented bd_btrfs_delete_subvolume_recursive with conditional version 6.12 dependency checking; refactored bd_btrfs_delete_subvolume to delegate to the new recursive function with recursive=FALSE; updated bd_btrfs_is_tech_avail to perform version checks based on mode flags.
Test Coverage
tests/btrfs_test.py
Added new test class with comprehensive test for recursive subvolume deletion, including nested subvolume creation and version-conditional error handling for btrfs-progs below 6.12.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately and concisely describes the main change: adding a new bd_btrfs_delete_subvolume_recursive function to the btrfs API.
Linked Issues check ✅ Passed The pull request fully implements the requirements from issue #1107: adds bd_btrfs_delete_subvolume_recursive function for recursive subvolume deletion, preserves API stability by keeping the existing function, and enforces btrfs-progs version 6.12 requirement.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing recursive subvolume deletion: new function declaration/implementation, tech mode enum, version checking logic, and comprehensive test coverage. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/btrfs_test.py (1)

270-280: Consider making the 6.12 gate coverage deterministic.

This test covers only one branch per host version. A small fake_utils/NOSTORAGE test for BlockDev.btrfs_is_tech_avail(BlockDev.BtrfsTech.SUBVOL, BlockDev.BtrfsTechMode.DELETE_RECURSIVE) would catch regressions in the new tech-mode gate regardless of the CI runner’s installed btrfs-progs version.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/btrfs_test.py` around lines 270 - 280, Add a deterministic unit test
that checks the tech-mode gate instead of relying on host btrfs-progs: create a
small test in tests/btrfs_test.py (or new test module) that uses the
fake_utils/NOSTORAGE environment to simulate storage absent and asserts
BlockDev.btrfs_is_tech_avail(BlockDev.BtrfsTech.SUBVOL,
BlockDev.BtrfsTechMode.DELETE_RECURSIVE) returns the expected boolean; if true,
call BlockDev.btrfs_delete_subvolume_recursive(TEST_MNT, "subvol1", True, None)
and assert success, otherwise assert it raises GLib.GError with the "Too low
version of btrfs" message—this ensures both branches of the version gate are
covered deterministically.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/plugin_apis/btrfs.api`:
- Around line 323-324: Update the gtk-doc text for the `@recursive` parameter in
the btrfs subvolume deletion docs (the gtk-doc block that mentions "@recursive"
in the btrfs API docs and the matching comment block in the btrfs plugin
implementation) to reflect upstream caveats: state that recursive deletion
requires btrfs-progs >= 6.12, is not atomic, and when run unprivileged
inaccessible child subvolumes may be skipped rather than deleted; ensure both
the documentation in the API gtk-doc block (the comment referring to `@recursive`)
and the corresponding comment in the btrfs.c plugin are changed to the new
wording so they match.

---

Nitpick comments:
In `@tests/btrfs_test.py`:
- Around line 270-280: Add a deterministic unit test that checks the tech-mode
gate instead of relying on host btrfs-progs: create a small test in
tests/btrfs_test.py (or new test module) that uses the fake_utils/NOSTORAGE
environment to simulate storage absent and asserts
BlockDev.btrfs_is_tech_avail(BlockDev.BtrfsTech.SUBVOL,
BlockDev.BtrfsTechMode.DELETE_RECURSIVE) returns the expected boolean; if true,
call BlockDev.btrfs_delete_subvolume_recursive(TEST_MNT, "subvol1", True, None)
and assert success, otherwise assert it raises GLib.GError with the "Too low
version of btrfs" message—this ensures both branches of the version gate are
covered deterministically.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8d5866ad-1884-4568-85dc-f513ccc7cec7

📥 Commits

Reviewing files that changed from the base of the PR and between 81c7a4b and 45deda1.

📒 Files selected for processing (5)
  • docs/libblockdev-sections.txt
  • src/lib/plugin_apis/btrfs.api
  • src/plugins/btrfs.c
  • src/plugins/btrfs.h
  • tests/btrfs_test.py

Comment thread src/lib/plugin_apis/btrfs.api
@vojtechtrefny
Copy link
Copy Markdown
Member Author

/packit build

@vojtechtrefny
Copy link
Copy Markdown
Member Author

/packit build

@vojtechtrefny vojtechtrefny merged commit 809e9b3 into storaged-project:master Apr 24, 2026
49 of 50 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.

Support for recursive deletion of btrfs subvolumes

2 participants