1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

feature #3782: Quotas for single snapshot deletion

This commit is contained in:
Ruben S. Montero 2015-06-17 17:45:37 +02:00
parent b2101281ec
commit 9964cb27e2
5 changed files with 91 additions and 8 deletions

View File

@ -174,6 +174,13 @@ public:
*/ */
unsigned int get_total_size() const; unsigned int get_total_size() const;
/**
* Get the size (virtual) in mb of the given snapshot
* @param id of the snapshot
* @return size or 0 if not found
*/
unsigned int get_snapshot_size(unsigned int id) const;
/** /**
* Get Attribute from the given snapshot * Get Attribute from the given snapshot
* @param id of the snapshot * @param id of the snapshot
@ -181,7 +188,7 @@ public:
* *
* @return value or empty if not found * @return value or empty if not found
*/ */
string get_snapshot_attribute(unsigned int id, const char* name); string get_snapshot_attribute(unsigned int id, const char* name) const;
private: private:

View File

@ -24,6 +24,7 @@
#include "Log.h" #include "Log.h"
#include "NebulaLog.h" #include "NebulaLog.h"
#include "NebulaUtil.h" #include "NebulaUtil.h"
#include "Quotas.h"
#include <time.h> #include <time.h>
#include <set> #include <set>
@ -1534,8 +1535,11 @@ public:
* called before actually deleting the snapshot. * called before actually deleting the snapshot.
* @param disk_id of the disk * @param disk_id of the disk
* @param snap_id of the snapshot * @param snap_id of the snapshot
* @param type of quota used by this snapshot
* @param quotas template with snapshot usage
*/ */
void delete_disk_snapshot(int disk_id, int snap_id); void delete_disk_snapshot(int disk_id, int snap_id, Quotas::QuotaType& type,
Template **quotas);
/** /**
* Get information about the disk to take the snapshot from * Get information about the disk to take the snapshot from

View File

@ -1722,6 +1722,9 @@ void LifeCycleManager::disk_snapshot_success(int vid)
{ {
string disk_id, tm_mad, ds_id, snap_id; string disk_id, tm_mad, ds_id, snap_id;
Quotas::QuotaType qt;
Template *quotas = 0;
VirtualMachine * vm = vmpool->get(vid,true); VirtualMachine * vm = vmpool->get(vid,true);
if ( vm == 0 ) if ( vm == 0 )
@ -1743,6 +1746,9 @@ void LifeCycleManager::disk_snapshot_success(int vid)
int isnap_id = strtol(snap_id.c_str(),NULL,0); int isnap_id = strtol(snap_id.c_str(),NULL,0);
int idisk_id = strtol(disk_id.c_str(),NULL,0); int idisk_id = strtol(disk_id.c_str(),NULL,0);
int uid = vm->get_uid();
int gid = vm->get_gid();
switch (vm->get_lcm_state()) switch (vm->get_lcm_state())
{ {
case VirtualMachine::DISK_SNAPSHOT_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
@ -1753,7 +1759,7 @@ void LifeCycleManager::disk_snapshot_success(int vid)
case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF:
vm->log("LCM", Log::INFO, "VM disk snapshot deleted."); vm->log("LCM", Log::INFO, "VM disk snapshot deleted.");
vm->delete_disk_snapshot(idisk_id, isnap_id); vm->delete_disk_snapshot(idisk_id, isnap_id, qt, &quotas);
break; break;
default: default:
@ -1770,6 +1776,13 @@ void LifeCycleManager::disk_snapshot_success(int vid)
vm->unlock(); vm->unlock();
if ( quotas != 0 )
{
Quotas::quota_del(qt, uid, gid, quotas);
delete quotas;
}
return; return;
} }
@ -1780,6 +1793,9 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
{ {
string disk_id, tm_mad, ds_id, snap_id; string disk_id, tm_mad, ds_id, snap_id;
Quotas::QuotaType qt;
Template *quotas = 0;
VirtualMachine * vm = vmpool->get(vid,true); VirtualMachine * vm = vmpool->get(vid,true);
if ( vm == 0 ) if ( vm == 0 )
@ -1801,11 +1817,14 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
int isnap_id = strtol(snap_id.c_str(),NULL,0); int isnap_id = strtol(snap_id.c_str(),NULL,0);
int idisk_id = strtol(disk_id.c_str(),NULL,0); int idisk_id = strtol(disk_id.c_str(),NULL,0);
int uid = vm->get_uid();
int gid = vm->get_gid();
switch (vm->get_lcm_state()) switch (vm->get_lcm_state())
{ {
case VirtualMachine::DISK_SNAPSHOT_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
vm->log("LCM", Log::ERROR, "Could not take disk snapshot."); vm->log("LCM", Log::ERROR, "Could not take disk snapshot.");
vm->delete_disk_snapshot(idisk_id, isnap_id); vm->delete_disk_snapshot(idisk_id, isnap_id, qt, &quotas);
break; break;
case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF:
@ -1827,6 +1846,13 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
vm->unlock(); vm->unlock();
if ( quotas != 0 )
{
Quotas::quota_del(qt, uid, gid, quotas);
delete quotas;
}
return; return;
} }

View File

@ -271,9 +271,9 @@ const VectorAttribute * Snapshots::get_snapshot(unsigned int id) const
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
string Snapshots::get_snapshot_attribute(unsigned int id, const char * name) string Snapshots::get_snapshot_attribute(unsigned int id, const char * name) const
{ {
VectorAttribute * snapshot = get_snapshot(id); const VectorAttribute * snapshot = get_snapshot(id);
if (snapshot == 0) if (snapshot == 0)
{ {
@ -283,6 +283,22 @@ string Snapshots::get_snapshot_attribute(unsigned int id, const char * name)
return snapshot->vector_value(name); return snapshot->vector_value(name);
} }
/* -------------------------------------------------------------------------- */
unsigned int Snapshots::get_snapshot_size(unsigned int id) const
{
unsigned int snap_size = 0;
const VectorAttribute * snapshot = get_snapshot(id);
if (snapshot != 0)
{
snapshot->vector_value("SIZE", snap_size);
}
return snap_size;
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -4289,12 +4289,17 @@ int VirtualMachine::revert_disk_snapshot(int did, int snap_id)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void VirtualMachine::delete_disk_snapshot(int did, int snap_id) void VirtualMachine::delete_disk_snapshot(int did, int snap_id,
Quotas::QuotaType& type, Template **quotas)
{ {
map<int, Snapshots *>::iterator it; map<int, Snapshots *>::iterator it;
VectorAttribute * disk = get_disk(did);
unsigned int snap_size; unsigned int snap_size;
VectorAttribute * delta_disk;
VectorAttribute * disk = get_disk(did);
*quotas = 0;
if ( disk == 0 ) if ( disk == 0 )
{ {
return; return;
@ -4307,6 +4312,8 @@ void VirtualMachine::delete_disk_snapshot(int did, int snap_id)
return; return;
} }
unsigned int ssize = it->second->get_snapshot_size(snap_id);
it->second->delete_snapshot(snap_id); it->second->delete_snapshot(snap_id);
snap_size = it->second->get_total_size(); snap_size = it->second->get_total_size();
@ -4321,5 +4328,28 @@ void VirtualMachine::delete_disk_snapshot(int did, int snap_id)
delete tmp; delete tmp;
} }
if ( is_persistent(disk) )
{
*quotas = new Template();
(*quotas)->add("DATASTORE", disk->vector_value("DATASTORE_ID"));
(*quotas)->add("SIZE", (long long) ssize);
type = Quotas::DATASTORE;
}
else
{
*quotas = new Template();
delta_disk = new VectorAttribute("DISK");
delta_disk->replace("TYPE", "FS");
delta_disk->replace("SIZE", ssize);
(*quotas)->add("VMS", 0);
(*quotas)->set(delta_disk);
type = Quotas::VM;
}
} }