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
impl File
Sourcefn new(file: File, filename: Option<PathBuf>, direct_io: bool) -> Result<Self>
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.
Sourcefn probe_alignments(
file: &mut File,
min_req_align: usize,
min_mem_align: usize,
) -> (usize, usize)
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
.
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 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 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 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 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_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§async fn resize(
&self,
new_size: u64,
prealloc_mode: PreallocateMode,
) -> Result<()>
async fn resize( &self, new_size: u64, prealloc_mode: PreallocateMode, ) -> Result<()>
Source§fn zero_align(&self) -> usize
fn zero_align(&self) -> usize
Source§fn discard_align(&self) -> usize
fn discard_align(&self) -> usize
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 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_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()
.