1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-02 10:50:07 +03:00

feature #3782: Copy snapshots from Image to VM disks, and back. Still

needs to do the same on attach dettach operations
This commit is contained in:
Ruben S. Montero 2015-06-01 19:28:37 +02:00
parent a841b12e94
commit e599187ad5
5 changed files with 44 additions and 8 deletions

View File

@ -29,6 +29,7 @@
#include <vector>
class AuthRequest;
class Snapshots;
using namespace std;
@ -158,6 +159,7 @@ public:
* or the default one
* @param uid of VM owner (to look for the image id within its images)
* @param image_id on success returns the acquired image id
* @param snaps list of snapshots associated to this image
* @param error_str string describing the error
*
* @return 0 on success, -1 otherwise
@ -169,6 +171,7 @@ public:
string& dev_prefix,
int uid,
int& image_id,
Snapshots ** snaps,
string& error_str);
/**
* Generates an Authorization token for the DISK attribute

View File

@ -1398,6 +1398,7 @@ public:
int max_disk_id,
int uid,
int& image_id,
Snapshots ** snap,
string& error_str);
/**
* Returns the disk that is waiting for an attachment action

View File

@ -905,6 +905,7 @@ int DispatchManager::attach(int vid,
set<string> used_targets;
VectorAttribute * disk;
Snapshots * snap;
VirtualMachine * vm = vmpool->get(vid, true);
@ -958,6 +959,7 @@ int DispatchManager::attach(int vid,
max_disk_id,
uid,
image_id,
&snap,
error_str);
vm = vmpool->get(vid, true);

View File

@ -19,6 +19,7 @@
/* ************************************************************************** */
#include "ImagePool.h"
#include "Snapshots.h"
#include "AuthManager.h"
#include "Nebula.h"
#include "PoolObjectAuth.h"
@ -313,6 +314,7 @@ int ImagePool::disk_attribute(int vm_id,
string& dev_prefix,
int uid,
int& image_id,
Snapshots ** snap,
string& error_str)
{
string source;
@ -326,6 +328,8 @@ int ImagePool::disk_attribute(int vm_id,
Nebula& nd = Nebula::instance();
ImageManager * imagem = nd.get_imagem();
*snap = 0;
if (!(source = disk->vector_value("IMAGE")).empty())
{
int uiid = get_disk_uid(disk,uid);
@ -412,6 +416,12 @@ int ImagePool::disk_attribute(int vm_id,
image_id = img->get_oid();
datastore_id = img->get_ds_id();
if (img->snapshots.size() > 0)
{
*snap = new Snapshots(img->snapshots);
(*snap)->set_disk_id(disk_id);
}
img->unlock();
if (rc == -1)

View File

@ -1798,6 +1798,8 @@ int VirtualMachine::get_disk_images(string& error_str)
// -------------------------------------------------------------------------
for(int i=0; i<num_disks; i++)
{
Snapshots * snap;
disk = dynamic_cast<VectorAttribute * >(disks[i]);
if ( disk == 0 )
@ -1812,9 +1814,22 @@ int VirtualMachine::get_disk_images(string& error_str)
dev_prefix,
uid,
image_id,
&snap,
error_str);
if (rc == 0 )
{
if (snap != 0)
{
if (img_type == Image::OS || img_type == Image::DATABLOCK)
{
snapshots.insert(pair<int, Snapshots *>(i, snap));
}
else
{
delete snap;
}
}
acquired_images.push_back(image_id);
target = disk->vector_value("TARGET");
@ -2004,6 +2019,7 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
int max_disk_id,
int uid,
int& image_id,
Snapshots ** snap,
string& error_str)
{
vector<Attribute *> disks;
@ -2051,6 +2067,7 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
dev_prefix,
uid,
image_id,
snap,
error_str);
if ( rc != 0 )
{
@ -2071,7 +2088,9 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
imagem->release_image(vm_id, image_id, false);
delete snap;
delete new_disk;
return 0;
}
}
@ -2524,17 +2543,18 @@ void VirtualMachine::release_disk_images()
img_error = state != ACTIVE || lcm_state != EPILOG;
disk->vector_value("DISK_ID", did);
map<int, Snapshots *>::iterator it = snapshots.find(did);
if (it != snapshots.end())
{
imagem->set_image_snapshots(iid, *(it->second), img_error);
}
if ( disk->vector_value("IMAGE_ID", iid) == 0 )
{
disk->vector_value("DISK_ID", did);
map<int, Snapshots *>::iterator it = snapshots.find(did);
if (it != snapshots.end())
{
imagem->set_image_snapshots(iid, *(it->second), img_error);
}
imagem->release_image(oid, iid, img_error);
}