@@ -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