vmm_sys_util::aio

Struct IoContext

Source
pub struct IoContext(/* private fields */);
Expand description

Newtype for aio_context_t.

Implementations§

Source§

impl IoContext

Source

pub fn new(nr_events: c_uint) -> Result<Self>

Create a new aio context instance.

Refer to Linux io_setup.

§Arguments
  • nr_events: maximum number of concurrently processing IO operations.
Source

pub fn submit(&self, iocbs: &[&mut IoControlBlock]) -> Result<usize>

Submit asynchronous I/O blocks for processing.

Refer to Linux io_submit.

§Arguments
  • iocbs: array of AIO control blocks, which will be submitted to the context.
§Examples
extern crate vmm_sys_util;
use vmm_sys_util::aio::*;

let file = File::open("/dev/zero").unwrap();
let ctx = IoContext::new(128).unwrap();
let mut buf: [u8; 4096] = unsafe { std::mem::uninitialized() };
let iocbs = [&mut IoControlBlock {
    aio_fildes: file.as_raw_fd() as u32,
    aio_lio_opcode: IOCB_CMD_PREAD as u16,
    aio_buf: buf.as_mut_ptr() as u64,
    aio_nbytes: buf.len() as u64,
    ..Default::default()
}];
assert_eq!(ctx.submit(&iocbs[..]).unwrap(), 1);
Source

pub fn cancel(&self, iocb: &IoControlBlock, result: &mut IoEvent) -> Result<()>

Cancel an outstanding asynchronous I/O operation.

Refer to Linux io_cancel. Note: according to current Linux kernel implementation(v4.19), libc::SYS_io_cancel always return failure, thus rendering it useless.

§Arguments
  • iocb: The iocb for the operation to be canceled.
  • result: If the operation is successfully canceled, the event will be copied into the memory pointed to by result without being placed into the completion queue.
Source

pub fn get_events( &self, min_nr: c_long, events: &mut [IoEvent], timeout: Option<&mut timespec>, ) -> Result<usize>

Read asynchronous I/O events from the completion queue.

Refer to Linux io_getevents.

§Arguments
  • min_nr: read at least min_nr events.
  • events: array to receive the io operation results.
  • timeout: optional amount of time to wait for events.
§Examples
extern crate vmm_sys_util;
use vmm_sys_util::aio::*;

let file = File::open("/dev/zero").unwrap();
let ctx = IoContext::new(128).unwrap();
let mut buf: [u8; 4096] = unsafe { std::mem::uninitialized() };
let iocbs = [
    &mut IoControlBlock {
        aio_fildes: file.as_raw_fd() as u32,
        aio_lio_opcode: IOCB_CMD_PREAD as u16,
        aio_buf: buf.as_mut_ptr() as u64,
        aio_nbytes: buf.len() as u64,
        ..Default::default()
    },
    &mut IoControlBlock {
        aio_fildes: file.as_raw_fd() as u32,
        aio_lio_opcode: IOCB_CMD_PREAD as u16,
        aio_buf: buf.as_mut_ptr() as u64,
        aio_nbytes: buf.len() as u64,
        ..Default::default()
    },
];

let mut rc = ctx.submit(&iocbs[..]).unwrap();
let mut events = [unsafe { std::mem::uninitialized::<IoEvent>() }];
rc = ctx.get_events(1, &mut events, None).unwrap();
assert_eq!(rc, 1);
assert!(events[0].res > 0);
rc = ctx.get_events(1, &mut events, None).unwrap();
assert_eq!(rc, 1);
assert!(events[0].res > 0);

Trait Implementations§

Source§

impl Debug for IoContext

Source§

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

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

impl Drop for IoContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<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.