From 5e83d0c93f6060865e03178c32785e3f3805240e Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 13 Oct 2022 12:00:31 +0530 Subject: [PATCH 1/3] Move all crates in crates directory Based on what other rust-vmm workspaces do, move all crates to crates directory. Signed-off-by: Viresh Kumar --- Cargo.toml | 8 ++++---- README.md | 8 ++++---- {gpio => crates/gpio}/Cargo.toml | 0 {gpio => crates/gpio}/README.md | 0 {gpio => crates/gpio}/src/backend.rs | 0 {gpio => crates/gpio}/src/gpio.rs | 0 {gpio => crates/gpio}/src/main.rs | 0 {gpio => crates/gpio}/src/vhu_gpio.rs | 0 {i2c => crates/i2c}/Cargo.toml | 0 {i2c => crates/i2c}/README.md | 0 {i2c => crates/i2c}/src/i2c.rs | 0 {i2c => crates/i2c}/src/main.rs | 0 {i2c => crates/i2c}/src/vhu_i2c.rs | 0 {rng => crates/rng}/Cargo.toml | 0 {rng => crates/rng}/README.md | 0 {rng => crates/rng}/src/main.rs | 0 {rng => crates/rng}/src/vhu_rng.rs | 0 {vsock => crates/vsock}/Cargo.toml | 0 {vsock => crates/vsock}/README.md | 0 {vsock => crates/vsock}/src/main.rs | 0 {vsock => crates/vsock}/src/rxops.rs | 0 {vsock => crates/vsock}/src/rxqueue.rs | 0 {vsock => crates/vsock}/src/thread_backend.rs | 0 {vsock => crates/vsock}/src/txbuf.rs | 0 {vsock => crates/vsock}/src/vhu_vsock.rs | 0 {vsock => crates/vsock}/src/vhu_vsock_thread.rs | 0 {vsock => crates/vsock}/src/vsock_conn.rs | 0 27 files changed, 8 insertions(+), 8 deletions(-) rename {gpio => crates/gpio}/Cargo.toml (100%) rename {gpio => crates/gpio}/README.md (100%) rename {gpio => crates/gpio}/src/backend.rs (100%) rename {gpio => crates/gpio}/src/gpio.rs (100%) rename {gpio => crates/gpio}/src/main.rs (100%) rename {gpio => crates/gpio}/src/vhu_gpio.rs (100%) rename {i2c => crates/i2c}/Cargo.toml (100%) rename {i2c => crates/i2c}/README.md (100%) rename {i2c => crates/i2c}/src/i2c.rs (100%) rename {i2c => crates/i2c}/src/main.rs (100%) rename {i2c => crates/i2c}/src/vhu_i2c.rs (100%) rename {rng => crates/rng}/Cargo.toml (100%) rename {rng => crates/rng}/README.md (100%) rename {rng => crates/rng}/src/main.rs (100%) rename {rng => crates/rng}/src/vhu_rng.rs (100%) rename {vsock => crates/vsock}/Cargo.toml (100%) rename {vsock => crates/vsock}/README.md (100%) rename {vsock => crates/vsock}/src/main.rs (100%) rename {vsock => crates/vsock}/src/rxops.rs (100%) rename {vsock => crates/vsock}/src/rxqueue.rs (100%) rename {vsock => crates/vsock}/src/thread_backend.rs (100%) rename {vsock => crates/vsock}/src/txbuf.rs (100%) rename {vsock => crates/vsock}/src/vhu_vsock.rs (100%) rename {vsock => crates/vsock}/src/vhu_vsock_thread.rs (100%) rename {vsock => crates/vsock}/src/vsock_conn.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 258a969..4d1a538 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [workspace] members = [ - "gpio", - "i2c", - "rng", - "vsock", + "crates/gpio", + "crates/i2c", + "crates/rng", + "crates/vsock", ] diff --git a/README.md b/README.md index aa4315b..61fa52b 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ crates. Here is the list of device backends that we support: -- [GPIO](https://github.com/rust-vmm/vhost-device/blob/main/gpio/README.md) -- [I2C](https://github.com/rust-vmm/vhost-device/blob/main/i2c/README.md) -- [RNG](https://github.com/rust-vmm/vhost-device/blob/main/rng/README.md) -- [VSOCK](https://github.com/rust-vmm/vhost-device/blob/main/vsock/README.md) +- [GPIO](https://github.com/rust-vmm/vhost-device/blob/main/crates/gpio/README.md) +- [I2C](https://github.com/rust-vmm/vhost-device/blob/main/crates/i2c/README.md) +- [RNG](https://github.com/rust-vmm/vhost-device/blob/main/crates/rng/README.md) +- [VSOCK](https://github.com/rust-vmm/vhost-device/blob/main/crates/vsock/README.md) ## Testing and Code Coverage diff --git a/gpio/Cargo.toml b/crates/gpio/Cargo.toml similarity index 100% rename from gpio/Cargo.toml rename to crates/gpio/Cargo.toml diff --git a/gpio/README.md b/crates/gpio/README.md similarity index 100% rename from gpio/README.md rename to crates/gpio/README.md diff --git a/gpio/src/backend.rs b/crates/gpio/src/backend.rs similarity index 100% rename from gpio/src/backend.rs rename to crates/gpio/src/backend.rs diff --git a/gpio/src/gpio.rs b/crates/gpio/src/gpio.rs similarity index 100% rename from gpio/src/gpio.rs rename to crates/gpio/src/gpio.rs diff --git a/gpio/src/main.rs b/crates/gpio/src/main.rs similarity index 100% rename from gpio/src/main.rs rename to crates/gpio/src/main.rs diff --git a/gpio/src/vhu_gpio.rs b/crates/gpio/src/vhu_gpio.rs similarity index 100% rename from gpio/src/vhu_gpio.rs rename to crates/gpio/src/vhu_gpio.rs diff --git a/i2c/Cargo.toml b/crates/i2c/Cargo.toml similarity index 100% rename from i2c/Cargo.toml rename to crates/i2c/Cargo.toml diff --git a/i2c/README.md b/crates/i2c/README.md similarity index 100% rename from i2c/README.md rename to crates/i2c/README.md diff --git a/i2c/src/i2c.rs b/crates/i2c/src/i2c.rs similarity index 100% rename from i2c/src/i2c.rs rename to crates/i2c/src/i2c.rs diff --git a/i2c/src/main.rs b/crates/i2c/src/main.rs similarity index 100% rename from i2c/src/main.rs rename to crates/i2c/src/main.rs diff --git a/i2c/src/vhu_i2c.rs b/crates/i2c/src/vhu_i2c.rs similarity index 100% rename from i2c/src/vhu_i2c.rs rename to crates/i2c/src/vhu_i2c.rs diff --git a/rng/Cargo.toml b/crates/rng/Cargo.toml similarity index 100% rename from rng/Cargo.toml rename to crates/rng/Cargo.toml diff --git a/rng/README.md b/crates/rng/README.md similarity index 100% rename from rng/README.md rename to crates/rng/README.md diff --git a/rng/src/main.rs b/crates/rng/src/main.rs similarity index 100% rename from rng/src/main.rs rename to crates/rng/src/main.rs diff --git a/rng/src/vhu_rng.rs b/crates/rng/src/vhu_rng.rs similarity index 100% rename from rng/src/vhu_rng.rs rename to crates/rng/src/vhu_rng.rs diff --git a/vsock/Cargo.toml b/crates/vsock/Cargo.toml similarity index 100% rename from vsock/Cargo.toml rename to crates/vsock/Cargo.toml diff --git a/vsock/README.md b/crates/vsock/README.md similarity index 100% rename from vsock/README.md rename to crates/vsock/README.md diff --git a/vsock/src/main.rs b/crates/vsock/src/main.rs similarity index 100% rename from vsock/src/main.rs rename to crates/vsock/src/main.rs diff --git a/vsock/src/rxops.rs b/crates/vsock/src/rxops.rs similarity index 100% rename from vsock/src/rxops.rs rename to crates/vsock/src/rxops.rs diff --git a/vsock/src/rxqueue.rs b/crates/vsock/src/rxqueue.rs similarity index 100% rename from vsock/src/rxqueue.rs rename to crates/vsock/src/rxqueue.rs diff --git a/vsock/src/thread_backend.rs b/crates/vsock/src/thread_backend.rs similarity index 100% rename from vsock/src/thread_backend.rs rename to crates/vsock/src/thread_backend.rs diff --git a/vsock/src/txbuf.rs b/crates/vsock/src/txbuf.rs similarity index 100% rename from vsock/src/txbuf.rs rename to crates/vsock/src/txbuf.rs diff --git a/vsock/src/vhu_vsock.rs b/crates/vsock/src/vhu_vsock.rs similarity index 100% rename from vsock/src/vhu_vsock.rs rename to crates/vsock/src/vhu_vsock.rs diff --git a/vsock/src/vhu_vsock_thread.rs b/crates/vsock/src/vhu_vsock_thread.rs similarity index 100% rename from vsock/src/vhu_vsock_thread.rs rename to crates/vsock/src/vhu_vsock_thread.rs diff --git a/vsock/src/vsock_conn.rs b/crates/vsock/src/vsock_conn.rs similarity index 100% rename from vsock/src/vsock_conn.rs rename to crates/vsock/src/vsock_conn.rs From 5005c96c3a13962db2af948c00ee962d2d5cf3c6 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 13 Oct 2022 13:05:26 +0530 Subject: [PATCH 2/3] vsock: Minor cleanups Minor cleanups. Signed-off-by: Viresh Kumar --- crates/vsock/src/main.rs | 2 +- crates/vsock/src/vhu_vsock.rs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/vsock/src/main.rs b/crates/vsock/src/main.rs index 6892324..410d124 100644 --- a/crates/vsock/src/main.rs +++ b/crates/vsock/src/main.rs @@ -28,7 +28,7 @@ struct VsockArgs { #[clap(long, default_value_t = 3)] guest_cid: u64, - /// Unix socket to which a hypervisor conencts to and sets up the control path with the device. + /// Unix socket to which a hypervisor connects to and sets up the control path with the device. #[clap(long)] socket: String, diff --git a/crates/vsock/src/vhu_vsock.rs b/crates/vsock/src/vhu_vsock.rs index e7a3dbd..5f7dd38 100644 --- a/crates/vsock/src/vhu_vsock.rs +++ b/crates/vsock/src/vhu_vsock.rs @@ -1,6 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause -use std::{io, result, sync::Mutex, u16, u32, u64, u8}; +use std::{ + io::{self, Result as IoResult}, + sync::Mutex, + u16, u32, u64, u8, +}; use thiserror::Error as ThisError; use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; @@ -40,7 +44,7 @@ pub(crate) const VSOCK_HOST_CID: u64 = 2; /// Connection oriented packet pub(crate) const VSOCK_TYPE_STREAM: u16 = 1; -// Vsock packet operation ID +/// Vsock packet operation ID /// Connection request pub(crate) const VSOCK_OP_REQUEST: u16 = 1; @@ -57,7 +61,7 @@ pub(crate) const VSOCK_OP_CREDIT_UPDATE: u16 = 6; /// Flow control credit request pub(crate) const VSOCK_OP_CREDIT_REQUEST: u16 = 7; -// Vsock packet flags +/// Vsock packet flags /// VSOCK_OP_SHUTDOWN: Packet sender will receive no more data pub(crate) const VSOCK_FLAGS_SHUTDOWN_RCV: u32 = 1; @@ -69,7 +73,7 @@ const QUEUE_MASK: u64 = 0b11; pub(crate) type Result = std::result::Result; -/// Below enum defines custom error types. +/// Custom error types #[derive(Debug, ThisError)] pub(crate) enum Error { #[error("Failed to handle event other than EPOLLIN event")] @@ -246,10 +250,7 @@ impl VhostUserBackendMut for VhostUserVsockBackend { } } - fn update_memory( - &mut self, - atomic_mem: GuestMemoryAtomic, - ) -> result::Result<(), io::Error> { + fn update_memory(&mut self, atomic_mem: GuestMemoryAtomic) -> IoResult<()> { for thread in self.threads.iter() { thread.lock().unwrap().mem = Some(atomic_mem.clone()); } @@ -262,7 +263,7 @@ impl VhostUserBackendMut for VhostUserVsockBackend { evset: EventSet, vrings: &[VringRwLock], thread_id: usize, - ) -> result::Result { + ) -> IoResult { let vring_rx = &vrings[0]; let vring_tx = &vrings[1]; From 20819e52846328de5a3dbbf1629b8d5fc5beca03 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Thu, 13 Oct 2022 12:13:07 +0530 Subject: [PATCH 3/3] Run cargo update Run cargo update to automatically upgrade dependencies. Signed-off-by: Viresh Kumar --- Cargo.lock | 85 ++++++++---------------------------------------------- 1 file changed, 12 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6da01dd..9b199d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,31 +60,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.22" +version = "4.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "6ea54a38e4bce14ff6931c72e5b3c43da7051df056913d4e7e1fcdb1c03df69d" dependencies = [ "atty", "bitflags", - "clap_derive 3.2.18", - "clap_lex 0.2.4", - "indexmap", - "once_cell", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap" -version = "4.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ed45cc2c62a3eff523e718d8576ba762c83a3146151093283ac62ae11933a73" -dependencies = [ - "atty", - "bitflags", - "clap_derive 4.0.10", - "clap_lex 0.3.0", + "clap_derive", + "clap_lex", "once_cell", "strsim", "termcolor", @@ -92,9 +75,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad" dependencies = [ "heck", "proc-macro-error", @@ -103,28 +86,6 @@ dependencies = [ "syn", ] -[[package]] -name = "clap_derive" -version = "4.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db342ce9fda24fb191e2ed4e102055a4d381c1086a06630174cd8da8d5d917ce" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "clap_lex" version = "0.3.0" @@ -267,12 +228,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "heck" version = "0.4.0" @@ -294,16 +249,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "instant" version = "0.1.12" @@ -315,9 +260,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.134" +version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" [[package]] name = "libgpiod" @@ -549,12 +494,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - [[package]] name = "thiserror" version = "1.0.37" @@ -603,7 +542,7 @@ dependencies = [ name = "vhost-device-gpio" version = "0.1.0" dependencies = [ - "clap 4.0.11", + "clap", "env_logger", "libc", "libgpiod", @@ -621,7 +560,7 @@ dependencies = [ name = "vhost-device-i2c" version = "0.1.0" dependencies = [ - "clap 4.0.11", + "clap", "env_logger", "libc", "log", @@ -638,7 +577,7 @@ dependencies = [ name = "vhost-device-rng" version = "0.1.0" dependencies = [ - "clap 4.0.11", + "clap", "env_logger", "epoll", "libc", @@ -674,7 +613,7 @@ name = "vhost-user-vsock" version = "0.1.0" dependencies = [ "byteorder", - "clap 3.2.22", + "clap", "env_logger", "epoll", "futures",