Commit graph

530 commits

Author SHA1 Message Date
Rob Bradford
f178b08d27 vhost-user: Return error when connection broken
Return an error wen recvmsg() returns without a message using the
libc::ECONNRESET error so that the upper levels will correctly
interpret this as the connection being broken.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2020-09-04 17:59:53 +03:00
Liu Bo
ee5d3d1288 vhost-user: add the ability to set slave req fd
This adds the missing part of supporting virtiofs dax on the slave end,
that is, receiving a socket pair fd from the master end to set up a
communication channel for sending setupmapping & removemapping messages.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Liu Bo
3e87bd964e vhost-user: add SlaveFsCacheReq handle map/unmap
This introduces SlaveFsCacheReq which implements
VhostUserMasterReqHandler to handle map/unmap requests.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Sebastien Boeuf
09bd21f75e vhost-user: Fix unit test race condition
The unit tests are run from cargo test through multiple threads of the
same process. For this reason, all these threads share their file
descriptors (because that's how this works on Linux), which means that
any of them can close a file descriptor opened from another thread.

In the context of create_listener() and accept_connection() tests, they
can run concurrently and this generates some failure when the file
descriptor create_listener() is binding to is being closed from the
accept_connection() test.

In order to avoid such race condition, this patch simply removes the
part of the unit test performing an explicit and unsafe file descriptor
closure.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2020-09-04 17:59:53 +03:00
Rob Bradford
19e14bc77b vhost-user: Retry connect to vhost-user backends
If the connection to the backend fails, sleep and retry up to a count.
This failure could happen because the backend is not yet ready to handle
the connection which is a common case when working with a spawned
backend.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2020-09-04 17:59:53 +03:00
Eryu Guan
c650790558 vhost-user: Export VHOST_USER_FS_SLAVE_ENTRIES
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Rob Bradford
83f45776a0 vhost-user: Mark some broken tests ignored
If we use the workspace based testing methodology then we start testing
some code inside vhost_rs that is broken.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2020-09-04 17:59:53 +03:00
Sergio Lopez
ead9be163d vhost-user: fix VhostUserConfig payload management
The VhostUserConfig carries a message with a payload, the contents of
which depend on the kind of device being emulated.

With this change, we calculate the offset of the payload within the
message, check its size corresponds to the expected one, and pass it
to the backend as a reference to a slice adjusted to the payload
dimensions.

The backend will be responsible of validating the payload, as it's the
one aware of its expected contents.

Signed-off-by: Sergio Lopez <slp@redhat.com>
2020-09-04 17:59:53 +03:00
Rob Bradford
0b38d99a64 vhost-user: Add clippy override
clippy wants us to use "if let Some(fd) = fd {}" but to combine that
with && is an experimental feature.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2020-09-04 17:59:53 +03:00
Yang Zhong
18c4468c42 vhost-user: Add INFLIGHT_SHMFD protocol feature
Add to the vhost_rs crate the INFLIGHT_SHMFD protocol feature that was
missing from the list. The feature has been recently introduced in
vhost-user specification, which is the reason why it was missing.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
2020-09-04 17:59:53 +03:00
Sebastien Boeuf
d0850abc14 vhost-user: Fix GET_CONFIG command
Following the vhost-user specification that can be found at
https://github.com/qemu/qemu/blob/master/docs/interop/
vhost-user.rst#virtio-device-config-space
this patch fixes the GET_CONFIG command.

This command is very specific as it needs to provide a body and a
payload corresponding to the content of the configuration structure as
an array of bytes. As a reply, it receives the body and payload provided
by the slave.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2020-09-04 17:59:53 +03:00
Yang Zhong
897bc18f57 vhost-user: The vhost user version we support
The vhost user version should be same with backend.
define VHOST_USER_VERSION    (0x1)

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
2020-09-04 17:59:53 +03:00
Sebastien Boeuf
37414831aa vhost-user: Wait for full request to be satisfied
The recvmsg syscall can split a request in multiple packets unless we
use the flag MSG_WAITALL to make sure the request will wait for the
whole data to be transferred before returning.

This flag is needed to prevent the vhost crate from returning the error
PartialMessage, which occured sporadically when using virtio-fs, and
which was detected as part of our continuous integration testing.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2020-09-04 17:59:53 +03:00
Sebastien Boeuf
e2d4c8686b vhost-user: Allow MasterReqHandler to reply
No matter if the communication is coming from the master or the slave,
it should always reply with an ack if the message header specifies that
it expects a reply.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2020-09-04 17:59:53 +03:00
Yang Zhong
2f9c795290 vhost-user: Change get_config()/set_config()
Use acked_protocol_features to replace acked_virtio_features in
get_config()/set_config() for protocol features like CONFIG.

This patch also fix wrong GET_CONFIG setting for set_config().

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
2020-09-04 17:59:53 +03:00
Yang Zhong
4ff21ad9d9 vhost-user: Change the VhostUserConfigFlags
The latest vhost user spec from Qemu doc only define two members in
VhostSetConfigType, master and live migration. These changes can make
rust-vmm compatible with vhost user backend.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
2020-09-04 17:59:53 +03:00
Sebastien Boeuf
c3506d3bc0 vhost-user: Make number of queues configurable
We need the vhost-user protocol crate to be more generic to allow
communication with a configurable amount of virtqueues.

This is a workaround for the virtio-fs backend. According to the
vhost-user specification, the master should issue get_queue_num()
to get the maximum number of queues supported by the slave. With
current virtio-fs implementations, it needs multiple virtques, but
it doesn't support the get_queue_num() request and not set the MQ
feature bit too. So this is a workaround to hard-code the max_queue_num
on the master side.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
0c1edfc628 Add tests for vhost-user
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2020-09-04 17:59:53 +03:00
Daniel Prilik
883e6f6557 Initial support for handling slave requests
Not all slave requests are implemented, only the subset of messages
used by virtio-fs.

The SlaveReqHandler struct creates the slave-master socketpair, and
handles all incoming / outgoing message validation and handler
routing. SlaveReqHandler::new accepts a struct that implements
VhostUserSlaveReqHandler, overriding the default handlers for
relevant slave requests.  SlaveReqHandler::new also returns a
UnixStream that must be sent to the slave via
Master::set_slave_request_fd.

As both Master and Slave requests share the same wire-format,
it could be easy to mix up the two when handling requests,
so this commit introduces PhantomData markers to Endpoints
and VhostUserMsgHeader that specify if they operate on
MasterReqs or SlaveReqs.

Lastly, some library internals, notably the Listener and Endpoint
structs, have been marked as pub(crate). This necessitates a small
refactor of how Slaves are constructed, introducing a SlaveListener
struct which returns a valid Slave when the socket accepts a
connection.

Signed-off-by: Daniel Prilik <danielprilik@gmail.com>
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
7c1cd619eb Implement vhost-user slave side endpoint
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel Prilik <daniel@prilik.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
ac2c67a6ae Implement vhost-user master side endpoint
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Daniel Prilik <daniel@prilik.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
36c283d523 Implement unix domain socket based comm channel
Implement unix domain socket based communication channel for vhost-user,
which could pass file decriptors between processes.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel Prilik <daniel@prilik.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
560a28589c Define communication messages of vhost-user spec
Only basic messages are defined, and the vhost-user spec is also under
development. So feel free to add needed messages.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: Daniel Prilik <daniel@prilik.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
4f0ca8c860 Enable support of the in-kernel vhost-vsock driver
Implement vhost_kern::Vsock to control the in-kernel vhost-vsock driver.
The implementation is derived from the crosvm project.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
8663025a80 Enable support of in-kernel vhost driver
The implementation is derived from the crosvm project.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
f697910ec2 Simplify the auto-generated vhost binding
The auto-generated vhost binding is small, it would be better
to include it into the vhost crate instead of building another
dedicated crate for it.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
bcbbaaabb3 Add traits to support vhost backend devices
These interfaces are derived from the firecracker and crosvm projects.
They may be extended when enable support of vhost-user protocol.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Liu Jiang
5d61e36bda Add license files for BSD-Alibaba, BSD-Google
Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-09-04 17:59:53 +03:00
Samuel Ortiz
8cb0b09bec CODEOWNERS: Make PullAssigner the default owner
The PullAssigner bot [1] will pick 2 github handles from the gate
keepers list [2] and assign them for reviewing any new PR.
The bot goes uses a round robin algorithm to select handles from the
list.

What happens when the CODEOWNERS file gets populated with real
owners? Following the PR review and approval process [3], the
PullAssigner bot will either pick only one or zero reviewers from the
gate keepers list, if the CODEOWNERS file points to exactly one or more
than one actual ownwer, respectively.

[1] https://pullpanda.com/assigner
[2] https://github.com/rust-vmm/community/blob/master/GATEKEEPERS.md
[3] https://github.com/rust-vmm/community#pr-review-and-approval

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-10 13:59:28 +08:00
Liu Jiang
e0ee5887f7 Initial commit 2019-04-03 14:38:29 +08:00