Skip to content

Comments

Ramdisk refactor#38

Merged
ming1 merged 6 commits intomainfrom
ramdisk-refactor
Sep 24, 2025
Merged

Ramdisk refactor#38
ming1 merged 6 commits intomainfrom
ramdisk-refactor

Conversation

@ming1
Copy link
Collaborator

@ming1 ming1 commented Sep 24, 2025

  • refactor to apply UblkCtrlAsyn for handling both ctrl and io in single context
  • support to create UblkCtrlAsync in async io task

This reverts commit d0564da.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
These functions provide public access to the thread-local control ring
for both read-only and mutable operations. They delegate to the existing
internal macros while offering a cleaner function-based interface.

The documentation examples use the correct IoUring::<Entry128>::builder()
API and include necessary imports for AsRawFd trait.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
…e with_queue_ring() APIs

- Add with_task_io_ring() and with_task_io_ring_mut() functions that provide
  direct access to thread-local queue ring without requiring UblkQueue parameter
- Deprecate with_queue_ring() and with_queue_ring_mut() since 0.5.0 with
  helpful migration messages pointing to the new APIs
- Migrate all internal usage from old APIs to new APIs:
  - examples/null.rs: Updated imports and function calls
  - src/io.rs tests: Updated test cases and fixed type annotations
- Export new functions through public API in lib.rs for external users
- Fix build warnings:
  - Add #[allow(deprecated)] to public exports to suppress expected warnings
  - Fix unused variable warnings by prefixing with underscore
- Maintain backward compatibility while providing cleaner interface

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Implements a function to poll uring events from both QUEUE_RING and CTRL_URING
in a single async task context using smol::Async().readable(). The main use case
is for examples like ramdisk.rs where both ublk IO and control commands need to
be handled in the same task.

Key features:
- Uses smol::future::race() to wait for either ring to be readable
- Reaps events from both rings and calls ublk_wake_task() for completions
- Prevents fd release using into_inner().into_raw_fd() pattern
- Proper error handling and abort detection from both rings

Implementation details:
- Function located in examples/ramdisk.rs to avoid library dependency on smol
- Made CTRL_URING and control ring macros public for example access
- Integrated into ramdisk.rs replacing wait_and_handle_io_events()
- Keeps library executor-agnostic while providing dual ring polling example

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Complete implementation of async control device creation with proper I/O handling:

- **create_ublk_ctrl_async()**: Demonstrates UblkCtrlBuilder::build_async() usage
  - Uses smol::LocalExecutor for async task execution
  - Implements futures::join!() pattern to coordinate control and executor tasks
  - Returns Result<UblkCtrlAsync, UblkError> from build_async().await
  - Uses shared RefCell state for task coordination

- **Enhanced poll_and_handle_rings()**: Dual ring polling with configurable behavior
  - Added check_done parameter for conditional abort checking
  - Polls both QUEUE_RING and CTRL_URING using smol::Async
  - Handles I/O events from both rings with proper error handling

- **Task Coordination**: Control task sets completion flag, executor task monitors it
- **Proper Lifetime Management**: Fixed borrowing issues with multiple executor clones
- **I/O Ring Integration**: Added task ring initialization for proper queue operations
- **Error Handling**: All compilation errors and warnings resolved
- **Async Patterns**: Demonstrates best practices for async control device creation

- `create_ublk_ctrl_async()`: Async control creation with dual task coordination
- `poll_and_handle_rings()`: Enhanced dual ring polling with race conditions
- Task ring initialization with custom setup for optimal performance

The example now showcases complete async control device lifecycle management
while maintaining compatibility with existing synchronous patterns.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
- Simplify coordination in create_ublk_ctrl_async() using atomic bool instead of RefCell
- Extract helper functions in poll_and_handle_rings() to reduce duplication
- Unify event handling logic between queue and control rings
- Improve code readability and remove verbose comments
- Remove unused squeue import

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
@ming1 ming1 merged commit 8325011 into main Sep 24, 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