You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ha...@apache.org on 2024/02/05 08:26:49 UTC
(cloudstack) 08/18: Added volume check and repair changes only during VM start and volume attach operations
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 e08aac037b7c52f5536632343882353858eddddc
Author: Harikrishna Patnala <ha...@gmail.com>
AuthorDate: Fri Jan 12 13:33:41 2024 +0530
Added volume check and repair changes only during VM start and volume attach operations
---
.../subsystem/api/storage/VolumeService.java | 2 ++
.../engine/orchestration/VolumeOrchestrator.java | 6 ++---
.../storage/volume/VolumeServiceImpl.java | 29 +++++++++++-----------
.../com/cloud/storage/VolumeApiServiceImpl.java | 6 +++++
4 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
index 4350e264125..be5ca340b6f 100644
--- a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
+++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
@@ -117,4 +117,6 @@ public interface VolumeService {
void moveVolumeOnSecondaryStorageToAnotherAccount(Volume volume, Account sourceAccount, Account destAccount);
Pair<String, String> checkAndRepairVolume(VolumeInfo volume);
+
+ void checkAndRepairVolumeBasedOnConfig(DataObject dataObject, Host host);
}
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 bf82c468dbe..4e157303b71 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
@@ -1916,13 +1916,11 @@ 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);
+ volService.checkAndRepairVolumeBasedOnConfig(volFactory.getVolume(vol.getId()), host);
} 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()));
+ s_logger.debug(String.format("Unable to check and repair volume [%s] on host [%s], due to %s.", volToString, host, e.getMessage()));
}
}
} else if (task.type == VolumeTaskType.MIGRATE) {
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 fad413d3635..c0628007326 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,20 +251,7 @@ public class VolumeServiceImpl implements VolumeService {
DataStoreDriver dataStoreDriver = dataStore != null ? dataStore.getDriver() : null;
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
- boolean result = ((PrimaryDataStoreDriver)dataStoreDriver).grantAccess(dataObject, host, dataStore);
-
- if (HypervisorType.KVM.equals(host.getHypervisorType()) && DataObjectType.VOLUME.equals(dataObject.getType())) {
- 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 ((PrimaryDataStoreDriver)dataStoreDriver).grantAccess(dataObject, host, dataStore);
}
return false;
@@ -2778,6 +2765,20 @@ public class VolumeServiceImpl implements VolumeService {
return snapshot;
}
+ @Override
+ public void checkAndRepairVolumeBasedOnConfig(DataObject dataObject, Host host) {
+ if (HypervisorType.KVM.equals(host.getHypervisorType()) && DataObjectType.VOLUME.equals(dataObject.getType())) {
+ 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);
+ }
+ }
+ }
+
@Override
public Pair<String, String> checkAndRepairVolume(VolumeInfo volume) {
Long poolId = volume.getPoolId();
diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index 6df17ca4dda..e58dd110afd 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -4396,6 +4396,12 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
try {
// if we don't have a host, the VM we are attaching the disk to has never been started before
if (host != null) {
+ try {
+ volService.checkAndRepairVolumeBasedOnConfig(volFactory.getVolume(volumeToAttach.getId()), host);
+ } catch (Exception e) {
+ s_logger.debug(String.format("Unable to check and repair volume [%s] on host [%s], due to %s.", volumeToAttach.getName(), host, e.getMessage()));
+ }
+
try {
volService.grantAccess(volFactory.getVolume(volumeToAttach.getId()), host, dataStore);
} catch (Exception e) {