Skip to content

feat: drive lock and gui preferences - #81

Open
RevokeTime wants to merge 2 commits into
speed47:masterfrom
RevokeTime:feat-drive-lock
Open

RevokeTime wants to merge 2 commits into
speed47:masterfrom
RevokeTime:feat-drive-lock

Conversation

@RevokeTime

Copy link
Copy Markdown

Lock the drive when starting the scan to prevent external processes from interfering with it; this also helps mitigate the issue described in #76, making the scanning process more stable.

…event interference

Implement multi-tier optical drive locking to protect active test runs
(ERRC, JB, FE/TE, RT, WT) against external interference from physical
tray button presses, background filesystem activity, and other processes:

1. Transport & MMC Layer (lib/qpxtransport):
   - Add lock_device() / unlock_device() to Scsi_Command across all platforms.
   - Linux: apply flock(fd, LOCK_EX | LOCK_NB) to inhibit udisks2 media
     change polling (GESN/TUR) and desktop automounting, and CDROM_LOCKDOOR ioctl.
   - Windows: issue FSCTL_LOCK_VOLUME / FSCTL_DISMOUNT_VOLUME to isolate
     volume filesystem access, and IOCTL_CDROM_EXCLUSIVE_ACCESS with
     ExclusiveAccessLockDevice to obtain cdrom.sys driver exclusive access.
   - Implement lock_drive(drive_info*) and unlock_drive(drive_info*) combining
     OS exclusive locks with SCSI MMC SPC_PREVENT_ALLOW_MEDIUM_REMOVAL (1/0).
   - Add automatic unlock fallback in drive_info::~drive_info() to prevent deadlocks.

2. Scan Engine (lib/qpxscan):
   - Wrap qscanner::run() with lock_drive() upon test startup and unlock_drive()
     upon test completion or abort.
   - Add safety fallback unlock in qscanner::~qscanner() if still locked.
   - Support toggling via set_lock_drive(bool) / is_lock_drive_enabled().

3. CLI (console/qscan):
   - Enable optical drive locking by default during tests.
   - Add --no-lock command line option to allow opting out.

4. GUI (gui):
   - Add lock_drive boolean option to QPxSettings (persisted under /devices).
   - Add "Lock drive during scan tests (prevent external interference)"
     checkbox in Preferences -> Devices.
   - Propagate lock_drive setting from mainwindow into device and pass
     --no-lock to qscan child process when locking is disabled.
…ests safely

Implement graceful stop and emergency hardware unlock mechanisms in the GUI
to prevent the optical drive from remaining locked when tests hang or when
the user forcefully closes the application window:

1. Emergency Hardware Unlock (gui/device):
   - Add force_unlock() to issue synchronous MMC PREVENT_ALLOW_MEDIUM_REMOVAL (0)
     hardware commands directly to the optical drive.
   - Add force_stop_and_unlock(timeout_ms) which prioritizes graceful process
     termination (proc->terminate() / Windows stop event), waits up to timeout_ms,
     force-kills hung child processes if unresponsive, and executes force_unlock().
   - Add repeat-stop force kill to stop_tests(): double-clicking the Stop button
     while a test is hanging immediately escalates to proc->kill() and unlocks.
   - Invoke force_stop_and_unlock() in device::~device() for clean teardown.

2. Window Close Interception (gui/mainwindow):
   - Override closeEvent() to detect active scan tests on any device.
   - Display a confirmation dialog warning the user that tests will be aborted
     and the drive unlocked.
   - On confirmation, trigger force_stop_and_unlock() across all active devices
     before exiting cleanly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant