From 9e786e4032a1b4a0859d2e5d3933bce1f57caeda Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Tue, 31 Aug 2021 13:31:58 +0530 Subject: [PATCH] i2c: Fix breakage introduced by vhost-user-backend vhost-user-backend repository received few updates recently, which caused this one to break. Update the code here to fix the breakage. Signed-off-by: Viresh Kumar --- src/i2c/Cargo.toml | 4 ++-- src/i2c/src/main.rs | 10 +++++++--- src/i2c/src/vhu_i2c.rs | 37 +++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/i2c/Cargo.toml b/src/i2c/Cargo.toml index 1a14eee..d308a1a 100644 --- a/src/i2c/Cargo.toml +++ b/src/i2c/Cargo.toml @@ -16,8 +16,8 @@ clap = { version = "=3.0.0-beta.2", features = ["yaml"] } epoll = "4.3" libc = ">=0.2.95" log = ">=0.4.6" -vhost = { git = "https://github.com/rust-vmm/vhost", features = ["vhost-user-slave"] } +vhost = { version = "0.1", features = ["vhost-user-slave"] } vhost-user-backend = { git = "https://github.com/rust-vmm/vhost-user-backend" } virtio-bindings = ">=0.1" -vm-memory = ">=0.3.0" +vm-memory = "0.6" vmm-sys-util = ">=0.8.0" diff --git a/src/i2c/src/main.rs b/src/i2c/src/main.rs index ce6db51..fc0e1ac 100644 --- a/src/i2c/src/main.rs +++ b/src/i2c/src/main.rs @@ -15,6 +15,7 @@ use std::thread::spawn; use vhost::{vhost_user, vhost_user::Listener}; use vhost_user_backend::VhostUserDaemon; use vhu_i2c::VhostUserI2cBackend; +use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap}; fn start_backend(cmd_args: ArgMatches, dryrun: bool) -> Result<(), String> { let mut handles = Vec::new(); @@ -49,9 +50,12 @@ fn start_backend(cmd_args: ArgMatches, dryrun: bool) -> Resu return; } - let mut daemon = - VhostUserDaemon::new(String::from("vhost-device-i2c-backend"), backend.clone()) - .unwrap(); + let mut daemon = VhostUserDaemon::new( + String::from("vhost-device-i2c-backend"), + backend.clone(), + GuestMemoryAtomic::new(GuestMemoryMmap::new()), + ) + .unwrap(); daemon.start(listener).unwrap(); diff --git a/src/i2c/src/vhu_i2c.rs b/src/i2c/src/vhu_i2c.rs index 53b5a66..c4dc996 100644 --- a/src/i2c/src/vhu_i2c.rs +++ b/src/i2c/src/vhu_i2c.rs @@ -7,10 +7,10 @@ use crate::i2c::*; use std::mem::size_of; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; use std::{convert, error, fmt, io}; use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; -use vhost_user_backend::{VhostUserBackend, Vring}; +use vhost_user_backend::{VhostUserBackendMut, Vring}; use virtio_bindings::bindings::virtio_net::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1}; use virtio_bindings::bindings::virtio_ring::{ VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC, @@ -102,11 +102,12 @@ impl VhostUserI2cBackend { } /// Process the requests in the vring and dispatch replies - fn process_queue(&self, vring: &mut Vring) -> Result { + fn process_queue(&self, vring: &Vring) -> Result { let mut reqs: Vec = Vec::new(); let requests: Vec<_> = vring - .mut_queue() + .get_mut() + .get_queue_mut() .iter() .map_err(|_| Error::DescriptorNotFound)? .collect(); @@ -205,11 +206,7 @@ impl VhostUserI2cBackend { len += desc_buf.len(); } - if vring - .mut_queue() - .add_used(desc_chain.head_index(), len) - .is_err() - { + if vring.add_used(desc_chain.head_index(), len).is_err() { println!("Couldn't return used descriptors to the ring"); } } @@ -222,8 +219,8 @@ impl VhostUserI2cBackend { } } -/// VhostUserBackend trait methods -impl VhostUserBackend for VhostUserI2cBackend { +/// VhostUserBackendMut trait methods +impl VhostUserBackendMut for VhostUserI2cBackend { fn num_queues(&self) -> usize { NUM_QUEUES } @@ -258,10 +255,10 @@ impl VhostUserBackend for VhostUserI2cBackend { } fn handle_event( - &self, + &mut self, device_event: u16, evset: epoll::Events, - vrings: &[Arc>], + vrings: &[Vring], _thread_id: usize, ) -> VhostUserBackendResult { if evset != epoll::Events::EPOLLIN { @@ -270,7 +267,7 @@ impl VhostUserBackend for VhostUserI2cBackend { match device_event { 0 => { - let mut vring = vrings[0].write().unwrap(); + let vring = &vrings[0]; if self.event_idx { // vm-virtio's Queue implementation only checks avail_index @@ -278,15 +275,15 @@ impl VhostUserBackend for VhostUserI2cBackend { // calling process_queue() until it stops finding new // requests on the queue. loop { - vring.mut_queue().disable_notification().unwrap(); - self.process_queue(&mut vring)?; - if !vring.mut_queue().enable_notification().unwrap() { + vring.disable_notification().unwrap(); + self.process_queue(vring)?; + if !vring.enable_notification().unwrap() { break; } } } else { // Without EVENT_IDX, a single call is enough. - self.process_queue(&mut vring)?; + self.process_queue(vring)?; } } @@ -298,10 +295,10 @@ impl VhostUserBackend for VhostUserI2cBackend { Ok(false) } - fn exit_event(&self, _thread_index: usize) -> Option<(EventFd, Option)> { + fn exit_event(&self, _thread_index: usize) -> Option<(EventFd, u16)> { Some(( self.exit_event.try_clone().expect("Cloning exit eventfd"), - None, + NUM_QUEUES as u16, )) } }