@@ -571,9 +571,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
571571 * 1st parameter: VM's name;<br>
572572 * 2nd parameter: disk's label (target.dev tag from VM's XML);<br>
573573 * 3rd parameter: the absolute path of the base file;
574- * 4th parameter: the flag '--delete', if Libvirt supports it. Libvirt started to support it on version <b>6.0.0</b>;
575574 */
576- private static final String COMMAND_MERGE_SNAPSHOT = "virsh blockcommit %s %s --base %s --active --wait %s --pivot " ;
575+ private static final String COMMAND_MERGE_SNAPSHOT = "virsh blockcommit %s %s --base %s" ;
577576
578577 public long getHypervisorLibvirtVersion () {
579578 return hypervisorLibvirtVersion ;
@@ -5878,7 +5877,7 @@ public void mergeSnapshotIntoBaseFile(Domain vm, String diskLabel, String baseFi
58785877 if (AgentPropertiesFileHandler .getPropertyValue (AgentProperties .LIBVIRT_EVENTS_ENABLED )) {
58795878 mergeSnapshotIntoBaseFileWithEventsAndConfigurableTimeout (vm , diskLabel , baseFilePath , topFilePath , active , snapshotName , volume , conn );
58805879 } else {
5881- mergeSnapshotIntoBaseFileWithoutEvents (vm , diskLabel , baseFilePath , snapshotName , volume , conn );
5880+ mergeSnapshotIntoBaseFileWithoutEvents (vm , diskLabel , baseFilePath , topFilePath , active , snapshotName , volume , conn );
58825881 }
58835882 }
58845883
@@ -5949,10 +5948,10 @@ protected void mergeSnapshotIntoBaseFileWithEventsAndConfigurableTimeout(Domain
59495948 * @param snapshotName Name of the snapshot;
59505949 * @throws LibvirtException
59515950 */
5952- protected void mergeSnapshotIntoBaseFileWithoutEvents (Domain vm , String diskLabel , String baseFilePath , String snapshotName , VolumeObjectTO volume , Connect conn ) throws LibvirtException {
5951+ protected void mergeSnapshotIntoBaseFileWithoutEvents (Domain vm , String diskLabel , String baseFilePath , String topFilePath , boolean active , String snapshotName , VolumeObjectTO volume , Connect conn ) throws LibvirtException {
59535952 boolean isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit = LibvirtUtilitiesHelper .isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit (conn );
59545953 String vmName = vm .getName ();
5955- String mergeCommand = String . format ( COMMAND_MERGE_SNAPSHOT , vmName , diskLabel , baseFilePath , isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit ? "--delete" : "" );
5954+ String mergeCommand = buildMergeCommand ( vmName , diskLabel , baseFilePath , topFilePath , active , isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit );
59565955 String mergeResult = Script .runSimpleBashScript (mergeCommand );
59575956
59585957 if (mergeResult == null ) {
@@ -5969,6 +5968,22 @@ protected void mergeSnapshotIntoBaseFileWithoutEvents(Domain vm, String diskLabe
59695968 throw new CloudRuntimeException (errorMsg );
59705969 }
59715970
5971+ protected String buildMergeCommand (String vmName , String diskLabel , String baseFilePath , String topFilePath , boolean active , boolean delete ) {
5972+ StringBuilder cmd = new StringBuilder (COMMAND_MERGE_SNAPSHOT );
5973+ if (StringUtils .isNotEmpty (topFilePath )) {
5974+ cmd .append (" --top " );
5975+ cmd .append (topFilePath );
5976+ }
5977+ if (active ) {
5978+ cmd .append (" --active --pivot" );
5979+ }
5980+ if (delete ) {
5981+ cmd .append (" --delete" );
5982+ }
5983+ cmd .append (" --wait" );
5984+ return String .format (cmd .toString (), vmName , diskLabel , baseFilePath );
5985+ }
5986+
59725987 /**
59735988 * This was created to facilitate testing.
59745989 * */
0 commit comments