1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

B #5261: Fix PCI references after vm migrate fails (#877)

This commit is contained in:
Pavel Czerný 2021-02-25 11:45:13 +01:00 committed by GitHub
parent b6538876b5
commit ecd36bcb9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 5 deletions

View File

@ -271,6 +271,15 @@ public:
}
};
/**
* Revert changes in PCI Devices after migrate failure
* @param sr host share capacity info
*/
void revert_pci(HostShareCapacity& sr)
{
host_share.revert_pci(sr);
}
/**
* Tests whether a VM device capacity can be allocated in the host
* @param sr capacity requested by the VM

View File

@ -71,6 +71,12 @@ public:
*/
void del(HostShareCapacity &sr);
/**
* Revert changes in PCI Devices
* @param sr capacity info by the VM
*/
void revert_pci(HostShareCapacity &sr);
/**
* Check if this share can host a VM.
* @param cpu requested by the VM

View File

@ -84,7 +84,12 @@ public:
/**
* Remove the VM assignment from the PCI device list
*/
void del(const std::vector<VectorAttribute *> &devs);
void del(const std::vector<VectorAttribute *> &devs, int vmid);
/**
* Revert the VM assignment from the PCI device list
*/
void revert(std::vector<VectorAttribute *> &devs);
/**
* Updates the PCI list with monitor data, it will create or

View File

@ -370,7 +370,7 @@ void HostShare::del(HostShareCapacity &sr)
ds.del(sr);
pci.del(sr.pci);
pci.del(sr.pci, sr.vmid);
numa.del(sr);
@ -379,6 +379,13 @@ void HostShare::del(HostShareCapacity &sr)
/* -------------------------------------------------------------------------- */
void HostShare::revert_pci(HostShareCapacity &sr)
{
pci.revert(sr.pci);
}
/* -------------------------------------------------------------------------- */
bool HostShare::test(HostShareCapacity& sr, string& error) const
{
if ( !test_compute(sr.cpu, sr.mem, error) )

View File

@ -181,13 +181,13 @@ void HostSharePCI::add(vector<VectorAttribute *> &devs, int vmid)
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/
void HostSharePCI::del(const vector<VectorAttribute *> &devs)
void HostSharePCI::del(const vector<VectorAttribute *> &devs, int vmid)
{
for (auto device : devs)
{
auto pci_it = pci_devices.find(device->vector_value("PREV_ADDRESS"));
if (pci_it != pci_devices.end())
if (pci_it != pci_devices.end() && pci_it->second->vmid == vmid)
{
pci_it->second->vmid = -1;
pci_it->second->attrs->replace("VMID",-1);
@ -199,7 +199,7 @@ void HostSharePCI::del(const vector<VectorAttribute *> &devs)
pci_it = pci_devices.find(device->vector_value("ADDRESS"));
if (pci_it != pci_devices.end())
if (pci_it != pci_devices.end() && pci_it->second->vmid == vmid)
{
pci_it->second->vmid = -1;
pci_it->second->attrs->replace("VMID",-1);
@ -213,6 +213,44 @@ void HostSharePCI::del(const vector<VectorAttribute *> &devs)
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/
void HostSharePCI::revert(vector<VectorAttribute *> &devs)
{
string address;
for (auto device : devs)
{
device->vector_value("PREV_ADDRESS", address);
if (!address.empty())
{
auto dev = pci_devices[address];
if (!dev)
{
continue;
}
device->replace("DOMAIN", dev->attrs->vector_value("DOMAIN"));
device->replace("BUS", dev->attrs->vector_value("BUS"));
device->replace("SLOT", dev->attrs->vector_value("SLOT"));
device->replace("FUNCTION",dev->attrs->vector_value("FUNCTION"));
device->replace("ADDRESS", address);
device->remove("PREV_ADDRESS");
int node = -1;
if (dev->attrs->vector_value("NUMA_NODE", node)==0 && node !=-1)
{
device->replace("NUMA_NODE", node);
}
break;
}
}
}
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/
void HostSharePCI::set_monitorization(Template& ht)
{
string address;

View File

@ -98,6 +98,15 @@ void LifeCycleManager::revert_migrate_after_failure(VirtualMachine* vm)
{
hpool->del_capacity(vm->get_hid(), sr);
if (!sr.pci.empty())
{
if (auto host = hpool->get(vm->get_previous_hid()))
{
// Revert PCI assignment in sr
host->revert_pci(sr);
}
}
vm->rollback_previous_vnc_port();
}