Reviewed-by: Daniel Barboza <dhbarboza82(a)gmail.com>
On 07/16/2015 01:42 PM, Jose Ricardo Ziviani wrote:
- A PCI device can have more than one function. In this case each
function must be detached from host before attaching to the vm.
Signed-off-by: Jose Ricardo Ziviani <joserz(a)linux.vnet.ibm.com>
---
src/kimchi/model/vmhostdevs.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/kimchi/model/vmhostdevs.py b/src/kimchi/model/vmhostdevs.py
index ea75fce..76033f0 100644
--- a/src/kimchi/model/vmhostdevs.py
+++ b/src/kimchi/model/vmhostdevs.py
@@ -196,6 +196,22 @@ class VMHostDevsModel(object):
pci_infos = [dev_model.lookup(dev_name) for dev_name in group_names]
pci_infos.append(dev_info)
+ # all devices in the group that is going to be attached to the vm
+ # must be detached from the host first
+ with RollbackContext() as rollback:
+ for pci_info in pci_infos:
+ try:
+ dev = self.conn.get().nodeDeviceLookupByName(
+ pci_info['name'])
+ dev.dettach()
+ except Exception:
+ raise OperationFailed('KCHVMHDEV0005E',
+ {'name': pci_info['name']})
+ else:
+ rollback.prependDefer(dev.reAttach)
+
+ rollback.commitAll()
+
device_flags = get_vm_config_flag(dom, mode='all')
with RollbackContext() as rollback: