From b0c13985f54aadebd282ec9cb1a61c2c7c8ee0a1 Mon Sep 17 00:00:00 2001 From: Taihsiang Ho Date: Wed, 15 Oct 2014 13:38:11 +0800 Subject: Implement xhci driver detection for the controller of superspeed usb as udisks1 device. Now both of udisks1 and udisks2 USB disk device xhci detection are integrated and works. LP: #1378724 --- bin/removable_storage_test | 70 ++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/bin/removable_storage_test b/bin/removable_storage_test index 97734de5..5df6d78e 100755 --- a/bin/removable_storage_test +++ b/bin/removable_storage_test @@ -253,24 +253,6 @@ class DiskTest(): else: self.rem_disks_memory_cards_nm[dev_file] = None self.rem_disks_nm[dev_file] = None - # LP: #1313581 - # Compare the pci slot name of the devices using xhci and - # the pci slot name of the disks, - # which is usb3 disks in this case so far, - # to make sure the usb3 disk does be on the bus using xhci - # TODO: it will be better to extend to be all kinds of drivers. - try: - udev_devices_xhci = get_udev_xhci_devices(udev_client) - for udev_device_xhci in udev_devices_xhci: - pci_slot_name = udev_device_xhci.get_property('PCI_SLOT_NAME') - for udev_device in udev_devices: - devpath = udev_device.get_property('DEVPATH') - if (self._compare_pci_slot_from_devpath(devpath, - pci_slot_name)): - self.rem_disks_xhci[ - udev_device.get_property('DEVNAME')] = 'xhci' - except: - logging.error("Failed to get driver information.") def _probe_disks_udisks1(self, bus): """ @@ -321,6 +303,32 @@ class DiskTest(): self.rem_disks_nm[dev_file] = None self.rem_disks_memory_cards_nm[dev_file] = None + def get_disks_xhci(self): + """ + Compare + 1. the pci slot name of the devices using xhci + 2. the pci slot name of the disks, + which is usb3 disks in this case so far, + to make sure the usb3 disk does be on the controller using xhci + """ + # LP: #1378724 + udev_client = GUdev.Client() + # Get a collection of all udev devices corresponding to block devices + udev_devices = get_udev_block_devices(udev_client) + try: + udev_devices_xhci = get_udev_xhci_devices(udev_client) + for udev_device_xhci in udev_devices_xhci: + pci_slot_name = udev_device_xhci.get_property('PCI_SLOT_NAME') + for udev_device in udev_devices: + devpath = udev_device.get_property('DEVPATH') + if (self._compare_pci_slot_from_devpath(devpath, + pci_slot_name)): + self.rem_disks_xhci[ + udev_device.get_property('DEVNAME')] = 'xhci' + return self.rem_disks_xhci + except: + logging.error("Failed to get driver information.") + def mount(self): passed_mount = {} @@ -647,17 +655,31 @@ def main(): else: # LP: 1313581 if (args.driver == 'xhci_hcd'): - if(5000000000 == test.rem_disks_speed[disk] and - 'xhci' == test.rem_disks_xhci[disk]): + # The speed reported by udisks is sometimes + # less than 5G bits/s, for example, it may be 705032705 bits/s + # So using + # 500000000 = 500 M bits/s > 480 M bits/s ( USB 2.0 spec.) + # to make sure that it is higher USB version than 2.0 + # + # int() for int(test.rem_disks_speed[disk]) + # is necessary + # because the speed value of the dictionary rem_disks_speed is + # 1. str or int from _probe_disks_udisks2 + # 2. int from _probe_disks_udisks1. + # This is really a mess. : ( + # + print("\t\t--------------------------------") + if(500000000 < int(test.rem_disks_speed[disk]) and + 'xhci' == test.get_disks_xhci()[disk]): print("\t\tDevice Detected: SuperSpeed USB") print("\t\tDriver Detected: xhci_hcd") else: # Give it a hint for the detection failure. # LP: #1362902 - print("No SuperSpeed USB using xhci_hcd \ - was detected correctly.") - print("Hint: please use dmesg to check \ - the system status again.") + print(("\t\tNo SuperSpeed USB using xhci_hcd " + "was detected correctly.")) + print(("\t\tHint: please use dmesg to check " + "the system status again.")) return 1 # Pass is not assured if (not args.pass_speed or -- cgit v1.2.3 From b79f445fb4fb807b37097bda5778a5259842b20a Mon Sep 17 00:00:00 2001 From: Taihsiang Ho Date: Fri, 17 Oct 2014 13:11:06 +0800 Subject: handling exception in a more precise way --- bin/removable_storage_test | 63 +++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/bin/removable_storage_test b/bin/removable_storage_test index 5df6d78e..02493b19 100755 --- a/bin/removable_storage_test +++ b/bin/removable_storage_test @@ -315,19 +315,17 @@ class DiskTest(): udev_client = GUdev.Client() # Get a collection of all udev devices corresponding to block devices udev_devices = get_udev_block_devices(udev_client) - try: - udev_devices_xhci = get_udev_xhci_devices(udev_client) - for udev_device_xhci in udev_devices_xhci: - pci_slot_name = udev_device_xhci.get_property('PCI_SLOT_NAME') - for udev_device in udev_devices: - devpath = udev_device.get_property('DEVPATH') - if (self._compare_pci_slot_from_devpath(devpath, - pci_slot_name)): - self.rem_disks_xhci[ - udev_device.get_property('DEVNAME')] = 'xhci' - return self.rem_disks_xhci - except: - logging.error("Failed to get driver information.") + # Get a collection of all udev devices corresponding to xhci devices + udev_devices_xhci = get_udev_xhci_devices(udev_client) + for udev_device_xhci in udev_devices_xhci: + pci_slot_name = udev_device_xhci.get_property('PCI_SLOT_NAME') + for udev_device in udev_devices: + devpath = udev_device.get_property('DEVPATH') + if (self._compare_pci_slot_from_devpath(devpath, + pci_slot_name)): + self.rem_disks_xhci[ + udev_device.get_property('DEVNAME')] = 'xhci' + return self.rem_disks_xhci def mount(self): passed_mount = {} @@ -654,25 +652,50 @@ def main(): else: # LP: 1313581 + # Try to figure out whether the disk + # is SuperSpeed USB and using xhci_hcd driver. if (args.driver == 'xhci_hcd'): # The speed reported by udisks is sometimes - # less than 5G bits/s, for example, it may be 705032705 bits/s + # less than 5G bits/s, for example, + # it may be 705032705 bits/s # So using - # 500000000 = 500 M bits/s > 480 M bits/s ( USB 2.0 spec.) + # 500000000 + # = 500 M bits/s + # > 480 M bits/s ( USB 2.0 spec.) # to make sure that it is higher USB version than 2.0 # # int() for int(test.rem_disks_speed[disk]) # is necessary - # because the speed value of the dictionary rem_disks_speed is + # because the speed value of + # the dictionary rem_disks_speed is # 1. str or int from _probe_disks_udisks2 # 2. int from _probe_disks_udisks1. # This is really a mess. : ( - # print("\t\t--------------------------------") - if(500000000 < int(test.rem_disks_speed[disk]) and - 'xhci' == test.get_disks_xhci()[disk]): + if(500000000 < int(test.rem_disks_speed[disk])): print("\t\tDevice Detected: SuperSpeed USB") - print("\t\tDriver Detected: xhci_hcd") + # Unlike rem_disks_speed, + # which must has the connect speed + # for each disk devices, + # disk devices may not use xhci as + # controller drivers. + # This will raise KeyError for no + # associated disk device was found. + xhci_disks = test.get_disks_xhci() + # pep8 style suggest to limit the try clause + # to the absolute minimum amount of code necessary + try: + disk_xhci_flag = xhci_disks[disk] + except KeyError: + print("\t\tDisk does not use xhci_hci.") + return 1 + else: + if('xhci' == disk_xhci_flag): + print("\t\tDriver Detected: xhci_hcd") + else: + print("\t\tDisk does not use xhci_hci.") + logging.debug("disk_xhci_flag is not xhci") + return 1 else: # Give it a hint for the detection failure. # LP: #1362902 -- cgit v1.2.3