-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mechanism to reset device just before attaching
Some device require reset after interacting with previous driver. When device was used with usbip-host before, it took care of that when detaching from previous target (VM). But if it was attached to some other driver in sys-usb before, this needs to be done manually. To limit possible impact, make this opt-in. There are two methods to opt into this feature: 1. Enable it for all devices using (adjust sys-usb name if applicable): qvm-service --enable sys-usb usb-reset-on-attach 2. Enable for specific device by setting QUBES_USB_RESET udev property. QubesOS/qubes-issues#8953
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
import os | ||
import fcntl | ||
from pathlib import Path | ||
|
||
# from /usr/include/linux/usbdevice_fs.h | ||
# _IO('U', 20) | ||
USBDEVFS_RESET = 0x5514 | ||
|
||
def main(): | ||
if len(sys.argv) != 2: | ||
print("Usage: usb-reset sysfs-devpath", file=sys.stderr()) | ||
exit(2) | ||
devpath = sys.argv[1] | ||
uevent = (Path(devpath) / "uevent").read_text() | ||
devname = [line.partition("=")[2] | ||
for line in uevent.splitlines() | ||
if line.startswith("DEVNAME=")][0] | ||
with (Path("/dev") / devname).open("w") as dev_f: | ||
fcntl.ioctl(dev_f, USBDEVFS_RESET, 0) | ||
|
||
if __name__ == "__main__": | ||
main() |