mirror of
https://github.com/jetkvm/kvm.git
synced 2026-05-21 05:20:35 +00:00
203c6ae6fd
* fix: reset USB gadget when virtual media unmount fails with EBUSY (#834) When unmountImageLocked() gets EBUSY from the kernel (host OS still accessing the virtual disk via PREVENT MEDIUM REMOVAL), fall back to gadget.RebindUsb(true) to force-disconnect the host, then retry the unmount. Uses RebindUsb directly instead of UpdateGadgetConfig to avoid hitting the same EBUSY when writing configfs attributes before rebind. After rebind, properly reopen keyboard HID file (ResetHIDFiles + sleep + OpenKeyboardHidFile) matching the pattern in setMassStorageMode(). Also propagate unmount errors to RPC callers and only clear currentVirtualMediaState after the unmount actually succeeds. Adds E2E test that mounts an ISO on the remote host to trigger PREVENT MEDIUM REMOVAL, then verifies unmount succeeds and keyboard recovers. * fix: recover HID chardev after DWC3 rebind race on RV1106 The DWC3 USB controller on the RV1106 has a race condition where rapid unbind→bind of the UDC can permanently corrupt HID chardev state — /dev/hidg0 returns ENXIO even though the device node exists and the UDC shows "configured". This can be triggered by UpdateGadgetConfig's transaction rebind and by host-initiated USB device resets during mass storage media changes. Three-part fix: 1. rebindUsb(): after binding, verify /dev/hidg0 is openable. If not, unbind again with a 100ms pause for kernel cleanup, then rebind. 2. setMassStorageMode(): pre-set recovery timer before UpdateGadgetConfig to prevent the poller from interfering. After the 1s sleep, if OpenKeyboardHidFile fails, do a corrective RebindUsb + retry. 3. checkUSBState() poller: when a state transition occurs and OpenKeyboardHidFile fails, trigger a corrective rebind to recover from host-initiated USB resets that corrupt the chardev. * fix: suppress USB recovery poller before rebind in unmount and mode-change paths The auto-recovery poller could see transient "not attached" UDC state during RebindUsb and trigger a competing rebind, corrupting HID chardev state. Add setUSBRecoveryTimer calls before the rebind in unmountImageLocked and before the corrective rebind in setMassStorageMode. * test: replace blind sleep with two-phase wait in factory-reset e2e test Wait for device to become unreachable before polling for it to come back, preventing false passes from stale pre-reset responses. * refactor: simplify branch — extract helpers, remove duplication, fix flaky tests - Extract rebindAndRecoverHID() in Go to deduplicate USB recovery sequences - Remove redundant setUSBRecoveryTimer() call after UpdateGadgetConfig() - Extract waitForKeyboardReady() helper replacing 5 duplicate retry loops - Consolidate 3 duplicate remoteExec definitions into single remoteHostExec() - Use shared SSH_OPTS from helpers.ts instead of hardcoded SSH options - Fix remote agent omitempty on mouse X/Y causing undefined in TypeScript - Poll keys-down state in disconnect test to avoid race condition * fix: remove dead IsHidgChardevHealthy export, reset HID files before rebind - Remove unused exported IsHidgChardevHealthy wrapper (only the unexported isHidgChardevHealthy is called, inside rebindUsb) - Move ResetHIDFiles() before RebindUsb in checkUSBState so stale file handles are closed even if the rebind fails — prevents silent mouse write failures on dead inodes after a successful unbind + failed bind