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

feature #4630: Automatic assgiment of passthrough devices. Attribute and

deployment file
This commit is contained in:
Ruben S. Montero 2016-07-18 14:26:30 +02:00
parent 086ccd4f09
commit b6dbd9c92c
6 changed files with 121 additions and 6 deletions

View File

@ -117,6 +117,19 @@ public:
static int get_pci_value(const char * name,
const VectorAttribute * pci_device,
unsigned int& value);
/**
* Sets the PCI device address in the Virtual Machine as follows;
* - VM_DOMAIN: 0x0000
* - VM_BUS: dbus or VM_BUS in PCI attribute
* - VM_SLOT: PCI_ID + 1
* - VM_FUNCTION: 0
* - VM_ADDRESS: BUS:SLOT.0
* @param pci_device to set the address in
* @param default_bus if not set in PCI attribute (PCI_PASSTHROUGH_BUS
* in oned.conf)
* @return -1 if wrong bus 0 on success
*/
static int set_pci_address(VectorAttribute * pci_device, const string& dbus);
private:
/**

View File

@ -199,6 +199,10 @@ DEFAULT_COST = [
# for vxlan networks.
# start: First VNI to use
# NOTE: reserved is not supported by this pool
#
# PCI_PASSTHROUGH_BUS: Default bus to attach passthrough devices in the guest,
# in hex notation. It may be overwritten in the PCI device using the BUS
# attribute.
#*******************************************************************************
NETWORK_SIZE = 254
@ -214,6 +218,8 @@ VXLAN_IDS = [
START = "2"
]
#PCI_PASSTHROUGH_BUS = "0x01"
#*******************************************************************************
# DataStore Configuration
#*******************************************************************************

View File

@ -267,6 +267,65 @@ int HostSharePCI::get_pci_value(const char * name,
return 1;
}
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/
int HostSharePCI::set_pci_address(VectorAttribute * pci_device,
const string& dbus)
{
string bus;
ostringstream oss;
unsigned int ibus, slot;
// ------------------- DOMAIN & FUNCTION -------------------------
pci_device->replace("VM_DOMAIN", "0x0000");
pci_device->replace("VM_FUNCTION", "0");
// --------------------------- BUS -------------------------------
bus = pci_device->vector_value("VM_BUS");
if ( bus.empty() )
{
bus = dbus;
}
istringstream iss(bus);
iss >> hex >> ibus;
if (iss.fail() || !iss.eof())
{
return -1;
}
oss << showbase << internal << setfill('0') << hex << setw(4) << ibus;
pci_device->replace("VM_BUS", oss.str());
// --------------------- SLOT (PCI_ID +1) -----------------------
oss.str("");
pci_device->vector_value("PCI_ID", slot);
slot = slot + 1;
oss << showbase << internal << setfill('0') << hex << setw(4) << slot;
pci_device->replace("VM_SLOT", oss.str());
// ------------------- ADDRESS (BUS:SLOT.0) ---------------------
oss.str("");
oss << noshowbase<<internal<<hex<<setfill('0')<<setw(2) << ibus << ":"
<< noshowbase<<internal<<hex<<setfill('0')<<setw(2) << slot << ".0";
pci_device->replace("VM_ADDRESS", oss.str());
return 0;
}
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/

View File

@ -451,6 +451,7 @@ void OpenNebulaTemplate::set_conf_default()
# MAC_PREFIX
# VLAN_ID
# VXLAN_ID
# PCI_PASSTHROUGH_BUS
#*******************************************************************************
*/
set_conf_single("MAC_PREFIX", "02:00");
@ -468,6 +469,8 @@ void OpenNebulaTemplate::set_conf_default()
vattribute = new VectorAttribute("VXLAN_IDS",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));
set_conf_single("PCI_PASSTHROUGH_BUS", "0x01");
/*
#*******************************************************************************
# Datastore Configuration

View File

@ -1202,12 +1202,14 @@ int VirtualMachine::parse_context_variables(VectorAttribute ** context,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static int check_pci_attributes(VectorAttribute * pci, string& error_str)
static int check_pci_attributes(VectorAttribute * pci, const string& default_bus,
string& error_str)
{
static string attrs[] = {"VENDOR", "DEVICE", "CLASS"};
static int num_attrs = 3;
bool found = false;
string bus;
bool found = false;
for (int i = 0; i < num_attrs; i++)
{
@ -1231,6 +1233,12 @@ static int check_pci_attributes(VectorAttribute * pci, string& error_str)
return -1;
}
if ( HostSharePCI::set_pci_address(pci, default_bus) != 0 )
{
error_str = "Wrong BUS in PCI attribute";
return -1;
}
return 0;
}
@ -1250,9 +1258,14 @@ int VirtualMachine::parse_pci(string& error_str)
obj_template->set(*it);
}
Nebula& nd = Nebula::instance();
string default_bus;
nd.get_configuration_attribute("PCI_PASSTHROUGH_BUS", default_bus);
for (it = array_pci.begin(); it !=array_pci.end(); ++it)
{
if ( check_pci_attributes(*it, error_str) != 0 )
if ( check_pci_attributes(*it, default_bus, error_str) != 0 )
{
return -1;
}

View File

@ -184,10 +184,15 @@ int LibVirtDriver::deployment_description_kvm(
vector<const VectorAttribute *> pci;
string domain = "";
string domain = "";
/* bus is already defined for disks */
string slot = "";
string func = "";
string slot = "";
string func = "";
string vm_domain = "";
string vm_bus = "";
string vm_slot = "";
string vm_func = "";
const VectorAttribute * features;
@ -1014,6 +1019,11 @@ int LibVirtDriver::deployment_description_kvm(
slot = pci[i]->vector_value("SLOT");
func = pci[i]->vector_value("FUNCTION");
vm_domain = pci[i]->vector_value("VM_DOMAIN");
vm_bus = pci[i]->vector_value("VM_BUS");
vm_slot = pci[i]->vector_value("VM_SLOT");
vm_func = pci[i]->vector_value("VM_FUNCTION");
if ( domain.empty() || bus.empty() || slot.empty() || func.empty() )
{
vm->log("VMM", Log::WARNING,
@ -1033,6 +1043,17 @@ int LibVirtDriver::deployment_description_kvm(
<< "/>\n";
file << "\t\t\t</source>\n";
if ( !vm_domain.empty() && !vm_bus.empty() && !vm_slot.empty() &&
!vm_func.empty() )
{
file << "\t\t\t\t<address type='pci'"
<< " domain=" << one_util::escape_xml_attr(vm_domain)
<< " bus=" << one_util::escape_xml_attr(vm_bus)
<< " slot=" << one_util::escape_xml_attr(vm_slot)
<< " function=" << one_util::escape_xml_attr(vm_func)
<< "/>\n";
}
file << "\t\t</hostdev>" << endl;
}