mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-24 21:34:01 +03:00
feature #3782: Add snapshots to Image object. Transfer them back from VM
disk
This commit is contained in:
parent
c2bf13fe00
commit
9e30da08c1
@ -21,6 +21,7 @@
|
||||
#include "ImageTemplate.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "ObjectCollection.h"
|
||||
#include "Snapshots.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -486,6 +487,16 @@ public:
|
||||
*/
|
||||
ImageTemplate * clone_template(const string& new_name) const;
|
||||
|
||||
/**
|
||||
* Set the snapshots for this image
|
||||
* @param snapshot list
|
||||
*/
|
||||
void set_snapshots(const Snapshots& s)
|
||||
{
|
||||
snapshots = s;
|
||||
snapshots.clear_disk_id();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -579,6 +590,11 @@ private:
|
||||
*/
|
||||
ObjectCollection img_clone_collection;
|
||||
|
||||
/**
|
||||
* Snapshot list for this image
|
||||
*/
|
||||
Snapshots snapshots;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
@ -26,6 +26,7 @@ using namespace std;
|
||||
extern "C" void * image_action_loop(void *arg);
|
||||
|
||||
class Image;
|
||||
class Snapshots;
|
||||
class Template;
|
||||
|
||||
class ImageManager : public MadManager, public ActionListener
|
||||
@ -189,6 +190,15 @@ public:
|
||||
*/
|
||||
void monitor_datastore(int ds_id);
|
||||
|
||||
/**
|
||||
* Set the snapshots for the given image. The image MUST be persistent
|
||||
* and of type OS or DATABLOCK.
|
||||
* @param iid id of image
|
||||
* @param s snapshot list
|
||||
* @param failed the associated VM releasing the images is FAILED
|
||||
*/
|
||||
void set_image_snapshots(int iid, const Snapshots& s, bool failed);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Generic name for the Image driver
|
||||
|
@ -56,7 +56,8 @@ Image::Image(int _uid,
|
||||
ds_id(-1),
|
||||
ds_name(""),
|
||||
vm_collection("VMS"),
|
||||
img_clone_collection("CLONES")
|
||||
img_clone_collection("CLONES"),
|
||||
snapshots(-1)
|
||||
{
|
||||
if (_image_template != 0)
|
||||
{
|
||||
@ -334,11 +335,12 @@ error_common:
|
||||
|
||||
string& Image::to_xml(string& xml) const
|
||||
{
|
||||
string template_xml;
|
||||
string perms_xml;
|
||||
ostringstream oss;
|
||||
string vm_collection_xml;
|
||||
string clone_collection_xml;
|
||||
string template_xml;
|
||||
string perms_xml;
|
||||
ostringstream oss;
|
||||
string vm_collection_xml;
|
||||
string clone_collection_xml;
|
||||
string snapshots_xml;
|
||||
|
||||
oss <<
|
||||
"<IMAGE>" <<
|
||||
@ -366,6 +368,7 @@ string& Image::to_xml(string& xml) const
|
||||
vm_collection.to_xml(vm_collection_xml) <<
|
||||
img_clone_collection.to_xml(clone_collection_xml) <<
|
||||
obj_template->to_xml(template_xml) <<
|
||||
snapshots.to_xml(snapshots_xml) <<
|
||||
"</IMAGE>";
|
||||
|
||||
xml = oss.str();
|
||||
@ -462,6 +465,17 @@ int Image::from_xml(const string& xml)
|
||||
|
||||
ObjectXML::free_nodes(content);
|
||||
|
||||
content.clear();
|
||||
|
||||
ObjectXML::get_nodes("/IMAGE/SNAPSHOTS", content);
|
||||
|
||||
if (!content.empty())
|
||||
{
|
||||
rc += snapshots.from_xml_node(content[0]);
|
||||
|
||||
ObjectXML::free_nodes(content);
|
||||
content.clear();
|
||||
}
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
|
@ -895,3 +895,49 @@ string * ImageManager::format_message(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManager::set_image_snapshots(int iid, const Snapshots& s, bool failed)
|
||||
{
|
||||
Image * img = ipool->get(iid,true);
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch(img->get_type())
|
||||
{
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
break;
|
||||
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
case Image::CDROM:
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (img->get_state())
|
||||
{
|
||||
case Image::USED_PERS:
|
||||
break;
|
||||
|
||||
case Image::USED:
|
||||
case Image::LOCKED:
|
||||
case Image::CLONE:
|
||||
case Image::DELETE:
|
||||
case Image::INIT:
|
||||
case Image::DISABLED:
|
||||
case Image::READY:
|
||||
case Image::ERROR:
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
img->set_snapshots(s);
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
|
@ -2495,9 +2495,10 @@ int VirtualMachine::set_attach_nic(int nic_id)
|
||||
|
||||
void VirtualMachine::release_disk_images()
|
||||
{
|
||||
int iid;
|
||||
int save_as_id;
|
||||
int num_disks;
|
||||
int iid;
|
||||
int save_as_id;
|
||||
int num_disks;
|
||||
int did = -1;
|
||||
|
||||
bool img_error;
|
||||
|
||||
@ -2523,6 +2524,15 @@ 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 )
|
||||
{
|
||||
imagem->release_image(oid, iid, img_error);
|
||||
@ -2532,6 +2542,7 @@ void VirtualMachine::release_disk_images()
|
||||
{
|
||||
imagem->release_image(oid, save_as_id, img_error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user