Eli Mesika has uploaded a new change for review.

Change subject: core:unlock_entity is not locating locked snapshots
......................................................................

core:unlock_entity is not locating locked snapshots

Adding handling of
1) -t snapshot flag to display locked snapshots where -q is used

2) -t snapshot to remove a specific snapshot

3) -r if run with -t vm then all vm snapshots are removed as well

Change-Id: I415be6fbe99a97740c9d4e9c55c1ad63bc689531
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=958370
Signed-off-by: Eli Mesika <emes...@redhat.com>
---
M backend/manager/dbscripts/common_sp.sql
M backend/manager/dbscripts/dbfunctions.sh
M backend/manager/dbscripts/unlock_entity.sh
3 files changed, 33 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/94/14494/1

diff --git a/backend/manager/dbscripts/common_sp.sql 
b/backend/manager/dbscripts/common_sp.sql
index 212975c..a96cecf 100644
--- a/backend/manager/dbscripts/common_sp.sql
+++ b/backend/manager/dbscripts/common_sp.sql
@@ -479,6 +479,21 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+-- Unlocks a specific disk
+create or replace FUNCTION fn_db_unlock_snapshot(v_id UUID)
+returns void
+AS $procedure$
+declare
+    OK varchar;
+    LOCKED varchar;
+begin
+    OK:='OK';
+    LOCKED:='LOCKED';
+    update snapshots set status = OK where status = LOCKED and snapshot_id = 
v_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
 -- Unlocks all VM/Template disks
 create or replace FUNCTION fn_db_unlock_entity(v_object_type varchar(10), 
v_name varchar(255), v_recursive boolean)
 returns void
@@ -490,6 +505,8 @@
     TEMPLATE_OK integer;
     TEMPLATE_LOCKED integer;
     IMAGE_LOCKED integer;
+    SNAPSHOT_OK varchar;
+    SNAPSHOT_LOCKED varchar;
     v_id UUID;
 begin
     DOWN:=0;
@@ -498,6 +515,8 @@
     TEMPLATE_OK:=0;
     TEMPLATE_LOCKED:=1;
     IMAGE_LOCKED:=15;
+    SNAPSHOT_OK:='OK';
+    SNAPSHOT_LOCKED:='LOCKED';
     v_id := vm_guid from vm_static where vm_name = v_name and entity_type 
ilike v_object_type;
     -- set VM status to DOWN
     if (v_object_type = 'vm') then
@@ -508,10 +527,12 @@
             update vm_static set template_status = TEMPLATE_OK where 
template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
         end if;
     end if;
-    --unlock images if recursive flag is set
+    --unlock images and snapshots  if recursive flag is set
     if (v_recursive) then
         update images set imagestatus = OK where imagestatus = LOCKED and
         image_group_id in (select device_id from vm_device where vm_id = v_id 
and is_plugged);
+
+        update snapshots set status = SNAPSHOT_OK where status ilike 
SNAPSHOT_LOCKED and vm_id = v_id;
     end if;
 END; $procedure$
 LANGUAGE plpgsql;
diff --git a/backend/manager/dbscripts/dbfunctions.sh 
b/backend/manager/dbscripts/dbfunctions.sh
index 38d384e..8a91d3c 100755
--- a/backend/manager/dbscripts/dbfunctions.sh
+++ b/backend/manager/dbscripts/dbfunctions.sh
@@ -432,6 +432,8 @@
       CMD="select fn_db_unlock_entity('${object_type}', '${id}', 
${recursive});"
    elif [ "${object_type}" = "disk" ]; then
       CMD="select fn_db_unlock_disk('${id}');"
+   elif [ "${object_type}" = "snapshot" ]; then
+      CMD="select fn_db_unlock_snapshot('${id}');"
    else
       printf "Error : $* "
    fi
@@ -454,6 +456,7 @@
    LOCKED=2
    TEMPLATE_LOCKED=1
    IMAGE_LOCKED=15;
+   SNAPSHOT_LOCKED=LOCKED
    if [ "${object_type}" = "vm" ]; then
        CMD="select vm_name as vm_name from vm_static a ,vm_dynamic b
             where a.vm_guid = b.vm_guid and status = ${IMAGE_LOCKED};"
@@ -465,6 +468,9 @@
             entity_type ilike 'VM' and
             image_group_id in
             (select device_id from vm_device where is_plugged);"
+       psql -w -c "${CMD}" -U ${USERNAME} -d "${DATABASE}" -h "${SERVERNAME}" 
-p "${PORT}"
+       CMD="select vm_name as vm_name, snapshot_id as snapshot_id  from 
vm_static a ,snapshots b
+            where a.vm_guid = b.vm_id and status ilike '${SNAPSHOT_LOCKED}';"
        psql -w -c "${CMD}" -U ${USERNAME} -d "${DATABASE}" -h "${SERVERNAME}" 
-p "${PORT}"
    elif [ "${object_type}" = "template" ]; then
        CMD="select vm_name as template_name from vm_static
@@ -484,6 +490,10 @@
             where a.disk_id = b.image_group_id and
                   b.image_group_id = c.device_id and
                   imagestatus = ${LOCKED} and is_plugged;"
+   elif [ "${object_type}" = "snapshot" ]; then
+       CMD="select vm_id as entity_id, snapshot_id
+            from snapshots a
+            where status ilike '${SNAPSHOT_LOCKED}';"
        psql -w -c "${CMD}" -U ${USERNAME} -d "${DATABASE}" -h "${SERVERNAME}" 
-p "${PORT}"
    fi
 }
diff --git a/backend/manager/dbscripts/unlock_entity.sh 
b/backend/manager/dbscripts/unlock_entity.sh
index 5ec9d01..5ddec37 100755
--- a/backend/manager/dbscripts/unlock_entity.sh
+++ b/backend/manager/dbscripts/unlock_entity.sh
@@ -10,7 +10,7 @@
 usage() {
     printf "Usage: ${ME} -t TYPE -i ID [-h] [-s SERVERNAME [-p PORT]] [-d 
DATABASE] [-u USERNAME] [-l LOGFILE] [-r] [-q] [-v]\n"
     printf "\n"
-    printf "\t-t TYPE       - The object type {vm | template | disk} \n"
+    printf "\t-t TYPE       - The object type {vm | template | disk | 
snapshot} \n"
     printf "\t-i ID         - The object name in case of vm/template , UUID in 
case of a disk \n"
     printf "\t-s SERVERNAME - The database servername for the database  (def. 
${SERVERNAME})\n"
     printf "\t-p PORT       - The database port for the database        (def. 
${PORT})\n"


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

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

Reply via email to