mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
Bug #3883: Attach disk doesn't check cluster compatibility. It also sets all
output values in set_up_attach_disk. Changed some checks in
DispatchManager::attach
(cherry picked from commit 4227b80cc5
)
This commit is contained in:
parent
c9ccd944d0
commit
17f38ea37e
@ -832,6 +832,24 @@ public:
|
||||
return previous_history->hid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cluster id where the VM is or is going to execute. The hasHistory()
|
||||
* function MUST be called before this one.
|
||||
*/
|
||||
int get_cid()
|
||||
{
|
||||
return history->cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cluster id where the VM was executing. The hasPreviousHistory()
|
||||
* function MUST be called before this one.
|
||||
*/
|
||||
int get_previous_cid()
|
||||
{
|
||||
return previous_history->cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets start time of a VM.
|
||||
* @param _stime time when the VM started
|
||||
|
@ -902,6 +902,7 @@ int DispatchManager::attach(int vid,
|
||||
int uid;
|
||||
int oid;
|
||||
int image_id;
|
||||
int image_cluster_id;
|
||||
|
||||
set<string> used_targets;
|
||||
VectorAttribute * disk;
|
||||
@ -965,20 +966,17 @@ int DispatchManager::attach(int vid,
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
if ( image_id != -1 )
|
||||
{
|
||||
imagem->release_image(oid, image_id, false);
|
||||
}
|
||||
if ( disk != 0 )
|
||||
{
|
||||
imagem->release_image(oid, image_id, false);
|
||||
|
||||
delete snap;
|
||||
delete disk;
|
||||
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();
|
||||
error_str = "VM does not exist after setting its state to HOTPLUG.";
|
||||
|
||||
NebulaLog::log("DiM", Log::ERROR, error_str);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1002,6 +1000,37 @@ int DispatchManager::attach(int vid,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check that we don't have a cluster incompatibility.
|
||||
if (disk->vector_value("CLUSTER_ID", image_cluster_id) == 0)
|
||||
{
|
||||
if (vm->get_cid() != image_cluster_id)
|
||||
{
|
||||
imagem->release_image(oid, image_id, false);
|
||||
|
||||
delete snap;
|
||||
delete disk;
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
|
||||
{
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->set_state(VirtualMachine::LCM_INIT);
|
||||
vm->set_state(VirtualMachine::POWEROFF);
|
||||
}
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
error_str = "Could not attach disk because of cluster incompatibility.";
|
||||
|
||||
NebulaLog::log("DiM", Log::ERROR, error_str);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the VM info in the history before the disk is attached to the
|
||||
// VM template
|
||||
vm->set_vm_info();
|
||||
|
@ -307,15 +307,15 @@ int ImagePool::get_disk_id(const string& id_s)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::acquire_disk( int vm_id,
|
||||
VectorAttribute * disk,
|
||||
int disk_id,
|
||||
Image::ImageType& img_type,
|
||||
string& dev_prefix,
|
||||
int uid,
|
||||
int& image_id,
|
||||
Snapshots ** snap,
|
||||
string& error_str)
|
||||
int ImagePool::acquire_disk(int vm_id,
|
||||
VectorAttribute * disk,
|
||||
int disk_id,
|
||||
Image::ImageType& img_type,
|
||||
string& dev_prefix,
|
||||
int uid,
|
||||
int& image_id,
|
||||
Snapshots ** snap,
|
||||
string& error_str)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
|
@ -2092,15 +2092,15 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
|
||||
// Acquire the new disk image
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
int rc = ipool->acquire_disk( vm_id,
|
||||
new_disk,
|
||||
max_disk_id + 1,
|
||||
img_type,
|
||||
dev_prefix,
|
||||
uid,
|
||||
image_id,
|
||||
snap,
|
||||
error_str);
|
||||
int rc = ipool->acquire_disk(vm_id,
|
||||
new_disk,
|
||||
max_disk_id + 1,
|
||||
img_type,
|
||||
dev_prefix,
|
||||
uid,
|
||||
image_id,
|
||||
snap,
|
||||
error_str);
|
||||
if ( rc != 0 )
|
||||
{
|
||||
delete new_disk;
|
||||
@ -2123,6 +2123,9 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
|
||||
delete new_disk;
|
||||
delete snap;
|
||||
|
||||
*snap = 0;
|
||||
image_id = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user