pub struct File {
file: RwLock<File>,
filename: Option<PathBuf>,
req_align: usize,
mem_align: usize,
zero_align: usize,
discard_align: usize,
size: AtomicU64,
common_storage_helper: CommonStorageHelper,
discard_unsupported: AtomicBool,
}Expand description
Use a plain file or host block device as a storage object.
Fields§
§file: RwLock<File>The file.
filename: Option<PathBuf>For debug purposes, and to resolve relative filenames.
req_align: usizeMinimal I/O alignment for requests.
mem_align: usizeMinimal memory buffer alignment.
zero_align: usizeMinimum required alignment for zero writes.
discard_align: usizeMinimum required alignment for effective discards.
size: AtomicU64Cached file length.
Third parties changing the length concurrently is pretty certain to break things anyway.
common_storage_helper: CommonStorageHelperStorage helper.
discard_unsupported: AtomicBoolSet once we know that discard is unsupported and we can skip trying.
Implementations§
Source§impl File
impl File
Sourcepub fn from_open_file(file: File, opts: StorageOpenOptions) -> Result<Self>
pub fn from_open_file(file: File, opts: StorageOpenOptions) -> Result<Self>
Use an existing file with explicitly known open options.
The filename is not used to reopen the file, but is retained to resolve relative paths. The writable and direct I/O options must match how the file was opened.
Sourcefn new(
file: File,
filename: Option<PathBuf>,
direct_io: bool,
writable: bool,
) -> Result<Self>
fn new( file: File, filename: Option<PathBuf>, direct_io: bool, writable: bool, ) -> Result<Self>
Central internal function to create a File object.
Sourcefn detect_open_mode(file: &File) -> (bool, bool)
fn detect_open_mode(file: &File) -> (bool, bool)
Detect access and direct I/O modes for an externally supplied file.
Returns (direct_io, writable), indicating whether direct I/O is enabled and whether the
file is open for writing.
Sourcefn host_page_size() -> usize
fn host_page_size() -> usize
Host page size, rounded up to a power of two.
Sourcefn get_fs_zero_discard_align(file: &File) -> (usize, usize)
fn get_fs_zero_discard_align(file: &File) -> (usize, usize)
Filesystem block size used as write-zeroes / discard alignment.
Sourcefn probe_alignments(
file: &mut File,
min_req_align: usize,
min_mem_align: usize,
writable: bool,
) -> (usize, usize, usize, usize)
fn probe_alignments( file: &mut File, min_req_align: usize, min_mem_align: usize, writable: bool, ) -> (usize, usize, usize, usize)
Probe minimal direct I/O request, memory, zero and discard alignments.
Start at min_req_align and min_mem_align.
Sourcefn probe_access(
file: &mut File,
slice: &mut [u8],
offset: off_t,
may_write: &mut bool,
) -> Result<bool>
fn probe_access( file: &mut File, slice: &mut [u8], offset: off_t, may_write: &mut bool, ) -> Result<bool>
Do an alignment-probing I/O access.
Return Ok(true) if everything was OK, and Ok(false) if the request was reported to be
misaligned.
may_write is a boolean that controls whether this is allowed to write (the same data read
before) to improve reliability. Is automatically set to false if writing is found to not
be possible.
Sourcefn get_min_dio_req_align(file: &File) -> usize
fn get_min_dio_req_align(file: &File) -> usize
Get system-reported minimum request alignment for direct I/O.
Sourcefn get_min_dio_mem_align(_file: &File) -> usize
fn get_min_dio_mem_align(_file: &File) -> usize
Get system-reported minimum memory alignment for direct I/O.
Sourcefn do_open_sync(
opts: StorageOpenOptions,
base_fs_opts: OpenOptions,
) -> Result<Self>
fn do_open_sync( opts: StorageOpenOptions, base_fs_opts: OpenOptions, ) -> Result<Self>
Implementation for anything that opens a file.
Sourcefn map_os_err(err: Error) -> Error
fn map_os_err(err: Error) -> Error
For special operations, ensure the error kind is usable.
When invoking OS I/O operations directly, we turn the returned raw OS error code into an
io::Error object via io::Error::last_os_error(). To differentiate between different
error cases, in generic imago code, we then don’t use that raw error code, but the error
kind (io::ErrorKind) instead, specifically it’s important to properly return an error of
kind io::ErrorKind::Unsupported when an operation is unsupported, so fall-backs can be
employed.
Rust’s standard library only assigns this error kind (Unsupported) to EOPNOTSUPP (=
ENOTSUP) and ENOSYS. However, some “special” operations (fallocate(),
fcntl(F_PUNCHHOLE), ioctl(), …) can return other error codes for when an operation is
not supported on a specific file, e.g. ENODEV or ENXIO.
Assign the appropriate error kind to such errors so the generic code can handle them.
Sourcefn try_discard_by_truncate(&self, offset: u64, length: u64) -> Result<bool>
fn try_discard_by_truncate(&self, offset: u64, length: u64) -> Result<bool>
Attempt to discard range by truncating the file.
If the range reaches the end of the file, truncate and restore the original file length.
Return true on success.
If the range is not at the end of the file, i.e. another method of discarding is needed,
return false.
Trait Implementations§
Source§impl Storage for File
impl Storage for File
Source§fn open_sync(opts: StorageOpenOptions) -> Result<Self>
fn open_sync(opts: StorageOpenOptions) -> Result<Self>
Storage::open().Source§async fn create_open(opts: StorageCreateOptions) -> Result<Self>
async fn create_open(opts: StorageCreateOptions) -> Result<Self>
Source§fn zero_align(&self) -> usize
fn zero_align(&self) -> usize
Source§fn discard_align(&self) -> usize
fn discard_align(&self) -> usize
Source§fn resolve_relative_path<P: AsRef<Path>>(&self, relative: P) -> Result<PathBuf>
fn resolve_relative_path<P: AsRef<Path>>(&self, relative: P) -> Result<PathBuf>
Source§async unsafe fn pure_readv(
&self,
bufv: IoVectorMut<'_>,
offset: u64,
) -> Result<()>
async unsafe fn pure_readv( &self, bufv: IoVectorMut<'_>, offset: u64, ) -> Result<()>
Source§async unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>
async unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>
Source§async unsafe fn pure_write_allocated_zeroes(
&self,
offset: u64,
length: u64,
) -> Result<()>
async unsafe fn pure_write_allocated_zeroes( &self, offset: u64, length: u64, ) -> Result<()>
Source§async unsafe fn pure_discard(&self, offset: u64, length: u64) -> Result<()>
async unsafe fn pure_discard(&self, offset: u64, length: u64) -> Result<()>
Source§async fn sync(&self) -> Result<()>
async fn sync(&self) -> Result<()>
Source§fn get_storage_helper(&self) -> &CommonStorageHelper
fn get_storage_helper(&self) -> &CommonStorageHelper
StorageExt
implementation).Source§impl TryFrom<File> for File
impl TryFrom<File> for File
Source§fn try_from(file: File) -> Result<Self>
fn try_from(file: File) -> Result<Self>
Use the given existing std::fs::File.
Convert the given existing std::fs::File object into an imago storage object.
When using this, the resulting object will not know its own filename. That makes it impossible to auto-resolve relative paths to it, e.g. qcow2 backing file names.
Auto Trait Implementations§
impl !Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
impl UnwindSafe for File
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> DynStorage for Swhere
S: Storage + 'static,
impl<S> DynStorage for Swhere
S: Storage + 'static,
Source§fn dyn_mem_align(&self) -> usize
fn dyn_mem_align(&self) -> usize
Storage::mem_align().Source§fn dyn_req_align(&self) -> usize
fn dyn_req_align(&self) -> usize
Storage::req_align().Source§fn dyn_zero_align(&self) -> usize
fn dyn_zero_align(&self) -> usize
Storage::zero_align().Source§fn dyn_discard_align(&self) -> usize
fn dyn_discard_align(&self) -> usize
Storage::discard_align().Source§fn dyn_resolve_relative_path(&self, relative: &Path) -> Result<PathBuf, Error>
fn dyn_resolve_relative_path(&self, relative: &Path) -> Result<PathBuf, Error>
Storage::resolve_relative_path().Source§fn dyn_get_filename(&self) -> Option<PathBuf>
fn dyn_get_filename(&self) -> Option<PathBuf>
Storage::get_filename()Source§unsafe fn dyn_pure_readv<'a>(
&'a self,
bufv: IoVectorMut<'a>,
offset: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>
unsafe fn dyn_pure_readv<'a>( &'a self, bufv: IoVectorMut<'a>, offset: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>
Storage::pure_readv(). Read moreSource§unsafe fn dyn_pure_writev<'a>(
&'a self,
bufv: IoVector<'a>,
offset: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>
unsafe fn dyn_pure_writev<'a>( &'a self, bufv: IoVector<'a>, offset: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>
Storage::pure_writev(). Read moreSource§unsafe fn dyn_pure_write_zeroes(
&self,
offset: u64,
length: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
unsafe fn dyn_pure_write_zeroes( &self, offset: u64, length: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
Storage::pure_write_zeroes(). Read moreSource§unsafe fn dyn_pure_write_allocated_zeroes(
&self,
offset: u64,
length: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
unsafe fn dyn_pure_write_allocated_zeroes( &self, offset: u64, length: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
Storage::pure_write_allocated_zeroes(). Read moreSource§unsafe fn dyn_pure_discard(
&self,
offset: u64,
length: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
unsafe fn dyn_pure_discard( &self, offset: u64, length: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
Storage::pure_discard(). Read moreSource§fn dyn_flush(&self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
fn dyn_flush(&self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
Storage::flush().Source§fn dyn_sync(&self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
fn dyn_sync(&self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
Storage::sync().Source§unsafe fn dyn_invalidate_cache(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
unsafe fn dyn_invalidate_cache( &self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
Storage::invalidate_cache(). Read moreSource§fn dyn_get_storage_helper(&self) -> &CommonStorageHelper
fn dyn_get_storage_helper(&self) -> &CommonStorageHelper
Storage::get_storage_helper().Source§fn dyn_resize(
&self,
new_size: u64,
prealloc_mode: PreallocateMode,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
fn dyn_resize( &self, new_size: u64, prealloc_mode: PreallocateMode, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>
Storage::resize().