mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-29 18:50:08 +03:00
B #1863: Added clear snapshot method. Removed all snapshot from image if snapshot_pool is empty.
(cherry picked from commit 9d2f439cb027c6e2e45d6fa79be4d0c37989f8a2)
This commit is contained in:
parent
37222d65dc
commit
0c2dcba089
@ -261,6 +261,12 @@ public:
|
||||
*/
|
||||
void set_image_snapshots(int iid, const Snapshots& s);
|
||||
|
||||
/**
|
||||
* Clear the snapshots of an image by setting an empty set.
|
||||
* @param iid id of image
|
||||
*/
|
||||
void clear_image_snapshots(int iid);
|
||||
|
||||
/**
|
||||
* Set the size for the given image. The image MUST be persistent
|
||||
* and of type OS or DATABLOCK.
|
||||
|
@ -157,6 +157,14 @@ public:
|
||||
return snapshot_pool.size();
|
||||
};
|
||||
|
||||
/**
|
||||
* @return true if snapshot_pool is empty
|
||||
*/
|
||||
bool empty() const
|
||||
{
|
||||
return snapshot_pool.empty();
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if snapshot exists
|
||||
* @param snap_id of the snapshot
|
||||
|
@ -1027,7 +1027,14 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s)
|
||||
return;
|
||||
}
|
||||
|
||||
img->set_snapshots(s);
|
||||
if (s.empty())
|
||||
{
|
||||
img->clear_snapshots();
|
||||
}
|
||||
else
|
||||
{
|
||||
img->set_snapshots(s);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
@ -1037,6 +1044,16 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManager::clear_image_snapshots(int iid)
|
||||
{
|
||||
Snapshots _snaps(-1, false);
|
||||
|
||||
set_image_snapshots(iid, _snaps);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManager::set_image_size(int iid, long long size)
|
||||
{
|
||||
Image * img = ipool->get(iid);
|
||||
|
@ -1871,7 +1871,6 @@ void LifeCycleManager::disk_snapshot_success(int vid)
|
||||
const VirtualMachineDisk * disk;
|
||||
Snapshots snaps(-1, false);
|
||||
const Snapshots* tmp_snaps;
|
||||
bool has_snaps = false;
|
||||
string error_str;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
@ -1925,10 +1924,8 @@ void LifeCycleManager::disk_snapshot_success(int vid)
|
||||
vm->clear_snapshot_disk();
|
||||
|
||||
tmp_snaps = vm->get_disk_snapshots(disk_id, error_str);
|
||||
|
||||
if(tmp_snaps != 0)
|
||||
if (tmp_snaps != 0)
|
||||
{
|
||||
has_snaps = true;
|
||||
snaps = *tmp_snaps;
|
||||
}
|
||||
|
||||
@ -1976,7 +1973,7 @@ void LifeCycleManager::disk_snapshot_success(int vid)
|
||||
}
|
||||
|
||||
// Update image if it is persistent and ln mode does not clone it
|
||||
if ( img_id != -1 && is_persistent && has_snaps && target == "NONE" )
|
||||
if ( img_id != -1 && is_persistent && target == "NONE" )
|
||||
{
|
||||
imagem->set_image_snapshots(img_id, snaps);
|
||||
}
|
||||
@ -2017,7 +2014,6 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
|
||||
const VirtualMachineDisk* disk;
|
||||
Snapshots snaps(-1, false);
|
||||
const Snapshots* tmp_snaps;
|
||||
bool has_snaps = false;
|
||||
string error_str;
|
||||
|
||||
bool img_owner, vm_owner;
|
||||
@ -2072,10 +2068,8 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
|
||||
vm->clear_snapshot_disk();
|
||||
|
||||
tmp_snaps = vm->get_disk_snapshots(disk_id, error_str);
|
||||
|
||||
if(tmp_snaps != 0)
|
||||
if (tmp_snaps != 0)
|
||||
{
|
||||
has_snaps = true;
|
||||
snaps = *tmp_snaps;
|
||||
}
|
||||
|
||||
@ -2123,7 +2117,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
|
||||
}
|
||||
|
||||
// Update image if it is persistent and ln mode does not clone it
|
||||
if ( img_id != -1 && is_persistent && has_snaps && target != "SYSTEM" )
|
||||
if ( img_id != -1 && is_persistent && target != "SYSTEM" )
|
||||
{
|
||||
imagem->set_image_snapshots(img_id, snaps);
|
||||
}
|
||||
|
@ -911,9 +911,15 @@ void VirtualMachineDisks::release_images(int vmid, bool image_error,
|
||||
}
|
||||
|
||||
/* ------- Update snapshots on source image if needed ----------- */
|
||||
if ( (*it)->has_snapshots() )
|
||||
const Snapshots * snaps = (*it)->get_snapshots();
|
||||
|
||||
if (snaps != 0)
|
||||
{
|
||||
imagem->set_image_snapshots(iid, *(*it)->get_snapshots());
|
||||
imagem->set_image_snapshots(iid, *snaps);
|
||||
}
|
||||
else
|
||||
{
|
||||
imagem->clear_image_snapshots(iid);
|
||||
}
|
||||
|
||||
/* --------- Compute space to free on image datastore ----------- */
|
||||
|
@ -1072,9 +1072,15 @@ void VirtualMachinePool::delete_attach_disk(int vid)
|
||||
Quotas::quota_del(Quotas::VM, uid, gid, &tmpl);
|
||||
}
|
||||
|
||||
if ( disk->has_snapshots() )
|
||||
const Snapshots * snaps = disk->get_snapshots();
|
||||
|
||||
if (snaps != 0)
|
||||
{
|
||||
imagem->set_image_snapshots(image_id, *disk->get_snapshots());
|
||||
imagem->set_image_snapshots(image_id, *snaps);
|
||||
}
|
||||
else
|
||||
{
|
||||
imagem->clear_image_snapshots(image_id);
|
||||
}
|
||||
|
||||
imagem->release_image(oid, image_id, false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user