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

B #2587: Derive disk bus from prefix and machine (#3700)

This commit is contained in:
Jan Orel 2019-09-16 17:47:19 +02:00 committed by Ruben S. Montero
parent 38a29571de
commit bbde2f91c5
2 changed files with 64 additions and 4 deletions

View File

@ -335,6 +335,39 @@ static void vtopol(ofstream& file, const VectorAttribute * topology,
}
}
/**
* Returns disk bus based on this table:
* \ prefix hd sd vd
* chipset \
* pc-q35-* sata [sd_default] virtio
* (other) ide [sd_default] virtio
*
* sd_default - SD_DISK_BUS value from vmm_exec_kvm.conf/template
* 'sata' or 'scsi'
*/
static string get_disk_bus(std::string &machine, std::string &target,
std::string &sd_default)
{
switch(target[0])
{
case 's': // sd_ disk
return sd_default;
case 'v': // vd_ disk
return "virtio";
default:
{
std::size_t found = machine.find("q35");
if (found != std::string::npos)
{
return "sata";
}
}
}
return "ide";
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -517,6 +550,9 @@ int LibVirtDriver::deployment_description_kvm(
std::string numa_tune = "";
std::string mbacking = "";
std::string sd_bus;
std::string disk_bus;
string vm_xml;
// ------------------------------------------------------------------------
@ -605,6 +641,7 @@ int LibVirtDriver::deployment_description_kvm(
bootloader = os->vector_value("BOOTLOADER");
arch = os->vector_value("ARCH");
machine = os->vector_value("MACHINE");
sd_bus = os->vector_value("SD_DISK_BUS");
}
if ( arch.empty() )
@ -656,6 +693,11 @@ int LibVirtDriver::deployment_description_kvm(
get_default("OS","KERNEL_CMD",kernel_cmd);
}
if ( sd_bus.empty() )
{
get_default("OS", "SD_DISK_BUS", sd_bus);
}
// Start writing to the file with the info we got
if ( !kernel.empty() )
@ -1073,7 +1115,17 @@ int LibVirtDriver::deployment_description_kvm(
// ---- target device to map the disk ----
file << "\t\t\t<target dev=" << one_util::escape_xml_attr(target) << "/>\n";
file << "\t\t\t<target dev=" << one_util::escape_xml_attr(target);
disk_bus = get_disk_bus(machine, target, sd_bus);
if (!disk_bus.empty())
{
file << " bus="<< one_util::escape_xml_attr(disk_bus);
}
file <<"/>\n";
// ---- boot order for this device ----
@ -1226,8 +1278,16 @@ int LibVirtDriver::deployment_description_kvm(
file << "\t\t<disk type='file' device='cdrom'>\n"
<< "\t\t\t<source file="
<< one_util::escape_xml_attr(fname.str()) << "/>\n"
<< "\t\t\t<target dev="
<< one_util::escape_xml_attr(target) << "/>\n"
<< "\t\t\t<target dev=" << one_util::escape_xml_attr(target);
disk_bus = get_disk_bus(machine, target, sd_bus);
if (!disk_bus.empty())
{
file << " bus="<< one_util::escape_xml_attr(disk_bus);
}
file <<"/>\n"
<< "\t\t\t<readonly/>\n"
<< "\t\t\t<driver name='qemu' type='raw'/>\n"
<< "\t\t</disk>\n";

View File

@ -18,7 +18,7 @@
# (all domains will use these values as defaults). These values can
# be overridden in each VM template. Valid atributes are:
# - emulator
# - os [kernel,initrd,boot,root,kernel_cmd,arch,machine]
# - os [kernel,initrd,boot,root,kernel_cmd,arch,machine,sd_disk_bus]
# - vcpu
# - features [acpi, pae, apic, hyperv, localtime, guest_agent, virtio_scsi_queues]
# - disk [driver, cache, io, discard, total_bytes_sec, total_iops_sec, read_bytes_sec, write_bytes_sec, read_iops_sec, write_iops_sec]