Skip to content

kvm: find disk to detach by resolved path - #14975

Open
rp- wants to merge 1 commit into
apache:4.22from
LINBIT:4.22-fix-linstor-detach-legacy-path
Open

rp- wants to merge 1 commit into
apache:4.22from
LINBIT:4.22-fix-linstor-detach-legacy-path

Conversation

@rp-

@rp- rp- commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes detachVolume on KVM reporting success without detaching the disk, when the running instance references the volume through a different path than the one the storage plugin returns.

On detach, KVMStorageProcessor.attachOrDetachDisk searched the disk in the live domain XML by comparing the path string of the volume with the source of each disk. If nothing matched, it logged

Could not find disk [...] attached to VM instance with UUID [...]. We will set it as detached in the database to ensure consistency.

and returned without sending detach-device. The detach was answered as successful, so the volume was marked as detached in the database while it stayed attached to the running instance.

This happens for Linstor volumes of instances started before #12300. Their domain XML still has /dev/drbdX (live migration keeps it), while the plugin now returns /dev/drbd/by-res/<resource>/0, a symlink to the same device. Consequences, as described in #14508:

  • the guest keeps the disk and QEMU keeps the DRBD device open
  • attaching the volume to an instance on another host fails with Wrong medium type
  • attaching it back to the same instance fails with target 'vdb' duplicated for disk sources ...
  • attaching it to another instance on the same host succeeds, so two running instances have the same device open

With this change the disk is searched with the new findDiskDefByPath:

  1. The path is compared as is, as before.
  2. If that finds nothing, the files both paths resolve to are compared (Path.toRealPath()).

The detach then uses the disk definition taken from the domain XML, so detach-device and the check that the device is gone both use the path the domain knows.

The second step only applies to absolute local paths that exist, so network disks (RBD, Gluster) are not affected. If no disk matches after resolving either, the behavior is unchanged.

Not part of this PR: the live resize notification in resizevolume.sh also selects the disk by path (virsh domblklist ... | grep $path), so for such instances the guest only sees a new size after a restart.

Fixes: #14508

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

N/A

How Has This Been Tested?

Unit tests in KVMStorageProcessorTest (all 42 tests of the class pass), with three new tests for findDiskDefByPath:

  • findDiskDefByPathTestReturnsDiskWithSamePath: a disk with the identical path is returned.
  • findDiskDefByPathTestReturnsDiskAttachedWithTargetOfLink: the volume path is a symlink and the domain has the link target, as in the Linstor case; the right disk is returned.
  • findDiskDefByPathTestReturnsNullWhenNoDiskUsesThePath: no disk is returned for another existing device, a path that does not exist, and a non-absolute (network) path.

How did you try to break this feature and the system with this change?

  • The exact comparison still runs first, so for instances whose domain XML has the path the plugin returns nothing changes, for any storage type.
  • The resolved comparison cannot match a different device: two paths only match if they resolve to the same file.
  • Disks without a path (e.g. an empty cdrom), paths that do not exist and non-absolute paths are skipped instead of failing the detach; the tests above cover these.

detachVolume looked up the disk in the domain XML by comparing the
path string of the volume with the source of the disks. If the domain
references the same device through a different path nothing was found,
no detach-device was sent, but the detach was still answered as
successful. The volume was then marked as detached while it stayed
attached to the running instance and could be attached to a second one.

This happens for Linstor volumes of instances started before apache#12300:
their domain XML still has /dev/drbdX while the plugin now returns
/dev/drbd/by-res/<resource>/0.

If no disk matches the path as is, compare the files the paths
resolve to.

Fixes: apache#14508
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 18.35%. Comparing base (89a1f73) to head (9916f02).

Files with missing lines Patch % Lines
...ud/hypervisor/kvm/storage/KVMStorageProcessor.java 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #14975   +/-   ##
=========================================
  Coverage     18.34%   18.35%           
- Complexity    16679    16690   +11     
=========================================
  Files          5940     5940           
  Lines        537840   537860   +20     
  Branches      65940    65942    +2     
=========================================
+ Hits          98668    98708   +40     
+ Misses       427946   427926   -20     
  Partials      11226    11226           
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.44% <96.15%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KVM + Linstor: detachVolume reports success but leaves the disk attached when the domain XML still has the legacy /dev/drbdNNNN path

1 participant