Merged
Conversation
Collaborator
ming1
commented
Sep 5, 2025
- support control command async/.await
- then multiple ublk devices can be created efficiently in single process or even single pthead
- next step is to allow multiple UblkQueue to be handled in single thread context
Implement complete async constructor chain for UblkCtrl to enable non-blocking device initialization in async applications: - Add UblkCtrlInner::add_async() - async device addition using ublk_ctrl_cmd_async() - Add UblkCtrlInner::handle_device_lifecycle_async() - async device lifecycle management - Add UblkCtrlInner::new_async() - async constructor with device lifecycle handling - Add UblkCtrlInner::new_with_params_async() - async legacy constructor wrapper - Update UblkCtrl::new_async() - now uses full async infrastructure instead of sync delegation - UblkCtrl::new_simple_async() - already uses new_async(), now inherits async behavior This enables proper async/await support for device creation while maintaining backward compatibility with existing synchronous constructors. All async methods follow established patterns using UblkUringOpFuture and ublk_ctrl_cmd_async(). Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add async version of device information retrieval functionality: - Add UblkCtrlInner::read_dev_info_async() with fallback mechanism - Add UblkCtrlInner::__read_dev_info_async() and __read_dev_info2_async() - Add public UblkCtrl::read_dev_info_async() method - Update handle_device_lifecycle_async() to use async read_dev_info - Follows established async patterns using ublk_ctrl_cmd_async() - Maintains same fallback logic as synchronous version (INFO2 -> INFO) This enables non-blocking device information retrieval for async applications while preserving backward compatibility with existing synchronous methods. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add async version of device parameter retrieval functionality: - Add UblkCtrlInner::get_params_async() using ublk_ctrl_cmd_async() - Add public UblkCtrl::get_params_async() method - Follows established async patterns for non-blocking parameter retrieval - Uses existing UblkCtrlCmdData::new_read_buffer_cmd() helper - Maintains same functionality as synchronous get_params() method - Enhance test_async_constructors to verify get_params_async() works This enables non-blocking device parameter retrieval for async applications while preserving backward compatibility with existing synchronous methods. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add async version of queue affinity retrieval functionality: - Add UblkCtrlInner::get_queue_affinity_async() using ublk_ctrl_cmd_async() - Add public UblkCtrl::get_queue_affinity_async() method with comprehensive docs - Follows established async patterns for non-blocking affinity retrieval - Uses existing UblkCtrlCmdData::new_data_buffer_cmd() helper - Maintains same functionality as synchronous get_queue_affinity() method - Add dedicated test_get_queue_affinity_async() test for comprehensive coverage - Enhance test_async_constructors to verify get_queue_affinity_async() works This enables non-blocking queue affinity retrieval for async applications while preserving backward compatibility with existing synchronous methods. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add async version of device information dump functionality: - Add UblkCtrl::dump_async() method returning Future<Result<(), UblkError>> - Uses read_dev_info_async() and get_params_async() for non-blocking driver communication - Maintains same output format and error handling as synchronous dump() method - Follows established async patterns using existing async infrastructure - Enhanced test_async_apis to include dump_async() verification - Renamed test from test_async_constructors to test_async_apis for broader coverage This enables non-blocking device information dumping for async applications while preserving backward compatibility with existing synchronous methods. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add new del_dev_async_await() method alongside existing del_dev_async(): - Add UblkCtrl::del_dev_async_await() - proper async/await pattern for device deletion - Add UblkCtrlInner::del_await() - internal implementation using ublk_ctrl_cmd_async() - Follows same command selection logic as synchronous del() method - Uses established async/await patterns like other async methods - Preserves existing del_dev_async() method signature and behavior - Enhanced test coverage in test_device_management_async_methods This provides an alternative async deletion method that follows the established async/await patterns used throughout the libublk-rs async API, while maintaining backward compatibility with the existing del_dev_async() method. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add test_create_ublk_async() with complete async device lifecycle testing: - Add io_async_fn() for async I/O request handling using BufDesc::Slice - Add q_async_fn() for spawning async I/O tasks per queue depth - Add device_handler_async() for full async device lifecycle testing - Test includes: device creation, I/O handling, start_dev_async, dump_async, kill_dev_async - Uses unified buffer management with submit_io_cmd_unified() - Demonstrates proper async executor usage with smol::LocalExecutor - Tests complete async workflow from device creation to destruction - Uses ublk_join_tasks() for proper async task coordination This provides comprehensive integration testing for the complete async API, validating that all async methods work together in real device scenarios. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
- Add detect_features_async() method to UblkCtrlInner for async feature detection - Add __get_features_async() method using async uring infrastructure - Update new_async() to use detect_features_async().await instead of sync version - Maintains consistency with async/await patterns throughout the codebase - All tests pass including async-specific functionality verification Signed-off-by: Ming Lei <tom.leiming@gmail.com>
…c device startup - Add set_params_async() method to UblkCtrlInner for async parameter setting - Add prep_start_dev_async() method using read_dev_info_async() and set_params_async() - Add public set_params_async() API for consistency with other async methods - Update start_dev_async() to use prep_start_dev_async().await for fully async startup - Keep flush_json() synchronous as it uses file I/O, not uring infrastructure - All tests pass including comprehensive async device creation verification Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Drop() Trait can't be implemented as async, so for async/await uses, the device has to be removed in async/.await manually, then Drop() needn't to delete the device any more. Add one removed flag for avoiding duplicated removal. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
The interface is just added recently, not released yet, so rename it. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Replace LazyCell with OnceCell for conditional initialization of the thread-local CTRL_URING, following the same pattern established for QUEUE_RING in commit c2a582b. Changes: - Replace LazyCell<RefCell<IoUring>> with OnceCell<RefCell<IoUring>> - Add with_ctrl_ring_internal!() and with_ctrl_ring_mut_internal!() macros for safe access patterns - Export ublk_init_ctrl_task_ring() public API for custom io_uring initialization with configurable flags and queue sizes - Add init_ctrl_task_ring_default() private helper for default initialization (SQ size: 16) - Update UblkCtrlInner::new() and new_async() to use the new helper - Update all CTRL_URING usage in ctrl.rs and uring_async.rs to use the new macro-based approach The new API allows users to customize control ring setup before UblkCtrl creation: - Custom SQ/CQ sizes - SQPOLL and IOPOLL modes - Custom io_uring flags - Maintains full backward compatibility Signed-off-by: Ming Lei <tom.leiming@gmail.com>
…rocess Firstly this test covers UblkCtrl async/.await support. Secondly it shows the power of UblkCtrl async/.await, cause we can support many devices in single process context. Next step is to improve src/io.rs to allow multiples queues handled in single thread context. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
ced5204 to
28e5a0e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.