Commit Graph

16 Commits

Author SHA1 Message Date
Stefano Garzarella
e6a85ffd5e vsock: reorder use declarations
Following the other crates, reorder the use declaration in 3 groups:
    1. standard library
    2. external crates
    3. local crates

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:45 +02:00
Stefano Garzarella
a76f9ebe16 vsock: remove "vsock_" prefix where is redundant
In several places the "vsock_" prefix doesn't add much and makes
names longer, let's remove it where it's not needed.

Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:45 +02:00
Stefano Garzarella
c452d1c2f9 vsock: move VsockArgs in main.rs
VsockArgs is used only by main.rs, so we can move its definition
there. Let's also move the test.

Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:45 +02:00
Stefano Garzarella
f7f239e390 vsock: use pub(crate) for types used only by our binary
This is a binary crate and most of the types shouldn't be visible
out of this crate. Change also documentation with ///.

If we would like to export some types as part of a library in the
future, we will adjust the visibility accordingly.

Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:45 +02:00
Stefano Garzarella
a6d157f5e5 vsock: add more tests and update coverage_score
Add several tests to get good coverage. Unfortunately,
it's a lot of new code and not easy to test everything.
We may add more mocks and tests in the future.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:45 +02:00
Stefano Garzarella
498c7490e1 vsock: fix VhostUserVsockBackend::get_config
VIRTIO spec defines `guest_cid` in LE byte order.
Let's introduce VirtioVsockConfig based on the virtio-spec 1.2.
For now it contains only `guest_cid`, but in the future it could
contain other fields.

Let's also handle correctly `offset` and `size`, returning an empty
Vec if they are not valid.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:45 +02:00
Stefano Garzarella
167206dea3 vsock: try to avoid panic as much as we can
Instead of panic, let's propagate errors or print warnings
where we can't.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:14 +02:00
Stefano Garzarella
1605f54fab vsock: send credit update only when needed
If we don't remove any bytes from the buffer, it's useless to
send a credit update since the credit hasn't changed.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:39:27 +02:00
Stefano Garzarella
5986155c8a vsock: don't panic if "connect PORT\n" is malformed
Instead of panic if the local peer doesn't send "connect PORT\n"
correctly, let's print an error, ignoring the command.

Print an error message also when allocating local port fails.

Reported-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:39:27 +02:00
Stefano Garzarella
d6775cd90d vsock: clean up comments and fix log messages
Remove old comments, useless code, and code commented.

Avoid println!() to print messages and replaced with dbg!(), info!(),
or error!().

Also init `env_logger` like other daemons in the main().

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:39:27 +02:00
Stefano Garzarella
8fa597e941 vsock: add SPDX-License-Identifier in each file
Harsha specified `license = "Apache-2.0 OR BSD-3-Clause"` in
vsock/Cargo.toml, so let's add a properly SPDX tag in the
vsock files.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:21:54 +02:00
Stefano Garzarella
df1073bf2e vsock: use VsockPacket from the virtio-vsock crate
Replace our VsockPacket with the new one implemented in the
virtio-vsock crate.

Based on Alex Bennée and Laura Loghin commit:
https://github.com/stsquad/vhost-device/commit/6752266608dd

  To achieve this the following changes where made:
    - deleted the internal packet.rs
    - convert the send_pkt/recv_pkt helpers to be BitmapSlice aware
    - update push from LocalTxBuf
    - tweak a few API calls due to minor diffs

Fixed tests and moved some helpers from the removed
vsock/src/packet.rs file.

Co-developed-by: Laura Loghin <lauralg@amazon.com>
Co-developed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:21:54 +02:00
Stefano Garzarella
896d346135 vsock: replace the deprecated App::from_yaml
clap::App::from_yaml() is deprecated since clap-3.0.0, let's
switch to clap::Parser.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:21:54 +02:00
Stefano Garzarella
a1daeec3bc vsock: update Cargo.toml dependencies
Update the dependencies aligning with the other crates
in this workspace.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:21:54 +02:00
Stefano Garzarella
69882e1dfc vsock: fix clippy warnings
clippy complains of some minor issues, probably because the
new version has been improved. Let's fix them.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:21:54 +02:00
Harshavardhan Unnibhavi
e20698695b vhost-user-vsock: virtio-vsock device emulation
This commit introduces a vhost-user-vsock device that enables
communicaton between an application running in the guest i.e
inside a VM and an application running on the host i.e outside
the VM. The device exposes unix sockets to which the VMM and
host-side applications connect to. Applications in the guest
communicate over VM sockets. Applicaitons on the host connect to
the unix socket i.e communicate over AF_UNIX sockets.

Signed-off-by: Harshavardhan Unnibhavi <harshanavkis@gmail.com>
[sgarzare: rebased, updated Cargo.lock, updated clap version to
 avoid build issues, and fixed clap issues with the new version]
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 14:21:54 +02:00