Skip to content

Commit ac71d45

Browse files
dianpopaShadowCurse
authored andcommitted
devices: doc for the vsock device
Doc for the vsock device Signed-off-by: Diana Popa <dpopa@amazon.com>
1 parent 4a5dc87 commit ac71d45

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

src/vmm/src/devices/virtio/vsock/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub(crate) const VIRTIO_VSOCK_EVENT_TRANSPORT_RESET: u32 = 0;
5050
pub(crate) const AVAIL_FEATURES: u64 =
5151
1 << uapi::VIRTIO_F_VERSION_1 as u64 | 1 << uapi::VIRTIO_F_IN_ORDER as u64;
5252

53+
/// Structure representing the vsock device.
5354
#[derive(Debug)]
5455
pub struct Vsock<B> {
5556
cid: u64,
@@ -77,6 +78,8 @@ impl<B> Vsock<B>
7778
where
7879
B: VsockBackend + Debug,
7980
{
81+
/// Auxiliary function for creating a new virtio-vsock device with the given VM CID, vsock
82+
/// backend and empty virtio queues.
8083
pub fn with_queues(
8184
cid: u64,
8285
backend: B,
@@ -109,14 +112,17 @@ where
109112
Self::with_queues(cid, backend, queues)
110113
}
111114

115+
/// Provides the ID of this vsock device as used in MMIO device identification.
112116
pub fn id(&self) -> &str {
113117
defs::VSOCK_DEV_ID
114118
}
115119

120+
/// Retrieve the cid associated with this vsock device.
116121
pub fn cid(&self) -> u64 {
117122
self.cid
118123
}
119124

125+
/// Access the backend behind the device.
120126
pub fn backend(&self) -> &B {
121127
&self.backend
122128
}

src/vmm/src/devices/virtio/vsock/event_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ where
102102
false
103103
}
104104

105+
/// Notify backend of new events.
105106
pub fn notify_backend(&mut self, evset: EventSet) -> bool {
106107
debug!("vsock: backend event");
107108

108109
self.backend.notify(evset);
109110
// After the backend has been kicked, it might've freed up some resources, so we
110111
// can attempt to send it more data to process.
111112
// In particular, if `self.backend.send_pkt()` halted the TX queue processing (by
112-
// reurning an error) at some point in the past, now is the time to try walking the
113+
// returning an error) at some point in the past, now is the time to try walking the
113114
// TX queue again.
114115
let mut raise_irq = self.process_tx();
115116
if self.backend.has_pending_rx() {

src/vmm/src/devices/virtio/vsock/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
// Use of this source code is governed by a BSD-style license that can be
66
// found in the THIRD-PARTY file.
77

8+
//! The Firecracker vsock device aims to provide full virtio-vsock support to
9+
//! software running inside the guest VM, while bypassing vhost kernel code on the
10+
//! host. To that end, Firecracker implements the virtio-vsock device model, and
11+
//! mediates communication between AF_UNIX sockets (on the host end) and AF_VSOCK
12+
//! sockets (on the guest end).
13+
814
mod csm;
915
mod device;
1016
mod event_handler;
@@ -93,6 +99,7 @@ mod defs {
9399
}
94100
}
95101

102+
/// Vsock device related errors.
96103
#[derive(Debug)]
97104
pub enum VsockError {
98105
/// The vsock data/buffer virtio descriptor length is smaller than expected.

src/vmm/src/devices/virtio/vsock/persist.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,35 @@ use super::*;
1616
use crate::devices::virtio::persist::VirtioDeviceState;
1717
use crate::devices::virtio::{DeviceState, TYPE_VSOCK};
1818

19+
/// The Vsock serializable state.
1920
// NOTICE: Any changes to this structure require a snapshot version bump.
2021
#[derive(Debug, Clone, Versionize)]
2122
pub struct VsockState {
23+
/// The vsock backend state.
2224
pub backend: VsockBackendState,
25+
/// The vsock frontend state.
2326
pub frontend: VsockFrontendState,
2427
}
2528

29+
/// The Vsock frontend serializable state.
2630
// NOTICE: Any changes to this structure require a snapshot version bump.
27-
/// The Vsock serializable state.
2831
#[derive(Debug, Clone, Versionize)]
2932
pub struct VsockFrontendState {
33+
/// Context IDentifier.
3034
pub cid: u64,
3135
virtio_state: VirtioDeviceState,
3236
}
3337

34-
// NOTICE: Any changes to this structure require a snapshot version bump.
3538
/// An enum for the serializable backend state types.
39+
// NOTICE: Any changes to this structure require a snapshot version bump.
3640
#[derive(Debug, Clone, Versionize)]
3741
pub enum VsockBackendState {
42+
/// UDS backend state.
3843
Uds(VsockUdsState),
3944
}
4045

41-
// NOTICE: Any changes to this structure require a snapshot version bump.
4246
/// The Vsock Unix Backend serializable state.
47+
// NOTICE: Any changes to this structure require a snapshot version bump.
4348
#[derive(Debug, Clone, Versionize)]
4449
pub struct VsockUdsState {
4550
/// The path for the UDS socket.
@@ -49,14 +54,16 @@ pub struct VsockUdsState {
4954
/// A helper structure that holds the constructor arguments for VsockUnixBackend
5055
#[derive(Debug)]
5156
pub struct VsockConstructorArgs<B> {
57+
/// Pointer to guest memory.
5258
pub mem: GuestMemoryMmap,
59+
/// The vsock Unix Backend.
5360
pub backend: B,
5461
}
5562

5663
/// A helper structure that holds the constructor arguments for VsockUnixBackend
5764
#[derive(Debug)]
5865
pub struct VsockUdsConstructorArgs {
59-
// cid available in VsockFrontendState.
66+
/// cid available in VsockFrontendState.
6067
pub cid: u64,
6168
}
6269

src/vmm/src/devices/virtio/vsock/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mod defs {
2626
pub const MUXER_KILLQ_SIZE: usize = 128;
2727
}
2828

29+
/// Vsock backend related errors.
2930
#[derive(Debug)]
3031
pub enum VsockUnixBackendError {
3132
/// Error registering a new epoll-listening FD.

src/vmm/src/devices/virtio/vsock/unix/muxer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ impl VsockMuxer {
329329
Ok(muxer)
330330
}
331331

332+
/// Return the file system path of the host-side Unix socket.
332333
pub fn host_sock_path(&self) -> &str {
333334
&self.host_sock_path
334335
}

0 commit comments

Comments
 (0)