vhost-user-backend: Add vhost-user bitmap trait bounds

Any bitmap used in the vhost-user backend must implement the
BitmapReplace trait, which provides the functionality to replace the
internal bitmap in runtime.

This internal bitmap is required because in the vm-memory crate the
bitmap is expected to exist at the time of creating the memory regions,
and in the case of vhost-user the bitmap is added at runtime, also it
could be replaced at a later time. In addition, the vhost user protocol
does not specify whether the previous bitmap is still active after
replying to the VHOST_USER_SET_LOG_BASE message, so we must be sure
that the in-flight requests are using the new bitmap after the message
reply.

Signed-off-by: German Maglione <gmaglione@redhat.com>
This commit is contained in:
German Maglione 2023-11-15 11:28:51 +01:00 committed by Erik Schilling
parent d05f1b5e12
commit 4443df57bb
2 changed files with 4 additions and 2 deletions

View file

@ -12,6 +12,7 @@ use std::os::unix::io::AsRawFd;
use std::sync::Arc;
use std::thread;
use crate::bitmap::BitmapReplace;
#[cfg(feature = "postcopy")]
use userfaultfd::{Uffd, UffdBuilder};
use vhost::vhost_user::message::{
@ -230,7 +231,7 @@ where
impl<T: VhostUserBackend> VhostUserBackendReqHandlerMut for VhostUserHandler<T>
where
T::Bitmap: NewBitmap + Clone,
T::Bitmap: BitmapReplace + NewBitmap + Clone,
{
fn set_owner(&mut self) -> VhostUserResult<()> {
if self.owned {

View file

@ -29,6 +29,7 @@ mod handler;
pub use self::handler::VhostUserHandlerError;
pub mod bitmap;
use crate::bitmap::BitmapReplace;
mod vring;
pub use self::vring::{
@ -97,7 +98,7 @@ pub struct VhostUserDaemon<T: VhostUserBackend> {
impl<T> VhostUserDaemon<T>
where
T: VhostUserBackend + Clone + 'static,
T::Bitmap: NewBitmap + Clone + Send + Sync,
T::Bitmap: BitmapReplace + NewBitmap + Clone + Send + Sync,
T::Vring: Clone + Send + Sync,
{
/// Create the daemon instance, providing the backend implementation of `VhostUserBackend`.