Skip to content

fix: Replace deprecated lvdisplay with pvs for LVM detection in detect_mounts - #198

Open
sayalibhavsar wants to merge 3 commits into
mainfrom
fix-detect-mounts-lvm
Open

fix: Replace deprecated lvdisplay with pvs for LVM detection in detect_mounts#198
sayalibhavsar wants to merge 3 commits into
mainfrom
fix-detect-mounts-lvm

Conversation

@sayalibhavsar

Copy link
Copy Markdown
Contributor

Description

Replace the old /dev/mapper + lvdisplay --maps LVM detection in detect_mounts with a pvs-based approach that directly queries all physical volumes, derives base disk names (handling both SCSI/virtio and NVMe/mmcblk partition suffixes), and guards with command -v pvs so systems without lvm2 are unaffected.

Before/After Comparison

Before: Walked /dev/mapper/* and parsed lvdisplay --maps output, producing malformed paths (missing /dev prefix) and incorrect base devices for NVMe partitions (nvme0n1p3 → nvme0n1pcinstead of nvme0n1).

After: pvs --noheadings -o pv_name lists every PV directly, and sed strips partition suffixes correctly for both SCSI (sda1 → sda) and NVMe/mmcblk (nvme0n1p2 → nvme0n1) devices.

Clerical Stuff

This closes #57
Relates to JIRA: RPOPC-610

…t_mounts

The old code walked /dev/mapper/* and parsed lvdisplay --maps output to
find physical volumes.  Replace with a pvs-based approach that directly
queries all LVM PVs and also derives base disk names (handling both
SCSI/virtio and NVMe/mmcblk partition suffixes).  Guard the block with
command -v pvs so systems without lvm2 are unaffected.
@sayalibhavsar sayalibhavsar self-assigned this Jul 24, 2026
@github-actions

Copy link
Copy Markdown

This relates to RPOPC-610

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of LVM physical volumes currently in use by querying pvs.
    • Added consistent normalization for partitioned device names, including NVMe and MMC devices.
    • Improved handling of LVM discovery failures by logging errors, cleaning up temporary data, and reporting the device-in-use condition.

Walkthrough

detect_mounts now discovers LVM physical volumes through pvs, records normalized device paths, and treats all discovered physical volumes as in use.

Changes

LVM physical-volume discovery

Layer / File(s) Summary
Collect and normalize physical volumes
detect_mounts
Replaces /dev/mapper and lvdisplay --maps scanning with conditional pvs querying. It records each physical volume and normalized base device, handles nvme and mmcblk suffixes, and exits with E_DEVICE_IN_USE when the query fails.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes replacing deprecated lvdisplay usage with pvs for LVM detection.
Description check ✅ Passed The description includes all required sections, before/after behavior, issue closure, and JIRA reference.
Linked Issues check ✅ Passed The change addresses issue #57 by discovering LVM physical volumes and recording their normalized base disks.
Out of Scope Changes check ✅ Passed The changes are limited to the requested LVM detection update and related device-name handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@detect_mounts`:
- Around line 22-23: Update the pvs discovery logic in detect_mounts to capture
and validate the command’s exit status, not just whether pvs is installed. Treat
query failures such as locks, configuration errors, permissions, or missing
metadata as a failed-closed condition, while still skipping discovery when pvs
is genuinely unavailable; do not allow an empty result from a failed query to
report success.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b26bfc65-3731-4b57-be89-d15abe5788c9

📥 Commits

Reviewing files that changed from the base of the PR and between 281bd49 and 5cb75e1.

📒 Files selected for processing (1)
  • detect_mounts

Comment thread detect_mounts Outdated
@sayalibhavsar
sayalibhavsar requested a review from dvalinrh July 28, 2026 04:25
dvalinrh
dvalinrh previously approved these changes Jul 28, 2026

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

Address what coderabbit found, and done. Simply catch the error, report it and exit out. To make sure the calling program does not simply continue on, put all the disks into the in use file.

Capture pvs exit status instead of silently discarding errors with
2>/dev/null. On failure (LVM lock, permissions, missing metadata),
report the error to stderr and mark all requested disks as in-use
so the caller cannot proceed with a destructive operation.
Comment thread detect_mounts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
detect_mounts (1)

29-37: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Resolve mapped PVs to their backing disks.

pvs can report PV names that are device-mapper devices, symlinks such as /dev/disk/by-id/..., or namespaced devices with partition suffixes. This only strips a partition suffix and writes /dev/<base>, so detect_mounts /dev/sdX can report success while that disk backs an LVM PV through a mapping. Resolve each PV through its full block-device parent chain via lsblk or sysfs before writing mount_tmp, or explicitly restrict and validate the supported PV path forms.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@detect_mounts` around lines 29 - 37, Update the PV-processing loop around
pv_output to resolve each reported PV through its complete block-device parent
chain, including device-mapper devices, symlinks, and namespaced partitioned
devices, before writing entries to mount_tmp. Use lsblk or sysfs for the
resolution and retain the resolved backing disk alongside the PV entry; do not
rely solely on stripping partition suffixes.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@detect_mounts`:
- Around line 29-37: Update the PV-processing loop around pv_output to resolve
each reported PV through its complete block-device parent chain, including
device-mapper devices, symlinks, and namespaced partitioned devices, before
writing entries to mount_tmp. Use lsblk or sysfs for the resolution and retain
the resolved backing disk alongside the PV entry; do not rely solely on
stripping partition suffixes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 442f2027-bf87-49fd-bdb0-cb10ffe52c72

📥 Commits

Reviewing files that changed from the base of the PR and between c87d030 and 630cc9b.

📒 Files selected for processing (1)
  • detect_mounts

@sayalibhavsar
sayalibhavsar requested a review from dvalinrh August 10, 2026 18:37
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.

detect_mount needs to look at lvms

2 participants