[−][src]Struct glommio::io::DmaFile
Constructs a file that can issue DMA operations. All access uses Direct I/O, and all operations including open and close are asynchronous.
Implementations
impl DmaFile
[src]
pub fn align_up(&self, v: u64) -> u64
[src]
align a value up to the minimum alignment needed to access this file
pub fn align_down(&self, v: u64) -> u64
[src]
align a value down to the minimum alignment needed to access this file
impl DmaFile
[src]
pub fn is_same(&self, other: &DmaFile) -> bool
[src]
Returns true if the DmaFiles represent the same file on the underlying device.
Files are considered to be the same if they live in the same file system and have the same Linux inode. Note that based on this rule a symlink is not considered to be the same file.
Files will be considered to be the same if:
- A file is opened multiple times (different file descriptors, but same file!)
- they are hard links.
Examples
use glommio::LocalExecutor; use glommio::io::DmaFile; use std::os::unix::io::AsRawFd; let ex = LocalExecutor::make_default(); ex.run(async { let mut wfile = DmaFile::create("myfile.txt").await.unwrap(); let mut rfile = DmaFile::open("myfile.txt").await.unwrap(); // Different objects (OS file descriptors), so they will be different... assert_ne!(wfile.as_raw_fd(), rfile.as_raw_fd()); // However they represent the same object. assert!(wfile.is_same(&rfile)); wfile.close().await; rfile.close().await; });
pub fn alloc_dma_buffer(size: usize) -> DmaBuffer
[src]
Allocates a buffer that is suitable for using to write to this file.
pub async fn create<P: AsRef<Path>>(path: P) -> Result<DmaFile>
[src]
Similar to create() in the standard library, but returns a DMA file
pub async fn open<P: AsRef<Path>>(path: P) -> Result<DmaFile>
[src]
Similar to open() in the standard library, but returns a DMA file
pub async fn write_at<'_>(&'_ self, buf: DmaBuffer, pos: u64) -> Result<usize>
[src]
Writes the buffer in buf to a specific position in the file.
It is expected that the buffer and the position be properly aligned for Direct I/O. In most platforms that means 4096 bytes. There is no write_at_aligned, since a non aligned write would require a read-modify-write.
Buffers should be allocated through alloc_dma_buffer
, which guarantees
proper alignment, but alignment on position is still up to the user.
This method acquires ownership of the buffer so the buffer can be kept alive while the kernel has it.
Note that it is legal to return fewer bytes than the buffer size. That is the situation, for example, when the device runs out of space (See the man page for write(2) for details)
Examples
use glommio::LocalExecutor; use glommio::io::DmaFile; let ex = LocalExecutor::make_default(); ex.run(async { let file = DmaFile::create("test.txt").await.unwrap(); let mut buf = DmaFile::alloc_dma_buffer(4096); let res = file.write_at(buf, 0).await.unwrap(); assert!(res <= 4096); file.close().await.unwrap(); });
pub async fn read_at_aligned<'_>(
&'_ self,
pos: u64,
size: usize
) -> Result<ReadResult>
[src]
&'_ self,
pos: u64,
size: usize
) -> Result<ReadResult>
Reads from a specific position in the file and returns the buffer.
The position must be aligned to for Direct I/O. In most platforms that means 512 bytes.
pub async fn read_at<'_>(&'_ self, pos: u64, size: usize) -> Result<ReadResult>
[src]
Reads into buffer in buf from a specific position in the file.
It is not necessary to respect the O_DIRECT alignment of the file, and this API will internally convert the positions and sizes to match, at a cost.
If you can guarantee proper alignment, prefer read_at_aligned instead
pub async fn fdatasync<'_>(&'_ self) -> Result<()>
[src]
Issues fdatasync into the underlying file.
pub async fn pre_allocate<'_>(&'_ self, size: u64) -> Result<()>
[src]
pre-allocates space in the filesystem to hold a file at least as big as the size argument
pub async fn hint_extent_size<'_>(&'_ self, size: usize) -> Result<i32>
[src]
Allocating blocks at the filesystem level turns asynchronous writes into threaded synchronous writes, as we need to first find the blocks to host the file.
If the extent is larger, that means many blocks are allocated at a time. For instance, if the extent size is 1MB, that means that only 1 out of 4 256kB writes will be turned synchronous. Combined with diligent use of fallocate we can greatly minimize context switches.
It is important not to set the extent size too big. Writes can fail otherwise if the extent can't be allocated
pub async fn truncate<'_>(&'_ self, size: u64) -> Result<()>
[src]
Truncates a file to the specified size.
Warning: synchronous operation, will block the reactor
pub async fn rename<P: AsRef<Path>, '_>(&'_ mut self, new_path: P) -> Result<()>
[src]
rename this file.
Warning: synchronous operation, will block the reactor
pub async fn remove<'_>(&'_ self) -> Result<()>
[src]
remove this file
The file does not have to be closed to be removed. Removing removes the name from the filesystem but the file will still be accessible for as long as it is open.
Warning: synchronous operation, will block the reactor
pub async fn file_size<'_>(&'_ self) -> Result<u64>
[src]
Returns the size of a file, in bytes
pub async fn close(self) -> Result<()>
[src]
Closes this DMA file.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for DmaFile
impl Send for DmaFile
impl Sync for DmaFile
impl Unpin for DmaFile
impl UnwindSafe for DmaFile
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,