Skip to content

Commit 7c7b2ae

Browse files
authored
Fix KVM incremental volume snapshot creation (#12666)
1 parent b196e97 commit 7c7b2ae

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

agent/conf/agent.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,6 @@ iscsi.session.cleanup.enabled=false
457457

458458
# Instance conversion VIRT_V2V_TMPDIR env var
459459
#convert.instance.env.virtv2v.tmpdir=
460+
461+
# Time, in seconds, to wait before retrying to rebase during the incremental snapshot process.
462+
# incremental.snapshot.retry.rebase.wait=60

agent/src/main/java/com/cloud/agent/properties/AgentProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ public Property<Integer> getWorkers() {
885885
*/
886886
public static final Property<Boolean> CREATE_FULL_CLONE = new Property<>("create.full.clone", false);
887887

888+
/**
889+
* Time, in seconds, to wait before retrying to rebase during the incremental snapshot process.
890+
* */
891+
public static final Property<Integer> INCREMENTAL_SNAPSHOT_RETRY_REBASE_WAIT = new Property<>("incremental.snapshot.retry.rebase.wait", 60);
892+
888893

889894
public static class Property <T>{
890895
private String name;

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ public class KVMStorageProcessor implements StorageProcessor {
185185

186186
private int incrementalSnapshotTimeout;
187187

188+
private int incrementalSnapshotRetryRebaseWait;
189+
188190
private static final String CHECKPOINT_XML_TEMP_DIR = "/tmp/cloudstack/checkpointXMLs";
189191

190192
private static final String BACKUP_XML_TEMP_DIR = "/tmp/cloudstack/backupXMLs";
@@ -252,6 +254,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
252254
_cmdsTimeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CMDS_TIMEOUT) * 1000;
253255

254256
incrementalSnapshotTimeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.INCREMENTAL_SNAPSHOT_TIMEOUT) * 1000;
257+
incrementalSnapshotRetryRebaseWait = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.INCREMENTAL_SNAPSHOT_RETRY_REBASE_WAIT) * 1000;
255258
return true;
256259
}
257260

@@ -2093,8 +2096,25 @@ protected void rebaseSnapshot(SnapshotObjectTO snapshotObjectTO, KVMStoragePool
20932096
QemuImg qemuImg = new QemuImg(wait);
20942097
qemuImg.rebase(snapshotFile, parentSnapshotFile, PhysicalDiskFormat.QCOW2.toString(), false);
20952098
} catch (LibvirtException | QemuImgException e) {
2096-
logger.error("Exception while rebasing incremental snapshot [{}] due to: [{}].", snapshotName, e.getMessage(), e);
2097-
throw new CloudRuntimeException(e);
2099+
if (!StringUtils.contains(e.getMessage(), "Is another process using the image")) {
2100+
logger.error("Exception while rebasing incremental snapshot [{}] due to: [{}].", snapshotName, e.getMessage(), e);
2101+
throw new CloudRuntimeException(e);
2102+
}
2103+
retryRebase(snapshotName, wait, e, snapshotFile, parentSnapshotFile);
2104+
}
2105+
}
2106+
2107+
private void retryRebase(String snapshotName, int wait, Exception e, QemuImgFile snapshotFile, QemuImgFile parentSnapshotFile) {
2108+
logger.warn("Libvirt still has not released the lock, will wait [{}] milliseconds and try again later.", incrementalSnapshotRetryRebaseWait);
2109+
try {
2110+
Thread.sleep(incrementalSnapshotRetryRebaseWait);
2111+
QemuImg qemuImg = new QemuImg(wait);
2112+
qemuImg.rebase(snapshotFile, parentSnapshotFile, PhysicalDiskFormat.QCOW2.toString(), false);
2113+
} catch (LibvirtException | QemuImgException | InterruptedException ex) {
2114+
logger.error("Unable to rebase snapshot [{}].", snapshotName, ex);
2115+
CloudRuntimeException cre = new CloudRuntimeException(ex);
2116+
cre.addSuppressed(e);
2117+
throw cre;
20982118
}
20992119
}
21002120

0 commit comments

Comments
 (0)