From 6bcc97bd084896f3ccd56f8f4645184db979c007 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 12 Nov 2015 22:30:36 +0100 Subject: [PATCH] bug #4022: Do not set snapshots on persistent images if its TM ln mode is SYSTEM. Update quota update and snapshot survival after delete --recreate according to: +--------+-------------------------------------+ |LN/CLONE| PERSISTENT | NO PERSISTENT | | |---------+---------+-----------------+ | TARGET | created | quota | created | quota | +--------+---------+---------+-----------------+ | SYSTEM | system | VM + DS | system | VM | | SELF | image | DS | image | DS | | NONE | image | DS | image | DS | +----------------------------------------------+ Snapshots created at system ds (LN_TARGET/TM_TARGET) will be deleted after a recreate. (cherry picked from commit c5ad05fc60680cda2763973f5079598c2bf166e7) --- include/Quotas.h | 2 +- include/VirtualMachine.h | 14 ------- src/datastore/Datastore.cc | 7 ---- src/dm/DispatchManagerActions.cc | 2 +- src/lcm/LifeCycleActions.cc | 2 +- src/lcm/LifeCycleStates.cc | 8 +++- src/rm/RequestManagerVirtualMachine.cc | 16 ++++--- src/um/Quotas.cc | 2 +- src/vm/VirtualMachine.cc | 58 ++++++++++++++------------ 9 files changed, 49 insertions(+), 62 deletions(-) diff --git a/include/Quotas.h b/include/Quotas.h index d8ad27306c..bbcd348658 100644 --- a/include/Quotas.h +++ b/include/Quotas.h @@ -197,7 +197,7 @@ public: * *ARE FREED* by this function * @param ds_quotas a map with image_id and a tmpl with usage attributes */ - static void bulk_ds_del(map& ds_quotas); + static void ds_del(map& ds_quotas); /** * Delete usage from the given quota counters. diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 679ce7fa83..aeba1adb8b 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1299,20 +1299,6 @@ public: */ static string disk_tm_target(const VectorAttribute * disk); - /** - * Returns the disk SHARED attribute from the TM - * @param disk - * @return true or false. - */ - static bool disk_tm_shared(const VectorAttribute * disk) - { - bool shared; - - disk->vector_value("SHARED", shared); - - return shared; - } - /** * Returns a set of the security group IDs in use in this VM * @param sgs a set of security group IDs diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index a120d98257..9ca71c0e0a 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -140,13 +140,6 @@ void Datastore::disk_attribute( disk->replace("LN_TARGET", st); } - get_template_attribute("SHARED", st); - - if(!st.empty()) - { - disk->replace("SHARED", st); - } - for (it = inherit_attrs.begin(); it != inherit_attrs.end(); it++) { get_template_attribute((*it).c_str(), inherit_val); diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 3031e0b8bd..66a5aac144 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -946,7 +946,7 @@ int DispatchManager::resubmit( if ( !ds_quotas.empty() ) { - Quotas::bulk_ds_del(ds_quotas); + Quotas::ds_del(ds_quotas); } if ( vm_quotas != 0 ) diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index fa81c1b486..20e7230d7e 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -856,7 +856,7 @@ void LifeCycleManager::clean_action(int vid) if ( !ds_quotas.empty() ) { - Quotas::bulk_ds_del(ds_quotas); + Quotas::ds_del(ds_quotas); } if ( vm_quotas != 0 ) diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 04915f3d0e..73e0a99c05 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1808,6 +1808,7 @@ void LifeCycleManager::disk_snapshot_success(int vid) disk->vector_value("IMAGE_ID", img_id); bool is_persistent = VirtualMachine::is_persistent(disk); + string target = VirtualMachine::disk_tm_target(disk); vmpool->update(vm); @@ -1837,7 +1838,8 @@ void LifeCycleManager::disk_snapshot_success(int vid) delete vm_quotas; } - if(img_id != -1 && is_persistent && has_snaps) + // Update image if it is persistent and ln mode does not clone it + if ( img_id != -1 && is_persistent && has_snaps && target != "SYSTEM" ) { imagem->set_image_snapshots(img_id, snaps); } @@ -1943,6 +1945,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) disk->vector_value("IMAGE_ID", img_id); bool is_persistent = VirtualMachine::is_persistent(disk); + string target = VirtualMachine::disk_tm_target(disk); vmpool->update(vm); @@ -1972,7 +1975,8 @@ void LifeCycleManager::disk_snapshot_failure(int vid) delete vm_quotas; } - if(img_id != -1 && is_persistent && has_snaps) + // Update image if it is persistent and ln mode does not clone it + if ( img_id != -1 && is_persistent && has_snaps && target != "SYSTEM" ) { imagem->set_image_snapshots(img_id, snaps); } diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index b9814811cd..ee072746cc 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -2362,7 +2362,6 @@ void VirtualMachineDiskSnapshotCreate::request_execute( Template ds_deltas; Template vm_deltas; - bool do_vm_quota; int rc; int snap_id; @@ -2393,8 +2392,9 @@ void VirtualMachineDiskSnapshotCreate::request_execute( string disk_size = disk->vector_value("SIZE"); string ds_id = disk->vector_value("DATASTORE_ID"); - bool persistent = VirtualMachine::is_persistent(disk); bool is_volatile = VirtualMachine::is_volatile(disk); + bool is_system = VirtualMachine::disk_tm_target(disk) == "SYSTEM"; + bool do_ds_quota = VirtualMachine::is_persistent(disk) || !is_system; int img_id = -1; disk->vector_value("IMAGE_ID", img_id); @@ -2414,7 +2414,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute( RequestAttributes vm_att_quota; //--------------------------- Persistent Images ---------------------------- - if (persistent) + if (do_ds_quota) { PoolObjectAuth img_perms; @@ -2451,9 +2451,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute( } //--------------------- Account for System DS storage ---------------------- - do_vm_quota = (VirtualMachine::disk_tm_target(disk) != "NONE");// self or system - - if (do_vm_quota) + if (is_system) { if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false ) { @@ -2471,7 +2469,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute( if (!quota_resize_authorization(id, &vm_deltas, vm_att_quota)) { - if (persistent) + if (do_ds_quota) { quota_rollback(&ds_deltas, Quotas::DATASTORE, ds_att_quota); } @@ -2487,12 +2485,12 @@ void VirtualMachineDiskSnapshotCreate::request_execute( if ( rc != 0 ) { - if (persistent) + if (do_ds_quota) { quota_rollback(&ds_deltas, Quotas::DATASTORE, ds_att_quota); } - if (do_vm_quota) + if (is_system) { quota_rollback(&vm_deltas, Quotas::VM, vm_att_quota); } diff --git a/src/um/Quotas.cc b/src/um/Quotas.cc index a2270cf412..d86f877ab5 100644 --- a/src/um/Quotas.cc +++ b/src/um/Quotas.cc @@ -285,7 +285,7 @@ void Quotas::quota_del(QuotaType type, int uid, int gid, Template * tmpl) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void Quotas::bulk_ds_del(map& ds_quotas) +void Quotas::ds_del(map& ds_quotas) { Nebula& nd = Nebula::instance(); ImagePool * ipool = nd.get_ipool(); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 060a693e19..054f31f5d7 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2425,7 +2425,7 @@ long long VirtualMachine::get_system_disk_size(Template * tmpl) { size += disk_size; } - else if ( disk_tm_target(disk) != "NONE") // self or system + else if ( disk_tm_target(disk) == "SYSTEM") { size += disk_size; @@ -4587,16 +4587,16 @@ void VirtualMachine::delete_disk_snapshot(int did, int snap_id, delete tmp; } - if ( is_persistent(disk) ) - { + if (is_persistent(disk) || disk_tm_target(disk) != "SYSTEM") + { *ds_quotas = new Template(); (*ds_quotas)->add("DATASTORE", disk->vector_value("DATASTORE_ID")); (*ds_quotas)->add("SIZE", ssize); (*ds_quotas)->add("IMAGES",0 ); - } + } - if (disk_tm_target(disk) != "NONE") // self or system + if (disk_tm_target(disk) == "SYSTEM") { *vm_quotas = new Template(); @@ -4609,6 +4609,16 @@ void VirtualMachine::delete_disk_snapshot(int did, int snap_id, } } +// +--------+-------------------------------------+ +// |LN/CLONE| PERSISTENT | NO PERSISTENT | +// | |---------+---------+-----------------+ +// | TARGET | created | quota | created | quota | +// +--------+---------+---------+-----------------+ +// | SYSTEM | system | VM + DS | system | VM | +// | SELF | image | DS | image | DS | +// | NONE | image | DS | image | DS | +// +----------------------------------------------+ + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -4647,34 +4657,30 @@ void VirtualMachine::delete_non_persistent_disk_snapshots(Template **vm_quotas, continue; } + if ( disk_tm_target(disk) != "SYSTEM" ) + { + continue; + } + if (is_persistent(disk)) { - if (!disk_tm_shared(disk)) - { - int image_id; + int image_id; - if ( disk->vector_value("IMAGE_ID", image_id) != 0 ) - { - continue; - } - - Template * d_ds = new Template(); - - d_ds->add("DATASTORE", disk->vector_value("DATASTORE_ID")); - d_ds->add("SIZE", it->second->get_total_size()); - d_ds->add("IMAGES", 0); - - ds_quotas.insert(pair(image_id, d_ds)); - } - else + if ( disk->vector_value("IMAGE_ID", image_id) != 0 ) { continue; } + + Template * d_ds = new Template(); + + d_ds->add("DATASTORE", disk->vector_value("DATASTORE_ID")); + d_ds->add("SIZE", it->second->get_total_size()); + d_ds->add("IMAGES", 0); + + ds_quotas.insert(pair(image_id, d_ds)); } - else if (disk_tm_target(disk) != "NONE") // self or system - { - system_disk += it->second->get_total_size(); - } + + system_disk += it->second->get_total_size(); it->second->clear();