Greg Padgett has uploaded a new change for review.

Change subject: core: Don't erroneously remove template->storage mappings
......................................................................

core: Don't erroneously remove template->storage mappings

If a storage domain is destroyed and a template has a disk on that SD,
the image is removed regardless of whether that image also resides on
other SDs.  In the case where the template disk has been copied, the
template and images should remain intact and only the references for the
specific SD being removed should be deleted.

Change-Id: I058d160622990d2b42ccc02a61551c6f61550ade
Signed-off-by: Greg Padgett <[email protected]>
---
M backend/manager/dbscripts/storages_sp.sql
1 file changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/7192/1

diff --git a/backend/manager/dbscripts/storages_sp.sql 
b/backend/manager/dbscripts/storages_sp.sql
index a718aca..ec7eac2 100644
--- a/backend/manager/dbscripts/storages_sp.sql
+++ b/backend/manager/dbscripts/storages_sp.sql
@@ -516,24 +516,30 @@
 BEGIN
        
    BEGIN
+      -- Images residing on only the specified storage domain
       CREATE GLOBAL TEMPORARY TABLE tt_TEMPSTORAGEDOMAINMAPTABLE AS select 
image_id
-         from image_storage_domain_map where storage_domain_id = 
v_storage_domain_id;
+         from image_storage_domain_map where storage_domain_id = 
v_storage_domain_id
+         except select image_id from image_storage_domain_map where 
storage_domain_id != v_storage_domain_id;
       exception when others then
          truncate table tt_TEMPSTORAGEDOMAINMAPTABLE;
          insert into tt_TEMPSTORAGEDOMAINMAPTABLE select image_id
-         from image_storage_domain_map where storage_domain_id = 
v_storage_domain_id;
+         from image_storage_domain_map where storage_domain_id = 
v_storage_domain_id
+         except select image_id from image_storage_domain_map where 
storage_domain_id != v_storage_domain_id;
    END;
 
    BEGIN
+      -- Templates with any images residing on only the specified storage 
domain
       CREATE GLOBAL TEMPORARY TABLE TEMPLATES_IDS_TEMPORARY_TABLE AS select 
vm_device.vm_id as vm_guid
          from images_storage_domain_view
          JOIN vm_device ON vm_device.device_id = 
images_storage_domain_view.disk_id
+         JOIN tt_TEMPSTORAGEDOMAINMAPTABLE ON 
tt_TEMPSTORAGEDOMAINMAPTABLE.image_id = images_storage_domain_view.image_guid
          where entity_type = 'TEMPLATE' and storage_id = v_storage_domain_id;
       exception when others then
          truncate table TEMPLATES_IDS_TEMPORARY_TABLE;
          insert into TEMPLATES_IDS_TEMPORARY_TABLE select vm_device.vm_id as 
vm_guid
          from images_storage_domain_view
          JOIN vm_device ON vm_device.device_id = 
images_storage_domain_view.disk_id
+         JOIN tt_TEMPSTORAGEDOMAINMAPTABLE ON 
tt_TEMPSTORAGEDOMAINMAPTABLE.image_id = images_storage_domain_view.image_guid
          where entity_type = 'TEMPLATE' and storage_id = v_storage_domain_id;
    END;
 
@@ -541,7 +547,7 @@
 
    delete FROM permissions where object_id in (select vm_id as vm_guid from 
vm_images_view
                                                               JOIN vm_device 
ON vm_device.device_id = vm_images_view.disk_id
-                                                              where 
v_storage_domain_id in (SELECT id FROM fnsplitteruuid(storage_id)));
+                                                              where 
v_storage_domain_id in (SELECT id FROM fnsplitteruuid(storage_id)) and 
vm_images_view.entity_type <> 'TEMPLATE');
    delete FROM snapshots WHERE vm_id in (select vm_id as vm_guid from 
vm_images_view
                                          JOIN vm_device ON vm_device.device_id 
= vm_images_view.disk_id
                                          where v_storage_domain_id in (SELECT 
id FROM fnsplitteruuid(storage_id)));


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I058d160622990d2b42ccc02a61551c6f61550ade
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Greg Padgett <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to