Skip to content

Commit

Permalink
core: code improvements of LSM cleanup destination method
Browse files Browse the repository at this point in the history
Some code improvements for method that should handle destination
disk cleanups in case of Live Storage Migration failure.

1. Renaming cleanup method to "cleanupDestDiskAfterFailure()".
2. Internal code reorganization for readability.

Signed-off-by: Pavel Bar <pbar@redhat.com>
Bug-Url: https://bugzilla.redhat.com/2102149
  • Loading branch information
barpavel committed Aug 2, 2022
1 parent 24c9d60 commit 8bf2224
Showing 1 changed file with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,10 @@ public boolean performNextOperation(int completedChildCount) {
}

updateStage(LiveDiskMigrateStage.SOURCE_IMAGE_DELETION);
removeImage(getParameters().getSourceStorageDomainId(), getParameters()
.getImageGroupID(), getParameters().getDestinationImageId(), AuditLogType
.USER_MOVE_IMAGE_GROUP_FAILED_TO_DELETE_SRC_IMAGE);
removeImage(getParameters().getSourceStorageDomainId(),
getParameters().getImageGroupID(),
getParameters().getDestinationImageId(),
AuditLogType.USER_MOVE_IMAGE_GROUP_FAILED_TO_DELETE_SRC_IMAGE);
updateStage(LiveDiskMigrateStage.LIVE_MIGRATE_DISK_EXEC_COMPLETED);
return true;
}
Expand Down Expand Up @@ -388,7 +389,7 @@ protected void endWithFailure() {
}

super.endWithFailure();
handleDestDisk();
cleanupDestDiskAfterFailure();

// Handle snapshot removal
log.info("Attempting to remove the auto-generated snapshot");
Expand Down Expand Up @@ -743,39 +744,42 @@ private String getDiskIsBeingMigratedMessage(Disk disk) {
+ String.format("$DiskName %1$s", disk != null ? disk.getDiskAlias() : "");
}

private void handleDestDisk() {
if (getParameters().getLiveDiskMigrateStage() != LiveDiskMigrateStage.CREATE_SNAPSHOT &&
getParameters().getLiveDiskMigrateStage() != LiveDiskMigrateStage.CLONE_IMAGE_STRUCTURE &&
getParameters().getLiveDiskMigrateStage() != LiveDiskMigrateStage.SOURCE_IMAGE_DELETION) {
if (Guid.Empty.equals(getParameters().getVdsId())) {
log.error("Failed during live storage migration of disk '{}' of vm '{}', as the vm is not running" +
" on any host not attempting to end the replication before the target disk deletion",
getParameters().getImageGroupID(), getParameters().getVmId());
} else {
log.error("Failed during live storage migration of disk '{}' of vm '{}', attempting to end " +
"replication before deleting the target disk",
getParameters().getImageGroupID(), getParameters().getVmId());
try {
replicateDiskFinish(getParameters().getSourceStorageDomainId(),
getParameters().getSourceStorageDomainId());
} catch (Exception e) {
if (e instanceof EngineException &&
EngineError.ReplicationNotInProgress.equals(((EngineException) e).getErrorCode())) {
log.warn("Replication is not in progress, proceeding with removing the target disk");
} else {
log.error("Replication end of disk '{}' in vm '{}' back to the source failed, skipping deletion of " +
"the target disk", getParameters().getImageGroupID(), getParameters().getVmId());
return;
}
}
}
private void cleanupDestDiskAfterFailure() {
if (getParameters().getLiveDiskMigrateStage() == LiveDiskMigrateStage.CREATE_SNAPSHOT ||
getParameters().getLiveDiskMigrateStage() == LiveDiskMigrateStage.CLONE_IMAGE_STRUCTURE ||
getParameters().getLiveDiskMigrateStage() == LiveDiskMigrateStage.SOURCE_IMAGE_DELETION) {
return;
}

log.error("Attempting to delete the target of disk '{}' of vm '{}'",
if (Guid.Empty.equals(getParameters().getVdsId())) {
log.error("Failed during live storage migration of disk '{}' of vm '{}', as the vm is not running" +
" on any host not attempting to end the replication before the target disk deletion",
getParameters().getImageGroupID(), getParameters().getVmId());
removeImage(getParameters().getTargetStorageDomainId(), getParameters()
.getImageGroupID(), getParameters().getDestinationImageId(), AuditLogType
.USER_MOVE_IMAGE_GROUP_FAILED_TO_DELETE_DST_IMAGE);
} else {
log.error("Failed during live storage migration of disk '{}' of vm '{}', attempting to end " +
"replication before deleting the target disk",
getParameters().getImageGroupID(), getParameters().getVmId());
try {
replicateDiskFinish(getParameters().getSourceStorageDomainId(),
getParameters().getSourceStorageDomainId());
} catch (Exception e) {
if (e instanceof EngineException &&
EngineError.ReplicationNotInProgress.equals(((EngineException) e).getErrorCode())) {
log.warn("Replication is not in progress, proceeding with removing the target disk");
} else {
log.error("Replication end of disk '{}' in vm '{}' back to the source failed, skipping deletion of " +
"the target disk", getParameters().getImageGroupID(), getParameters().getVmId());
return;
}
}
}

log.error("Attempting to delete the target of disk '{}' of vm '{}'",
getParameters().getImageGroupID(), getParameters().getVmId());
removeImage(getParameters().getTargetStorageDomainId(),
getParameters().getImageGroupID(),
getParameters().getDestinationImageId(),
AuditLogType.USER_MOVE_IMAGE_GROUP_FAILED_TO_DELETE_DST_IMAGE);
}

@Override
Expand Down

0 comments on commit 8bf2224

Please sign in to comment.