kvm: suspend/resume in deleting vm snapshot on kvm (#4033)

This commit is contained in:
Wei Zhou 2020-04-16 15:14:47 +02:00 committed by GitHub
parent 1d34eed43c
commit 2637a86ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.log4j.Logger;
import org.libvirt.Connect;
import org.libvirt.Domain;
import org.libvirt.DomainInfo.DomainState;
import org.libvirt.DomainSnapshot;
import org.libvirt.LibvirtException;
@ -58,6 +59,9 @@ public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper<
snapshot = dm.snapshotLookupByName(cmd.getTarget().getSnapshotName());
s_logger.debug("Suspending domain " + vmName);
dm.suspend(); // suspend the vm to avoid image corruption
snapshot.delete(0); // only remove this snapshot, not children
return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
@ -100,6 +104,10 @@ public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper<
} finally {
if (dm != null) {
try {
if (dm.getInfo().state == DomainState.VIR_DOMAIN_PAUSED) {
s_logger.debug("Resuming domain " + vmName);
dm.resume();
}
dm.free();
} catch (LibvirtException l) {
s_logger.trace("Ignoring libvirt error.", l);