<div dir="ltr">Reviewed-by: Daniel Barboza <<a href="mailto:dhbarboza82@gmail.com">dhbarboza82@gmail.com</a>></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 15, 2015 at 6:38 PM, Aline Manera <span dir="ltr"><<a href="mailto:alinefm@linux.vnet.ibm.com" target="_blank">alinefm@linux.vnet.ibm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">According to libvirt documentation, the device must be detached from host to<br>
avoid problems in the host system.<br>
<br>
In my tests, the host crashed after attaching a FC HBA as PCI passthrough<br>
device to a guest using Kimchi. A host reboot was needed to recover the system.<br>
<br>
For reference:<br>
<a href="https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/chap-Virtualization-PCI_passthrough.html" rel="noreferrer" target="_blank">https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/chap-Virtualization-PCI_passthrough.html</a><br>
<br>
Signed-off-by: Aline Manera <<a href="mailto:alinefm@linux.vnet.ibm.com">alinefm@linux.vnet.ibm.com</a>><br>
---<br>
src/kimchi/i18n.py | 1 +<br>
src/kimchi/model/vmhostdevs.py | 21 ++++++++++++++++++---<br>
2 files changed, 19 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py<br>
index 00a6c7c..d2ffa34 100644<br>
--- a/src/kimchi/i18n.py<br>
+++ b/src/kimchi/i18n.py<br>
@@ -126,6 +126,7 @@ messages = {<br>
"For Intel CPU, add intel_iommu=on to your Kernel parameter in /boot/grub2/grub.conf. "<br>
"For AMD CPU, add iommu=pt iommu=1."),<br>
"KCHVMHDEV0004E": _('"name" should be a device name string'),<br>
+ "KCHVMHDEV0005E": _('The device %(name)s is probably in use by the host. Unable to attach it to the guest.'),<br>
<br>
"KCHVMIF0001E": _("Interface %(iface)s does not exist in virtual machine %(name)s"),<br>
"KCHVMIF0002E": _("Network %(network)s specified for virtual machine %(name)s does not exist"),<br>
diff --git a/src/kimchi/model/vmhostdevs.py b/src/kimchi/model/vmhostdevs.py<br>
index 946b1f6..ea75fce 100644<br>
--- a/src/kimchi/model/vmhostdevs.py<br>
+++ b/src/kimchi/model/vmhostdevs.py<br>
@@ -25,6 +25,7 @@ from lxml import etree, objectify<br>
from lxml.builder import E<br>
<br>
from kimchi.exception import InvalidOperation, InvalidParameter, NotFoundError<br>
+from kimchi.exception import OperationFailed<br>
from kimchi.model.config import CapabilitiesModel<br>
from kimchi.model.host import DeviceModel, DevicesModel<br>
from kimchi.model.utils import get_vm_config_flag<br>
@@ -122,9 +123,23 @@ class VMHostDevsModel(object):<br>
dev_name = params['name']<br>
self._passthrough_device_validate(dev_name)<br>
dev_info = DeviceModel(conn=self.conn).lookup(dev_name)<br>
- attach_device = getattr(<br>
- self, '_attach_%s_device' % dev_info['device_type'])<br>
- return attach_device(vmid, dev_info)<br>
+<br>
+ with RollbackContext() as rollback:<br>
+ try:<br>
+ dev = self.conn.get().nodeDeviceLookupByName(dev_name)<br>
+ dev.dettach()<br>
+ except Exception:<br>
+ raise OperationFailed('KCHVMHDEV0005E', {'name': dev_name})<br>
+ else:<br>
+ rollback.prependDefer(dev.reAttach)<br>
+<br>
+ attach_device = getattr(<br>
+ self, '_attach_%s_device' % dev_info['device_type'])<br>
+<br>
+ info = attach_device(vmid, dev_info)<br>
+ rollback.commitAll()<br>
+<br>
+ return info<br>
<br>
def _get_pci_device_xml(self, dev_info):<br>
if 'detach_driver' not in dev_info:<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.0<br>
<br>
_______________________________________________<br>
Kimchi-devel mailing list<br>
<a href="mailto:Kimchi-devel@ovirt.org">Kimchi-devel@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/kimchi-devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman/listinfo/kimchi-devel</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Daniel Henrique Barboza<div>Senior Software Engineer - IBM Linux Technology Center </div></div></div>
</div>