Skip to content

Commit 046a8a8

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 816772a commit 046a8a8

8 files changed

Lines changed: 658 additions & 252 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;

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 452 additions & 251 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,6 @@ DiskProfile allocateTemplatedVolume(Type type, String name,
119119
String getStoragePoolOfVolume(long volumeId);
120120

121121
boolean validateVolumeSizeRange(long size);
122+
123+
void updateVolumeDiskChain(long volumeId, String path, String chainInfo);
122124
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,4 +2870,22 @@ public String getStoragePoolOfVolume(long volumeId) {
28702870
VolumeVO vol = _volsDao.findById(volumeId);
28712871
return dataStoreMgr.getPrimaryDataStore(vol.getPoolId()).getUuid();
28722872
}
2873+
2874+
public void updateVolumeDiskChain(long volumeId, String path, String chainInfo) {
2875+
VolumeVO vol = _volsDao.findById(volumeId);
2876+
boolean needUpdate = false;
2877+
if(!vol.getPath().equalsIgnoreCase(path))
2878+
needUpdate = true;
2879+
2880+
if(chainInfo != null && (vol.getChainInfo() == null || !chainInfo.equalsIgnoreCase(vol.getChainInfo())))
2881+
needUpdate = true;
2882+
2883+
if(needUpdate) {
2884+
s_logger.info("Update volume disk chain info. vol: " + vol.getId() + ", " + vol.getPath() + " -> " + path
2885+
+ ", " + vol.getChainInfo() + " -> " + chainInfo);
2886+
vol.setPath(path);
2887+
vol.setChainInfo(chainInfo);
2888+
_volsDao.update(volumeId, vol);
2889+
}
2890+
}
28732891
}

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
4343
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4444
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
45+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
4546
import org.apache.log4j.Logger;
4647

4748
import com.cloud.agent.AgentManager;
@@ -70,8 +71,10 @@
7071
import com.cloud.agent.api.StartupRoutingCommand.VmState;
7172
import com.cloud.agent.api.StopAnswer;
7273
import com.cloud.agent.api.StopCommand;
74+
import com.cloud.agent.api.to.DiskTO;
7375
import com.cloud.agent.api.to.NicTO;
7476
import com.cloud.agent.api.to.VirtualMachineTO;
77+
import com.cloud.agent.api.to.VolumeTO;
7578
import com.cloud.agent.manager.Commands;
7679
import com.cloud.agent.manager.allocator.HostAllocator;
7780
import com.cloud.alert.AlertManager;
@@ -925,6 +928,8 @@ else if (_uservmDetailsDao.findDetail(vm.getId(),"cpuOvercommitRatio") != null)
925928
destHostId = finalHost.getId();
926929
}
927930
if (vmGuru.finalizeStart(vmProfile, destHostId, cmds, ctx)) {
931+
syncDiskChainChange(startAnswer);
932+
928933
if (!changeState(vm, Event.OperationSucceeded, destHostId, work, Step.Done)) {
929934
throw new ConcurrentOperationException("Unable to transition to a new state.");
930935
}
@@ -1015,6 +1020,18 @@ else if (_uservmDetailsDao.findDetail(vm.getId(),"cpuOvercommitRatio") != null)
10151020

10161021
return startedVm;
10171022
}
1023+
1024+
private void syncDiskChainChange(StartAnswer answer) {
1025+
VirtualMachineTO vmSpec = answer.getVirtualMachine();
1026+
1027+
for(DiskTO disk : vmSpec.getDisks()) {
1028+
if(disk.getType() != Volume.Type.ISO) {
1029+
VolumeObjectTO vol = (VolumeObjectTO)disk.getData();
1030+
1031+
volumeMgr.updateVolumeDiskChain(vol.getId(), vol.getPath(), vol.getChainInfo());
1032+
}
1033+
}
1034+
}
10181035

