Arik Hadas has uploaded a new change for review.

Change subject: core: model hibernation volumes as disks in the DB
......................................................................

core: model hibernation volumes as disks in the DB

Change-Id: I295bd98ead191c1eab54c471ea28a217dee52051
Signed-off-by: Arik Hadas <[email protected]>
---
A packaging/dbscripts/upgrade/03_06_0705_model_hibernation_volumes_as_disks.sql
1 file changed, 139 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/73/37673/1

diff --git 
a/packaging/dbscripts/upgrade/03_06_0705_model_hibernation_volumes_as_disks.sql 
b/packaging/dbscripts/upgrade/03_06_0705_model_hibernation_volumes_as_disks.sql
new file mode 100644
index 0000000..9c89c12
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_06_0705_model_hibernation_volumes_as_disks.sql
@@ -0,0 +1,139 @@
+-- add memory disks columns
+SELECT fn_db_add_column('snapshots', 'memory_metadata', 'uuid default NULL');
+SELECT fn_db_add_column('snapshots', 'memory_dump', 'uuid default NULL');
+
+SELECT fn_db_create_constraint('snapshots', 'fk_snapshots_metadata_disk_id', 
'FOREIGN KEY (memory_metadata) REFERENCES base_disks(disk_id) ON DELETE SET 
NULL');
+SELECT fn_db_create_constraint('snapshots', 'fk_snapshots_dump_disk_id', 
'FOREIGN KEY (memory_dump) REFERENCES base_disks(disk_id) ON DELETE SET NULL');
+
+-- meta data image
+INSERT INTO images(image_guid,
+    creation_date,
+    size,
+    it_guid,
+    imagestatus,
+    volume_type,
+    volume_format,
+    image_group_id
+    )
+SELECT
+    cast(split_part(memory_volume, ',', 6) as uuid),
+    'now',
+    10240,
+    '00000000-0000-0000-0000-000000000000',
+    1, -- ok
+    2, -- spare
+    4, -- cow
+    cast(split_part(memory_volume, ',', 5) as uuid)
+FROM snapshots
+    LEFT OUTER JOIN vm_dynamic ON vm_guid = vm_id
+WHERE length(memory_volume) != 0 AND snapshot_type = 'ACTIVE' AND status = 
'13';
+
+-- memory dump image
+INSERT INTO images(image_guid,
+    creation_date,
+    size,
+    it_guid,
+    imagestatus,
+    volume_type,
+    volume_format,
+    image_group_id
+    )
+SELECT
+    cast(split_part(memory_volume, ',', 4) as uuid),
+    'now',
+    (mem_size_mb + 200 + (64 * num_of_monitors)) * 1024 * 1024,
+    '00000000-0000-0000-0000-000000000000',
+    1, -- ok
+    0, -- unknown (will be updated later on)
+    5, -- raw
+    cast(split_part(memory_volume, ',', 3) as uuid)
+FROM snapshots
+    LEFT OUTER JOIN vms ON vm_guid = vm_id
+WHERE length(memory_volume) != 0 AND snapshot_type = 'ACTIVE' AND status = 
'13';
+
+-- update volume type for memory dumps
+UPDATE images
+SET volume_type = 1
+FROM snapshots
+    LEFT OUTER JOIN vm_dynamic ON vm_guid = vm_id 
+WHERE
+   length(memory_volume) != 0 AND snapshot_type = 'ACTIVE' AND status = '13' 
AND
+   image_guid = cast(split_part(memory_volume, ',', 4) as uuid) AND
+   (SELECT storage_type from storage_domains where id = 
cast(split_part(memory_volume, ',', 1) as uuid)) IN (2, 3);
+
+UPDATE images
+SET volume_type = 2
+FROM snapshots
+    LEFT OUTER JOIN vm_dynamic ON vm_guid = vm_id
+WHERE
+   volume_type = 0 AND length(memory_volume) != 0 AND image_guid = 
cast(split_part(memory_volume, ',', 4) as uuid) AND
+   snapshot_type = 'ACTIVE' AND status = '13';
+
+-- add to image <-> storage domain map
+INSERT INTO image_storage_domain_map(image_id,
+    storage_domain_id
+    )
+SELECT
+    cast(split_part(memory_volume, ',', 4) as uuid),
+    cast(split_part(memory_volume, ',', 1) as uuid)
+FROM snapshots
+    LEFT OUTER JOIN vm_dynamic ON vm_guid = vm_id
+WHERE length(memory_volume) != 0 AND snapshot_type = 'ACTIVE' AND status = 
'13';
+
+INSERT INTO image_storage_domain_map(image_id,
+    storage_domain_id
+    )
+SELECT
+    cast(split_part(memory_volume, ',', 6) as uuid),
+    cast(split_part(memory_volume, ',', 1) as uuid)
+FROM snapshots
+    LEFT OUTER JOIN vm_dynamic ON vm_guid = vm_id
+WHERE length(memory_volume) != 0 AND snapshot_type = 'ACTIVE' AND status = 
'13';
+
+-- add base disks
+INSERT INTO base_disks(disk_id,
+   disk_interface,
+   disk_alias,
+   disk_description,
+   shareable,
+   boot
+   )
+SELECT
+   cast(split_part(memory_volume, ',', 5) as uuid),
+   'VirtIO',
+   vm_name||'_memory_metadata',
+   'Hibernation meta-data',
+   false,
+   false
+FROM snapshots
+    LEFT OUTER JOIN vms ON vm_guid = vm_id
+WHERE length(memory_volume) != 0 AND snapshot_type = 'ACTIVE' AND status = 
'13';
+
+INSERT INTO base_disks(disk_id,
+   disk_interface,
+   disk_alias,
+   disk_description,
+   shareable,
+   boot
+   )
+SELECT
+   cast(split_part(memory_volume, ',', 3) as uuid),
+   'VirtIO',
+   vm_name||'_memory_dump',
+   'Hibernation memory-dump',
+   false,
+   false
+FROM snapshots
+    LEFT OUTER JOIN vms ON vm_guid = vm_id
+WHERE length(memory_volume) != 0 AND snapshot_type = 'ACTIVE' AND status = 
'13';
+
+-- remove memory volume
+UPDATE snapshots SET
+ memory_dump=cast(split_part(memory_volume, ',', 3) as uuid),
+ memory_metadata=cast(split_part(memory_volume, ',', 5) as uuid),
+ memory_volume = NULL
+ FROM snapshots
+     LEFT OUTER JOIN vm_dynamic ON vm_guid = vm_id
+ WHERE length(memory_volume) != 0 AND vm_guid = vm_id AND status = '13';
+
+


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

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

Reply via email to