From 617204b1a3d02ae1bb45acde4eed06383eed8def Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 23 Aug 2024 13:23:24 +0530 Subject: [PATCH] server: fix volume migration check for local volume attach on a stopped vm Fixes #8645 When a local storage volume is being attached to a stopped VM, volume migration is only needed when it is not present on the last host as the current host ID will be null in the database. Signed-off-by: Abhishek Kumar --- .../main/java/com/cloud/storage/VolumeApiServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index 553f72b719b2..f14e81962274 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -4312,7 +4312,11 @@ private boolean needMoveVolume(VolumeVO existingVolume, VolumeInfo newVolume) { } } else if (storeForNewStoreScope.getScopeType() == ScopeType.HOST && (storeForExistingStoreScope.getScopeType() == ScopeType.CLUSTER || storeForExistingStoreScope.getScopeType() == ScopeType.ZONE)) { - Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId(); + VMInstanceVO vm = _vmInstanceDao.findById(existingVolume.getInstanceId()); + Long hostId = vm.getHostId(); + if (hostId == null) { + hostId = vm.getLastHostId(); + } if (storeForNewStoreScope.getScopeId().equals(hostId)) { return false; }