virtio-devices: vhost_user: Set proper avail index to vhost-user backend

We should try to read the last avail index from the vring memory aera. This
is necessary when handling vhost-user socket reconnection.

Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
This commit is contained in:
Jiachen Zhang 2021-06-03 12:10:03 +08:00 committed by Sebastien Boeuf
parent b443900cc2
commit 058946772a
2 changed files with 10 additions and 2 deletions

View File

@ -15,6 +15,7 @@ use vhost::vhost_user::message::VhostUserVirtioFeatures;
use vhost::vhost_user::Master;
use vhost::Error as VhostError;
use vm_memory::{Error as MmapError, GuestAddressSpace, GuestMemoryAtomic};
use vm_virtio::Error as VirtioError;
use vmm_sys_util::eventfd::EventFd;
use vu_common_ctrl::{connect_vhost_user, reinitialize_vhost_user};
@ -111,6 +112,8 @@ pub enum Error {
MissingRegionFd,
/// Missing IrqFd
MissingIrqFd,
/// Failed getting the available index.
GetAvailableIndex(VirtioError),
}
type Result<T> = std::result::Result<T, Error>;

View File

@ -143,8 +143,13 @@ pub fn setup_vhost_user(
vu.set_vring_addr(queue_index, &config_data)
.map_err(Error::VhostUserSetVringAddr)?;
vu.set_vring_base(queue_index, 0u16)
.map_err(Error::VhostUserSetVringBase)?;
vu.set_vring_base(
queue_index,
queue
.avail_index_from_memory(mem)
.map_err(Error::GetAvailableIndex)?,
)
.map_err(Error::VhostUserSetVringBase)?;
if let Some(eventfd) = virtio_interrupt.notifier(&VirtioInterruptType::Queue, Some(&queue))
{