Skip to content

Commit af0f642

Browse files
kvm: Suspending the VM prior to deleting snapshots to avoid corruption, th… (#4032)
These changes are related to PR #3194, but include suspending/resuming the VM when doing a VM snapshot as well, when deleting a VM snapshot, as it is performing the same operations via Libvirt. Also, there was an issue with the UI/localization changes in the prior PR, as that PR was altering the Volume snapshot behavior, but was altering the VM snapshot wording. Both have been altered in this PR. Issuing this in response to the work happening in PR #4029.
1 parent 7874918 commit af0f642

19 files changed

Lines changed: 47 additions & 11 deletions

File tree

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.apache.log4j.Logger;
2525
import org.libvirt.Connect;
2626
import org.libvirt.Domain;
27-
import org.libvirt.DomainInfo.DomainState;
27+
import org.libvirt.DomainInfo;
2828
import org.libvirt.DomainSnapshot;
2929
import org.libvirt.LibvirtException;
3030

@@ -52,18 +52,33 @@ public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingR
5252
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
5353
Domain dm = null;
5454
DomainSnapshot snapshot = null;
55+
DomainInfo.DomainState oldState = null;
56+
boolean tryingResume = false;
57+
Connect conn = null;
5558
try {
5659
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
57-
Connect conn = libvirtUtilitiesHelper.getConnection();
60+
conn = libvirtUtilitiesHelper.getConnection();
5861
dm = libvirtComputingResource.getDomain(conn, vmName);
5962

6063
snapshot = dm.snapshotLookupByName(cmd.getTarget().getSnapshotName());
6164

62-
s_logger.debug("Suspending domain " + vmName);
63-
dm.suspend(); // suspend the vm to avoid image corruption
65+
oldState = dm.getInfo().state;
66+
if (oldState == DomainInfo.DomainState.VIR_DOMAIN_RUNNING) {
67+
s_logger.debug("Suspending domain " + vmName);
68+
dm.suspend(); // suspend the vm to avoid image corruption
69+
}
6470

6571
snapshot.delete(0); // only remove this snapshot, not children
6672

73+
if (oldState == DomainInfo.DomainState.VIR_DOMAIN_RUNNING) {
74+
// Resume the VM
75+
tryingResume = true;
76+
dm = libvirtComputingResource.getDomain(conn, vmName);
77+
if (dm.getInfo().state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
78+
dm.resume();
79+
}
80+
}
81+
6782
return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
6883
} catch (LibvirtException e) {
6984
String msg = " Delete VM snapshot failed due to " + e.toString();
@@ -97,21 +112,26 @@ public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingR
97112
} else if (snapshot == null) {
98113
s_logger.debug("Can not find vm snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + ", return true");
99114
return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
115+
} else if (tryingResume) {
116+
s_logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e);
117+
return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
100118
}
101119

102120
s_logger.warn(msg, e);
103121
return new DeleteVMSnapshotAnswer(cmd, false, msg);
104122
} finally {
105123
if (dm != null) {
124+
// Make sure if the VM is paused, then resume it, in case we got an exception during our delete() and didn't have the chance before
106125
try {
107-
if (dm.getInfo().state == DomainState.VIR_DOMAIN_PAUSED) {
126+
dm = libvirtComputingResource.getDomain(conn, vmName);
127+
if (oldState == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && dm.getInfo().state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
108128
s_logger.debug("Resuming domain " + vmName);
109129
dm.resume();
110130
}
111131
dm.free();
112-
} catch (LibvirtException l) {
113-
s_logger.trace("Ignoring libvirt error.", l);
114-
};
132+
} catch (LibvirtException e) {
133+
s_logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e);
134+
}
115135
}
116136
}
117137
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ public Answer backupSnapshot(final CopyCommand cmd) {
10311031
}
10321032
}
10331033
} catch (final Exception ex) {
1034-
s_logger.debug("Failed to delete snapshots on primary", ex);
1034+
s_logger.error("Failed to delete snapshots on primary", ex);
10351035
}
10361036
}
10371037

