rp- opened a new pull request, #14975:
URL: https://github.com/apache/cloudstack/pull/14975

   ### 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)
   - [x] 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
   - [x] 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to