mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-26 10:03:37 +03:00
Merge branch 'bug-1480'
This commit is contained in:
commit
b3b5ea3ab4
@ -758,9 +758,10 @@ public:
|
||||
* Writes the context file for this VM, and gets the paths to be included
|
||||
* in the context block device (CBD)
|
||||
* @param files space separated list of paths to be included in the CBD
|
||||
* @return 0 if success
|
||||
* @param disk_id CONTEXT/DISK_ID attribute value
|
||||
* @return -1 in case of error, 0 if the VM has no context, 1 on success
|
||||
*/
|
||||
int generate_context(string &files);
|
||||
int generate_context(string &files, int &disk_id);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Datastore related functions
|
||||
@ -805,16 +806,16 @@ public:
|
||||
|
||||
/**
|
||||
* Collects information about VM DISKS
|
||||
* @param num_disks of the VM
|
||||
* @param max_disk_id of the VM
|
||||
* @param used_targets by the DISKS of the VM
|
||||
*/
|
||||
void get_disk_info(int& num_disks, set<string>& used_targets);
|
||||
void get_disk_info(int& max_disk_id, set<string>& used_targets);
|
||||
|
||||
/**
|
||||
* Generate a DISK attributed to be attached to the VM.
|
||||
* @param tmpl Template containing a single DISK vector attribute.
|
||||
* @param used_targets targets in use by current DISKS
|
||||
* @param num_disks of the VM
|
||||
* @param max_disk_id Max DISK/DISK_ID of the VM
|
||||
* @param uid of the VM owner
|
||||
* @param image_id returns the id of the aquired image
|
||||
* @param error_str describes the error
|
||||
@ -825,7 +826,7 @@ public:
|
||||
static VectorAttribute * set_up_attach_disk(
|
||||
VirtualMachineTemplate * tmpl,
|
||||
set<string>& used_targets,
|
||||
int num_disks,
|
||||
int max_disk_id,
|
||||
int uid,
|
||||
int& image_id,
|
||||
string& error_str);
|
||||
|
@ -910,7 +910,7 @@ int DispatchManager::attach(int vid,
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int num_disks;
|
||||
int max_disk_id;
|
||||
int uid;
|
||||
int image_id;
|
||||
|
||||
@ -945,7 +945,7 @@ int DispatchManager::attach(int vid,
|
||||
return -1;
|
||||
}
|
||||
|
||||
vm->get_disk_info(num_disks, used_targets);
|
||||
vm->get_disk_info(max_disk_id, used_targets);
|
||||
|
||||
vm->set_state(VirtualMachine::HOTPLUG);
|
||||
|
||||
@ -959,7 +959,7 @@ int DispatchManager::attach(int vid,
|
||||
|
||||
disk = VirtualMachine::set_up_attach_disk(tmpl,
|
||||
used_targets,
|
||||
num_disks,
|
||||
max_disk_id,
|
||||
uid,
|
||||
image_id,
|
||||
error_str);
|
||||
|
@ -226,11 +226,11 @@ int TransferManager::prolog_transfer_command(
|
||||
string ds_id;
|
||||
string vm_ds_id;
|
||||
|
||||
int disk_index;
|
||||
int disk_id;
|
||||
|
||||
vm_ds_id = vm->get_ds_id();
|
||||
|
||||
disk->vector_value("DISK_ID", disk_index);
|
||||
disk->vector_value("DISK_ID", disk_id);
|
||||
|
||||
type = disk->vector_value("TYPE");
|
||||
|
||||
@ -255,7 +255,7 @@ int TransferManager::prolog_transfer_command(
|
||||
<< vm_tm_mad << " "
|
||||
<< size << " "
|
||||
<< vm->get_hostname() << ":"
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_index << " "
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
|
||||
<< vm->get_oid() << " "
|
||||
<< vm_ds_id
|
||||
<< endl;
|
||||
@ -281,7 +281,7 @@ int TransferManager::prolog_transfer_command(
|
||||
<< size << " "
|
||||
<< format << " "
|
||||
<< vm->get_hostname() << ":"
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_index << " "
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
|
||||
<< vm->get_oid() << " "
|
||||
<< vm_ds_id
|
||||
<< endl;
|
||||
@ -332,7 +332,7 @@ int TransferManager::prolog_transfer_command(
|
||||
}
|
||||
|
||||
xfr << vm->get_hostname() << ":"
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_index << " "
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
|
||||
<< vm->get_oid() << " "
|
||||
<< ds_id
|
||||
<< endl;
|
||||
@ -372,6 +372,7 @@ void TransferManager::prolog_action(int vid)
|
||||
|
||||
vector<const Attribute *> attrs;
|
||||
int num;
|
||||
int disk_id;
|
||||
|
||||
int context_result;
|
||||
|
||||
@ -435,9 +436,9 @@ void TransferManager::prolog_action(int vid)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Generate context file (There are 0...num-1 disks, constext is disk.num)
|
||||
// Generate context file
|
||||
// -------------------------------------------------------------------------
|
||||
context_result = vm->generate_context(files);
|
||||
context_result = vm->generate_context(files, disk_id);
|
||||
|
||||
if ( context_result == -1 )
|
||||
{
|
||||
@ -457,7 +458,7 @@ void TransferManager::prolog_action(int vid)
|
||||
}
|
||||
|
||||
xfr << vm->get_hostname() << ":"
|
||||
<< vm->get_remote_system_dir() << "/disk." << num << " "
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
|
||||
<< vm->get_oid() << " "
|
||||
<< vm->get_ds_id()
|
||||
<< endl;
|
||||
@ -802,7 +803,7 @@ void TransferManager::epilog_transfer_command(
|
||||
string save;
|
||||
string tm_mad;
|
||||
string ds_id;
|
||||
int disk_index;
|
||||
int disk_id;
|
||||
|
||||
if ( isVolatile(disk) == true )
|
||||
{
|
||||
@ -822,7 +823,7 @@ void TransferManager::epilog_transfer_command(
|
||||
}
|
||||
}
|
||||
|
||||
disk->vector_value("DISK_ID", disk_index);
|
||||
disk->vector_value("DISK_ID", disk_id);
|
||||
|
||||
transform(save.begin(),save.end(),save.begin(),(int(*)(int))toupper);
|
||||
|
||||
@ -849,7 +850,7 @@ void TransferManager::epilog_transfer_command(
|
||||
xfr << "MVDS "
|
||||
<< tm_mad << " "
|
||||
<< vm->get_hostname() << ":"
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_index << " "
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
|
||||
<< source << " "
|
||||
<< vm->get_oid() << " "
|
||||
<< ds_id
|
||||
@ -861,7 +862,7 @@ void TransferManager::epilog_transfer_command(
|
||||
xfr << "DELETE "
|
||||
<< tm_mad << " "
|
||||
<< vm->get_hostname() << ":"
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_index << " "
|
||||
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
|
||||
<< vm->get_oid() << " "
|
||||
<< ds_id
|
||||
<< endl;
|
||||
|
@ -1005,8 +1005,9 @@ static void assign_disk_targets(queue<pair <string, VectorAttribute *> >& _queue
|
||||
|
||||
int VirtualMachine::get_disk_images(string& error_str)
|
||||
{
|
||||
int num_disks, rc;
|
||||
int num_disks, num_context, rc;
|
||||
vector<Attribute *> disks;
|
||||
vector<Attribute *> context_disks;
|
||||
ImagePool * ipool;
|
||||
VectorAttribute * disk;
|
||||
vector<int> acquired_images;
|
||||
@ -1030,11 +1031,17 @@ int VirtualMachine::get_disk_images(string& error_str)
|
||||
// -------------------------------------------------------------------------
|
||||
// The context is the first of the cdroms
|
||||
// -------------------------------------------------------------------------
|
||||
num_disks = obj_template->get("CONTEXT", disks);
|
||||
num_context = obj_template->get("CONTEXT", context_disks);
|
||||
num_disks = obj_template->get("DISK", disks);
|
||||
|
||||
if ( num_disks > 0 )
|
||||
if ( num_disks > 20 )
|
||||
{
|
||||
disk = dynamic_cast<VectorAttribute * >(disks[0]);
|
||||
goto error_max_disks;
|
||||
}
|
||||
|
||||
if ( num_context > 0 )
|
||||
{
|
||||
disk = dynamic_cast<VectorAttribute * >(context_disks[0]);
|
||||
|
||||
if ( disk != 0 )
|
||||
{
|
||||
@ -1048,20 +1055,15 @@ int VirtualMachine::get_disk_images(string& error_str)
|
||||
{
|
||||
cdrom_disks.push(make_pair(ipool->default_dev_prefix(), disk));
|
||||
}
|
||||
|
||||
// Disk IDs are 0..num-1, context disk is is num
|
||||
disk->replace("DISK_ID", num_disks);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Set DISK attributes & Targets
|
||||
// -------------------------------------------------------------------------
|
||||
disks.clear();
|
||||
num_disks = obj_template->get("DISK", disks);
|
||||
|
||||
if ( num_disks > 20 )
|
||||
{
|
||||
goto error_max_disks;
|
||||
}
|
||||
|
||||
for(int i=0; i<num_disks; i++)
|
||||
{
|
||||
disk = dynamic_cast<VectorAttribute * >(disks[i]);
|
||||
@ -1157,7 +1159,7 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::get_disk_info(int& num_disks,
|
||||
void VirtualMachine::get_disk_info(int& max_disk_id,
|
||||
set<string>& used_targets)
|
||||
{
|
||||
vector<Attribute *> disks;
|
||||
@ -1165,6 +1167,11 @@ void VirtualMachine::get_disk_info(int& num_disks,
|
||||
|
||||
string target;
|
||||
|
||||
int disk_id;
|
||||
int num_disks;
|
||||
|
||||
max_disk_id = 0;
|
||||
|
||||
num_disks = obj_template->get("DISK", disks);
|
||||
|
||||
for(int i=0; i<num_disks; i++)
|
||||
@ -1182,8 +1189,17 @@ void VirtualMachine::get_disk_info(int& num_disks,
|
||||
{
|
||||
used_targets.insert(target);
|
||||
}
|
||||
|
||||
disk->vector_value("DISK_ID", disk_id);
|
||||
|
||||
if ( disk_id > max_disk_id )
|
||||
{
|
||||
max_disk_id = disk_id;
|
||||
}
|
||||
}
|
||||
|
||||
disks.clear();
|
||||
|
||||
if ( obj_template->get("CONTEXT", disks) > 0 )
|
||||
{
|
||||
disk = dynamic_cast<VectorAttribute * >(disks[0]);
|
||||
@ -1196,6 +1212,13 @@ void VirtualMachine::get_disk_info(int& num_disks,
|
||||
{
|
||||
used_targets.insert(target);
|
||||
}
|
||||
|
||||
disk->vector_value("DISK_ID", disk_id);
|
||||
|
||||
if ( disk_id > max_disk_id )
|
||||
{
|
||||
max_disk_id = disk_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1206,7 +1229,7 @@ void VirtualMachine::get_disk_info(int& num_disks,
|
||||
VectorAttribute * VirtualMachine::set_up_attach_disk(
|
||||
VirtualMachineTemplate * tmpl,
|
||||
set<string>& used_targets,
|
||||
int num_disks,
|
||||
int max_disk_id,
|
||||
int uid,
|
||||
int& image_id,
|
||||
string& error_str)
|
||||
@ -1242,7 +1265,7 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
int rc = ipool->disk_attribute(new_disk,
|
||||
num_disks + 1, //Preserv CONTEXT disk.i file
|
||||
max_disk_id + 1,
|
||||
img_type,
|
||||
dev_prefix,
|
||||
uid,
|
||||
@ -1546,7 +1569,7 @@ void VirtualMachine::release_network_leases()
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::generate_context(string &files)
|
||||
int VirtualMachine::generate_context(string &files, int &disk_id)
|
||||
{
|
||||
ofstream file;
|
||||
|
||||
@ -1598,6 +1621,8 @@ int VirtualMachine::generate_context(string &files)
|
||||
|
||||
file.close();
|
||||
|
||||
context->vector_value("DISK_ID", disk_id);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -129,10 +129,10 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
}
|
||||
|
||||
//Every process gets 1024 shares by default (cgroups), scale this with CPU
|
||||
if(vm->get_template_attribute("CPU", cpu))
|
||||
if(vm->get_template_attribute("CPU", cpu))
|
||||
{
|
||||
file << "\t<cputune>" << endl
|
||||
<< "\t\t<shares>"<< ceil( cpu * CGROUP_BASE_CPU_SHARES )
|
||||
<< "\t\t<shares>"<< ceil( cpu * CGROUP_BASE_CPU_SHARES )
|
||||
<< "</shares>" << endl
|
||||
<< "\t</cputune>"<< endl;
|
||||
}
|
||||
@ -339,19 +339,19 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
if ( type == "BLOCK" )
|
||||
{
|
||||
file << "\t\t<disk type='block' device='disk'>" << endl
|
||||
<< "\t\t\t<source dev='" << vm->get_remote_system_dir()
|
||||
<< "\t\t\t<source dev='" << vm->get_remote_system_dir()
|
||||
<< "/disk." << disk_id << "'/>" << endl;
|
||||
}
|
||||
else if ( type == "CDROM" )
|
||||
{
|
||||
file << "\t\t<disk type='file' device='cdrom'>" << endl
|
||||
<< "\t\t\t<source file='" << vm->get_remote_system_dir()
|
||||
<< "\t\t\t<source file='" << vm->get_remote_system_dir()
|
||||
<< "/disk." << disk_id << "'/>" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
file << "\t\t<disk type='file' device='disk'>" << endl
|
||||
<< "\t\t\t<source file='" << vm->get_remote_system_dir()
|
||||
<< "\t\t\t<source file='" << vm->get_remote_system_dir()
|
||||
<< "/disk." << disk_id << "'/>" << endl;
|
||||
}
|
||||
|
||||
@ -408,13 +408,14 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
context = dynamic_cast<const VectorAttribute *>(attrs[0]);
|
||||
target = context->vector_value("TARGET");
|
||||
driver = context->vector_value("DRIVER");
|
||||
disk->vector_value_str("DISK_ID", disk_id);
|
||||
|
||||
if ( !target.empty() )
|
||||
{
|
||||
file << "\t\t<disk type='file' device='cdrom'>" << endl;
|
||||
|
||||
file << "\t\t\t<source file='" << vm->get_remote_system_dir()
|
||||
<< "/disk." << num << "'/>" << endl;
|
||||
file << "\t\t\t<source file='" << vm->get_remote_system_dir()
|
||||
<< "/disk." << disk_id << "'/>" << endl;
|
||||
|
||||
file << "\t\t\t<target dev='" << target << "'/>" << endl;
|
||||
file << "\t\t\t<readonly/>" << endl;
|
||||
|
@ -276,12 +276,13 @@ int LibVirtDriver::deployment_description_vmware(
|
||||
{
|
||||
context = dynamic_cast<const VectorAttribute *>(attrs[0]);
|
||||
target = context->vector_value("TARGET");
|
||||
disk->vector_value_str("DISK_ID", disk_id);
|
||||
|
||||
if ( !target.empty() )
|
||||
{
|
||||
file << "\t\t<disk type='file' device='cdrom'>" << endl;
|
||||
file << "\t\t\t<source file='[" << vm->get_ds_id() <<"] "
|
||||
<< vm->get_oid() << "/disk." << num << ".iso'/>" << endl;
|
||||
<< vm->get_oid() << "/disk." << disk_id << ".iso'/>" << endl;
|
||||
file << "\t\t\t<target dev='" << target << "'/>" << endl;
|
||||
file << "\t\t\t<readonly/>" << endl;
|
||||
file << "\t\t</disk>" << endl;
|
||||
|
@ -295,6 +295,7 @@ int XenDriver::deployment_description(
|
||||
context = dynamic_cast<const VectorAttribute *>(attrs[0]);
|
||||
target = context->vector_value("TARGET");
|
||||
driver = context->vector_value("DRIVER");
|
||||
disk->vector_value_str("DISK_ID", disk_id);
|
||||
|
||||
if ( !target.empty() )
|
||||
{
|
||||
@ -309,8 +310,8 @@ int XenDriver::deployment_description(
|
||||
file << default_driver;
|
||||
}
|
||||
|
||||
file << vm->get_remote_system_dir() << "/disk." << num <<","<< target <<","
|
||||
<< "r'," << endl;
|
||||
file << vm->get_remote_system_dir() << "/disk." << disk_id
|
||||
<< "," << target << "," << "r'," << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user