Skip to content

Commit c679fc0

Browse files
author
Alex Huang
committed
bug 10632: allow volume to be recreated when it is in recreating state
1 parent cae81c9 commit c679fc0

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.LinkedList;
3232
import java.util.List;
3333
import java.util.Map;
34+
import java.util.Random;
3435
import java.util.Set;
3536
import java.util.UUID;
3637
import java.util.concurrent.Executors;
@@ -112,8 +113,8 @@
112113
import com.cloud.host.Host;
113114
import com.cloud.host.HostVO;
114115
import com.cloud.host.Status;
115-
import com.cloud.host.dao.HostDetailsDao;
116116
import com.cloud.host.dao.HostDao;
117+
import com.cloud.host.dao.HostDetailsDao;
117118
import com.cloud.hypervisor.Hypervisor.HypervisorType;
118119
import com.cloud.hypervisor.HypervisorGuruManager;
119120
import com.cloud.network.NetworkManager;
@@ -183,8 +184,6 @@
183184
import com.cloud.vm.dao.UserVmDao;
184185
import com.cloud.vm.dao.VMInstanceDao;
185186

186-
import java.util.Random;
187-
188187
@Local(value = { StorageManager.class, StorageService.class })
189188
public class StorageManagerImpl implements StorageManager, StorageService, Manager, ClusterManagerListener {
190189
private static final Logger s_logger = Logger.getLogger(StorageManagerImpl.class);
@@ -1683,7 +1682,7 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
16831682

16841683
if (diskOffering.getDiskSize() > 0) {
16851684
size = diskOffering.getDiskSize();
1686-
}
1685+
}
16871686

16881687
if (!validateVolumeSizeRange(size)) {// convert size from mb to gb for validation
16891688
throw new InvalidParameterValueException("Invalid size for custom volume creation: " + size + " ,max volume size is:" + _maxVolumeSizeInGb);
@@ -1697,7 +1696,7 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
16971696

16981697
if (snapshotCheck.getStatus() != Snapshot.Status.BackedUp) {
16991698
throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.Status.BackedUp + " state yet and can't be used for volume creation");
1700-
}
1699+
}
17011700

17021701
diskOfferingId = (cmd.getDiskOfferingId() != null) ? cmd.getDiskOfferingId() : snapshotCheck.getDiskOfferingId();
17031702
zoneId = snapshotCheck.getDataCenterId();
@@ -2627,7 +2626,7 @@ public void prepare(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDe
26272626
}
26282627
if (assignedPool != null) {
26292628
Volume.State state = vol.getState();
2630-
if (state == Volume.State.Allocated) {
2629+
if (state == Volume.State.Allocated && state == Volume.State.Creating) {
26312630
recreateVols.add(vol);
26322631
} else {
26332632
if (vol.isRecreatable()) {
@@ -2649,7 +2648,7 @@ public void prepare(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDe
26492648
}
26502649
if (s_logger.isDebugEnabled()) {
26512650
s_logger.debug("No need to recreate the volume: "+vol+ ", since it already has a pool assigned: "+vol.getPoolId()+", adding disk to VM");
2652-
}
2651+
}
26532652
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
26542653
vm.addDisk(new VolumeTO(vol, pool));
26552654
}
@@ -2714,7 +2713,7 @@ protected VolumeVO switchVolume(VolumeVO existingVolume, VirtualMachineProfile<?
27142713
txn.start();
27152714
_volsDao.update(existingVolume, Volume.Event.Destroy);
27162715

2717-
Long templateIdToUse = null;
2716+
Long templateIdToUse = null;
27182717
Long volTemplateId = existingVolume.getTemplateId();
27192718
long vmTemplateId = vm.getTemplateId();
27202719
if (volTemplateId != null && volTemplateId.longValue() != vmTemplateId) {

0 commit comments

Comments
 (0)