Unbind the device identified by "dev_id" from its current driver
(dev_id, force)
| 323 | |
| 324 | |
| 325 | def unbind_one(dev_id, force): |
| 326 | '''Unbind the device identified by "dev_id" from its current driver''' |
| 327 | dev = devices[dev_id] |
| 328 | if not has_driver(dev_id): |
| 329 | print("Notice: %s %s %s is not currently managed by any driver" % |
| 330 | (dev["Slot"], dev["Device_str"], dev["Interface"]), file=sys.stderr) |
| 331 | return |
| 332 | |
| 333 | # prevent us disconnecting ourselves |
| 334 | if dev["Ssh_if"] and not force: |
| 335 | print("Warning: routing table indicates that interface %s is active. " |
| 336 | "Skipping unbind" % dev_id, file=sys.stderr) |
| 337 | return |
| 338 | |
| 339 | # write to /sys to unbind |
| 340 | filename = "/sys/bus/pci/drivers/%s/unbind" % dev["Driver_str"] |
| 341 | try: |
| 342 | f = open(filename, "a") |
| 343 | except OSError as err: |
| 344 | sys.exit("Error: unbind failed for %s - Cannot open %s: %s" % |
| 345 | (dev_id, filename, err)) |
| 346 | f.write(dev_id) |
| 347 | f.close() |
| 348 | |
| 349 | |
| 350 | def bind_one(dev_id, driver, force): |
no test coverage detected