duende-ublk
ublk device lifecycle management for swap-critical daemons.
Problem: Orphaned ublk Devices
When a ublk daemon crashes or is killed, the kernel may retain device state
even after the /dev/ublkbN block device disappears. This causes:
- "File exists" errors when creating new devices
- Device ID conflicts
- System requires reboot to clear stale state
ERROR: Failed to add device 0: File exists (os error 17)
Solution
use ;
API
Quick Start
use ;
// Detect orphaned devices
let orphans = detect_orphaned_devices?;
println!;
// Clean up all orphaned devices
let cleaned = cleanup_orphaned_devices?;
println!;
Manual Control
use UblkControl;
let mut ctrl = open?;
// Stop then delete a specific device
ctrl.stop_device?;
ctrl.delete_device?;
// Or use force_delete (stop + delete)
ctrl.force_delete?;
// Get device info
let info = ctrl.get_device_info?;
println!;
Kernel Interface
This crate uses io_uring URING_CMD to communicate with the ublk kernel driver.
Requires Linux 6.0+.
Requirements
- Linux 6.0+ kernel
ublkkernel module loaded- Root privileges or
CAP_SYS_ADMIN
io_uring Commands
| Command | Description |
|---|---|
UBLK_U_CMD_DEL_DEV |
Delete a device |
UBLK_U_CMD_STOP_DEV |
Stop a running device |
UBLK_U_CMD_GET_DEV_INFO |
Get device information |
Integration with duende-mlock
For swap-critical daemons, use with duende-mlock:
use lock_all;
use cleanup_orphaned_devices;
License
MIT OR Apache-2.0