Skip to content

Commit

Permalink
core: LSM - remove redundant code
Browse files Browse the repository at this point in the history
1) Remove "is qualified for live merge" check:
   Block commit is used since 4.2, see [1], [2].
   So "getVm().getStatus().isQualifiedForLiveSnapshotMerge()"
   check is not needed anymore.
2) Remove redundant enum check:
  a) Simplifying the "isRemoveAutoGeneratedSnapshotRequired()" method:
     There is no need to test the 2nd part in the condition that looks like:
       stage == enumA && stage != enumB
  b) After the above simplification, the method can be inlined to receive
     an even more simple code.

[1] https://bugzilla.redhat.com/1246114
[2] https://bugzilla.redhat.com/1369942

Signed-off-by: Pavel Bar <pbar@redhat.com>
  • Loading branch information
barpavel authored and ahadas committed Jul 20, 2022
1 parent abc92ef commit dfe2c4b
Showing 1 changed file with 1 addition and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public boolean performNextOperation(int completedChildCount) {
return true;
}

if (isRemoveAutoGeneratedSnapshotRequired()) {
if (getParameters().getLiveDiskMigrateStage() == LiveDiskMigrateStage.LIVE_MIGRATE_DISK_EXEC_COMPLETED) {
// This lock is required to prevent CreateSnapshotForVmCommand from
// running at the same time as RemoveSnapshotCommand
//
Expand Down Expand Up @@ -326,25 +326,6 @@ private void removeImage(Guid storageDomainId, Guid imageGroupId, Guid imageId,
}
}

private boolean isRemoveAutoGeneratedSnapshotRequired() {
boolean removeSnapshotRequired = getParameters().getLiveDiskMigrateStage() == LiveDiskMigrateStage.LIVE_MIGRATE_DISK_EXEC_COMPLETED &&
getParameters().getLiveDiskMigrateStage() != LiveDiskMigrateStage.AUTO_GENERATED_SNAPSHOT_REMOVE_END;
if (removeSnapshotRequired) {
if (!getVm().getStatus().isQualifiedForLiveSnapshotMerge()) {
// If the VM is not qualified for live merge, i.e. its status is not up, the auto-generated snapshot
// is not removed. Removing the snapshot while the VM isn't running will end up with cold merge
// and this is not desired here.
// Once cold merge enhanced to use qemu-img commit, this limit can be removed. See BZ 1246114.
// This behavior can be tracked by BZ 1369942.
log.warn("Auto-generated snapshot cannot be removed because VM isn't qualified for live merge. VM status is '{}'",
getVm().getStatus());
removeSnapshotRequired = false;
}
}

return removeSnapshotRequired;
}

private void removeAutogeneratedSnapshot(CommandContext commandContext, ActionType actionType, LiveMigrateDiskParameters parameters) {
RemoveSnapshotParameters removeSnapshotParameters = new RemoveSnapshotParameters(getParameters().getAutoGeneratedSnapshotId(),
getVmId());
Expand Down

0 comments on commit dfe2c4b

Please sign in to comment.