mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Use logical block size for alignment
O_DIRECT requires buffer addresses to be aligned to the backend device's logical block size. The existing bounce buffer logic in execute_async() hardcodes SECTOR_SIZE (512) for the alignment check and bounce buffer allocation. This is insufficient for devices with a 4096-byte logical block size, where misaligned buffers cause -EINVAL from the host kernel. Add an alignment() method to the AsyncIo trait that returns the backend's logical block size, defaulting to SECTOR_SIZE. The three raw I/O backends (io_uring, AIO, synchronous) probe the device topology via DiskTopology::probe() at creation time and return the actual logical block size. All image format backends would simply use the default value of 512 bytes since their underlying are not block devices. execute_async() now queries disk_image.alignment() instead of using the hardcoded SECTOR_SIZE Fixes: #7720 Signed-off-by: Saravanan D <saravanand@crusoe.ai>
This commit is contained in:
committed by
Rob Bradford
parent
272fa624ef
commit
00c05f4761
@@ -13,7 +13,7 @@ use vmm_sys_util::eventfd::EventFd;
|
||||
use crate::async_io::{
|
||||
AsyncIo, AsyncIoError, AsyncIoResult, BorrowedDiskFd, DiskFile, DiskFileError, DiskFileResult,
|
||||
};
|
||||
use crate::{DiskTopology, probe_sparse_support};
|
||||
use crate::{DiskTopology, SECTOR_SIZE, probe_sparse_support};
|
||||
|
||||
pub struct RawFileDiskSync {
|
||||
file: File,
|
||||
@@ -40,7 +40,11 @@ impl DiskFile for RawFileDiskSync {
|
||||
}
|
||||
|
||||
fn new_async_io(&self, _ring_depth: u32) -> DiskFileResult<Box<dyn AsyncIo>> {
|
||||
Ok(Box::new(RawFileSync::new(self.file.as_raw_fd())) as Box<dyn AsyncIo>)
|
||||
let mut raw = RawFileSync::new(self.file.as_raw_fd());
|
||||
raw.alignment = DiskTopology::probe(&self.file)
|
||||
.map(|t| t.logical_block_size)
|
||||
.unwrap_or(SECTOR_SIZE);
|
||||
Ok(Box::new(raw) as Box<dyn AsyncIo>)
|
||||
}
|
||||
|
||||
fn topology(&mut self) -> DiskTopology {
|
||||
@@ -65,6 +69,7 @@ pub struct RawFileSync {
|
||||
fd: RawFd,
|
||||
eventfd: EventFd,
|
||||
completion_list: VecDeque<(u64, i32)>,
|
||||
alignment: u64,
|
||||
}
|
||||
|
||||
impl RawFileSync {
|
||||
@@ -73,6 +78,7 @@ impl RawFileSync {
|
||||
fd,
|
||||
eventfd: EventFd::new(libc::EFD_NONBLOCK).expect("Failed creating EventFd for RawFile"),
|
||||
completion_list: VecDeque::new(),
|
||||
alignment: SECTOR_SIZE,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,6 +88,10 @@ impl AsyncIo for RawFileSync {
|
||||
&self.eventfd
|
||||
}
|
||||
|
||||
fn alignment(&self) -> u64 {
|
||||
self.alignment
|
||||
}
|
||||
|
||||
fn read_vectored(
|
||||
&mut self,
|
||||
offset: libc::off_t,
|
||||
|
||||
Reference in New Issue
Block a user