Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions qubes-rpc/qubes.USBDetach
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ if [ -z "$busid" ]; then
usbip_sockfd="/sys/bus/usb/devices/$busid/usbip_sockfd"
if [ -w "$usbip_sockfd" ]; then
echo -1 > "$usbip_sockfd"

# avoid zombie usb (visible from backend but held by usbip driver)
# disconnect usbip driver
if ! echo "$busid" > "/sys/bus/usb/drivers/usbip-host/unbind" 2>/dev/null; then
echo "Failed to unbind USB device $busid from usbip-host driver" >&2
exit 1
fi

# reset
if ! /usr/lib/qubes/usb-reset "/sys/bus/usb/devices/$busid"; then
echo "Failed to reset USB device $busid" >&2
exit 1
fi

# reload driver to make it fully available in backend again
if ! echo "$busid" > "/sys/bus/usb/drivers_probe"; then
echo "Failed to reload USB device $busid driver" >&2
exit 1
fi
else
echo "Device $busid not found or not attached to any VM!" >&2
exit 1
Expand Down