10191036
@Override
10201037
public <T extends VMInstanceVO> boolean stop(T vm, User user, Account account) throws ResourceUnavailableException {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.hypervisor.vmware.mo;
19+
20+
public class VirtualMachineDiskInfo {
21+
String diskDeviceBusName;
22+
String[] diskChain;
23+
24+
public VirtualMachineDiskInfo() {
25+
}
26+
27+
public String getDiskDeviceBusName() {
28+
return diskDeviceBusName;
29+
}
30+
31+
public void setDiskDeviceBusName(String diskDeviceBusName) {
32+
this.diskDeviceBusName = diskDeviceBusName;
33+
}
34+
35+
public String[] getDiskChain() {
36+
return diskChain;
37+
}
38+
39+
public void setDiskChain(String[] diskChain) {
40+
this.diskChain = diskChain;
41+
}
42+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package com.cloud.hypervisor.vmware.mo;
19+
20+
import java.util.ArrayList;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import java.util.Map;
24+
25+
public class VirtualMachineDiskInfoBuilder {
26+
Map<String, List<String>> disks;
27+
28+
public VirtualMachineDiskInfoBuilder() {
29+
disks = new HashMap<String, List<String>>();
30+
}
31+
32+
public void addDisk(String diskDeviceBusName, String diskBackingFilePath) {
33+
List<String> chain = getDiskChainContainer(diskDeviceBusName);
34+
chain.add(diskBackingFilePath);
35+
}
36+
37+
public int getDiskCount() {
38+
return disks.keySet().size();
39+
}
40+
41+
public List<VirtualMachineDiskInfo> getAllDiskInfo() {
42+
List<VirtualMachineDiskInfo> infoList = new ArrayList<VirtualMachineDiskInfo>();
43+
for(Map.Entry<String, List<String>> entry : disks.entrySet()) {
44+
VirtualMachineDiskInfo diskInfo = new VirtualMachineDiskInfo();
45+
diskInfo.setDiskDeviceBusName(entry.getKey());
46+
diskInfo.setDiskChain(entry.getValue().toArray(new String[1]));
47+
infoList.add(diskInfo);
48+
}
49+
return infoList;
50+
}
51+
52+
public VirtualMachineDiskInfo getDiskInfoByDeviceBusName(String diskDeviceBusName) {
53+
List<String> chain = disks.get(diskDeviceBusName);
54+
if(chain != null && chain.size() > 0) {
55+
VirtualMachineDiskInfo diskInfo = new VirtualMachineDiskInfo();
56+
diskInfo.setDiskDeviceBusName(diskDeviceBusName);
57+
diskInfo.setDiskChain(chain.toArray(new String[1]));
58+
return diskInfo;
59+
}
60+
61+
return null;
62+
}
63+
64+
public VirtualMachineDiskInfo getDiskInfoByBackingFileBaseName(String diskBackingFileBaseName) {
65+
for(Map.Entry<String, List<String>> entry : disks.entrySet()) {
66+
if(chainContains(entry.getValue(), diskBackingFileBaseName)) {
67+
VirtualMachineDiskInfo diskInfo = new VirtualMachineDiskInfo();
68+
diskInfo.setDiskDeviceBusName(entry.getKey());
69+
diskInfo.setDiskChain(entry.getValue().toArray(new String[1]));
70+
return diskInfo;
71+
}
72+
}
73+
74+
return null;
75+
}
76+
77+
private List<String> getDiskChainContainer(String diskDeviceBusName) {
78+
assert(diskDeviceBusName != null);
79+
List<String> chain = disks.get(diskDeviceBusName);
80+
if(chain == null) {
81+
chain = new ArrayList<String>();
82+
disks.put(diskDeviceBusName, chain);
83+
}
84+
return chain;
85+
}
86+
87+
private static boolean chainContains(List<String> chain, String diskBackingFileBaseName) {
88+
for(String backing : chain) {
89+
DatastoreFile file = new DatastoreFile(backing);
90+
91+
if(file.getFileBaseName().contains(diskBackingFileBaseName))
92+
return true;
93+
}
94+
95+
return false;
96+
}
97+
}

‎vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,31 @@ public String getDiskCurrentTopBackingFileInChain(String deviceBusName) throws E
18471847

18481848
return null;
18491849
}
1850+
1851+
public VirtualMachineDiskInfoBuilder getDiskInfoBuilder() throws Exception {
1852+
VirtualMachineDiskInfoBuilder builder = new VirtualMachineDiskInfoBuilder();
1853+
1854+
List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
1855+
1856+
if(devices != null && devices.size() > 0) {
1857+
for(VirtualDevice device : devices) {
1858+
if(device instanceof VirtualDisk) {
1859+
VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
1860+
if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
1861+
VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
1862+
1863+
while(diskBackingInfo != null) {
1864+
String deviceBusName = getDeviceBusName(devices, device);
1865+
builder.addDisk(deviceBusName, diskBackingInfo.getFileName());
1866+
diskBackingInfo = diskBackingInfo.getParent();
1867+
}
1868+
}
1869+
}
1870+
}
1871+
}
1872+
1873+
return builder;
1874+
}
18501875

18511876
@Deprecated
18521877
public List<Pair<String, ManagedObjectReference>> getDiskDatastorePathChain(VirtualDisk disk, boolean followChain) throws Exception {
@@ -1938,7 +1963,7 @@ private String getDeviceBusName(List<VirtualDevice> allDevices, VirtualDevice th
19381963
}
19391964
throw new Exception("Unable to find device controller");
19401965
}
1941-
1966+
19421967
public VirtualDisk[] getAllDiskDevice() throws Exception {
19431968
List<VirtualDisk> deviceList = new ArrayList<VirtualDisk>();
19441969
List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");

0 commit comments

Comments
 (0)