diff --git a/src/api/src/device_model.rs b/src/api/src/device_model.rs index def9668..61e320f 100644 --- a/src/api/src/device_model.rs +++ b/src/api/src/device_model.rs @@ -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::(), - )); - } - } - Ok(()) - } - - /// Requests an I/O request. - /// - /// # Return - /// - /// * `Result` - A Result containing the BaoIoRequest object on success. - pub fn request_io(&self) -> Result { + pub fn attach_io_client(&self) -> Result { // Create a new I/O request let mut request = BaoIoRequest { virtio_id: 0, @@ -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( diff --git a/src/api/src/ioctl.rs b/src/api/src/ioctl.rs index 94ec0ee..a59100e 100644 --- a/src/api/src/ioctl.rs +++ b/src/api/src/ioctl.rs @@ -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::() 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::() 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::() as u32 ); ioctl_ioc_nr!( BAO_IOCTL_IRQFD, _IOC_WRITE, BAO_IOCTL_TYPE, - 10 as u32, + 9 as u32, std::mem::size_of::() as u32 ); @@ -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()); } } diff --git a/src/vmm/src/vm.rs b/src/vmm/src/vm.rs index c75784a..b1383a0 100644 --- a/src/vmm/src/vm.rs +++ b/src/vmm/src/vm.rs @@ -179,15 +179,7 @@ impl Vm { pub fn run_io(self: Arc) -> 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);