From cc3170577c12aed73e9d59d440337ce3cc50216d Mon Sep 17 00:00:00 2001 From: Henrique Sato Date: Wed, 8 Oct 2025 08:39:28 -0300 Subject: [PATCH] Add `Hypervisor default` as cache mode for disk offerings (#10282) Co-authored-by: Henrique Sato --- api/src/main/java/com/cloud/offering/DiskOffering.java | 2 +- .../api/command/admin/offering/CreateDiskOfferingCmd.java | 2 +- .../command/admin/offering/CreateServiceOfferingCmd.java | 2 +- .../cloudstack/api/response/ServiceOfferingResponse.java | 2 +- .../org/apache/cloudstack/storage/to/VolumeObjectTO.java | 6 +++++- .../main/resources/META-INF/db/schema-42100to42200.sql | 3 +++ .../com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java | 2 +- .../datastore/adapter/ProviderAdapterDiskOffering.java | 8 +++++--- .../com/cloud/configuration/ConfigurationManagerImpl.java | 2 +- ui/public/locales/en.json | 3 ++- ui/public/locales/pt_BR.json | 3 ++- ui/src/views/offering/AddComputeOffering.vue | 3 +++ ui/src/views/offering/AddDiskOffering.vue | 5 ++++- 13 files changed, 30 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/com/cloud/offering/DiskOffering.java b/api/src/main/java/com/cloud/offering/DiskOffering.java index e1c41f77cbf..9407acfdec1 100644 --- a/api/src/main/java/com/cloud/offering/DiskOffering.java +++ b/api/src/main/java/com/cloud/offering/DiskOffering.java @@ -37,7 +37,7 @@ public interface DiskOffering extends InfrastructureEntity, Identity, InternalId State getState(); enum DiskCacheMode { - NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"); + NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"), HYPERVISOR_DEFAULT("hypervisor_default"); private final String _diskCacheMode; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java index c46e4cd6b44..557c76d63c3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java @@ -151,7 +151,7 @@ public class CreateDiskOfferingCmd extends BaseCmd { @Parameter(name = ApiConstants.CACHE_MODE, type = CommandType.STRING, required = false, - description = "the cache mode to use for this disk offering. none, writeback or writethrough", + 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", since = "4.14") private String cacheMode; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java index 3d20ed50a5d..ec109a2a4f3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java @@ -190,7 +190,7 @@ public class CreateServiceOfferingCmd extends BaseCmd { @Parameter(name = ApiConstants.CACHE_MODE, type = CommandType.STRING, required = false, - description = "the cache mode to use for this disk offering. none, writeback or writethrough", + 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", since = "4.14") private String cacheMode; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java index 4565a878b34..69f80b54010 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java @@ -197,7 +197,7 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations { private Boolean isCustomized; @SerializedName("cacheMode") - @Param(description = "the cache mode to use for this disk offering. none, writeback or writethrough", since = "4.14") + @Param(description = "the cache mode to use for this disk offering. none, writeback, writethrough or hypervisor default", since = "4.14") private String cacheMode; @SerializedName("vspherestoragepolicy") diff --git a/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java b/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java index 92f9ee497a4..827403ac5ef 100644 --- a/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java +++ b/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java @@ -116,8 +116,8 @@ public class VolumeObjectTO extends DownloadableObjectTO implements DataTO { iopsWriteRate = volume.getIopsWriteRate(); iopsWriteRateMax = volume.getIopsWriteRateMax(); iopsWriteRateMaxLength = volume.getIopsWriteRateMaxLength(); - cacheMode = volume.getCacheMode(); hypervisorType = volume.getHypervisorType(); + setCacheMode(volume.getCacheMode()); setDeviceId(volume.getDeviceId()); this.migrationOptions = volume.getMigrationOptions(); this.directDownload = volume.isDirectDownload(); @@ -343,6 +343,10 @@ public class VolumeObjectTO extends DownloadableObjectTO implements DataTO { } public void setCacheMode(DiskCacheMode cacheMode) { + if (DiskCacheMode.HYPERVISOR_DEFAULT.equals(cacheMode) && !Hypervisor.HypervisorType.KVM.equals(hypervisorType)) { + this.cacheMode = DiskCacheMode.NONE; + return; + } this.cacheMode = cacheMode; } diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql b/engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql index d6087ed9a5f..405f2af9564 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql @@ -26,6 +26,9 @@ CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('router_health_check', 'check_result', ' -- Increase length of scripts_version column to 128 due to md5sum to sha512sum change CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.domain_router', 'scripts_version', 'scripts_version', 'VARCHAR(128)'); +-- Increase the cache_mode column size from cloud.disk_offering table +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"'); + -- Add uuid column to ldap_configuration table CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_configuration', 'uuid', 'VARCHAR(40) NOT NULL'); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 46a5024bf15..bf002b37f35 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -707,7 +707,7 @@ public class LibvirtVMDef { } public enum DiskCacheMode { - NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"); + NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"), HYPERVISOR_DEFAULT("default"); String _diskCacheMode; DiskCacheMode(String cacheMode) { diff --git a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/adapter/ProviderAdapterDiskOffering.java b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/adapter/ProviderAdapterDiskOffering.java index 1db5efbb8ec..293f5f3db2a 100644 --- a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/adapter/ProviderAdapterDiskOffering.java +++ b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/adapter/ProviderAdapterDiskOffering.java @@ -34,7 +34,7 @@ public class ProviderAdapterDiskOffering { this.type = ProvisioningType.getProvisioningType(hiddenDiskOffering.getProvisioningType().toString()); } if (hiddenDiskOffering.getCacheMode() != null) { - this.diskCacheMode = DiskCacheMode.getDiskCasehMode(hiddenDiskOffering.getCacheMode().toString()); + this.diskCacheMode = DiskCacheMode.getDiskCacheMode(hiddenDiskOffering.getCacheMode().toString()); } if (hiddenDiskOffering.getState() != null) { this.state = State.valueOf(hiddenDiskOffering.getState().toString()); @@ -166,7 +166,7 @@ public class ProviderAdapterDiskOffering { } enum DiskCacheMode { - NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"); + NONE("none"), WRITEBACK("writeback"), WRITETHROUGH("writethrough"), HYPERVISOR_DEFAULT("hypervisor_default"); private final String _diskCacheMode; @@ -179,13 +179,15 @@ public class ProviderAdapterDiskOffering { return _diskCacheMode; } - public static DiskCacheMode getDiskCasehMode(String cacheMode) { + public static DiskCacheMode getDiskCacheMode(String cacheMode) { if (cacheMode.equals(NONE._diskCacheMode)) { return NONE; } else if (cacheMode.equals(WRITEBACK._diskCacheMode)) { return WRITEBACK; } else if (cacheMode.equals(WRITETHROUGH._diskCacheMode)) { return WRITETHROUGH; + } else if (cacheMode.equals(HYPERVISOR_DEFAULT._diskCacheMode)) { + return HYPERVISOR_DEFAULT; } else { throw new NotImplementedException("Invalid cache mode specified: " + cacheMode); } diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index b96de3c3501..6f9db1dcdbd 100644 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -8440,7 +8440,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati !Enums.getIfPresent(DiskOffering.DiskCacheMode.class, cacheMode.toUpperCase()).isPresent()) { throw new InvalidParameterValueException(String.format("Invalid cache mode (%s). Please specify one of the following " + - "valid cache mode parameters: none, writeback or writethrough", cacheMode)); + "valid cache mode parameters: none, writeback, writethrough or hypervisor_default.", cacheMode)); } } diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index 3cd8e8335ba..c372076e0f3 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -1211,6 +1211,7 @@ "label.hourly": "Hourly", "label.hypervisor": "Hypervisor", "label.hypervisor.capabilities": "Hypervisor Capabilities", +"label.hypervisor.default": "Hypervisor default", "label.hypervisor.type": "Hypervisor type", "label.hypervisors": "Hypervisors", "label.hypervisorsnapshotreserve": "Hypervisor Snapshot reserve", @@ -2813,7 +2814,7 @@ "label.windows": "Windows", "label.with.snapshotid": "with Snapshot ID", "label.write": "Write", -"label.writeback": "Write-back disk caching", +"label.writeback": "Write-back", "label.writecachetype": "Write-cache Type", "label.writeio": "Write (IO)", "label.writethrough": "Write-through", diff --git a/ui/public/locales/pt_BR.json b/ui/public/locales/pt_BR.json index 711dd36deff..c4b5add82fc 100644 --- a/ui/public/locales/pt_BR.json +++ b/ui/public/locales/pt_BR.json @@ -773,6 +773,7 @@ "label.hourly": "A cada hora", "label.hypervisor": "Virtualizador", "label.hypervisor.capabilities": "Recursos do virtualizador", +"label.hypervisor.default": "Padr\u00e3o do virtualizador", "label.hypervisor.type": "Tipo do virtualizador", "label.hypervisors": "Virtualizadores", "label.hypervisorsnapshotreserve": "Reserva de snapshot do virtualizador", @@ -1813,7 +1814,7 @@ "label.windows": "Windows", "label.with.snapshotid": "com o ID da snapshot", "label.write": "Escreva", -"label.writeback": "Cache de disco write-back", +"label.writeback": "Write-back", "label.writecachetype": "Tipo do cache de escrita", "label.writeio": "Escrita (IO)", "label.writethrough": "Write-through", diff --git a/ui/src/views/offering/AddComputeOffering.vue b/ui/src/views/offering/AddComputeOffering.vue index 0455551723c..dc4d5b18818 100644 --- a/ui/src/views/offering/AddComputeOffering.vue +++ b/ui/src/views/offering/AddComputeOffering.vue @@ -467,6 +467,9 @@ {{ $t('label.writethrough') }} + + {{ $t('label.hypervisor.default') }} + diff --git a/ui/src/views/offering/AddDiskOffering.vue b/ui/src/views/offering/AddDiskOffering.vue index 886465cfcf7..bfdd778d449 100644 --- a/ui/src/views/offering/AddDiskOffering.vue +++ b/ui/src/views/offering/AddDiskOffering.vue @@ -211,6 +211,9 @@ {{ $t('label.writethrough') }} + + {{ $t('label.hypervisor.default') }} + @@ -604,7 +607,7 @@ export default { width: 80vw; @media (min-width: 800px) { - width: 430px; + width: 480px; } }