Struct File

Source
pub struct File {
    file: RwLock<File>,
    filename: Option<PathBuf>,
    req_align: usize,
    mem_align: usize,
    size: AtomicU64,
    common_storage_helper: CommonStorageHelper,
}
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: usize

Minimal I/O alignment for requests.

§mem_align: usize

Minimal memory buffer alignment.

§size: AtomicU64

Cached file length.

Third parties changing the length concurrently is pretty certain to break things anyway.

§common_storage_helper: CommonStorageHelper

Storage helper.

Implementations§

Source§

impl File

Source

fn new(file: File, filename: Option<PathBuf>, direct_io: bool) -> Result<Self>

Central internal function to create a File object.

direct_io should be true if direct I/O was requested, and can be false if that status is unknown.

Source

fn probe_alignments( file: &mut File, min_req_align: usize, min_mem_align: usize, ) -> (usize, usize)

Probe minimal request and memory alignments.

Start at min_req_align and min_mem_align.

Source

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.

Source

fn get_min_dio_req_align(file: &File) -> usize

Get system-reported minimum request alignment for direct I/O.

Source

fn get_min_dio_mem_align(_file: &File) -> usize

Get system-reported minimum memory alignment for direct I/O.

Source

fn do_open_sync( opts: StorageOpenOptions, base_fs_opts: OpenOptions, ) -> Result<Self>

Implementation for anything that opens a file.

Source

fn try_discard_by_truncate(&self, offset: u64, length: u64) -> Result<bool>

Attempt to discard range by truncating the file.

If the given range is at the end of the file, discard it by simply truncating the file. 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 Debug for File

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for File

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Storage for File

Source§

async fn open(opts: StorageOpenOptions) -> Result<Self>

Open a storage object. Read more
Source§

fn open_sync(opts: StorageOpenOptions) -> Result<Self>

Synchronous wrapper around Storage::open().
Source§

async fn create_open(opts: StorageCreateOptions) -> Result<Self>

Create a storage object and open it. Read more
Source§

fn mem_align(&self) -> usize

Minimum required alignment for memory buffers.
Source§

fn req_align(&self) -> usize

Minimum required alignment for offsets and lengths.
Source§

fn size(&self) -> Result<u64>

Storage object length.
Source§

fn resolve_relative_path<P: AsRef<Path>>(&self, relative: P) -> Result<PathBuf>

Resolve the given path relative to this storage object. Read more
Source§

fn get_filename(&self) -> Option<PathBuf>

Return a filename, if possible. Read more
Source§

async unsafe fn pure_readv( &self, bufv: IoVectorMut<'_>, offset: u64, ) -> Result<()>

Read data at offset into bufv. Read more
Source§

async unsafe fn pure_writev( &self, bufv: IoVector<'_>, offset: u64, ) -> Result<()>

Write data from bufv to offset. Read more
Source§

async unsafe fn pure_write_zeroes(&self, offset: u64, length: u64) -> Result<()>

Ensure the given range reads back as zeroes. Read more
Source§

async unsafe fn pure_discard(&self, offset: u64, length: u64) -> Result<()>

Discard the given range, with undefined contents when read back. Read more
Source§

async fn flush(&self) -> Result<()>

Flush internal buffers. Read more
Source§

async fn sync(&self) -> Result<()>

Sync data already written to the storage hardware. Read more
Source§

async unsafe fn invalidate_cache(&self) -> Result<()>

Drop internal buffers. Read more
Source§

fn get_storage_helper(&self) -> &CommonStorageHelper

Return the storage helper object (used by the StorageExt implementation).
Source§

async fn resize( &self, new_size: u64, prealloc_mode: PreallocateMode, ) -> Result<()>

Resize to the given size. Read more
Source§

async fn create(opts: StorageCreateOptions) -> Result<()>

Create a storage object. Read more
Source§

fn zero_align(&self) -> usize

Minimum required alignment for zero writes.
Source§

fn discard_align(&self) -> usize

Minimum required alignment for effective discards.
Source§

impl TryFrom<File> for File

Source§

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.

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl !Freeze for File

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnwindSafe for File

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S> DynStorage for S
where S: Storage + 'static,

Source§

fn dyn_mem_align(&self) -> usize

Wrapper around Storage::mem_align().
Source§

fn dyn_req_align(&self) -> usize

Wrapper around Storage::req_align().
Source§

fn dyn_zero_align(&self) -> usize

Wrapper around Storage::zero_align().
Source§

fn dyn_discard_align(&self) -> usize

Wrapper around Storage::discard_align().
Source§

fn dyn_size(&self) -> Result<u64, Error>

Wrapper around Storage::size().
Source§

fn dyn_resolve_relative_path(&self, relative: &Path) -> Result<PathBuf, Error>

Source§

fn dyn_get_filename(&self) -> Option<PathBuf>

Source§

unsafe fn dyn_pure_readv<'a>( &'a self, bufv: IoVectorMut<'a>, offset: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>

Object-safe wrapper around Storage::pure_readv(). Read more
Source§

unsafe fn dyn_pure_writev<'a>( &'a self, bufv: IoVector<'a>, offset: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'a>>

Object-safe wrapper around Storage::pure_writev(). Read more
Source§

unsafe fn dyn_pure_write_zeroes( &self, offset: u64, length: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>

Object-safe wrapper around Storage::pure_write_zeroes(). Read more
Source§

unsafe fn dyn_pure_discard( &self, offset: u64, length: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>

Object-safe wrapper around Storage::pure_discard(). Read more
Source§

fn dyn_flush(&self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>

Object-safe wrapper around Storage::flush().
Source§

fn dyn_sync(&self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>

Object-safe wrapper around Storage::sync().
Source§

unsafe fn dyn_invalidate_cache( &self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>

Object-safe wrapper around Storage::invalidate_cache(). Read more
Source§

fn dyn_get_storage_helper(&self) -> &CommonStorageHelper

Source§

fn dyn_resize( &self, new_size: u64, prealloc_mode: PreallocateMode, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + '_>>

Wrapper around Storage::resize().
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<S> StorageExt for S
where S: Storage,

Source§

async fn readv(&self, bufv: IoVectorMut<'_>, offset: u64) -> Result<(), Error>

Read data at offset into bufv. Read more
Source§

async fn writev(&self, bufv: IoVector<'_>, offset: u64) -> Result<(), Error>

Write data from bufv to offset. Read more
Source§

async fn read( &self, buf: impl Into<IoVectorMut<'_>>, offset: u64, ) -> Result<(), Error>

Read data at offset into buf. Read more
Source§

async fn write( &self, buf: impl Into<IoVector<'_>>, offset: u64, ) -> Result<(), Error>

Write data from buf to offset. Read more
Source§

async fn write_zeroes(&self, offset: u64, length: u64) -> Result<(), Error>

Ensure the given range reads back as zeroes.
Source§

async fn discard(&self, offset: u64, length: u64) -> Result<(), Error>

Discard the given range, with undefined contents when read back. Read more
Source§

async fn weak_write_blocker(&self, range: Range<u64>) -> RangeBlockedGuard<'_>

Await concurrent strong write blockers for the given range. Read more
Source§

async fn strong_write_blocker(&self, range: Range<u64>) -> RangeBlockedGuard<'_>

Await any concurrent write request for the given range. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more