This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push:
new db0e7a65afb server: check hostId when attach disk to a Stopped vm with
local storage (#7886)
db0e7a65afb is described below
commit db0e7a65afbe839a2ea452f85200176d81cc4779
Author: Wei Zhou <[email protected]>
AuthorDate: Tue Aug 22 11:22:20 2023 +0200
server: check hostId when attach disk to a Stopped vm with local storage
(#7886)
This fixes #7834
---
.../engine/orchestration/VolumeOrchestrator.java | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
index f7c8c9c70bf..52bcf5033af 100644
---
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
+++
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
@@ -123,6 +123,7 @@ import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePool;
+import com.cloud.storage.StoragePoolHostVO;
import com.cloud.storage.StorageUtil;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.Volume;
@@ -131,6 +132,7 @@ import com.cloud.storage.VolumeApiService;
import com.cloud.storage.VolumeDetailVO;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.SnapshotDao;
+import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.storage.dao.VMTemplateDetailsDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.dao.VolumeDetailsDao;
@@ -243,6 +245,8 @@ public class VolumeOrchestrator extends ManagerBase
implements VolumeOrchestrati
VolumeApiService _volumeApiService;
@Inject
PassphraseDao passphraseDao;
+ @Inject
+ StoragePoolHostDao storagePoolHostDao;
@Inject
protected SnapshotHelper snapshotHelper;
@@ -656,7 +660,8 @@ public class VolumeOrchestrator extends ManagerBase
implements VolumeOrchestrati
}
@DB
- public VolumeInfo createVolume(VolumeInfo volumeInfo, VirtualMachine vm,
VirtualMachineTemplate template, DataCenter dc, Pod pod, Long clusterId,
ServiceOffering offering, DiskOffering diskOffering,
+ public VolumeInfo createVolume(VolumeInfo volumeInfo, VirtualMachine vm,
VirtualMachineTemplate template, DataCenter dc, Pod pod, Long clusterId,
+ Long hostId, ServiceOffering offering,
DiskOffering diskOffering,
List<StoragePool> avoids, long size,
HypervisorType hyperType) {
// update the volume's hv_ss_reserve (hypervisor snapshot reserve)
from a disk offering (used for managed storage)
volumeInfo =
volService.updateHypervisorSnapshotReserveForVolume(diskOffering,
volumeInfo.getId(), hyperType);
@@ -691,7 +696,7 @@ public class VolumeOrchestrator extends ManagerBase
implements VolumeOrchestrati
final HashSet<StoragePool> avoidPools = new
HashSet<StoragePool>(avoids);
- pool = findStoragePool(dskCh, dc, pod, clusterId, vm.getHostId(), vm,
avoidPools);
+ pool = findStoragePool(dskCh, dc, pod, clusterId, hostId, vm,
avoidPools);
if (pool == null) {
String msg = String.format("Unable to find suitable primary
storage when creating volume [%s].", volumeToString);
s_logger.error(msg);
@@ -1122,10 +1127,17 @@ public class VolumeOrchestrator extends ManagerBase
implements VolumeOrchestrati
if (s_logger.isTraceEnabled()) {
s_logger.trace(String.format("storage-pool %s/%s is associated
with cluster %d",storagePool.getName(), storagePool.getUuid(), clusterId));
}
+ Long hostId = vm.getHostId();
+ if (hostId == null && storagePool.isLocal()) {
+ List<StoragePoolHostVO> poolHosts =
storagePoolHostDao.listByPoolId(storagePool.getId());
+ if (poolHosts.size() > 0) {
+ hostId = poolHosts.get(0).getHostId();
+ }
+ }
VolumeInfo vol = null;
if (volumeInfo.getState() == Volume.State.Allocated) {
- vol = createVolume(volumeInfo, vm, rootDiskTmplt, dcVO, pod,
clusterId, svo, diskVO, new ArrayList<StoragePool>(), volumeInfo.getSize(),
rootDiskHyperType);
+ vol = createVolume(volumeInfo, vm, rootDiskTmplt, dcVO, pod,
clusterId, hostId, svo, diskVO, new ArrayList<StoragePool>(),
volumeInfo.getSize(), rootDiskHyperType);
} else if (volumeInfo.getState() == Volume.State.Uploaded) {
vol = copyVolume(storagePool, volumeInfo, vm, rootDiskTmplt, dcVO,
pod, diskVO, svo, rootDiskHyperType);
if (vol != null) {