Skip to content

Commit bae2666

Browse files
committed
CLOUDSTACK-3237: add disk chain sync logic to handle out-of-band chain changes that could happen in storage live migration and VM snapshot operations
1 parent e3a5b3f commit bae2666

8 files changed

Lines changed: 659 additions & 251 deletions

File tree

api/src/com/cloud/agent/api/to/VolumeTO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ public String getPoolUuid() {
126126
public String getChainInfo() {
127127
return chainInfo;
128128
}
129+
130+
public void setChainInfo(String chainInfo) {
131+
this.chainInfo = chainInfo;
132+
}
129133

130134
public String getOsType() {
131135
return guestOsType;

engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,6 @@ public interface VolumeOrchestrationService {
9292
boolean validateVolumeSizeRange(long size);
9393

9494
StoragePool findStoragePool(DiskProfile dskCh, DataCenter dc, Pod pod, Long clusterId, Long hostId, VirtualMachine vm, Set<StoragePool> avoid);
95+
96+
void updateVolumeDiskChain(long volumeId, String path, String chainInfo);
9597
}

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4747
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
4848
import org.apache.cloudstack.utils.identity.ManagementServerNode;
49+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
50+
import org.apache.log4j.Logger;
4951

5052
import com.cloud.agent.AgentManager;
5153
import com.cloud.agent.Listener;
@@ -76,8 +78,10 @@
7678
import com.cloud.agent.api.StopCommand;
7779
import com.cloud.agent.api.UnPlugNicAnswer;
7880
import com.cloud.agent.api.UnPlugNicCommand;
81+
import com.cloud.agent.api.to.DiskTO;
7982
import com.cloud.agent.api.to.NicTO;
8083
import com.cloud.agent.api.to.VirtualMachineTO;
84+
import com.cloud.agent.api.to.VolumeTO;
8185
import com.cloud.agent.manager.Commands;
8286
import com.cloud.agent.manager.allocator.HostAllocator;
8387
import com.cloud.alert.AlertManager;
@@ -902,6 +906,8 @@ else if (_uservmDetailsDao.findDetail(vm.getId(),"cpuOvercommitRatio") != null)
902906
destHostId = finalHost.getId();
903907
}
904908
if (vmGuru.finalizeStart(vmProfile, destHostId, cmds, ctx)) {
909+
syncDiskChainChange(startAnswer);
910+
905911
if (!changeState(vm, Event.OperationSucceeded, destHostId, work, Step.Done)) {
906912
throw new ConcurrentOperationException("Unable to transition to a new state.");
907913
}
@@ -992,6 +998,18 @@ else if (_uservmDetailsDao.findDetail(vm.getId(),"cpuOvercommitRatio") != null)
992998
+ "' (" + vm.getUuid() + "), see management server log for details");
993999
}
9941000
}
1001+
1002+
private void syncDiskChainChange(StartAnswer answer) {
1003+
VirtualMachineTO vmSpec = answer.getVirtualMachine();
1004+
1005+
for(DiskTO disk : vmSpec.getDisks()) {
1006+
if(disk.getType() != Volume.Type.ISO) {
1007+
VolumeObjectTO vol = (VolumeObjectTO)disk.getData();
1008+
1009+
volumeMgr.updateVolumeDiskChain(vol.getId(), vol.getPath(), vol.getChainInfo());
1010+
}
1011+
}
1012+
}
9951013

9961014
@Override
9971015
public void stop(String vmUuid) throws ResourceUnavailableException {

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,4 +1127,22 @@ public String getStoragePoolOfVolume(long volumeId) {
11271127
VolumeVO vol = _volsDao.findById(volumeId);
11281128
return dataStoreMgr.getPrimaryDataStore(vol.getPoolId()).getUuid();
11291129
}
1130+
1131+
public void updateVolumeDiskChain(long volumeId, String path, String chainInfo) {
1132+
VolumeVO vol = _volsDao.findById(volumeId);
1133+
boolean needUpdate = false;
1134+
if(!vol.getPath().equalsIgnoreCase(path))
1135+
needUpdate = true;
1136+
1137+
if(chainInfo != null && (vol.getChainInfo() == null || !chainInfo.equalsIgnoreCase(vol.getChainInfo())))
1138+
needUpdate = true;
1139+
1140+
if(needUpdate) {
1141+
s_logger.info("Update volume disk chain info. vol: " + vol.getId() + ", " + vol.getPath() + " -> " + path
1142+
+ ", " + vol.getChainInfo() + " -> " + chainInfo);
1143+
vol.setPath(path);
1144+
vol.setChainInfo(chainInfo);
1145+
_volsDao.update(volumeId, vol);
1146+
}
1147+
}
11301148
}

0 commit comments

Comments
 (0)