mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: check hostId when attach disk to a Stopped vm with local storage (#7886)
This fixes #7834
This commit is contained in:
parent
5097d2aa8b
commit
db0e7a65af
@ -123,6 +123,7 @@ import com.cloud.storage.Storage;
|
|||||||
import com.cloud.storage.Storage.ImageFormat;
|
import com.cloud.storage.Storage.ImageFormat;
|
||||||
import com.cloud.storage.StorageManager;
|
import com.cloud.storage.StorageManager;
|
||||||
import com.cloud.storage.StoragePool;
|
import com.cloud.storage.StoragePool;
|
||||||
|
import com.cloud.storage.StoragePoolHostVO;
|
||||||
import com.cloud.storage.StorageUtil;
|
import com.cloud.storage.StorageUtil;
|
||||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||||
import com.cloud.storage.Volume;
|
import com.cloud.storage.Volume;
|
||||||
@ -131,6 +132,7 @@ import com.cloud.storage.VolumeApiService;
|
|||||||
import com.cloud.storage.VolumeDetailVO;
|
import com.cloud.storage.VolumeDetailVO;
|
||||||
import com.cloud.storage.VolumeVO;
|
import com.cloud.storage.VolumeVO;
|
||||||
import com.cloud.storage.dao.SnapshotDao;
|
import com.cloud.storage.dao.SnapshotDao;
|
||||||
|
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||||
import com.cloud.storage.dao.VMTemplateDetailsDao;
|
import com.cloud.storage.dao.VMTemplateDetailsDao;
|
||||||
import com.cloud.storage.dao.VolumeDao;
|
import com.cloud.storage.dao.VolumeDao;
|
||||||
import com.cloud.storage.dao.VolumeDetailsDao;
|
import com.cloud.storage.dao.VolumeDetailsDao;
|
||||||
@ -243,6 +245,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||||||
VolumeApiService _volumeApiService;
|
VolumeApiService _volumeApiService;
|
||||||
@Inject
|
@Inject
|
||||||
PassphraseDao passphraseDao;
|
PassphraseDao passphraseDao;
|
||||||
|
@Inject
|
||||||
|
StoragePoolHostDao storagePoolHostDao;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected SnapshotHelper snapshotHelper;
|
protected SnapshotHelper snapshotHelper;
|
||||||
@ -656,7 +660,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DB
|
@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) {
|
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)
|
// 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);
|
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);
|
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) {
|
if (pool == null) {
|
||||||
String msg = String.format("Unable to find suitable primary storage when creating volume [%s].", volumeToString);
|
String msg = String.format("Unable to find suitable primary storage when creating volume [%s].", volumeToString);
|
||||||
s_logger.error(msg);
|
s_logger.error(msg);
|
||||||
@ -1122,10 +1127,17 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||||||
if (s_logger.isTraceEnabled()) {
|
if (s_logger.isTraceEnabled()) {
|
||||||
s_logger.trace(String.format("storage-pool %s/%s is associated with cluster %d",storagePool.getName(), storagePool.getUuid(), clusterId));
|
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;
|
VolumeInfo vol = null;
|
||||||
if (volumeInfo.getState() == Volume.State.Allocated) {
|
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) {
|
} else if (volumeInfo.getState() == Volume.State.Uploaded) {
|
||||||
vol = copyVolume(storagePool, volumeInfo, vm, rootDiskTmplt, dcVO, pod, diskVO, svo, rootDiskHyperType);
|
vol = copyVolume(storagePool, volumeInfo, vm, rootDiskTmplt, dcVO, pod, diskVO, svo, rootDiskHyperType);
|
||||||
if (vol != null) {
|
if (vol != null) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user