This is an automated email from the ASF dual-hosted git repository. harikrishna pushed a commit to branch CheckVolumeAPI in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit 94e7051c6e1d17f47c7c6441a05e095791fc129c Author: Harikrishna Patnala <[email protected]> AuthorDate: Tue Jan 30 13:12:54 2024 +0530 Introduced new global setting volume.check.and.repair.before.use to do volume check and repair before VM start or volume attach operations --- .../engine/orchestration/VolumeOrchestrator.java | 9 +++++++++ .../cloudstack/storage/volume/VolumeServiceImpl.java | 20 +++++++++++--------- .../java/com/cloud/storage/VolumeApiServiceImpl.java | 4 ++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index e95085d53f6..bf82c468dbe 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -1915,6 +1915,15 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } } } + } else { + // For unmanaged storage this is not a mandatory step but this is kept here so that volume can be checked and repaired if needed based on the + // global setting volume.check.and.repair.before.use + Host host = _hostDao.findById(vm.getVirtualMachine().getHostId()); + try { + volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore)pool); + } catch (Exception e) { + s_logger.debug(String.format("Unable to grant access to volume [%s] on host [%s], due to %s.", volToString, host, e.getMessage())); + } } } else if (task.type == VolumeTaskType.MIGRATE) { pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary); diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 553417bf2a0..fad413d3635 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -251,18 +251,20 @@ public class VolumeServiceImpl implements VolumeService { DataStoreDriver dataStoreDriver = dataStore != null ? dataStore.getDriver() : null; if (dataStoreDriver instanceof PrimaryDataStoreDriver) { - return ((PrimaryDataStoreDriver)dataStoreDriver).grantAccess(dataObject, host, dataStore); - } + boolean result = ((PrimaryDataStoreDriver)dataStoreDriver).grantAccess(dataObject, host, dataStore); - if (com.cloud.storage.VolumeApiServiceImpl.AllowVolumeCheckAndRepair.value()) { if (HypervisorType.KVM.equals(host.getHypervisorType()) && DataObjectType.VOLUME.equals(dataObject.getType())) { - s_logger.info(String.format("Trying to check and repair the volume %d", dataObject.getId())); - String repair = CheckVolumeAndRepairCmd.RepairValues.leaks.name(); - CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(repair); - VolumeInfo volumeInfo = volFactory.getVolume(dataObject.getId()); - volumeInfo.addPayload(payload); - checkAndRepairVolume(volumeInfo); + if (com.cloud.storage.VolumeApiServiceImpl.AllowVolumeCheckAndRepair.value()) { + s_logger.info(String.format("Trying to check and repair the volume %d", dataObject.getId())); + String repair = CheckVolumeAndRepairCmd.RepairValues.leaks.name(); + CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(repair); + VolumeInfo volumeInfo = volFactory.getVolume(dataObject.getId()); + volumeInfo.addPayload(payload); + checkAndRepairVolume(volumeInfo); + } } + + return result; } return false; diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index 7edca6b6c9d..6df17ca4dda 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -381,8 +381,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic public static ConfigKey<Long> storageTagRuleExecutionTimeout = new ConfigKey<>("Advanced", Long.class, "storage.tag.rule.execution.timeout", "2000", "The maximum runtime," + " in milliseconds, to execute a storage tag rule; if it is reached, a timeout will happen.", true); - public static final ConfigKey<Boolean> AllowVolumeCheckAndRepair = new ConfigKey<Boolean>("Hidden", Boolean.class, "volume.check.and.repair.before.instance.use", "true", - "To check and repair the volume if it has any leaks before performing any volume operation", true); + public static final ConfigKey<Boolean> AllowVolumeCheckAndRepair = new ConfigKey<Boolean>("Advanced", Boolean.class, "volume.check.and.repair.before.use", "false", + "To check and repair the volume if it has any leaks before performing volume attach or VM start operations", true); private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
