Introduced new global setting volume.check.and.repair.before.use to do volume check and repair before VM start or volume attach operations

This commit is contained in:
Harikrishna Patnala 2024-01-30 13:12:54 +05:30
parent 2710405e81
commit 94e7051c6e
3 changed files with 22 additions and 11 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;