<html><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><META name="Author" content="Novell GroupWise WebAccess"><style type="text/css"> 
body p 

        margin: 0px; 
}
</style></head><body style='font-family: Helvetica, Arial, sans-serif; font-size: 13px; '><div id="GroupWiseSection_1407925195000_lma@suse.com_B118D7016C3D0000BC7D000BCD69755F_" class="GroupWiseMessageBody"><div>Changes from V1 to V2:<br></div><span class="GroupwiseReplyHeader">* merge is_using_by_active_vm function to is_conflict_hostdev function according to Giuseppe's suggestion.<br>  (But remained hiding mechanism for conflict host device in active vm)<br><br>* Using is_dup flag to see whether or not comparing the bus & device fields because of Bus and device fields help to<br>  identity device uniqueness only for attached multiple usb devices which have same vendor/product in inactive vm.<br><br><br>>>> Lin Ma <lma@suse.com> 08/13/14 6:17 PM >>><br></span>If a host device is in use by an active guest, Doesn't append it to<br>list while adding hardware.<br><br>If a host device is in use by inactive guests, Then warn user and<br>let user make choice while adding hardware.<br><br>Signed-off-by: Lin Ma <lma@suse.com><br>---<br> virtManager/addhardware.py | 17 +++++++++++++++++<br> virtinst/devicehostdev.py  | 47 ++++++++++++++++++++++++++++++++++++++++++++++<br> 2 files changed, 64 insertions(+)<br><br>diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py<br>index 02cff57..eedb351 100644<br>--- a/virtManager/addhardware.py<br>+++ b/virtManager/addhardware.py<br>@@ -835,6 +835,11 @@ class vmmAddHardware(vmmGObjectUI):<br> <br>         devs = self.conn.get_nodedevs(devtype, devcap)<br>         for dev in devs:<br>+            if virtinst.VirtualHostDevice.is_conflict_hostdev \<br>+                    (self.conn.get_backend(), devtype, dev, "inactive"):<br>+                # Doesn't append device which is in use by an active VM to list.<br>+                continue<br>+<br>             prettyname = dev.pretty_name()<br> <br>             for subdev in subdevs:<br>@@ -1739,6 +1744,18 @@ class vmmAddHardware(vmmGObjectUI):<br> <br>         try:<br>             dev = virtinst.VirtualHostDevice(self.conn.get_backend())<br>+            # Hostdev collision<br>+            names = virtinst.VirtualHostDevice.is_conflict_hostdev \<br>+                    (self.conn.get_backend(), devtype, nodedev, "active", \<br>+                    is_dup)<br>+            if names:<br>+                res = self.err.yes_no(<br>+                        _('The device is already in use by other guests %s') %<br>+                         (names),<br>+                        _("Do you really want to use the device?"))<br>+                if not res:<br>+                    return False<br>+<br>             dev.set_from_nodedev(nodedev, use_full_usb=is_dup)<br>             self._dev = dev<br>         except Exception, e:<br>diff --git a/virtinst/devicehostdev.py b/virtinst/devicehostdev.py<br>index a5d1a2a..39a6213 100644<br>--- a/virtinst/devicehostdev.py<br>+++ b/virtinst/devicehostdev.py<br>@@ -89,5 +89,52 @@ class VirtualHostDevice(VirtualDevice):<br>     driver_name = XMLProperty("./driver/@name")<br>     rom_bar = XMLProperty("./rom/@bar", is_onoff=True)<br> <br>+    @staticmethod<br>+    def is_conflict_hostdev(conn, devtype, dev, vm_filter, is_dup=True):<br>+        if vm_filter == "active":<br>+            ret = []<br>+        vms = conn.fetch_all_guests()<br>+        for vm in vms:<br>+            _backend = vm.conn.lookupByName(vm.name)<br>+            if vm_filter == "inactive":<br>+                if not _backend.isActive():<br>+                    continue<br>+            elif vm_filter == "active":<br>+                if _backend.isActive():<br>+                    continue<br>+            for hostdev in vm.get_devices("hostdev"):<br>+                if devtype == NodeDevice.CAPABILITY_TYPE_USBDEV and \<br>+                        hostdev.type == "usb":<br>+                    if is_dup:<br>+                        if hostdev.bus == dev.bus and \<br>+                                hostdev.device == dev.device and \<br>+                                hostdev.vendor == dev.vendor_id and \<br>+                                hostdev.product == dev.product_id:<br>+                            if vm_filter == "inactive":<br>+                                return True<br>+                            elif vm_filter == "active":<br>+                                ret.append(vm.name)<br>+                    else:<br>+                        if hostdev.vendor == dev.vendor_id and \<br>+                                hostdev.product == dev.product_id:<br>+                            if vm_filter == "inactive":<br>+                                return True<br>+                            elif vm_filter == "active":<br>+                                ret.append(vm.name)<br>+                elif devtype == NodeDevice.CAPABILITY_TYPE_PCI and \<br>+                        hostdev.type == "pci":<br>+                    if str(int(hostdev.domain, 16)) == dev.domain and \<br>+                            str(int(hostdev.bus, 16)) == dev.bus and \<br>+                            str(int(hostdev.slot, 16)) == dev.slot and \<br>+                            str(int(hostdev.function, 16)) == dev.function:<br>+                        if vm_filter == "inactive":<br>+                            return True<br>+                        elif vm_filter == "active":<br>+                            ret.append(vm.name)<br>+        if vm_filter == "inactive":<br>+            return False<br>+        elif vm_filter == "active":<br>+            return ret<br>+<br> <br> VirtualHostDevice.register_type()<br>-- <br>1.8.4<br><br><br></lma@suse.com></div></body></html>