Skip to content

Commit 1768b5b

Browse files
JoaoJandreCopilot
andcommitted
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5caf6cd commit 1768b5b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,8 +2093,25 @@ protected void rebaseSnapshot(SnapshotObjectTO snapshotObjectTO, KVMStoragePool
20932093
QemuImg qemuImg = new QemuImg(wait);
20942094
qemuImg.rebase(snapshotFile, parentSnapshotFile, PhysicalDiskFormat.QCOW2.toString(), false);
20952095
} catch (LibvirtException | QemuImgException e) {
2096-
logger.error("Exception while rebasing incremental snapshot [{}] due to: [{}].", snapshotName, e.getMessage(), e);
2097-
throw new CloudRuntimeException(e);
2096+
if (!StringUtils.contains(e.getMessage(), "Is another process using the image")) {
2097+
logger.error("Exception while rebasing incremental snapshot [{}] due to: [{}].", snapshotName, e.getMessage(), e);
2098+
throw new CloudRuntimeException(e);
2099+
}
2100+
retryRebase(snapshotName, wait, e, snapshotFile, parentSnapshotFile);
2101+
}
2102+
}
2103+
2104+
private void retryRebase(String snapshotName, int wait, Exception e, QemuImgFile snapshotFile, QemuImgFile parentSnapshotFile) {
2105+
logger.warn("Libvirt still has not released the lock, will wait 60 seconds and try again later.");
2106+
try {
2107+
Thread.sleep(60*1000);
2108+
QemuImg qemuImg = new QemuImg(wait);
2109+
qemuImg.rebase(snapshotFile, parentSnapshotFile, PhysicalDiskFormat.QCOW2.toString(), false);
2110+
} catch (LibvirtException | QemuImgException | InterruptedException ex) {
2111+
logger.error("Unable to rebase snapshot [{}].", snapshotName, ex);
2112+
CloudRuntimeException cre = new CloudRuntimeException(ex);
2113+
cre.addSuppressed(e);
2114+
throw cre;
20982115
}
20992116
}
21002117

0 commit comments

Comments
 (0)