Skip to content

Commit b448d15

Browse files
committed
vmm: Cache guest events in a buffer of size 20
1 parent d3c819e commit b448d15

5 files changed

Lines changed: 23 additions & 1 deletion

File tree

vmm/rpc/proto/vmm_rpc.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ message VmInfo {
3535
string shutdown_progress = 12;
3636
// Image version
3737
string image_version = 13;
38+
// Events
39+
repeated GuestEvent events = 14;
40+
}
41+
42+
message GuestEvent {
43+
string event = 1;
44+
string body = 2;
3845
}
3946

4047
message Id {

vmm/src/app.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use id_pool::IdPool;
1717
use ra_rpc::client::RaClient;
1818
use serde::{Deserialize, Serialize};
1919
use serde_json::json;
20-
use std::collections::{BTreeSet, HashMap};
20+
use std::collections::{BTreeSet, HashMap, VecDeque};
2121
use std::net::IpAddr;
2222
use std::path::{Path, PathBuf};
2323
use std::sync::{Arc, Mutex, MutexGuard};
@@ -411,6 +411,13 @@ impl App {
411411
let Some(vm) = state.vms.values_mut().find(|vm| vm.config.cid == cid) else {
412412
bail!("VM not found");
413413
};
414+
vm.state.events.push_back(pb::GuestEvent {
415+
event: event.into(),
416+
body: body.clone(),
417+
});
418+
if vm.state.events.len() > self.config.event_buffer_size {
419+
vm.state.events.pop_front();
420+
}
414421
match event {
415422
"boot.progress" => {
416423
vm.state.boot_progress = body;
@@ -648,6 +655,7 @@ struct VmStateMut {
648655
boot_error: String,
649656
shutdown_progress: String,
650657
devices: GpuConfig,
658+
events: VecDeque<pb::GuestEvent>,
651659
}
652660

653661
impl VmStateMut {

vmm/src/app/qemu.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub struct VmInfo {
5151
pub shutdown_progress: String,
5252
pub image_version: String,
5353
pub gateway_enabled: bool,
54+
pub events: Vec<pb::GuestEvent>,
5455
}
5556

5657
#[derive(Debug, Builder)]
@@ -177,6 +178,7 @@ impl VmInfo {
177178
app_id: self.manifest.app_id.clone(),
178179
instance_id: self.instance_id.as_deref().map(Into::into),
179180
exited_at: self.exited_at.clone(),
181+
events: self.events.clone(),
180182
}
181183
}
182184
}
@@ -222,6 +224,7 @@ impl VmState {
222224
shutdown_progress: self.state.shutdown_progress.clone(),
223225
image_version: self.config.image.info.version.clone(),
224226
gateway_enabled: self.config.gateway_enabled,
227+
events: self.state.events.clone().into(),
225228
}
226229
}
227230
}

vmm/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ pub struct Config {
269269
#[serde(default)]
270270
pub node_name: String,
271271

272+
/// The buffer size in VMM process for guest events
273+
pub event_buffer_size: usize,
274+
272275
/// CVM configuration
273276
pub cvm: CvmConfig,
274277
/// Gateway configuration

vmm/vmm.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ log_level = "debug"
1111
address = "unix:./vmm.sock"
1212
reuse = true
1313
kms_url = "http://127.0.0.1:8081"
14+
event_buffer_size = 20
1415

1516
[cvm]
1617
qemu_path = ""

0 commit comments

Comments
 (0)