mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 21:21:32 +00:00
feature(krata): rename guest to zone (#266)
This commit is contained in:
@ -99,23 +99,23 @@ impl IpVendor {
|
||||
continue;
|
||||
};
|
||||
let assigned_ipv4 = store
|
||||
.read_string(format!("{}/krata/network/guest/ipv4", dom_path))
|
||||
.read_string(format!("{}/krata/network/zone/ipv4", dom_path))
|
||||
.await?
|
||||
.and_then(|x| Ipv4Network::from_str(&x).ok());
|
||||
let assigned_ipv6 = store
|
||||
.read_string(format!("{}/krata/network/guest/ipv6", dom_path))
|
||||
.read_string(format!("{}/krata/network/zone/ipv6", dom_path))
|
||||
.await?
|
||||
.and_then(|x| Ipv6Network::from_str(&x).ok());
|
||||
|
||||
if let Some(existing_ipv4) = assigned_ipv4 {
|
||||
if let Some(previous) = state.ipv4.insert(existing_ipv4.ip(), uuid) {
|
||||
error!("ipv4 conflict detected: guest {} owned {} but {} also claimed to own it, giving it to {}", previous, existing_ipv4.ip(), uuid, uuid);
|
||||
error!("ipv4 conflict detected: zone {} owned {} but {} also claimed to own it, giving it to {}", previous, existing_ipv4.ip(), uuid, uuid);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(existing_ipv6) = assigned_ipv6 {
|
||||
if let Some(previous) = state.ipv6.insert(existing_ipv6.ip(), uuid) {
|
||||
error!("ipv6 conflict detected: guest {} owned {} but {} also claimed to own it, giving it to {}", previous, existing_ipv6.ip(), uuid, uuid);
|
||||
error!("ipv6 conflict detected: zone {} owned {} but {} also claimed to own it, giving it to {}", previous, existing_ipv6.ip(), uuid, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -251,13 +251,13 @@ impl IpVendor {
|
||||
intermediate.ipv6.insert(self.gateway_ipv6, self.host_uuid);
|
||||
for (ipv4, uuid) in &state.pending_ipv4 {
|
||||
if let Some(previous) = intermediate.ipv4.insert(*ipv4, *uuid) {
|
||||
error!("ipv4 conflict detected: guest {} owned (pending) {} but {} also claimed to own it, giving it to {}", previous, ipv4, uuid, uuid);
|
||||
error!("ipv4 conflict detected: zone {} owned (pending) {} but {} also claimed to own it, giving it to {}", previous, ipv4, uuid, uuid);
|
||||
}
|
||||
intermediate.pending_ipv4.insert(*ipv4, *uuid);
|
||||
}
|
||||
for (ipv6, uuid) in &state.pending_ipv6 {
|
||||
if let Some(previous) = intermediate.ipv6.insert(*ipv6, *uuid) {
|
||||
error!("ipv6 conflict detected: guest {} owned (pending) {} but {} also claimed to own it, giving it to {}", previous, ipv6, uuid, uuid);
|
||||
error!("ipv6 conflict detected: zone {} owned (pending) {} but {} also claimed to own it, giving it to {}", previous, ipv6, uuid, uuid);
|
||||
}
|
||||
intermediate.pending_ipv6.insert(*ipv6, *uuid);
|
||||
}
|
||||
@ -271,16 +271,16 @@ impl IpVendor {
|
||||
domid: u32,
|
||||
) -> Result<Option<IpAssignment>> {
|
||||
let dom_path = format!("/local/domain/{}", domid);
|
||||
let Some(guest_ipv4) = self
|
||||
let Some(zone_ipv4) = self
|
||||
.store
|
||||
.read_string(format!("{}/krata/network/guest/ipv4", dom_path))
|
||||
.read_string(format!("{}/krata/network/zone/ipv4", dom_path))
|
||||
.await?
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(guest_ipv6) = self
|
||||
let Some(zone_ipv6) = self
|
||||
.store
|
||||
.read_string(format!("{}/krata/network/guest/ipv6", dom_path))
|
||||
.read_string(format!("{}/krata/network/zone/ipv6", dom_path))
|
||||
.await?
|
||||
else {
|
||||
return Ok(None);
|
||||
@ -300,10 +300,10 @@ impl IpVendor {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let Some(guest_ipv4) = Ipv4Network::from_str(&guest_ipv4).ok() else {
|
||||
let Some(zone_ipv4) = Ipv4Network::from_str(&zone_ipv4).ok() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(guest_ipv6) = Ipv6Network::from_str(&guest_ipv6).ok() else {
|
||||
let Some(zone_ipv6) = Ipv6Network::from_str(&zone_ipv6).ok() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(gateway_ipv4) = Ipv4Network::from_str(&gateway_ipv4).ok() else {
|
||||
@ -315,10 +315,10 @@ impl IpVendor {
|
||||
Ok(Some(IpAssignment {
|
||||
vendor: self.clone(),
|
||||
uuid,
|
||||
ipv4: guest_ipv4.ip(),
|
||||
ipv4_prefix: guest_ipv4.prefix(),
|
||||
ipv6: guest_ipv6.ip(),
|
||||
ipv6_prefix: guest_ipv6.prefix(),
|
||||
ipv4: zone_ipv4.ip(),
|
||||
ipv4_prefix: zone_ipv4.prefix(),
|
||||
ipv6: zone_ipv6.ip(),
|
||||
ipv6_prefix: zone_ipv6.prefix(),
|
||||
gateway_ipv4: gateway_ipv4.ip(),
|
||||
gateway_ipv6: gateway_ipv6.ip(),
|
||||
committed: true,
|
||||
|
@ -20,13 +20,13 @@ use xenplatform::domain::BaseDomainConfig;
|
||||
use crate::cfgblk::ConfigBlock;
|
||||
use crate::RuntimeContext;
|
||||
|
||||
use super::{GuestInfo, GuestState};
|
||||
use super::{ZoneInfo, ZoneState};
|
||||
|
||||
pub use xenclient::{
|
||||
pci::PciBdf, DomainPciDevice as PciDevice, DomainPciRdmReservePolicy as PciRdmReservePolicy,
|
||||
};
|
||||
|
||||
pub struct GuestLaunchRequest {
|
||||
pub struct ZoneLaunchRequest {
|
||||
pub format: LaunchPackedFormat,
|
||||
pub kernel: Vec<u8>,
|
||||
pub initrd: Vec<u8>,
|
||||
@ -42,11 +42,11 @@ pub struct GuestLaunchRequest {
|
||||
pub addons_image: Option<PathBuf>,
|
||||
}
|
||||
|
||||
pub struct GuestLauncher {
|
||||
pub struct ZoneLauncher {
|
||||
pub launch_semaphore: Arc<Semaphore>,
|
||||
}
|
||||
|
||||
impl GuestLauncher {
|
||||
impl ZoneLauncher {
|
||||
pub fn new(launch_semaphore: Arc<Semaphore>) -> Result<Self> {
|
||||
Ok(Self { launch_semaphore })
|
||||
}
|
||||
@ -54,16 +54,16 @@ impl GuestLauncher {
|
||||
pub async fn launch(
|
||||
&mut self,
|
||||
context: &RuntimeContext,
|
||||
request: GuestLaunchRequest,
|
||||
) -> Result<GuestInfo> {
|
||||
request: ZoneLaunchRequest,
|
||||
) -> Result<ZoneInfo> {
|
||||
let uuid = request.uuid.unwrap_or_else(Uuid::new_v4);
|
||||
let xen_name = format!("krata-{uuid}");
|
||||
let mut gateway_mac = MacAddr6::random();
|
||||
gateway_mac.set_local(true);
|
||||
gateway_mac.set_multicast(false);
|
||||
let mut container_mac = MacAddr6::random();
|
||||
container_mac.set_local(true);
|
||||
container_mac.set_multicast(false);
|
||||
let mut zone_mac = MacAddr6::random();
|
||||
zone_mac.set_local(true);
|
||||
zone_mac.set_multicast(false);
|
||||
|
||||
let _launch_permit = self.launch_semaphore.acquire().await?;
|
||||
let mut ip = context.ipvendor.assign(uuid).await?;
|
||||
@ -145,7 +145,7 @@ impl GuestLauncher {
|
||||
}
|
||||
let cmdline = cmdline_options.join(" ");
|
||||
|
||||
let guest_mac_string = container_mac.to_string().replace('-', ":");
|
||||
let zone_mac_string = zone_mac.to_string().replace('-', ":");
|
||||
let gateway_mac_string = gateway_mac.to_string().replace('-', ":");
|
||||
|
||||
let mut disks = vec![
|
||||
@ -191,16 +191,16 @@ impl GuestLauncher {
|
||||
("krata/uuid".to_string(), uuid.to_string()),
|
||||
("krata/loops".to_string(), loops.join(",")),
|
||||
(
|
||||
"krata/network/guest/ipv4".to_string(),
|
||||
"krata/network/zone/ipv4".to_string(),
|
||||
format!("{}/{}", ip.ipv4, ip.ipv4_prefix),
|
||||
),
|
||||
(
|
||||
"krata/network/guest/ipv6".to_string(),
|
||||
"krata/network/zone/ipv6".to_string(),
|
||||
format!("{}/{}", ip.ipv6, ip.ipv6_prefix),
|
||||
),
|
||||
(
|
||||
"krata/network/guest/mac".to_string(),
|
||||
guest_mac_string.clone(),
|
||||
"krata/network/zone/mac".to_string(),
|
||||
zone_mac_string.clone(),
|
||||
),
|
||||
(
|
||||
"krata/network/gateway/ipv4".to_string(),
|
||||
@ -240,7 +240,7 @@ impl GuestLauncher {
|
||||
initialized: false,
|
||||
}],
|
||||
vifs: vec![DomainNetworkInterface {
|
||||
mac: guest_mac_string.clone(),
|
||||
mac: zone_mac_string.clone(),
|
||||
mtu: 1500,
|
||||
bridge: None,
|
||||
script: None,
|
||||
@ -248,20 +248,20 @@ impl GuestLauncher {
|
||||
pcis: request.pcis.clone(),
|
||||
filesystems: vec![],
|
||||
extra_keys,
|
||||
extra_rw_paths: vec!["krata/guest".to_string()],
|
||||
extra_rw_paths: vec!["krata/zone".to_string()],
|
||||
};
|
||||
match context.xen.create(&config).await {
|
||||
Ok(created) => {
|
||||
ip.commit().await?;
|
||||
Ok(GuestInfo {
|
||||
Ok(ZoneInfo {
|
||||
name: request.name.as_ref().map(|x| x.to_string()),
|
||||
uuid,
|
||||
domid: created.domid,
|
||||
image: request.image.digest,
|
||||
loops: vec![],
|
||||
guest_ipv4: Some(IpNetwork::new(IpAddr::V4(ip.ipv4), ip.ipv4_prefix)?),
|
||||
guest_ipv6: Some(IpNetwork::new(IpAddr::V6(ip.ipv6), ip.ipv6_prefix)?),
|
||||
guest_mac: Some(guest_mac_string.clone()),
|
||||
zone_ipv4: Some(IpNetwork::new(IpAddr::V4(ip.ipv4), ip.ipv4_prefix)?),
|
||||
zone_ipv6: Some(IpNetwork::new(IpAddr::V6(ip.ipv6), ip.ipv6_prefix)?),
|
||||
zone_mac: Some(zone_mac_string.clone()),
|
||||
gateway_ipv4: Some(IpNetwork::new(
|
||||
IpAddr::V4(ip.gateway_ipv4),
|
||||
ip.ipv4_prefix,
|
||||
@ -271,7 +271,7 @@ impl GuestLauncher {
|
||||
ip.ipv6_prefix,
|
||||
)?),
|
||||
gateway_mac: Some(gateway_mac_string.clone()),
|
||||
state: GuestState { exit_code: None },
|
||||
state: ZoneState { exit_code: None },
|
||||
})
|
||||
}
|
||||
Err(error) => {
|
||||
|
@ -12,7 +12,7 @@ use xenstore::{XsdClient, XsdInterface};
|
||||
|
||||
use self::{
|
||||
autoloop::AutoLoop,
|
||||
launch::{GuestLaunchRequest, GuestLauncher},
|
||||
launch::{ZoneLaunchRequest, ZoneLauncher},
|
||||
power::PowerManagementContext,
|
||||
};
|
||||
|
||||
@ -29,29 +29,32 @@ type RuntimePlatform = xenplatform::x86pv::X86PvPlatform;
|
||||
#[cfg(not(target_arch = "x86_64"))]
|
||||
type RuntimePlatform = xenplatform::unsupported::UnsupportedPlatform;
|
||||
|
||||
pub struct GuestLoopInfo {
|
||||
#[derive(Clone)]
|
||||
pub struct ZoneLoopInfo {
|
||||
pub device: String,
|
||||
pub file: String,
|
||||
pub delete: Option<String>,
|
||||
}
|
||||
|
||||
pub struct GuestState {
|
||||
#[derive(Clone)]
|
||||
pub struct ZoneState {
|
||||
pub exit_code: Option<i32>,
|
||||
}
|
||||
|
||||
pub struct GuestInfo {
|
||||
#[derive(Clone)]
|
||||
pub struct ZoneInfo {
|
||||
pub name: Option<String>,
|
||||
pub uuid: Uuid,
|
||||
pub domid: u32,
|
||||
pub image: String,
|
||||
pub loops: Vec<GuestLoopInfo>,
|
||||
pub guest_ipv4: Option<IpNetwork>,
|
||||
pub guest_ipv6: Option<IpNetwork>,
|
||||
pub guest_mac: Option<String>,
|
||||
pub loops: Vec<ZoneLoopInfo>,
|
||||
pub zone_ipv4: Option<IpNetwork>,
|
||||
pub zone_ipv6: Option<IpNetwork>,
|
||||
pub zone_mac: Option<String>,
|
||||
pub gateway_ipv4: Option<IpNetwork>,
|
||||
pub gateway_ipv6: Option<IpNetwork>,
|
||||
pub gateway_mac: Option<String>,
|
||||
pub state: GuestState,
|
||||
pub state: ZoneState,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -75,8 +78,8 @@ impl RuntimeContext {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn list(&self) -> Result<Vec<GuestInfo>> {
|
||||
let mut guests: Vec<GuestInfo> = Vec::new();
|
||||
pub async fn list(&self) -> Result<Vec<ZoneInfo>> {
|
||||
let mut zones: Vec<ZoneInfo> = Vec::new();
|
||||
for domid_candidate in self.xen.store.list("/local/domain").await? {
|
||||
if domid_candidate == "0" {
|
||||
continue;
|
||||
@ -112,20 +115,20 @@ impl RuntimeContext {
|
||||
.store
|
||||
.read_string(&format!("{}/krata/loops", &dom_path))
|
||||
.await?;
|
||||
let guest_ipv4 = self
|
||||
let zone_ipv4 = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/guest/ipv4", &dom_path))
|
||||
.read_string(&format!("{}/krata/network/zone/ipv4", &dom_path))
|
||||
.await?;
|
||||
let guest_ipv6 = self
|
||||
let zone_ipv6 = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/guest/ipv6", &dom_path))
|
||||
.read_string(&format!("{}/krata/network/zone/ipv6", &dom_path))
|
||||
.await?;
|
||||
let guest_mac = self
|
||||
let zone_mac = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/guest/mac", &dom_path))
|
||||
.read_string(&format!("{}/krata/network/zone/mac", &dom_path))
|
||||
.await?;
|
||||
let gateway_ipv4 = self
|
||||
.xen
|
||||
@ -143,14 +146,14 @@ impl RuntimeContext {
|
||||
.read_string(&format!("{}/krata/network/gateway/mac", &dom_path))
|
||||
.await?;
|
||||
|
||||
let guest_ipv4 = if let Some(guest_ipv4) = guest_ipv4 {
|
||||
IpNetwork::from_str(&guest_ipv4).ok()
|
||||
let zone_ipv4 = if let Some(zone_ipv4) = zone_ipv4 {
|
||||
IpNetwork::from_str(&zone_ipv4).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let guest_ipv6 = if let Some(guest_ipv6) = guest_ipv6 {
|
||||
IpNetwork::from_str(&guest_ipv6).ok()
|
||||
let zone_ipv6 = if let Some(zone_ipv6) = zone_ipv6 {
|
||||
IpNetwork::from_str(&zone_ipv6).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@ -170,7 +173,7 @@ impl RuntimeContext {
|
||||
let exit_code = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/guest/exit-code", &dom_path))
|
||||
.read_string(&format!("{}/krata/zone/exit-code", &dom_path))
|
||||
.await?;
|
||||
|
||||
let exit_code: Option<i32> = match exit_code {
|
||||
@ -178,37 +181,37 @@ impl RuntimeContext {
|
||||
None => None,
|
||||
};
|
||||
|
||||
let state = GuestState { exit_code };
|
||||
let state = ZoneState { exit_code };
|
||||
|
||||
let loops = RuntimeContext::parse_loop_set(&loops);
|
||||
guests.push(GuestInfo {
|
||||
zones.push(ZoneInfo {
|
||||
name,
|
||||
uuid,
|
||||
domid,
|
||||
image,
|
||||
loops,
|
||||
guest_ipv4,
|
||||
guest_ipv6,
|
||||
guest_mac,
|
||||
zone_ipv4,
|
||||
zone_ipv6,
|
||||
zone_mac,
|
||||
gateway_ipv4,
|
||||
gateway_ipv6,
|
||||
gateway_mac,
|
||||
state,
|
||||
});
|
||||
}
|
||||
Ok(guests)
|
||||
Ok(zones)
|
||||
}
|
||||
|
||||
pub async fn resolve(&self, uuid: Uuid) -> Result<Option<GuestInfo>> {
|
||||
for guest in self.list().await? {
|
||||
if guest.uuid == uuid {
|
||||
return Ok(Some(guest));
|
||||
pub async fn resolve(&self, uuid: Uuid) -> Result<Option<ZoneInfo>> {
|
||||
for zone in self.list().await? {
|
||||
if zone.uuid == uuid {
|
||||
return Ok(Some(zone));
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn parse_loop_set(input: &Option<String>) -> Vec<GuestLoopInfo> {
|
||||
fn parse_loop_set(input: &Option<String>) -> Vec<ZoneLoopInfo> {
|
||||
let Some(input) = input else {
|
||||
return Vec::new();
|
||||
};
|
||||
@ -219,7 +222,7 @@ impl RuntimeContext {
|
||||
.map(|x| (x[0].clone(), x[1].clone(), x[2].clone()))
|
||||
.collect::<Vec<(String, String, String)>>();
|
||||
sets.iter()
|
||||
.map(|(device, file, delete)| GuestLoopInfo {
|
||||
.map(|(device, file, delete)| ZoneLoopInfo {
|
||||
device: device.clone(),
|
||||
file: file.clone(),
|
||||
delete: if delete == "none" {
|
||||
@ -228,7 +231,7 @@ impl RuntimeContext {
|
||||
Some(delete.clone())
|
||||
},
|
||||
})
|
||||
.collect::<Vec<GuestLoopInfo>>()
|
||||
.collect::<Vec<ZoneLoopInfo>>()
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,8 +252,8 @@ impl Runtime {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn launch(&self, request: GuestLaunchRequest) -> Result<GuestInfo> {
|
||||
let mut launcher = GuestLauncher::new(self.launch_semaphore.clone())?;
|
||||
pub async fn launch(&self, request: ZoneLaunchRequest) -> Result<ZoneInfo> {
|
||||
let mut launcher = ZoneLauncher::new(self.launch_semaphore.clone())?;
|
||||
launcher.launch(&self.context, request).await
|
||||
}
|
||||
|
||||
@ -259,7 +262,7 @@ impl Runtime {
|
||||
.context
|
||||
.resolve(uuid)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow!("unable to resolve guest: {}", uuid))?;
|
||||
.ok_or_else(|| anyhow!("unable to resolve zone: {}", uuid))?;
|
||||
let domid = info.domid;
|
||||
let store = XsdClient::open().await?;
|
||||
let dom_path = store.get_domain_path(domid).await?;
|
||||
@ -307,7 +310,7 @@ impl Runtime {
|
||||
if let Some(ip) = ip {
|
||||
if let Err(error) = self.context.ipvendor.recall(&ip).await {
|
||||
error!(
|
||||
"failed to recall ip assignment for guest {}: {}",
|
||||
"failed to recall ip assignment for zone {}: {}",
|
||||
uuid, error
|
||||
);
|
||||
}
|
||||
@ -316,7 +319,7 @@ impl Runtime {
|
||||
Ok(uuid)
|
||||
}
|
||||
|
||||
pub async fn list(&self) -> Result<Vec<GuestInfo>> {
|
||||
pub async fn list(&self) -> Result<Vec<ZoneInfo>> {
|
||||
self.context.list().await
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ pub struct CpuTopologyInfo {
|
||||
pub class: CpuClass,
|
||||
}
|
||||
|
||||
fn labelled_topo(input: &[SysctlCputopo]) -> Vec<CpuTopologyInfo> {
|
||||
fn labeled_topology(input: &[SysctlCputopo]) -> Vec<CpuTopologyInfo> {
|
||||
let mut cores: IndexMap<(u32, u32, u32), Vec<CpuTopologyInfo>> = IndexMap::new();
|
||||
let mut pe_cores = false;
|
||||
let mut last: Option<SysctlCputopo> = None;
|
||||
@ -140,9 +140,9 @@ impl PowerManagementContext {
|
||||
/// If there is a p-core/e-core split, then CPU class will be defined as
|
||||
/// `CpuClass::Performance` or `CpuClass::Efficiency`, else `CpuClass::Standard`.
|
||||
pub async fn cpu_topology(&self) -> Result<Vec<CpuTopologyInfo>> {
|
||||
let xentopo = self.context.xen.call.cpu_topology().await?;
|
||||
let logicaltopo = labelled_topo(&xentopo);
|
||||
Ok(logicaltopo)
|
||||
let xen_topology = self.context.xen.call.cpu_topology().await?;
|
||||
let logical_topology = labeled_topology(&xen_topology);
|
||||
Ok(logical_topology)
|
||||
}
|
||||
|
||||
/// Enable or disable SMT awareness in the scheduler.
|
||||
|
Reference in New Issue
Block a user