Maor Lipchuk has uploaded a new change for review.

Change subject: core: Force remove should not delete VMs with MSD.
......................................................................

core: Force remove should not delete VMs with MSD.

When the admin chooses to force destroy a storage domain, the operation
should remove all the entities related to the Data Storage Domain.

Since version 3.1 we have added the ability for VMs to have disks on multiple 
storage domains.
Today, when using force reomve on Storage Domain, we also remove VMs with disks 
on multiple storage domains,
those disks on the other data storage domains are left as floating disks in the 
system,
even though they might contain snapshots of the deleted VM.

This patch fix this behaviour by leaving the VMs with disks on MSD, when using 
force remove.
It also delete the devices which are related to those VMs,
since until now these devices were delete cascade with the VM.

Change-Id: Ic222ee55a711ea9101bf20ac812219714f70aab3
Signed-off-by: Maor Lipchuk <[email protected]>
---
M packaging/dbscripts/storages_sp.sql
1 file changed, 43 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/37/28537/1

diff --git a/packaging/dbscripts/storages_sp.sql 
b/packaging/dbscripts/storages_sp.sql
index 00405a9..b848502 100644
--- a/packaging/dbscripts/storages_sp.sql
+++ b/packaging/dbscripts/storages_sp.sql
@@ -674,15 +674,53 @@
      and entity_type = 'TEMPLATE';
 
    BEGIN
+      -- All the VMs which have disks on other storage domains.
+      CREATE TEMPORARY TABLE VMS_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE 
AS
+      SELECT DISTINCT vm_static.vm_guid
+      FROM vm_static
+      INNER JOIN (SELECT vm_static.vm_guid
+                  FROM vm_static
+                  INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
+                  INNER JOIN images i ON i.image_group_id = vd.device_id
+                  INNER JOIN (SELECT image_id
+                              FROM image_storage_domain_map
+                              WHERE image_storage_domain_map.storage_domain_id 
= v_storage_domain_id) isd_map
+                              ON i.image_guid = isd_map.image_id WHERE 
entity_type = 'VM') vms_with_disks_on_storage_domain ON vm_static.vm_guid = 
vms_with_disks_on_storage_domain.vm_guid
+      INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
+      INNER JOIN images i ON i.image_group_id = vd.device_id
+      INNER JOIN image_storage_domain_map on i.image_guid = 
image_storage_domain_map.image_id
+      WHERE image_storage_domain_map.storage_domain_id != v_storage_domain_id;
+         exception when others then
+         truncate table VMS_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE;
+         INSERT INTO VMS_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE
+         SELECT DISTINCT vm_static.vm_guid
+         FROM vm_static
+         INNER JOIN (SELECT vm_static.vm_guid
+                     FROM vm_static
+                     INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
+                     INNER JOIN images i ON i.image_group_id = vd.device_id
+                     INNER JOIN (SELECT image_id
+                                 FROM image_storage_domain_map
+                                 WHERE 
image_storage_domain_map.storage_domain_id = v_storage_domain_id) isd_map
+                                 ON i.image_guid = isd_map.image_id WHERE 
entity_type = 'VM') vms_with_disks_on_storage_domain ON vm_static.vm_guid = 
vms_with_disks_on_storage_domain.vm_guid
+         INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
+         INNER JOIN images i ON i.image_group_id = vd.device_id
+         INNER JOIN image_storage_domain_map on i.image_guid = 
image_storage_domain_map.image_id
+         WHERE image_storage_domain_map.storage_domain_id != 
v_storage_domain_id;
+   END;
+
+   BEGIN
      -- Vms which resides on the storage domain
      CREATE TEMPORARY TABLE VM_IDS_TEMPORARY_TABLE AS select 
vm_id,vm_images_view.entity_type as entity_type from vm_images_view
             JOIN vm_device ON vm_device.device_id = vm_images_view.disk_id
-            WHERE v_storage_domain_id in (SELECT * FROM 
fnsplitteruuid(storage_id));
+            WHERE v_storage_domain_id in (SELECT * FROM 
fnsplitteruuid(storage_id))
+              AND vm_id not in (SELECT vm_guid from 
VMS_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE);
      exception when others then
      truncate table VM_IDS_TEMPORARY_TABLE;
      insert into VM_IDS_TEMPORARY_TABLE select 
vm_id,vm_images_view.entity_type as entity_type from vm_images_view
             JOIN vm_device ON vm_device.device_id = vm_images_view.disk_id
-            WHERE v_storage_domain_id in (SELECT * FROM 
fnsplitteruuid(storage_id));
+            WHERE v_storage_domain_id in (SELECT * FROM 
fnsplitteruuid(storage_id))
+              AND vm_id not in (SELECT vm_guid from 
VMS_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE);
    END;
 
    delete FROM permissions where object_id in (select vm_id as vm_guid from 
VM_IDS_TEMPORARY_TABLE where entity_type <> 'TEMPLATE');
@@ -694,6 +732,9 @@
    delete FROM permissions where object_id in (select vm_guid from 
TEMPLATES_IDS_TEMPORARY_TABLE);
    delete FROM vm_static where vm_guid in(select vm_id as vm_guid from 
VM_IDS_TEMPORARY_TABLE where entity_type <> 'TEMPLATE');
 
+   -- Delete devices which are related to VMs with MSD (VMs which has not 
removed)
+   delete FROM vm_device where device_id in (select disk_id from 
STORAGE_DOMAIN_MAP_TABLE);
+
    -- Delete pools and snapshots of pools based on templates from the storage 
domain to be removed
    delete FROM snapshots where vm_id in (select vm_guid FROM vm_static where 
vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE));
    delete FROM vm_static where vmt_guid in (select vm_guid from 
TEMPLATES_IDS_TEMPORARY_TABLE);


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

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

Reply via email to