mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-02 10:50:07 +03:00
feature #3782: Transfer snapshot list from/to attach disks
This commit is contained in:
parent
e599187ad5
commit
da79447688
@ -1417,18 +1417,27 @@ public:
|
||||
*
|
||||
* @return the DISK or 0 if no disk was deleted
|
||||
*/
|
||||
VectorAttribute * delete_attach_disk();
|
||||
VectorAttribute * delete_attach_disk(Snapshots **snap);
|
||||
|
||||
/**
|
||||
* Adds a new disk to the virtual machine template. The disk should be
|
||||
* generated by the build_attach_disk
|
||||
* @param new_disk must be allocated in the heap
|
||||
* @param snap list of snapshots associated to the disk
|
||||
*/
|
||||
void set_attach_disk(VectorAttribute * new_disk)
|
||||
void set_attach_disk(VectorAttribute * new_disk, Snapshots * snap)
|
||||
{
|
||||
new_disk->replace("ATTACH", "YES");
|
||||
|
||||
obj_template->set(new_disk);
|
||||
|
||||
if (snap != 0)
|
||||
{
|
||||
int disk_id;
|
||||
|
||||
new_disk->vector_value("DISK_ID", disk_id);
|
||||
snapshots.insert(pair<int, Snapshots *>(disk_id, snap));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -970,6 +970,9 @@ int DispatchManager::attach(int vid,
|
||||
imagem->release_image(oid, image_id, false);
|
||||
}
|
||||
|
||||
delete snap;
|
||||
delete disk;
|
||||
|
||||
oss << "Could not attach a new disk to VM " << vid
|
||||
<< ", VM does not exist after setting its state to HOTPLUG." ;
|
||||
error_str = oss.str();
|
||||
@ -1003,7 +1006,7 @@ int DispatchManager::attach(int vid,
|
||||
// VM template
|
||||
vm->set_vm_info();
|
||||
|
||||
vm->set_attach_disk(disk);
|
||||
vm->set_attach_disk(disk, snap);
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
|
||||
{
|
||||
|
@ -429,6 +429,9 @@ int ImagePool::disk_attribute(int vm_id,
|
||||
imagem->release_image(vm_id, iid, false);
|
||||
error_str = "Unknown internal error";
|
||||
|
||||
delete *snap;
|
||||
*snap = 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -439,6 +442,9 @@ int ImagePool::disk_attribute(int vm_id,
|
||||
imagem->release_image(vm_id, iid, false);
|
||||
error_str = "Associated datastore for the image does not exist";
|
||||
|
||||
delete *snap;
|
||||
*snap = 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2035,6 +2035,7 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
|
||||
Image::ImageType img_type;
|
||||
|
||||
image_id = -1;
|
||||
*snap = 0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Get the DISK attribute from the template
|
||||
@ -2088,8 +2089,8 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
|
||||
|
||||
imagem->release_image(vm_id, image_id, false);
|
||||
|
||||
delete snap;
|
||||
delete new_disk;
|
||||
delete snap;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2184,13 +2185,15 @@ void VirtualMachine::clear_attach_disk()
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
VectorAttribute * VirtualMachine::delete_attach_disk()
|
||||
VectorAttribute * VirtualMachine::delete_attach_disk(Snapshots **snap)
|
||||
{
|
||||
vector<Attribute *> disks;
|
||||
VectorAttribute * disk;
|
||||
|
||||
int num_disks = obj_template->get("DISK", disks);
|
||||
|
||||
*snap = 0;
|
||||
|
||||
for(int i=0; i<num_disks; i++)
|
||||
{
|
||||
disk = dynamic_cast<VectorAttribute * >(disks[i]);
|
||||
@ -2202,6 +2205,18 @@ VectorAttribute * VirtualMachine::delete_attach_disk()
|
||||
|
||||
if ( disk->vector_value("ATTACH") == "YES" )
|
||||
{
|
||||
int disk_id;
|
||||
|
||||
disk->vector_value("DISK_ID", disk_id);
|
||||
|
||||
map<int, Snapshots *>::iterator it = snapshots.find(disk_id);
|
||||
|
||||
if (it != snapshots.end())
|
||||
{
|
||||
*snap = it->second;
|
||||
snapshots.erase(it);
|
||||
}
|
||||
|
||||
return static_cast<VectorAttribute * >(obj_template->remove(disk));
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ VirtualMachinePool::VirtualMachinePool(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::insert_index(const string& deploy_id, int vmid,
|
||||
int VirtualMachinePool::insert_index(const string& deploy_id, int vmid,
|
||||
bool replace)
|
||||
{
|
||||
ostringstream oss;
|
||||
@ -262,7 +262,7 @@ void VirtualMachinePool::drop_index(const string& deploy_id)
|
||||
return;
|
||||
}
|
||||
|
||||
oss << "DELETE FROM " << import_table << " WHERE deploy_id='"
|
||||
oss << "DELETE FROM " << import_table << " WHERE deploy_id='"
|
||||
<< deploy_name << "'";
|
||||
|
||||
db->exec(oss);
|
||||
@ -541,13 +541,13 @@ int VirtualMachinePool::db_int_cb(void * _int_output, int num, char **values, ch
|
||||
int VirtualMachinePool::get_vmid (const string& deploy_id)
|
||||
{
|
||||
int rc;
|
||||
int vmid = -1;
|
||||
int vmid = -1;
|
||||
ostringstream oss;
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&VirtualMachinePool::db_int_cb),
|
||||
static_cast<void *>(&vmid));
|
||||
|
||||
oss << "SELECT vmid FROM " << import_table
|
||||
oss << "SELECT vmid FROM " << import_table
|
||||
<< " WHERE deploy_id = '" << db->escape_str(deploy_id.c_str()) << "'";
|
||||
|
||||
rc = db->exec(oss, this);
|
||||
@ -634,7 +634,7 @@ int VirtualMachinePool::calculate_showback(
|
||||
vector<time_t> showback_slots;
|
||||
vector<time_t>::iterator slot_it;
|
||||
|
||||
|
||||
|
||||
map<int, map<time_t, SBRecord> > vm_cost;
|
||||
map<int, map<time_t, SBRecord> >::iterator vm_it;
|
||||
|
||||
@ -1032,6 +1032,7 @@ void VirtualMachinePool::delete_attach_disk(int vid, bool release_save_as)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
VectorAttribute * disk;
|
||||
Snapshots * snap;
|
||||
|
||||
int uid;
|
||||
int gid;
|
||||
@ -1044,7 +1045,7 @@ void VirtualMachinePool::delete_attach_disk(int vid, bool release_save_as)
|
||||
return;
|
||||
}
|
||||
|
||||
disk = vm->delete_attach_disk();
|
||||
disk = vm->delete_attach_disk(&snap);
|
||||
uid = vm->get_uid();
|
||||
gid = vm->get_gid();
|
||||
oid = vm->get_oid();
|
||||
@ -1068,6 +1069,12 @@ void VirtualMachinePool::delete_attach_disk(int vid, bool release_save_as)
|
||||
// Disk using an Image
|
||||
Quotas::quota_del(Quotas::IMAGE, uid, gid, &tmpl);
|
||||
|
||||
if (snap != 0)
|
||||
{
|
||||
imagem->set_image_snapshots(image_id, *snap, false);
|
||||
delete snap;
|
||||
}
|
||||
|
||||
imagem->release_image(oid, image_id, false);
|
||||
|
||||
// Release non-persistent images in the detach event
|
||||
|
Loading…
x
Reference in New Issue
Block a user