From ee871278eeff56fb00b9509589e0c307f0407ebc Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Mon, 22 Mar 2021 11:23:51 -0700 Subject: [PATCH] virtio-devices: Move the 'rate_limiter' module to its own crate To support I/O throttling on virt-net devices, we need to use the 'rate_limiter' module from the 'net_utils' crate. Given the 'virtio-devices' crate has dependency on the 'net_utils', we will need to move the 'rate_limiter' module out of the 'virtio-devices' crate to avoid circular dependency issue. Considering the 'rate_limiter' is not virtio specific and could be reused for non virtio devices, we move it to its own crate. Signed-off-by: Bo Chen --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + rate_limiter/Cargo.toml | 9 +++++++++ .../src/rate_limiter.rs => rate_limiter/src/lib.rs | 3 +++ virtio-devices/Cargo.toml | 1 + virtio-devices/src/block.rs | 2 +- virtio-devices/src/lib.rs | 1 - 7 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 rate_limiter/Cargo.toml rename virtio-devices/src/rate_limiter.rs => rate_limiter/src/lib.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 072a5f6b5..e1574a447 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -831,6 +831,15 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rate_limiter" +version = "0.1.0" +dependencies = [ + "libc", + "log 0.4.14", + "vmm-sys-util", +] + [[package]] name = "redox_syscall" version = "0.1.57" @@ -1274,6 +1283,7 @@ dependencies = [ "net_gen", "net_util", "pci", + "rate_limiter", "seccomp", "serde", "serde_derive", diff --git a/Cargo.toml b/Cargo.toml index d40097c26..95e6f9f8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,6 +76,7 @@ members = [ "option_parser", "pci", "qcow", + "rate_limiter", "vhost_user_backend", "vhost_user_block", "vhost_user_net", diff --git a/rate_limiter/Cargo.toml b/rate_limiter/Cargo.toml new file mode 100644 index 000000000..c8f6d98b2 --- /dev/null +++ b/rate_limiter/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rate_limiter" +version = "0.1.0" +edition = "2018" + +[dependencies] +libc = "0.2.91" +log = "0.4.14" +vmm-sys-util = "0.8.0" diff --git a/virtio-devices/src/rate_limiter.rs b/rate_limiter/src/lib.rs similarity index 99% rename from virtio-devices/src/rate_limiter.rs rename to rate_limiter/src/lib.rs index 257131977..6e0f2db11 100644 --- a/virtio-devices/src/rate_limiter.rs +++ b/rate_limiter/src/lib.rs @@ -43,6 +43,9 @@ //! It is meant to be used in an external event loop and thus implements the `AsRawFd` //! trait and provides an *event-handler* as part of its API. This *event-handler* //! needs to be called by the user on every event on the rate limiter's `AsRawFd` FD. +#[macro_use] +extern crate log; + use std::os::unix::io::{AsRawFd, RawFd}; use std::time::{Duration, Instant}; use std::{fmt, io}; diff --git a/virtio-devices/Cargo.toml b/virtio-devices/Cargo.toml index 1a56f9275..099d93a3c 100644 --- a/virtio-devices/Cargo.toml +++ b/virtio-devices/Cargo.toml @@ -21,6 +21,7 @@ log = "0.4.14" net_gen = { path = "../net_gen" } net_util = { path = "../net_util" } pci = { path = "../pci" } +rate_limiter = { path = "../rate_limiter" } seccomp = { git = "https://github.com/firecracker-microvm/firecracker", tag = "v0.22.0" } serde = ">=1.0.27" serde_derive = ">=1.0.27" diff --git a/virtio-devices/src/block.rs b/virtio-devices/src/block.rs index 37b21e410..847e2299b 100644 --- a/virtio-devices/src/block.rs +++ b/virtio-devices/src/block.rs @@ -14,7 +14,6 @@ use super::{ RateLimiterConfig, VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, }; -use crate::rate_limiter::{RateLimiter, TokenType}; use crate::seccomp_filters::{get_seccomp_filter, Thread}; use crate::VirtioInterrupt; use anyhow::anyhow; @@ -22,6 +21,7 @@ use block_util::{ async_io::AsyncIo, async_io::AsyncIoError, async_io::DiskFile, build_disk_image_id, Request, RequestType, VirtioBlockConfig, }; +use rate_limiter::{RateLimiter, TokenType}; use seccomp::{SeccompAction, SeccompFilter}; use std::io; use std::num::Wrapping; diff --git a/virtio-devices/src/lib.rs b/virtio-devices/src/lib.rs index a36b2eb93..6b956a012 100644 --- a/virtio-devices/src/lib.rs +++ b/virtio-devices/src/lib.rs @@ -40,7 +40,6 @@ pub mod mem; pub mod net; pub mod net_util; mod pmem; -mod rate_limiter; mod rng; pub mod seccomp_filters; pub mod transport;