Skip to content

utils: Resolve symlinks with an absolute target in bd_utils_resolve_device - #1217

Merged
vojtechtrefny merged 1 commit into
storaged-project:masterfrom
Geertsky:fix-resolve-device-absolute-symlink
Oct 21, 2026
Merged

vojtechtrefny merged 1 commit into
storaged-project:masterfrom
Geertsky:fix-resolve-device-absolute-symlink

Conversation

@Geertsky

@Geertsky Geertsky commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

bd_utils_resolve_device() only handled relative symlink targets such as ../dm-1. An absolute target such as /dev/mapper/vg-swap -> /dev/dm-1, as created in some environments (for example an initramfs with a different udev setup), was turned into /dev//dev/dm-1 and the resolution failed with Failed to stat '/dev//dev/dm-1'.

bd_swap_swapstatus() resolves /dev/mapper/* paths with this function and treats a failure as "device is not an active swap". Callers such as blivet (and so the linux-system-roles.storage role) then tried to activate an already active swap, which failed with Failed to activate swap on /dev/mapper/vg-swap: Device or resource busy.

Absolute targets are now resolved with realpath(), so chains of symlinks (/dev/vg/swap -> /dev/mapper/vg-swap -> /dev/dm-1) work too. Relative targets behave as before.

Testing:

  • compiled dev_utils.c on its own: an absolute symlink and a two-level chain resolve to the block device, a dangling symlink still returns an error; before the change both failed with Failed to stat '/dev//dev/...'
  • a build of libbd_utils with this change on a VM where /dev/mapper/vg.rh-swap -> /dev/dm-1: swapstatus("/dev/mapper/vg.rh-swap") went from False to True and the storage role no longer fails
  • added a case with an absolute symlink to UtilsDevUtilsTestCase.test_resolve_device; the full test suite was not run

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved device resolution for absolute and chained symbolic links.
    • Error messages now include the requested device and underlying system error when resolution fails.
    • Preserved existing handling for relative symbolic links.

…evice

Only relative symlink targets were handled. An absolute target such as
/dev/mapper/vg-swap -> /dev/dm-1, as created by udev rules in some
environments, was turned into "/dev//dev/dm-1" and the resolution failed.
bd_swap_swapstatus() then took the device for inactive and callers such
as blivet tried to activate an already active swap, which failed with
"Device or resource busy".

Resolve absolute targets with realpath() so chains of symlinks work too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: storaged-project/libblockdev/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fec004b7-6b54-4358-bf61-33c482e9f3d6
📥 Commits

Reviewing files that changed from the base of the PR and between 71fc27e and 31073f6.

📒 Files selected for processing: 2
  • src/utils/dev_utils.c
  • tests/utils_test.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The device resolver now fully resolves absolute symlink targets with realpath and returns an error if resolution fails. The test checks absolute symlink resolution with and without the /dev prefix.

Changes: Device resolution

Layer / File(s) Summary
Resolve absolute symlink targets
src/utils/dev_utils.c, tests/utils_test.py
The resolver uses realpath for absolute symlink targets and reports resolution failures. Relative symlink handling remains unchanged. The test checks resolution with and without the /dev prefix.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 31073

No actionable merge-blocking risk remains in the reviewed changes.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: resolving symlinks with absolute targets in bd_utils_resolve_device.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@vojtechtrefny

Copy link
Copy Markdown
Member

Jenkins, ok to test.

@vojtechtrefny vojtechtrefny 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.

Looks good to me, thank you.

@Geertsky

Copy link
Copy Markdown
Contributor Author

Looks good to me, thank you.

Thanks for the quick review!

@vojtechtrefny
vojtechtrefny merged commit 035a8ae into storaged-project:master Oct 21, 2026
52 of 54 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.

2 participants