Skip to content

Commit

Permalink
ref(ioctl): joining the attach and request methods
Browse files Browse the repository at this point in the history
This commit is based on adding the request method to
the attach method so that when the frontend device
model / VMM uses the attach method to wait for an
I/O request, when it returns it already takes the
respective request, thus avoiding making another
call to request the same.

Signed-off-by: joaopeixoto13 <[email protected]>
  • Loading branch information
joaopeixoto13 committed May 24, 2024
1 parent ae55473 commit 3759deb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 49 deletions.
24 changes: 2 additions & 22 deletions src/api/src/device_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,7 @@ impl BaoDeviceModel {
/// # Returns
///
/// A `Result` containing the result of the operation.
pub fn attach_io_client(&self) -> Result<()> {
unsafe {
let ret = ioctl(self.devmodel_fd, BAO_IOCTL_IO_ATTACH_CLIENT());

if ret < 0 {
return Err(Error::BaoIoctlError(
std::io::Error::last_os_error(),
std::any::type_name::<Self>(),
));
}
}
Ok(())
}

/// Requests an I/O request.
///
/// # Return
///
/// * `Result<BaoIoRequest>` - A Result containing the BaoIoRequest object on success.
pub fn request_io(&self) -> Result<BaoIoRequest> {
pub fn attach_io_client(&self) -> Result<BaoIoRequest> {
// Create a new I/O request
let mut request = BaoIoRequest {
virtio_id: 0,
Expand All @@ -163,9 +144,8 @@ impl BaoDeviceModel {
vcpu_id: 0,
ret: 0,
};
// Request the I/O request
unsafe {
let ret = ioctl(self.devmodel_fd, BAO_IOCTL_IO_REQUEST(), &mut request);
let ret = ioctl(self.devmodel_fd, BAO_IOCTL_IO_ATTACH_CLIENT(), &mut request);

if ret < 0 {
return Err(Error::BaoIoctlError(
Expand Down
28 changes: 10 additions & 18 deletions src/api/src/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,37 @@ ioctl_ioc_nr!(
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_ATTACH_CLIENT,
_IOC_NONE,
BAO_IOCTL_TYPE,
5 as u32,
0
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_REQUEST,
_IOC_WRITE | _IOC_READ,
BAO_IOCTL_TYPE,
6 as u32,
5 as u32,
std::mem::size_of::<BaoIoRequest>() as u32
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_REQUEST_NOTIFY_COMPLETED,
_IOC_WRITE,
BAO_IOCTL_TYPE,
7 as u32,
6 as u32,
std::mem::size_of::<BaoIoRequest>() as u32
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_NOTIFY_GUEST,
_IOC_NONE,
BAO_IOCTL_TYPE,
8 as u32,
7 as u32,
0
);
ioctl_ioc_nr!(
BAO_IOCTL_IOEVENTFD,
_IOC_WRITE,
BAO_IOCTL_TYPE,
9 as u32,
8 as u32,
std::mem::size_of::<BaoIoEventFd>() as u32
);
ioctl_ioc_nr!(
BAO_IOCTL_IRQFD,
_IOC_WRITE,
BAO_IOCTL_TYPE,
10 as u32,
9 as u32,
std::mem::size_of::<BaoIrqFd>() as u32
);

Expand All @@ -94,11 +87,10 @@ mod tests {
assert_eq!(0x4004_A602, BAO_IOCTL_VM_VIRTIO_BACKEND_DESTROY());
assert_eq!(0x0000_A603, BAO_IOCTL_IO_CREATE_CLIENT());
assert_eq!(0x0000_A604, BAO_IOCTL_IO_DESTROY_CLIENT());
assert_eq!(0x0000_A605, BAO_IOCTL_IO_ATTACH_CLIENT());
assert_eq!(0xC040_A606, BAO_IOCTL_IO_REQUEST());
assert_eq!(0x4040_A607, BAO_IOCTL_IO_REQUEST_NOTIFY_COMPLETED());
assert_eq!(0x0000_A608, BAO_IOCTL_IO_NOTIFY_GUEST());
assert_eq!(0x4020_A609, BAO_IOCTL_IOEVENTFD());
assert_eq!(0x4008_A60A, BAO_IOCTL_IRQFD());
assert_eq!(0xC040_A605, BAO_IOCTL_IO_ATTACH_CLIENT());
assert_eq!(0x4040_A606, BAO_IOCTL_IO_REQUEST_NOTIFY_COMPLETED());
assert_eq!(0x0000_A607, BAO_IOCTL_IO_NOTIFY_GUEST());
assert_eq!(0x4020_A608, BAO_IOCTL_IOEVENTFD());
assert_eq!(0x4008_A609, BAO_IOCTL_IRQFD());
}
}
10 changes: 1 addition & 9 deletions src/vmm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,7 @@ impl Vm {
pub fn run_io(self: Arc<Self>) -> Result<()> {
loop {
//Attach the I/O client.
match self.device_model.lock().unwrap().attach_io_client() {
Ok(()) => {}
Err(err) => {
return Err(err);
}
}

// Request the I/O client
let mut req = match self.device_model.lock().unwrap().request_io() {
let mut req = match self.device_model.lock().unwrap().attach_io_client() {
Ok(req) => req,
Err(err) => {
return Err(err);
Expand Down

0 comments on commit 3759deb

Please sign in to comment.