Skip to content

Commit 936951c

Browse files
committed
Sets IOPS limit to -1 for offerings with no IOPS limitatin
1 parent fd32974 commit 936951c

File tree

1 file changed

+46
-36
lines changed
  • plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource

1 file changed

+46
-36
lines changed

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

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@
7777
import org.apache.commons.lang3.StringUtils;
7878
import org.apache.logging.log4j.ThreadContext;
7979
import org.apache.commons.lang3.ObjectUtils;
80-
import org.apache.log4j.Logger;
81-
import org.apache.log4j.NDC;
8280
import org.joda.time.Duration;
8381

8482
import com.cloud.agent.IAgentControl;
@@ -888,8 +886,6 @@ private Answer execute(ResizeVolumeCommand cmd) {
888886
oldSize / Float.valueOf(ResourceType.bytesToMiB), newSize / Float.valueOf(ResourceType.bytesToMiB), vmName);
889887
logger.error(errorMsg);
890888
throw new Exception(errorMsg);
891-
} else if (newSize == oldSize && ObjectUtils.allNull(newMaxIops, newMinIops)) {
892-
return new ResizeVolumeAnswer(cmd, true, "success", newSize * ResourceType.bytesToKiB);
893889
}
894890

895891
if (vmName.equalsIgnoreCase("none")) {
@@ -983,21 +979,13 @@ private Answer execute(ResizeVolumeCommand cmd) {
983979
VirtualDisk disk = getDiskAfterResizeDiskValidations(vmMo, path);
984980
String vmdkAbsFile = VmwareHelper.getAbsoluteVmdkFile(disk);
985981

986-
StorageIOAllocationInfo limitIops = disk.getStorageIOAllocation();
987-
if (ObjectUtils.allNotNull(newMinIops, newMaxIops)) {
988-
Long iops = newMinIops + newMaxIops;
989-
s_logger.debug(LogUtils.logGsonWithoutException("Adding [%s] as the new IOPS limit of disk [%s].", iops, disk));
990-
StorageIOAllocationInfo newIops = new StorageIOAllocationInfo();
991-
newIops.setLimit(iops);
992-
limitIops = newIops;
993-
}
982+
setDiskIops(disk, newMinIops, newMaxIops);
994983

995984
if (vmdkAbsFile != null && !vmdkAbsFile.isEmpty()) {
996985
vmMo.updateAdapterTypeIfRequired(vmdkAbsFile);
997986
}
998987

999988
disk.setCapacityInKB(newSize);
1000-
disk.setStorageIOAllocation(limitIops);
1001989

1002990
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
1003991

@@ -1042,6 +1030,22 @@ private Answer execute(ResizeVolumeCommand cmd) {
10421030
}
10431031
}
10441032

1033+
/**
1034+
* Sets the disk IOPS which is the sum of min IOPS and max IOPS; if they are null, the IOPS limit is set to -1 (unlimited).
1035+
*/
1036+
private void setDiskIops(VirtualDisk disk, Long newMinIops, Long newMaxIops) {
1037+
StorageIOAllocationInfo storageIOAllocation = new StorageIOAllocationInfo();
1038+
Long iops = -1L;
1039+
1040+
if (ObjectUtils.allNotNull(newMinIops, newMaxIops)) {
1041+
iops = newMinIops + newMaxIops;
1042+
}
1043+
1044+
storageIOAllocation.setLimit(iops);
1045+
logger.debug(LogUtils.logGsonWithoutException("Setting [%s] as the IOPS limit of disk [%s].", iops == -1L ? "unlimited" : iops, disk));
1046+
disk.setStorageIOAllocation(storageIOAllocation);
1047+
}
1048+
10451049
private VirtualDisk getDiskAfterResizeDiskValidations(VirtualMachineMO vmMo, String volumePath) throws Exception {
10461050
Pair<VirtualDisk, String> vdisk = vmMo.getDiskDevice(volumePath);
10471051
if (vdisk == null) {
@@ -5118,29 +5122,8 @@ private Answer execute(MigrateVolumeCommand cmd) {
51185122
volumePath = vmMo.getVmdkFileBaseName(disk);
51195123
}
51205124
}
5121-
if (cmd.getNewIops() != null) {
5122-
String vmwareDocumentation = "https://kb.vmware.com/s/article/68164";
5123-
Long newIops = cmd.getNewIops();
5124-
VirtualDisk disk = vmMo.getDiskDevice(volumePath, true, true).first();
5125-
try {
5126-
s_logger.debug(LogUtils.logGsonWithoutException("Trying to change disk [%s] IOPS to [%s].", disk, newIops));
5127-
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
5128-
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
5129-
5130-
StorageIOAllocationInfo storageIOAllocation = new StorageIOAllocationInfo();
5131-
storageIOAllocation.setLimit(newIops);
5132-
disk.setStorageIOAllocation(storageIOAllocation);
5133-
5134-
deviceConfigSpec.setDevice(disk);
5135-
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
5136-
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
5137-
vmMo.configureVm(vmConfigSpec);
5138-
} catch (Exception e) {
5139-
s_logger.error(LogUtils.logGsonWithoutException("Failed to change disk [%s] IOPS to [%s] due to [%s]. This happens "
5140-
+ "when the disk controller is IDE. Please read this documentation for more information: [%s]. ", disk, newIops,
5141-
e.getMessage(), vmwareDocumentation), e);
5142-
}
5143-
}
5125+
5126+
setDiskIops(cmd, vmMo, volumePath);
51445127
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
51455128
chainInfo = _gson.toJson(diskInfoBuilder.getDiskInfoByBackingFileBaseName(volumePath, targetDsMo.getName()));
51465129
MigrateVolumeAnswer answer = new MigrateVolumeAnswer(cmd, true, null, volumePath);
@@ -5153,6 +5136,33 @@ private Answer execute(MigrateVolumeCommand cmd) {
51535136
}
51545137
}
51555138

5139+
/**
5140+
* Sets the disk IOPS limitation, if the {@link MigrateVolumeCommand} did not specify this limitation, then it is set to -1 (unlimited).
5141+
*/
5142+
private void setDiskIops(MigrateVolumeCommand cmd, VirtualMachineMO vmMo, String volumePath) throws Exception {
5143+
Long newIops = cmd.getNewIops() == null ? -1L : cmd.getNewIops();
5144+
VirtualDisk disk = vmMo.getDiskDevice(volumePath, true, true).first();
5145+
5146+
try {
5147+
logger.debug(LogUtils.logGsonWithoutException("Trying to change disk [%s] IOPS to [%s].", disk, newIops));
5148+
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
5149+
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
5150+
5151+
StorageIOAllocationInfo storageIOAllocation = new StorageIOAllocationInfo();
5152+
storageIOAllocation.setLimit(newIops);
5153+
disk.setStorageIOAllocation(storageIOAllocation);
5154+
5155+
deviceConfigSpec.setDevice(disk);
5156+
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
5157+
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
5158+
vmMo.configureVm(vmConfigSpec);
5159+
} catch (Exception e) {
5160+
String vmwareDocumentation = "https://kb.vmware.com/s/article/68164";
5161+
logger.error(LogUtils.logGsonWithoutException("Failed to change disk [%s] IOPS to [%s] due to [%s]. This happens when the disk controller is IDE." +
5162+
" Please read this documentation for more information: [%s]. ", disk, newIops, e.getMessage(), vmwareDocumentation), e);
5163+
}
5164+
}
5165+
51565166
private Pair<VirtualDisk, String> getVirtualDiskInfo(VirtualMachineMO vmMo, String srcDiskName) throws Exception {
51575167
Pair<VirtualDisk, String> deviceInfo = vmMo.getDiskDevice(srcDiskName);
51585168
if (deviceInfo == null) {

0 commit comments

Comments
 (0)