Skip to content

Commit

Permalink
ref(ioctls): remove create and destroy I/O clients calls
Browse files Browse the repository at this point in the history
This commit removes the creation and deletion ioctls
regarding I/O clients, since the VMM / Frontend DM
only interacts with the Control I/O Client. In this way,
the creation of this client is performed when the
backend device model is created by the
BAO_IOCTL_VM_VIRTIO_BACKEND_CREATE ioctl issued by the VMM.
To destroy the Control I/O Client, the VMM simply calls
the BAO_IOCTL_VM_VIRTIO_BACKEND_DESTROY ioctl which,
internally, it is called the delete method for all I/O
Clients (Control and Ioeventfd).

Signed-off-by: joaopeixoto13 <[email protected]>
  • Loading branch information
joaopeixoto13 committed May 24, 2024
1 parent 3759deb commit 0b358c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 67 deletions.
41 changes: 0 additions & 41 deletions src/api/src/device_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ impl BaoDeviceModel {
id,
};

// Create the I/O client.
device_model.create_io_client().unwrap();

Ok(device_model)
}

Expand All @@ -89,44 +86,6 @@ impl BaoDeviceModel {
Ok(())
}

/// Create an I/O client.
///
/// # Returns
///
/// A `Result` containing the result of the operation.
fn create_io_client(&self) -> Result<()> {
unsafe {
let ret = ioctl(self.devmodel_fd, BAO_IOCTL_IO_CREATE_CLIENT());

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

/// Destroy an I/O client.
///
/// # Returns
///
/// A `Result` containing the result of the operation.
pub fn destroy_io_client(&self) -> Result<()> {
unsafe {
let ret = ioctl(self.devmodel_fd, BAO_IOCTL_IO_DESTROY_CLIENT());

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

/// Attach the I/O client to the VM.
///
/// # Returns
Expand Down
36 changes: 10 additions & 26 deletions src/api/src/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,53 +26,39 @@ ioctl_ioc_nr!(
2 as u32,
std::mem::size_of::<u32>() as u32
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_CREATE_CLIENT,
_IOC_NONE,
BAO_IOCTL_TYPE,
3 as u32,
0
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_DESTROY_CLIENT,
_IOC_NONE,
BAO_IOCTL_TYPE,
4 as u32,
0
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_ATTACH_CLIENT,
_IOC_WRITE | _IOC_READ,
BAO_IOCTL_TYPE,
5 as u32,
3 as u32,
std::mem::size_of::<BaoIoRequest>() as u32
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_REQUEST_NOTIFY_COMPLETED,
_IOC_WRITE,
BAO_IOCTL_TYPE,
6 as u32,
4 as u32,
std::mem::size_of::<BaoIoRequest>() as u32
);
ioctl_ioc_nr!(
BAO_IOCTL_IO_NOTIFY_GUEST,
_IOC_NONE,
BAO_IOCTL_TYPE,
7 as u32,
5 as u32,
0
);
ioctl_ioc_nr!(
BAO_IOCTL_IOEVENTFD,
_IOC_WRITE,
BAO_IOCTL_TYPE,
8 as u32,
6 as u32,
std::mem::size_of::<BaoIoEventFd>() as u32
);
ioctl_ioc_nr!(
BAO_IOCTL_IRQFD,
_IOC_WRITE,
BAO_IOCTL_TYPE,
9 as u32,
7 as u32,
std::mem::size_of::<BaoIrqFd>() as u32
);

Expand All @@ -85,12 +71,10 @@ mod tests {
fn test_ioctls() {
assert_eq!(0x4004_A601, BAO_IOCTL_VM_VIRTIO_BACKEND_CREATE());
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!(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());
assert_eq!(0xC040_A603, BAO_IOCTL_IO_ATTACH_CLIENT());
assert_eq!(0x4040_A604, BAO_IOCTL_IO_REQUEST_NOTIFY_COMPLETED());
assert_eq!(0x0000_A605, BAO_IOCTL_IO_NOTIFY_GUEST());
assert_eq!(0x4020_A606, BAO_IOCTL_IOEVENTFD());
assert_eq!(0x4008_A607, BAO_IOCTL_IRQFD());
}
}

0 comments on commit 0b358c9

Please sign in to comment.