From 0bb4b87bcdea073bd66fe219d4c66157dbaa6488 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Tue, 19 May 2026 14:35:46 -0700 Subject: [PATCH] block: Add owned fixed VHD sync I/O path Implement the safe AsyncIo interface the fixed VHD synchronous wrapper and delegate the actual I/O through RawFileSync. This maintains the existing interfaces until the callers are converted later in the series. Signed-off-by: Dylan Reid --- block/src/fixed_vhd_sync.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/block/src/fixed_vhd_sync.rs b/block/src/fixed_vhd_sync.rs index bcf16f4f5..57bc15ac5 100644 --- a/block/src/fixed_vhd_sync.rs +++ b/block/src/fixed_vhd_sync.rs @@ -1,12 +1,14 @@ // Copyright © 2021 Intel Corporation // +// Copyright (c) Meta Platforms, Inc. and affiliates. +// // SPDX-License-Identifier: Apache-2.0 use std::os::unix::io::RawFd; use vmm_sys_util::eventfd::EventFd; -use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult}; +use crate::async_io::{AsyncIo, AsyncIoCompletion, AsyncIoError, AsyncIoOperation, AsyncIoResult}; use crate::raw_sync::RawFileSync; pub struct FixedVhdSync { @@ -66,12 +68,32 @@ impl AsyncIo for FixedVhdSync { self.raw_file_sync.write_vectored(offset, iovecs, user_data) } + fn submit_data_operation(&mut self, op: AsyncIoOperation) -> AsyncIoResult<()> { + let offset = op.offset(); + if offset as u64 >= self.size { + let error = std::io::Error::new( + std::io::ErrorKind::InvalidData, + format!( + "Invalid offset {}, can't be larger than file size {}", + offset, self.size + ), + ); + return Err(if op.is_read() { + AsyncIoError::ReadVectored(error) + } else { + AsyncIoError::WriteVectored(error) + }); + } + + self.raw_file_sync.submit_data_operation(op) + } + fn fsync(&mut self, user_data: Option) -> AsyncIoResult<()> { self.raw_file_sync.fsync(user_data) } - fn next_completed_request(&mut self) -> Option<(u64, i32)> { - self.raw_file_sync.next_completed_request() + fn next_completion(&mut self) -> Option { + self.raw_file_sync.next_completion() } fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> {