Merged
Conversation
Add as_slice(), as_mut_slice(), subslice(), and subslice_mut() methods to IoBuf for safe buffer access without unsafe pointer operations. These methods leverage existing Deref/DerefMut implementations and provide automatic bounds checking with Rust's memory safety guarantees. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Convert I/O handlers from raw pointer parameters to safe slice references: - Replace *mut u8 with Option<&[u8]> in handle_io_cmd() - Use IoBuf's as_slice() method for safe buffer access - Add educational comments explaining slice safety benefits - Maintain API compatibility through slice-to-pointer conversion This demonstrates safer patterns while preserving functionality with existing libublk APIs that still require raw pointers internally. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Replace all unsafe memory operations with safe slice-based alternatives: - Replace libc::memcpy() calls with copy_from_slice() and copy_to_slice() - Add comprehensive bounds checking to prevent buffer overflows - Update function signatures to use slice parameters (&mut [u8]) - Add extensive educational comments explaining slice safety benefits - Use IoBuf's safe slice access methods throughout Memory safety improvements: - Automatic bounds checking prevents buffer overflow vulnerabilities - Compile-time lifetime verification ensures memory safety - Eliminates unsafe pointer arithmetic and manual memory management - Slice operations provide zero-cost abstractions with safety guarantees This demonstrates how slice-based patterns can replace unsafe memory operations while maintaining performance and improving code safety. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Convert async I/O handler from raw pointer to slice-based patterns: - Update lo_handle_io_cmd_async() to use &mut [u8] parameter - Add comprehensive educational comments explaining slice-to-pointer conversion - Document when pointer conversion is necessary for libublk API compatibility - Use IoBuf's as_mut_slice() for safe buffer access in async context - Maintain async/await patterns while improving memory safety Educational improvements: - Explain io_uring raw pointer requirements for kernel interface - Show safe slice access patterns in both sync and async handlers - Document the conversion pattern: slices for safety, pointers for API calls - Demonstrate slice bounds checking benefits in async I/O operations This completes the slice-based conversion for all major example patterns while preserving the file-backed loop device functionality. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
- Replace synchronous wait_and_handle_io with async pattern using smol::LocalExecutor - Convert I/O handling to use async submit_io_cmd with await - Spawn individual async tasks for each queue tag (0..depth) - Use ublk_wait_and_handle_ios for async I/O event handling - Preserve memory copy operations for read/write in async context - Maintain mlock buffer verification logic for UBLK_DEV_F_MLOCK_IO_BUFFER - Remove unused rd_handle_io function and UblkError import - Update console output to indicate async mode Signed-off-by: Ming Lei <tom.leiming@gmail.com>
…sync ramdisk test - Update handle_io_cmd signature to accept IO buffer as &mut [u8] slice instead of *mut u8 - Add automatic bounds checking to prevent buffer overruns (bytes > io_buf.len()) - Replace unsafe libc::memcpy with safe slice operations using copy_from_slice() - Use std::slice::from_raw_parts for safe slice creation from ramdisk memory - Maintain ramdisk address as usize for device-wide memory access and thread safety - Improve memory safety while preserving zero-cost abstraction performance - Add educational comments explaining slice safety benefits over raw pointers Signed-off-by: Ming Lei <tom.leiming@gmail.com>
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.
Convert raw ptr into buffer slice for example/test code.