Greg Padgett has uploaded a new change for review.

Change subject: core: sync VM config after Live Merge
......................................................................

core: sync VM config after Live Merge

After a backwards merge, the child of a deleted snapshot will now have a
different image associated with it.  This needs to be reflected in the
VM configuration for the snapshot, else the disks will be marked illegal
in the UI and won't function properly when the snapshot is
previewed/reverted.

Change-Id: Ic37dc1e54b99893bca68088eee80c26e1fbf9f91
Signed-off-by: Greg Padgett <gpadg...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
2 files changed, 44 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/29803/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
index 3ac42ee..e925f4c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java
@@ -773,9 +773,18 @@
     }
 
     /**
-     * Prepare a single {@link 
org.ovirt.engine.core.common.businessentities.Snapshot} object representing a 
snapshot of a given VM without the give disk.
+     * Prepare a single {@link 
org.ovirt.engine.core.common.businessentities.Snapshot} object representing a 
snapshot of a given VM without the given disk.
      */
     public static Snapshot 
prepareSnapshotConfigWithoutImageSingleImage(Snapshot snapshot, Guid imageId) {
+        return prepareSnapshotConfigWithAlternateImage(snapshot, imageId, 
null);
+    }
+
+
+    /**
+     * Prepare a single {@link 
org.ovirt.engine.core.common.businessentities.Snapshot} object representing a 
snapshot of a given VM without the given disk,
+     * substituting a new disk in its place if a new disk is provided to the 
method.
+     */
+    public static Snapshot prepareSnapshotConfigWithAlternateImage(Snapshot 
snapshot, Guid oldImageId, DiskImage newImage) {
         try {
             OvfManager ovfManager = new OvfManager();
             String snapConfig = snapshot.getVmConfiguration();
@@ -793,18 +802,23 @@
                 Iterator<DiskImage> diskIter = snapshotImages.iterator();
                 while (diskIter.hasNext()) {
                     DiskImage imageInList = diskIter.next();
-                    if (imageInList.getImageId().equals(imageId)) {
-                        log.debugFormat("Recreating vmSnapshot {0} without the 
image {1}", snapshot.getId(), imageId);
+                    if (imageInList.getImageId().equals(oldImageId)) {
+                        log.debugFormat("Recreating vmSnapshot {0} without the 
image {1}", snapshot.getId(), oldImageId);
                         diskIter.remove();
                         break;
                     }
+                }
+
+                if (newImage != null) {
+                    log.debugFormat("Adding image {0} to vmSnapshot {1}", 
newImage.getImageId(), snapshot.getId());
+                    snapshotImages.add(newImage);
                 }
 
                 String newOvf = ovfManager.ExportVm(vmSnapshot, 
snapshotImages, ClusterUtils.getCompatibilityVersion(vmSnapshot));
                 snapshot.setVmConfiguration(newOvf);
             }
         } catch (OvfReaderException e) {
-            log.errorFormat("Can't remove image {0} from snapshot {1}", 
imageId, snapshot.getId());
+            log.errorFormat("Can't remove image {0} from snapshot {1}", 
oldImageId, snapshot.getId());
         }
         return snapshot;
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
index 413fa3b..0438f73 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotSingleDiskLiveCommand.java
@@ -22,6 +22,7 @@
 import org.ovirt.engine.core.common.businessentities.Image;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.Snapshot;
+import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmBlockJobType;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.CommandStatus;
@@ -294,6 +295,9 @@
 
             getBaseDiskDao().update(baseImage);
             getImageDao().update(baseImage.getImage());
+
+            
updateVmConfigurationForImageChange(topImage.getImage().getSnapshotId(),
+                    baseImage.getImageId(), topImage);
         }
 
         Set<Guid> imagesToUpdate = 
getParameters().getMergeStatusReturnValue().getImagesToRemove();
@@ -314,6 +318,28 @@
         }
     }
 
+    private void updateVmConfigurationForImageChange(final Guid snapshotId, 
final Guid oldImageId, final DiskImage newImage) {
+        try {
+            VM vm = getVm();
+            lockVmSnapshotsWithWait(vm);
+
+            TransactionSupport.executeInNewTransaction(
+                    new TransactionMethod<Object>() {
+                        @Override
+                        public Object runInTransaction() {
+                            Snapshot s = getSnapshotDao().get(snapshotId);
+                            s = 
ImagesHandler.prepareSnapshotConfigWithAlternateImage(s, oldImageId, newImage);
+                            getSnapshotDao().update(s);
+                            return null;
+                        }
+                    });
+        } finally {
+            if (getSnapshotsEngineLock() != null) {
+                getLockManager().releaseLock(getSnapshotsEngineLock());
+            }
+        }
+    }
+
     @Override
     protected void endSuccessfully() {
         setSucceeded(true);


-- 
To view, visit http://gerrit.ovirt.org/29803
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic37dc1e54b99893bca68088eee80c26e1fbf9f91
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Greg Padgett <gpadg...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to