Skip to content

Commit c29254b

Browse files
Likitha Shettyyadvr
authored andcommitted
CLOUDSTACK-8121. Data disk properties are not updated upon Creation/Deletion of VM snapshots.
Update the path and size of data volumes after snapshot creation/deletion by correctly trimming only the snapshot postfix of a disk. (cherry picked from commit ac491c9) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 271dae9 commit c29254b

3 files changed

Lines changed: 16 additions & 45 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java‎

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,36 +1159,6 @@ private long getVMSnapshotChainSize(VmwareContext context, VmwareHypervisorHost
11591159
return size;
11601160
}
11611161

1162-
private String extractSnapshotBaseFileName(String input) {
1163-
if (input == null) {
1164-
return null;
1165-
}
1166-
1167-
String result = input;
1168-
1169-
final String fileType = ".vmdk";
1170-
1171-
if (result.endsWith(fileType)) {
1172-
// get rid of fileType
1173-
result = result.substring(0, result.length() - (fileType).length());
1174-
}
1175-
1176-
final String token = "-";
1177-
1178-
String[] str = result.split(token);
1179-
int length = str.length;
1180-
1181-
if (length == 1 || length == 2) {
1182-
return result;
1183-
}
1184-
1185-
if (length > 2) {
1186-
return str[0] + token + str[1];
1187-
}
1188-
1189-
return result;
1190-
}
1191-
11921162
@Override
11931163
public CreateVMSnapshotAnswer execute(VmwareHostService hostService, CreateVMSnapshotCommand cmd) {
11941164
List<VolumeObjectTO> volumeTOs = cmd.getVolumeTOs();
@@ -1291,7 +1261,7 @@ private Map<String, String> getNewDiskMap(VirtualMachineMO vmMo) throws Exceptio
12911261
vmdkName = vmdkName.substring(vmdkName.indexOf(token) + token.length());
12921262
}
12931263

1294-
baseName = extractSnapshotBaseFileName(vmdkName);
1264+
baseName = VmwareHelper.trimSnapshotDeltaPostfix(vmdkName);
12951265
}
12961266

12971267
mapNewDisk.put(baseName, vmdkName);
@@ -1316,7 +1286,7 @@ private void setVolumeToPathAndSize(List<VolumeObjectTO> volumeTOs, Map<String,
13161286
baseName = oldPath.substring(1, oldPath.length() - 1);
13171287
}
13181288
else {
1319-
baseName = extractSnapshotBaseFileName(volumeTO.getPath());
1289+
baseName = VmwareHelper.trimSnapshotDeltaPostfix(volumeTO.getPath());
13201290
}
13211291

13221292
String newPath = mapNewDisk.get(baseName);

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.concurrent.Executors;
3535
import java.util.concurrent.Future;
3636

37-
import org.apache.commons.lang.StringUtils;
3837
import org.apache.log4j.Logger;
3938

4039
import com.google.gson.Gson;
@@ -1958,24 +1957,13 @@ public void ensureScsiDeviceController() throws Exception {
19581957
}
19591958
}
19601959

1961-
private static String trimSnapshotDeltaPostfix(String name) {
1962-
String[] tokens = name.split("-");
1963-
if (tokens.length > 1 && tokens[tokens.length - 1].matches("[0-9]{6,}")) {
1964-
List<String> trimmedTokens = new ArrayList<String>();
1965-
for (int i = 0; i < tokens.length - 1; i++)
1966-
trimmedTokens.add(tokens[i]);
1967-
return StringUtils.join(trimmedTokens, "-");
1968-
}
1969-
return name;
1970-
}
1971-
19721960
// return pair of VirtualDisk and disk device bus name(ide0:0, etc)
19731961
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception {
19741962
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
19751963

19761964
DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
19771965
String srcBaseName = dsSrcFile.getFileBaseName();
1978-
String trimmedSrcBaseName = trimSnapshotDeltaPostfix(srcBaseName);
1966+
String trimmedSrcBaseName = VmwareHelper.trimSnapshotDeltaPostfix(srcBaseName);
19791967

19801968
if (matchExactly) {
19811969
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with base name: " + srcBaseName);

‎vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Random;
3030
import java.util.UUID;
3131

32+
import org.apache.commons.lang.StringUtils;
3233
import org.apache.log4j.Logger;
3334

3435
import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
@@ -711,4 +712,16 @@ public static String getVCenterSafeUuid() {
711712
// Object name that is greater than 32 is not safe in vCenter
712713
return UUID.randomUUID().toString().replaceAll("-", "");
713714
}
715+
716+
public static String trimSnapshotDeltaPostfix(String name) {
717+
String[] tokens = name.split("-");
718+
if (tokens.length > 1 && tokens[tokens.length - 1].matches("[0-9]{6,}")) {
719+
List<String> trimmedTokens = new ArrayList<String>();
720+
for (int i = 0; i < tokens.length - 1; i++)
721+
trimmedTokens.add(tokens[i]);
722+
return StringUtils.join(trimmedTokens, "-");
723+
}
724+
return name;
725+
}
726+
714727
}

0 commit comments

Comments
 (0)