Bind method, takes a list of device locations
(dev_list, driver, force=False)
| 475 | |
| 476 | |
| 477 | def bind_all(dev_list, driver, force=False): |
| 478 | """Bind method, takes a list of device locations""" |
| 479 | global devices |
| 480 | |
| 481 | # a common user error is to forget to specify the driver the devices need to |
| 482 | # be bound to. check if the driver is a valid device, and if it is, show |
| 483 | # a meaningful error. |
| 484 | try: |
| 485 | dev_id_from_dev_name(driver) |
| 486 | # if we've made it this far, this means that the "driver" was a valid |
| 487 | # device string, so it's probably not a valid driver name. |
| 488 | sys.exit("Error: Driver '%s' does not look like a valid driver. " |
| 489 | "Did you forget to specify the driver to bind devices to?" % driver) |
| 490 | except ValueError: |
| 491 | # driver generated error - it's not a valid device ID, so all is well |
| 492 | pass |
| 493 | |
| 494 | # check if we're attempting to bind to a driver that isn't loaded |
| 495 | if not module_is_loaded(driver.replace('-', '_')): |
| 496 | sys.exit("Error: Driver '%s' is not loaded." % driver) |
| 497 | |
| 498 | try: |
| 499 | dev_list = map(dev_id_from_dev_name, dev_list) |
| 500 | except ValueError as ex: |
| 501 | sys.exit(ex) |
| 502 | |
| 503 | for d in dev_list: |
| 504 | bind_one(d, driver, force) |
| 505 | |
| 506 | # For kernels < 3.15 when binding devices to a generic driver |
| 507 | # (i.e. one that doesn't have a PCI ID table) using new_id, some devices |
| 508 | # that are not bound to any other driver could be bound even if no one has |
| 509 | # asked them to. hence, we check the list of drivers again, and see if |
| 510 | # some of the previously-unbound devices were erroneously bound. |
| 511 | if not exists("/sys/bus/pci/devices/%s/driver_override" % d): |
| 512 | for d in devices.keys(): |
| 513 | # skip devices that were already bound or that we know should be bound |
| 514 | if "Driver_str" in devices[d] or d in dev_list: |
| 515 | continue |
| 516 | |
| 517 | # update information about this device |
| 518 | devices[d] = dict(devices[d].items() |
| 519 | + get_pci_device_details(d, True).items()) |
| 520 | |
| 521 | # check if updated information indicates that the device was bound |
| 522 | if "Driver_str" in devices[d]: |
| 523 | unbind_one(d, force) |
| 524 | |
| 525 | |
| 526 | def display_devices(title, dev_list, extra_params=None): |
no test coverage detected