Skip to content

Commit f29c2f1

Browse files
committed
vhost-device-rng: add support for standalone daemons
This is fairly simple for the backend we just need to implement the specs message. The handling of GET/SET_STATUS is done by vhost internals. Signed-off-by: Alex Bennée <[email protected]>
1 parent 055f27f commit f29c2f1

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

Cargo.lock

+36-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rng/Cargo.toml

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ log = "0.4"
2121
rand = "0.8.5"
2222
tempfile = "3.5"
2323
thiserror = "1.0"
24-
vhost = { version = "0.8", features = ["vhost-user-slave"] }
25-
vhost-user-backend = "0.10"
24+
# vhost = { version = "0.8", features = ["vhost-user-slave"] }
25+
# vhost-user-backend = "0.10"
26+
# vhost = { path = "../../../vhost.git/crates/vhost/" }
27+
# vhost-user-backend = { path = "../../../vhost.git/crates/vhost-user-backend/" }
28+
vhost = { git = "https://github.com/stsquad/vhost", branch = "standalone/get-specs" }
29+
vhost-user-backend = { git = "https://github.com/stsquad/vhost", branch = "standalone/get-specs" }
30+
2631
virtio-bindings = "0.2.1"
2732
virtio-queue = "0.9"
2833
vm-memory = "0.12"

crates/rng/src/vhu_rng.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::time::{Duration, Instant};
1313
use std::{convert, io, result};
1414

1515
use thiserror::Error as ThisError;
16-
use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures};
16+
use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures, VhostUserBackendSpecs};
1717
use vhost_user_backend::{VhostUserBackendMut, VringRwLock, VringT};
1818
use virtio_bindings::bindings::virtio_config::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1};
1919
use virtio_bindings::bindings::virtio_ring::{
@@ -28,6 +28,7 @@ use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
2828

2929
const QUEUE_SIZE: usize = 1024;
3030
const NUM_QUEUES: usize = 1;
31+
const VIRTIO_ID_RNG: u32 = 4;
3132

3233
type Result<T> = std::result::Result<T, VuRngError>;
3334
type RngDescriptorChain = DescriptorChain<GuestMemoryLoadGuard<GuestMemoryMmap<()>>>;
@@ -222,6 +223,15 @@ impl<T: 'static + Read + Sync + Send> VhostUserBackendMut<VringRwLock, ()> for V
222223

223224
fn protocol_features(&self) -> VhostUserProtocolFeatures {
224225
VhostUserProtocolFeatures::MQ
226+
| VhostUserProtocolFeatures::STATUS
227+
| VhostUserProtocolFeatures::STANDALONE
228+
}
229+
230+
fn specs(&self) -> VhostUserBackendSpecs {
231+
VhostUserBackendSpecs::new(VIRTIO_ID_RNG,
232+
0,
233+
NUM_QUEUES as u32,
234+
NUM_QUEUES as u32)
225235
}
226236

227237
fn set_event_idx(&mut self, enabled: bool) {

0 commit comments

Comments
 (0)