ui/legacy/l10n/ar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ var dictionary = {
18881888
"message.action.stop.router": "All services provided by this virtual router will be interrupted. Please confirm that you want to stop this router.",
18891889
"message.action.stop.systemvm": "Please confirm that you want to stop this system VM.",
18901890
"message.action.take.snapshot": "Please confirm that you want to take a snapshot of this volume.",
1891+
"message.action.snapshot.fromsnapshot":"Please confirm that you want to take a snapshot of this VM snapshot.",
18911892
"message.action.unmanage.cluster": "Please confirm that you want to unmanage the cluster.",
18921893
"message.action.vmsnapshot.create": "Please confirm that you want to take a snapshot of this instance. <br>Please notice that the instance will be paused during the snapshoting, and resumed after snapshotting, if it runs on KVM.",
18931894
"message.action.vmsnapshot.delete": "Please confirm that you want to delete this VM snapshot.",

ui/legacy/l10n/ca.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ var dictionary = {
18881888
"message.action.stop.router": "All services provided by this virtual router will be interrupted. Please confirm that you want to stop this router.",
18891889
"message.action.stop.systemvm": "Please confirm that you want to stop this system VM.",
18901890
"message.action.take.snapshot": "Please confirm that you want to take a snapshot of this volume.",
1891+
"message.action.snapshot.fromsnapshot":"Please confirm that you want to take a snapshot of this VM snapshot.",
18911892
"message.action.unmanage.cluster": "Please confirm that you want to unmanage the cluster.",
18921893
"message.action.vmsnapshot.create": "Please confirm that you want to take a snapshot of this instance. <br>Please notice that the instance will be paused during the snapshoting, and resumed after snapshotting, if it runs on KVM.",
18931894
"message.action.vmsnapshot.delete": "Please confirm that you want to delete this VM snapshot.",

ui/legacy/l10n/de_DE.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ var dictionary = {
18901890
"message.action.stop.router": "Alle von diesem Router angebotenen Dienste werden unterbrochen. Bitte bestätigen Sie, dass Sie diesen Router stoppen möchten.",
18911891
"message.action.stop.systemvm": "Bitte bestätigen Sie, dass Sie diese System-VM stoppen möchten.",
18921892
"message.action.take.snapshot": "Bitte bestätigen Sie, dass Sie einen Schnappschuss von diesem Volumen sichern möchten.",
1893+
"message.action.snapshot.fromsnapshot":"Bitte bestätigen Sie, dass Sie einen Schnappschuss von diesem VM Schnappschuss sichern möchten.",
18931894
"message.action.unmanage.cluster": "Bitte bestätigen Sie, dass Sie das Cluster vernachlässigen möchten.",
18941895
"message.action.vmsnapshot.create": "Please confirm that you want to take a snapshot of this instance. <br>Please notice that the instance will be paused during the snapshoting, and resumed after snapshotting, if it runs on KVM.",
18951896
"message.action.vmsnapshot.delete": "Bitte bestätigen Sie, dass Sie diesen VM Schnappschuss löschen wollen.",

ui/legacy/l10n/en.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,8 @@ var dictionary = {
20482048
"message.action.stop.router":"All services provided by this virtual router will be interrupted. Please confirm that you want to stop this router.",
20492049
"message.action.router.health.checks":"Health checks result will be fetched from router.",
20502050
"message.action.stop.systemvm":"Please confirm that you want to stop this system VM.",
2051-
"message.action.take.snapshot":"Please confirm that you want to take a snapshot of this volume.",
2051+
"message.action.take.snapshot":"Please confirm that you want to take a snapshot of this volume.<br>Note that if this volume is in use by an instance running on KVM, the instance will be paused prior to, and resumed after creation of the snapshot",
2052+
"message.action.snapshot.fromsnapshot":"Please confirm that you want to take a snapshot of this VM snapshot.",
20522053
"message.action.unmanage.cluster":"Please confirm that you want to unmanage the cluster.",
20532054
"message.action.vmsnapshot.create":"Please confirm that you want to take a snapshot of this instance. <br>Please notice that the instance will be paused during the snapshoting, and resumed after snapshotting, if it runs on KVM.",
20542055
"message.action.vmsnapshot.delete":"Please confirm that you want to delete this VM snapshot. <br>Please notice that the instance will be paused before the snapshot deletion, and resumed after deletion, if it runs on KVM.",

ui/legacy/l10n/es.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,7 @@ var dictionary = {
18891889
"message.action.stop.router": "Todos los servicios provistos por este router virtual serán interrumpidos. Por favor confirmar que desea apagarlo.",
18901890
"message.action.stop.systemvm": "Por favor, confirme que desea detener esta MV de Sistema. ",
18911891
"message.action.take.snapshot": "Por favor, confirme que desea tomar una instantánea de este volúmen.",
1892+
"message.action.snapshot.fromsnapshot":"Por favor, confirme que desea tomar una instantánea de este instantánea VM.",
18921893
"message.action.unmanage.cluster": "Por favor, confirme que desea dejar de gestionar el Clúster.",
18931894
"message.action.vmsnapshot.create": "Please confirm that you want to take a snapshot of this instance. <br>Please notice that the instance will be paused during the snapshoting, and resumed after snapshotting, if it runs on KVM.",
18941895
"message.action.vmsnapshot.delete": "Por favor confirme que desea borrar esta instantánea de la MV.",

ui/legacy/l10n/fr_FR.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ var dictionary = {
18901890
"message.action.stop.router": "Tous les services fournit par ce routeur virtuel vont être interrompus. Confirmer l'arrêt de ce routeur.",
18911891
"message.action.stop.systemvm": "Arrêter cette VM ?",
18921892
"message.action.take.snapshot": "Confirmer la prise d'un instantané pour ce volume.",
1893+
"message.action.snapshot.fromsnapshot":"Confirmer la prise d'un instantané pour ce instantané VM.",
18931894
"message.action.unmanage.cluster": "Confirmez que vous ne voulez plus gérer le cluster",
18941895
"message.action.vmsnapshot.create": "Veuillez confirmer que vous souhaitez prendre un instantané de cette instance. <br>Notez que l'instance sera mise en pause durant la prise de l'instantané puis remise en route une fois terminée, si elle fonctionne sur KVM.",
18951896
"message.action.vmsnapshot.delete": "Confirmez que vous souhaitez supprimer cet instantané VM.",

ui/legacy/l10n/hu.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ var dictionary = {
18881888
"message.action.stop.router": "Minden ezzel a routerrel kapcsolatos szolgáltatás megszakad. Erősítsd meg, hogy le akarod állítani ezt a routert!",
18891889
"message.action.stop.systemvm": "Erősítsd meg, hogy le akarod állítani ezt a rendszer VM-et!",
18901890
"message.action.take.snapshot": "Erősítsd meg, hogy pillanatfelvételt kérsz erről a kötetről!",
1891+
"message.action.snapshot.fromsnapshot":"Erősítsd meg, hogy pillanatfelvételt kérsz erről a VM pillanatfelvételt!",
18911892
"message.action.unmanage.cluster": "Erősítsd meg, hogy megszakítod a fürt vezérlését!",
18921893
"message.action.vmsnapshot.create": "Please confirm that you want to take a snapshot of this instance. <br>Please notice that the instance will be paused during the snapshoting, and resumed after snapshotting, if it runs on KVM.",
18931894
"message.action.vmsnapshot.delete": "Erősítsd meg, hogy törölni akarod ezt a VM pillanatfelvételt!",

ui/legacy/l10n/it_IT.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ var dictionary = {
18881888
"message.action.stop.router": "Tutti i servizi forniti da questo router virtuale saranno interrotti. Si prega di confermare di voler arrestare questo router.",
18891889
"message.action.stop.systemvm": "Please confirm that you want to stop this system VM.",
18901890
"message.action.take.snapshot": "Please confirm that you want to take a snapshot of this volume.",
1891+
"message.action.snapshot.fromsnapshot":"Please confirm that you want to take a snapshot of this VM snapshot.",
18911892
"message.action.unmanage.cluster": "Please confirm that you want to unmanage the cluster.",
18921893
"message.action.vmsnapshot.create": "Please confirm that you want to take a snapshot of this instance. <br>Please notice that the instance will be paused during the snapshoting, and resumed after snapshotting, if it runs on KVM.",
18931894
"message.action.vmsnapshot.delete": "Please confirm that you want to delete this VM snapshot.",

0 commit comments

Comments
 (0)