use std::collections::HashMap; use xencall::XenCall; pub use xenplatform::domain::PlatformDomainConfig; use xenplatform::domain::PlatformDomainInfo; use crate::{ error::Result, tx::{ channel::ChannelDeviceConfig, fs9p::Fs9pDeviceConfig, pci::PciRootDeviceConfig, vbd::VbdDeviceConfig, vif::VifDeviceConfig, {BlockDeviceResult, DeviceResult}, }, }; pub struct DomainConfig { platform: Option, name: Option, backend_domid: u32, channels: Vec, vifs: Vec, vbds: Vec, fs9ps: Vec, pci: Option, extra_keys: HashMap, extra_rw_paths: Vec, start: bool, } impl Default for DomainConfig { fn default() -> Self { Self::new() } } impl DomainConfig { pub fn new() -> Self { Self { platform: None, name: None, backend_domid: 0, channels: Vec::new(), vifs: Vec::new(), vbds: Vec::new(), fs9ps: Vec::new(), pci: None, extra_keys: HashMap::new(), extra_rw_paths: Vec::new(), start: true, } } pub fn platform(&mut self, platform: PlatformDomainConfig) -> &mut Self { self.platform = Some(platform); self } pub fn get_platform(&self) -> &Option { &self.platform } pub fn name(&mut self, name: impl AsRef) -> &mut Self { self.name = Some(name.as_ref().to_string()); self } pub fn get_name(&self) -> &Option { &self.name } pub fn backend_domid(&mut self, backend_domid: u32) -> &mut Self { self.backend_domid = backend_domid; self } pub fn get_backend_domid(&self) -> u32 { self.backend_domid } pub fn add_channel(&mut self, channel: ChannelDeviceConfig) -> &mut Self { self.channels.push(channel); self } pub fn get_channels(&self) -> &Vec { &self.channels } pub fn add_vif(&mut self, vif: VifDeviceConfig) -> &mut Self { self.vifs.push(vif); self } pub fn get_vifs(&self) -> &Vec { &self.vifs } pub fn add_vbd(&mut self, vbd: VbdDeviceConfig) -> &mut Self { self.vbds.push(vbd); self } pub fn get_vbds(&self) -> &Vec { &self.vbds } pub fn add_fs9p(&mut self, fs9p: Fs9pDeviceConfig) -> &mut Self { self.fs9ps.push(fs9p); self } pub fn get_fs9ps(&self) -> &Vec { &self.fs9ps } pub fn pci(&mut self, pci: PciRootDeviceConfig) -> &mut Self { self.pci = Some(pci); self } pub fn get_pci(&self) -> &Option { &self.pci } pub fn add_extra_key(&mut self, key: impl AsRef, value: impl ToString) -> &mut Self { self.extra_keys .insert(key.as_ref().to_string(), value.to_string()); self } pub fn get_extra_keys(&self) -> &HashMap { &self.extra_keys } pub fn add_rw_path(&mut self, path: impl AsRef) -> &mut Self { self.extra_rw_paths.push(path.as_ref().to_string()); self } pub fn get_rw_paths(&self) -> &Vec { &self.extra_rw_paths } pub fn start(&mut self, start: bool) -> &mut Self { self.start = start; self } pub fn get_start(&self) -> bool { self.start } pub fn done(self) -> Self { self } pub(crate) async fn prepare( &mut self, domid: u32, call: &XenCall, platform: &PlatformDomainInfo, ) -> Result<()> { if let Some(pci) = self.pci.as_mut() { pci.prepare(domid, call).await?; } for channel in &mut self.channels { channel.prepare(platform).await?; } Ok(()) } } pub struct DomainResult { pub platform: PlatformDomainInfo, pub channels: Vec, pub vifs: Vec, pub vbds: Vec, pub fs9ps: Vec, pub pci: Option, }