mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Add punch_hole and write_zeroes to AsyncIo trait
Add punch_hole() and write_zeroes() methods to the AsyncIo trait with stub implementations for all backends. These will be used to support DISCARD and WRITE_ZEROES operations. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
41b23229a5
commit
7095605d84
@@ -96,6 +96,12 @@ pub enum AsyncIoError {
|
|||||||
/// Failed synchronizing file.
|
/// Failed synchronizing file.
|
||||||
#[error("Failed synchronizing file")]
|
#[error("Failed synchronizing file")]
|
||||||
Fsync(#[source] std::io::Error),
|
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.
|
/// Failed submitting batch requests.
|
||||||
#[error("Failed submitting batch requests")]
|
#[error("Failed submitting batch requests")]
|
||||||
SubmitBatchRequests(#[source] std::io::Error),
|
SubmitBatchRequests(#[source] std::io::Error),
|
||||||
@@ -118,6 +124,8 @@ pub trait AsyncIo: Send {
|
|||||||
user_data: u64,
|
user_data: u64,
|
||||||
) -> AsyncIoResult<()>;
|
) -> AsyncIoResult<()>;
|
||||||
fn fsync(&mut self, user_data: Option<u64>) -> AsyncIoResult<()>;
|
fn fsync(&mut self, user_data: Option<u64>) -> 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 next_completed_request(&mut self) -> Option<(u64, i32)>;
|
||||||
fn batch_requests_enabled(&self) -> bool {
|
fn batch_requests_enabled(&self) -> bool {
|
||||||
false
|
false
|
||||||
|
|||||||
@@ -115,6 +115,18 @@ impl AsyncIo for FixedVhdAsync {
|
|||||||
self.raw_file_async.next_completed_request()
|
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 {
|
fn batch_requests_enabled(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,4 +113,16 @@ impl AsyncIo for FixedVhdSync {
|
|||||||
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
||||||
self.raw_file_sync.next_completed_request()
|
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",
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
use crate::async_io::{
|
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::qcow::{QcowFile, RawFile, Result as QcowResult};
|
||||||
use crate::{AsyncAdaptor, BlockBackend};
|
use crate::{AsyncAdaptor, BlockBackend};
|
||||||
@@ -146,4 +146,16 @@ impl AsyncIo for QcowSync {
|
|||||||
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
||||||
self.completion_list.pop_front()
|
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",
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,4 +253,16 @@ impl AsyncIo for RawFileAsync {
|
|||||||
|
|
||||||
Ok(())
|
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",
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,4 +161,16 @@ impl AsyncIo for RawFileAsyncAio {
|
|||||||
Some((events[0].data, events[0].res as i32))
|
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",
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,4 +146,16 @@ impl AsyncIo for RawFileSync {
|
|||||||
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
||||||
self.completion_list.pop_front()
|
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",
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -9,7 +9,7 @@ use std::os::fd::AsRawFd;
|
|||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
use crate::async_io::{
|
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::vhdx::{Result as VhdxResult, Vhdx};
|
||||||
use crate::{AsyncAdaptor, BlockBackend, Error};
|
use crate::{AsyncAdaptor, BlockBackend, Error};
|
||||||
@@ -114,4 +114,16 @@ impl AsyncIo for VhdxSync {
|
|||||||
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
fn next_completed_request(&mut self) -> Option<(u64, i32)> {
|
||||||
self.completion_list.pop_front()
|
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",
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user