diff --git a/block/src/async_io.rs b/block/src/async_io.rs index bd4c7bbe5..f859f6e5b 100644 --- a/block/src/async_io.rs +++ b/block/src/async_io.rs @@ -96,6 +96,12 @@ pub enum AsyncIoError { /// Failed synchronizing file. #[error("Failed synchronizing file")] Fsync(#[source] std::io::Error), + /// Failed punching hole. + #[error("Failed punching hole")] + PunchHole(#[source] std::io::Error), + /// Failed writing zeroes. + #[error("Failed writing zeroes")] + WriteZeroes(#[source] std::io::Error), /// Failed submitting batch requests. #[error("Failed submitting batch requests")] SubmitBatchRequests(#[source] std::io::Error), @@ -118,6 +124,8 @@ pub trait AsyncIo: Send { user_data: u64, ) -> AsyncIoResult<()>; fn fsync(&mut self, user_data: Option) -> AsyncIoResult<()>; + fn punch_hole(&mut self, offset: u64, length: u64, user_data: u64) -> AsyncIoResult<()>; + fn write_zeroes(&mut self, offset: u64, length: u64, user_data: u64) -> AsyncIoResult<()>; fn next_completed_request(&mut self) -> Option<(u64, i32)>; fn batch_requests_enabled(&self) -> bool { false diff --git a/block/src/fixed_vhd_async.rs b/block/src/fixed_vhd_async.rs index df596a616..6e858f74a 100644 --- a/block/src/fixed_vhd_async.rs +++ b/block/src/fixed_vhd_async.rs @@ -115,6 +115,18 @@ impl AsyncIo for FixedVhdAsync { self.raw_file_async.next_completed_request() } + fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::PunchHole(std::io::Error::other( + "punch_hole not supported for fixed VHD", + ))) + } + + fn write_zeroes(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::WriteZeroes(std::io::Error::other( + "write_zeroes not supported for fixed VHD", + ))) + } + fn batch_requests_enabled(&self) -> bool { true } diff --git a/block/src/fixed_vhd_sync.rs b/block/src/fixed_vhd_sync.rs index fd44adfd0..ecb5e83ad 100644 --- a/block/src/fixed_vhd_sync.rs +++ b/block/src/fixed_vhd_sync.rs @@ -113,4 +113,16 @@ impl AsyncIo for FixedVhdSync { fn next_completed_request(&mut self) -> Option<(u64, i32)> { self.raw_file_sync.next_completed_request() } + + fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::PunchHole(std::io::Error::other( + "punch_hole not supported for fixed VHD", + ))) + } + + fn write_zeroes(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::WriteZeroes(std::io::Error::other( + "write_zeroes not supported for fixed VHD", + ))) + } } diff --git a/block/src/qcow_sync.rs b/block/src/qcow_sync.rs index 200fb36bd..ad9fb42d8 100644 --- a/block/src/qcow_sync.rs +++ b/block/src/qcow_sync.rs @@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex}; use vmm_sys_util::eventfd::EventFd; use crate::async_io::{ - AsyncIo, AsyncIoResult, BorrowedDiskFd, DiskFile, DiskFileError, DiskFileResult, + AsyncIo, AsyncIoError, AsyncIoResult, BorrowedDiskFd, DiskFile, DiskFileError, DiskFileResult, }; use crate::qcow::{QcowFile, RawFile, Result as QcowResult}; use crate::{AsyncAdaptor, BlockBackend}; @@ -146,4 +146,16 @@ impl AsyncIo for QcowSync { fn next_completed_request(&mut self) -> Option<(u64, i32)> { self.completion_list.pop_front() } + + fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::PunchHole(std::io::Error::other( + "punch_hole not supported for QCOW sync backend", + ))) + } + + fn write_zeroes(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::WriteZeroes(std::io::Error::other( + "write_zeroes not supported for QCOW sync backend", + ))) + } } diff --git a/block/src/raw_async.rs b/block/src/raw_async.rs index e36f249e8..165f5946e 100644 --- a/block/src/raw_async.rs +++ b/block/src/raw_async.rs @@ -253,4 +253,16 @@ impl AsyncIo for RawFileAsync { Ok(()) } + + fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::PunchHole(std::io::Error::other( + "punch_hole not supported for raw async backend", + ))) + } + + fn write_zeroes(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::WriteZeroes(std::io::Error::other( + "write_zeroes not supported for raw async backend", + ))) + } } diff --git a/block/src/raw_async_aio.rs b/block/src/raw_async_aio.rs index ad41872c7..6d9fab027 100644 --- a/block/src/raw_async_aio.rs +++ b/block/src/raw_async_aio.rs @@ -161,4 +161,16 @@ impl AsyncIo for RawFileAsyncAio { Some((events[0].data, events[0].res as i32)) } } + + fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::PunchHole(std::io::Error::other( + "punch_hole not supported with AIO backend", + ))) + } + + fn write_zeroes(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::WriteZeroes(std::io::Error::other( + "write_zeroes not supported with AIO backend", + ))) + } } diff --git a/block/src/raw_sync.rs b/block/src/raw_sync.rs index 0f9ce0702..aeeb3bea6 100644 --- a/block/src/raw_sync.rs +++ b/block/src/raw_sync.rs @@ -146,4 +146,16 @@ impl AsyncIo for RawFileSync { fn next_completed_request(&mut self) -> Option<(u64, i32)> { self.completion_list.pop_front() } + + fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::PunchHole(std::io::Error::other( + "punch_hole not supported for raw sync backend", + ))) + } + + fn write_zeroes(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::WriteZeroes(std::io::Error::other( + "write_zeroes not supported for raw sync backend", + ))) + } } diff --git a/block/src/vhdx_sync.rs b/block/src/vhdx_sync.rs index 47e7539dc..fc236c15d 100644 --- a/block/src/vhdx_sync.rs +++ b/block/src/vhdx_sync.rs @@ -9,7 +9,7 @@ use std::os::fd::AsRawFd; use vmm_sys_util::eventfd::EventFd; use crate::async_io::{ - AsyncIo, AsyncIoResult, BorrowedDiskFd, DiskFile, DiskFileError, DiskFileResult, + AsyncIo, AsyncIoError, AsyncIoResult, BorrowedDiskFd, DiskFile, DiskFileError, DiskFileResult, }; use crate::vhdx::{Result as VhdxResult, Vhdx}; use crate::{AsyncAdaptor, BlockBackend, Error}; @@ -114,4 +114,16 @@ impl AsyncIo for VhdxSync { fn next_completed_request(&mut self) -> Option<(u64, i32)> { self.completion_list.pop_front() } + + fn punch_hole(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::PunchHole(std::io::Error::other( + "punch_hole not supported for VHDX", + ))) + } + + fn write_zeroes(&mut self, _offset: u64, _length: u64, _user_data: u64) -> AsyncIoResult<()> { + Err(AsyncIoError::WriteZeroes(std::io::Error::other( + "write_zeroes not supported for VHDX", + ))) + } }