Commit 66cda80 ("Update vm-memory requirement from 0.6 to 0.7")
is required to build this crate with vm-memory v0.7
There were API changes since commit 6013dd9, so let's update
code and tests.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
There's a wrapper for epoll from vmm-sys-util, so use the wrapper
instead of the epoll crate directly. It may help to ease dependency
management.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
According to the vhost-user specs, we should start the vring upon
receiving the first kick, and stop it when we receive GET_VRING_BASE.
Strictly speaking, we should reset the underlying Queue on the first
kick, but it's actually easier to simply do that in GET_VRING_BASE and
be ready in case the guest re-initializes the vring.
Signed-off-by: Sergio Lopez <slp@redhat.com>
The vhost-user protocol doesn't impose an order for the SET_VRING_KICK
and SET_VRING_CALL messages, which implies it's valid to emit the
first before the latter.
With the current code, this means that if the VMM sends SET_VRING_KICK
before SET_VRING_CALL, and the guest has already placed a request into
the vring, we may miss signaling the guest as that request may be
processed before we have an EventFd for "call".
To fix this, delay listener registration until we have an EventFd for
both call and kick, using "VringState::Queue.ready" as an indicator
that the vring has not been initialized yet.
Signed-off-by: Sergio Lopez <slp@redhat.com>
In addition to bringing the features from the new vhost crate, this
fixes the breakage caused by rust-vmm/vmm-sys-util#135
Signed-off-by: Sergio Lopez <slp@redhat.com>
Backend::handle_event() takes an argument of `vrings: &[V]` with
`V: VringT`, so methods of VringT should not take `&mut self`.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Refine the way to manage epoll event id and simplify interfaces:
- Change VhostUserBackend::exit_event() to return Option<EventFd>
instead of Option<(EventFd, u16)>.
- Delete VringEpollHandler::exit_event_id.
- Add VringEpollHandler::register_event/unregister_event for internal
use.
- Make VringEpollHandler::register_listener/unregister_listener() for
external users only, and 'data` range [0..backend.num_queues()] is
reserved for queues and exit event.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Add VringT::get_mut() to get exclusive reference to underlying
VringState object, so the clients could avoid repeatedly lock/unlock
when using VringMutex and VringRwLock.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Enhance VhostUserBackend, VhostUserBackendMut, VringEpollHandler,
VhostUserHandler and VhostUserDaemon to support generic type
`V: VringT', so clients could choose different VringT implementations.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Introduce trait VringT, and provide three implementations of it:
VringState, VringMutex, VringRwLock.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
The builds are failing since the remote branch's name is changed to
main from master. Fix it by adding the rev for virtio-queue.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
VhostUserHandler waits for all working thread to exit in drop(), but
there's no mechanism to notify the working threads to exit. So add
VhostUserHandler::send_exit_event() to notify working threads to exit.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Add a generic type parameter `B: Bitmap` to several key structs to
support guest memory dirty page tracking.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Refine VhostUserBackend to support interior mutability to better
support multi-threading. The previous version of VhostUserBackend
has been renamed as VhostUserBackendMut, with an implementatio of
impl<T: VhostUserBackendMut> VhostUserBackend for RwLock<T> {
}
to ease transition.
The change also improves code readability.
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This implementation just returns Err(InvalidOperation), which is the
correct response for a backend that hasn't negotiated the inflight
feature. Eventually, it'd be nice if we allowed the backend to
negotiate this feature; harshanavkis@8b44378 and slp@3346318 are two
attempts at this.
This is intended as a simple, bikeshed-free way to get things compiling
again while we decide on, and implement, a way to actually support the
inflight feature.
Signed-off-by: Gaelan Steele <gbs@canishe.com>
We were explicitly calling libc::close() on fds we were replacing; but
since they were stored as EventFds, which close themselves on drop, this
is unnecessary. Manually closing them is useless at best; at worse, if
there's a race condition and another thread opens an fd between the
manual close and the normal close on drop, we could have closed someone
else's fd.
The new signatures come from an update to the vhost crate.
This commit is intended as a simple, bikeshed-free fix, but I don't
think it's the best way to handle this long-term. See below.
In most cases, we were converting the RawFd into a File anyway, and
the new code is trivial. In a few cases, though, we actually want an
EventFd, which now requires this nasty construction:
unsafe { EventFd::from_raw_fd(file.into_raw_fd())
This is safe--EventFd::from_raw_fd is unsafe becuase it expects to
uniquely own its fd, an invariant File also has--but a little
inelegant.
Ideally, we would either:
- change vmm-sys-util to provide a way to safely create an EventFd
from a File (this would be trivial; EventFd actually stores its
fd as a File internally),
- pass around a generic "uniquely owned fd" struct (like that
proposed by Rust RFC #3128) instead of a File, or
- change vhost to pass us an EventFd instead of a File where
appropriate (which, in practice, would mean implementing one of the
previous options in vhost)
Signed-off-by: Gaelan Steele <gbs@canishe.com>