Skip to content

Commit 39ef8f6

Browse files
hsato03Henrique Sato
authored andcommitted
Add Hypervisor default as cache mode for disk offerings (apache#10282)
Co-authored-by: Henrique Sato <[email protected]>
1 parent 4a9b4a4 commit 39ef8f6

File tree

13 files changed

+30
-13
lines changed

13 files changed

+30
-13
lines changed

api/src/main/java/com/cloud/offering/DiskOffering.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum State {
3737
State getState();
3838

3939
enum DiskCacheMode {
40-
NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough");
40+
NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"), HYPERVISOR_DEFAULT("hypervisor_default");
4141

4242
private final String _diskCacheMode;
4343

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public class CreateDiskOfferingCmd extends BaseCmd {
151151
@Parameter(name = ApiConstants.CACHE_MODE,
152152
type = CommandType.STRING,
153153
required = false,
154-
description = "the cache mode to use for this disk offering. none, writeback or writethrough",
154+
description = "the cache mode to use for this disk offering. none, writeback, writethrough or hypervisor default. If the hypervisor default cache mode is used on other hypervisors than KVM, it will fall back to none cache mode",
155155
since = "4.14")
156156
private String cacheMode;
157157

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public class CreateServiceOfferingCmd extends BaseCmd {
190190
@Parameter(name = ApiConstants.CACHE_MODE,
191191
type = CommandType.STRING,
192192
required = false,
193-
description = "the cache mode to use for this disk offering. none, writeback or writethrough",
193+
description = "the cache mode to use for this disk offering. none, writeback, writethrough or hypervisor default. If the hypervisor default cache mode is used on other hypervisors than KVM, it will fall back to none cache mode",
194194
since = "4.14")
195195
private String cacheMode;
196196

api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations {
197197
private Boolean isCustomized;
198198

199199
@SerializedName("cacheMode")
200-
@Param(description = "the cache mode to use for this disk offering. none, writeback or writethrough", since = "4.14")
200+
@Param(description = "the cache mode to use for this disk offering. none, writeback, writethrough or hypervisor default", since = "4.14")
201201
private String cacheMode;
202202

203203
@SerializedName("vspherestoragepolicy")

core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public VolumeObjectTO(VolumeInfo volume) {
116116
iopsWriteRate = volume.getIopsWriteRate();
117117
iopsWriteRateMax = volume.getIopsWriteRateMax();
118118
iopsWriteRateMaxLength = volume.getIopsWriteRateMaxLength();
119-
cacheMode = volume.getCacheMode();
120119
hypervisorType = volume.getHypervisorType();
120+
setCacheMode(volume.getCacheMode());
121121
setDeviceId(volume.getDeviceId());
122122
this.migrationOptions = volume.getMigrationOptions();
123123
this.directDownload = volume.isDirectDownload();
@@ -343,6 +343,10 @@ public void setDeviceId(Long deviceId) {
343343
}
344344

345345
public void setCacheMode(DiskCacheMode cacheMode) {
346+
if (DiskCacheMode.HYPERVISOR_DEFAULT.equals(cacheMode) && !Hypervisor.HypervisorType.KVM.equals(hypervisorType)) {
347+
this.cacheMode = DiskCacheMode.NONE;
348+
return;
349+
}
346350
this.cacheMode = cacheMode;
347351
}
348352

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('router_health_check', 'check_result', '
2626
-- Increase length of scripts_version column to 128 due to md5sum to sha512sum change
2727
CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.domain_router', 'scripts_version', 'scripts_version', 'VARCHAR(128)');
2828

29+
-- Increase the cache_mode column size from cloud.disk_offering table
30+
CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.disk_offering', 'cache_mode', 'cache_mode', 'varchar(18) DEFAULT "none" COMMENT "The disk cache mode to use for disks created with this offering"');
31+
2932
-- Add uuid column to ldap_configuration table
3033
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_configuration', 'uuid', 'VARCHAR(40) NOT NULL');
3134

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ public String toString() {
707707
}
708708

709709
public enum DiskCacheMode {
710-
NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough");
710+
NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"), HYPERVISOR_DEFAULT("default");
711711
String _diskCacheMode;
712712

713713
DiskCacheMode(String cacheMode) {

plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/adapter/ProviderAdapterDiskOffering.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ProviderAdapterDiskOffering(DiskOffering hiddenDiskOffering) {
3434
this.type = ProvisioningType.getProvisioningType(hiddenDiskOffering.getProvisioningType().toString());
3535
}
3636
if (hiddenDiskOffering.getCacheMode() != null) {
37-
this.diskCacheMode = DiskCacheMode.getDiskCasehMode(hiddenDiskOffering.getCacheMode().toString());
37+
this.diskCacheMode = DiskCacheMode.getDiskCacheMode(hiddenDiskOffering.getCacheMode().toString());
3838
}
3939
if (hiddenDiskOffering.getState() != null) {
4040
this.state = State.valueOf(hiddenDiskOffering.getState().toString());
@@ -166,7 +166,7 @@ enum State {
166166
}
167167

168168
enum DiskCacheMode {
169-
NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough");
169+
NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"), HYPERVISOR_DEFAULT("hypervisor_default");
170170

171171
private final String _diskCacheMode;
172172

@@ -179,13 +179,15 @@ public String toString() {
179179
return _diskCacheMode;
180180
}
181181

182-
public static DiskCacheMode getDiskCasehMode(String cacheMode) {
182+
public static DiskCacheMode getDiskCacheMode(String cacheMode) {
183183
if (cacheMode.equals(NONE._diskCacheMode)) {
184184
return NONE;
185185
} else if (cacheMode.equals(WRITEBACK._diskCacheMode)) {
186186
return WRITEBACK;
187187
} else if (cacheMode.equals(WRITETHROUGH._diskCacheMode)) {
188188
return WRITETHROUGH;
189+
} else if (cacheMode.equals(HYPERVISOR_DEFAULT._diskCacheMode)) {
190+
return HYPERVISOR_DEFAULT;
189191
} else {
190192
throw new NotImplementedException("Invalid cache mode specified: " + cacheMode);
191193
}

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8440,7 +8440,7 @@ protected void validateCacheMode(String cacheMode){
84408440
!Enums.getIfPresent(DiskOffering.DiskCacheMode.class,
84418441
cacheMode.toUpperCase()).isPresent()) {
84428442
throw new InvalidParameterValueException(String.format("Invalid cache mode (%s). Please specify one of the following " +
8443-
"valid cache mode parameters: none, writeback or writethrough", cacheMode));
8443+
"valid cache mode parameters: none, writeback, writethrough or hypervisor_default.", cacheMode));
84448444
}
84458445
}
84468446

ui/public/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@
12111211
"label.hourly": "Hourly",
12121212
"label.hypervisor": "Hypervisor",
12131213
"label.hypervisor.capabilities": "Hypervisor Capabilities",
1214+
"label.hypervisor.default": "Hypervisor default",
12141215
"label.hypervisor.type": "Hypervisor type",
12151216
"label.hypervisors": "Hypervisors",
12161217
"label.hypervisorsnapshotreserve": "Hypervisor Snapshot reserve",
@@ -2813,7 +2814,7 @@
28132814
"label.windows": "Windows",
28142815
"label.with.snapshotid": "with Snapshot ID",
28152816
"label.write": "Write",
2816-
"label.writeback": "Write-back disk caching",
2817+
"label.writeback": "Write-back",
28172818
"label.writecachetype": "Write-cache Type",
28182819
"label.writeio": "Write (IO)",
28192820
"label.writethrough": "Write-through",

0 commit comments

Comments
 (0)