Skip to content

Comments

Add ublk ctrl async#34

Merged
ming1 merged 3 commits intomainfrom
add-UblkCtrlAsync
Sep 15, 2025
Merged

Add ublk ctrl async#34
ming1 merged 3 commits intomainfrom
add-UblkCtrlAsync

Conversation

@ming1
Copy link
Collaborator

@ming1 ming1 commented Sep 15, 2025

  • Add UblkCtrlAsync for ctrl async/.await only
  • improve for_each_dev_id()

Separate async and sync control APIs by moving all async methods from
UblkCtrl to a new dedicated UblkCtrlAsync struct. This refactoring
improves API clarity and enforces proper async/sync usage patterns.

Changes:
- Create new UblkCtrlAsync struct with async-only methods
- Move async methods (*_async, *_async_await) from UblkCtrl to UblkCtrlAsync
- Extract async dependencies and helper functions to ctrl_async.rs
- Migrate async test cases to UblkCtrlAsync module
- Add ctrl_async module to lib.rs exports
- Remove 692 lines of async code from ctrl.rs, add 845 lines to ctrl_async.rs

This separation ensures that:
- Sync users only see sync APIs (UblkCtrl)
- Async users get dedicated async APIs (UblkCtrlAsync)
- No accidental mixing of sync/async patterns
- Cleaner, more focused API surface for each use case

The refactoring maintains full backward compatibility for existing
sync code while providing a clean async-first interface for new
async applications.

Also:

  Add async versions of UblkDev creation methods that accept &UblkCtrlAsync
  references, enabling proper async/sync API separation while maximizing
  code reuse.

  Changes:
  - Refactor UblkDev::new() to extract common logic into new_with_info() helper
  - Add UblkDev::new_async() method that accepts &UblkCtrlAsync
  - Update async tests to use new_async() instead of temporary sync controllers
  - Add comprehensive documentation examples for both sync and async usage

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Unexport UblkCtrlAsync now, and so get more time to think about the
interface and usage.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Replace runtime directory parsing with /sys/class/ublk-char iteration
to extract device IDs directly from kernel-exposed character devices.
This approach is more reliable and kernel-centric.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
@ming1 ming1 merged commit eef0385 into main Sep 15, 2025
8 checks passed
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