container: implement exit code xenbus notification

This commit is contained in:
Alex Zenla 2024-02-23 04:48:44 +00:00
parent 79acf4e814
commit 496cdd37be
No known key found for this signature in database
GPG Key ID: 067B238899B51269
6 changed files with 19 additions and 17 deletions

View File

@ -25,8 +25,8 @@ features = ["process"]
[dependencies.krata]
path = "../shared"
[dependencies.xenevtchn]
path = "../libs/xen/xenevtchn"
[dependencies.xenstore]
path = "../libs/xen/xenstore"
[lib]
path = "src/lib.rs"

View File

@ -4,6 +4,7 @@ use crate::childwait::{ChildEvent, ChildWait};
use anyhow::Result;
use nix::{libc::c_int, unistd::Pid};
use tokio::{select, time::sleep};
use xenstore::client::{XsdClient, XsdInterface};
pub struct ContainerBackground {
child: Pid,
@ -40,8 +41,11 @@ impl ContainerBackground {
}
async fn death(&mut self, code: c_int) -> Result<()> {
println!("[krata] container process exited: status = {}", code);
println!("[krata] looping forever");
let mut store = XsdClient::open().await?;
store
.write_string("krata/guest/exit-code", &code.to_string())
.await?;
drop(store);
loop {
sleep(Duration::from_secs(1)).await;
}

View File

@ -4,11 +4,10 @@ use advmac::MacAddr6;
use anyhow::{anyhow, Result};
use ipnetwork::Ipv4Network;
use krata::{
LaunchChannels, LaunchInfo, LaunchNetwork, LaunchNetworkIpv4, LaunchNetworkIpv6,
LaunchNetworkResolver,
LaunchInfo, LaunchNetwork, LaunchNetworkIpv4, LaunchNetworkIpv6, LaunchNetworkResolver,
};
use uuid::Uuid;
use xenclient::{DomainConfig, DomainDisk, DomainEventChannel, DomainNetworkInterface};
use xenclient::{DomainConfig, DomainDisk, DomainNetworkInterface};
use xenstore::client::XsdInterface;
use crate::image::{name::ImageName, ImageCompiler, ImageInfo};
@ -76,9 +75,6 @@ impl ControllerLaunch<'_> {
}),
env: request.env,
run: request.run,
channels: LaunchChannels {
exit: "krata-exit".to_string(),
},
};
let cfgblk = ConfigBlock::new(&uuid, &image_info)?;
@ -137,7 +133,7 @@ impl ControllerLaunch<'_> {
script: None,
}],
filesystems: vec![],
event_channels: vec![DomainEventChannel { name: "krata-exit" }],
event_channels: vec![],
extra_keys: vec![
("krata/uuid".to_string(), uuid.to_string()),
(
@ -177,6 +173,7 @@ impl ControllerLaunch<'_> {
gateway_mac_string.clone(),
),
],
extra_rw_paths: vec!["krata/guest".to_string()],
};
match self.context.xen.create(&config).await {
Ok(domid) => Ok((uuid, domid)),

View File

@ -27,6 +27,7 @@ async fn main() -> Result<()> {
vifs: vec![],
filesystems: vec![],
extra_keys: vec![],
extra_rw_paths: vec![],
event_channels: vec![],
};
let domid = client.create(&config).await?;

View File

@ -79,6 +79,7 @@ pub struct DomainConfig<'a> {
pub filesystems: Vec<DomainFilesystem<'a>>,
pub event_channels: Vec<DomainEventChannel<'a>>,
pub extra_keys: Vec<(String, String)>,
pub extra_rw_paths: Vec<String>,
}
impl XenClient {
@ -213,6 +214,11 @@ impl XenClient {
.await?;
}
for path in &config.extra_rw_paths {
tx.mknod(format!("{}/{}", dom_path, path).as_str(), rw_perm)
.await?;
}
tx.commit().await?;
}

View File

@ -25,15 +25,9 @@ pub struct LaunchNetwork {
pub resolver: LaunchNetworkResolver,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LaunchChannels {
pub exit: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LaunchInfo {
pub network: Option<LaunchNetwork>,
pub env: Option<Vec<String>>,
pub run: Option<Vec<String>>,
pub channels: LaunchChannels,
}