mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 13:11:31 +00:00
hypha: multiple cleanups to fix shared module
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use crate::image::ImageInfo;
|
||||
use crate::shared::LaunchInfo;
|
||||
use anyhow::Result;
|
||||
use backhand::{FilesystemWriter, NodeHeader};
|
||||
use hypha::LaunchInfo;
|
||||
use log::trace;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
|
@ -5,9 +5,9 @@ use crate::ctl::cfgblk::ConfigBlock;
|
||||
use crate::image::cache::ImageCache;
|
||||
use crate::image::name::ImageName;
|
||||
use crate::image::{ImageCompiler, ImageInfo};
|
||||
use crate::shared::{LaunchInfo, LaunchNetwork};
|
||||
use advmac::MacAddr6;
|
||||
use anyhow::{anyhow, Result};
|
||||
use hypha::{LaunchInfo, LaunchNetwork};
|
||||
use ipnetwork::Ipv4Network;
|
||||
use loopdev::LoopControl;
|
||||
use std::io::{Read, Write};
|
||||
@ -114,10 +114,9 @@ impl Controller {
|
||||
let cmdline_options = [if debug { "debug" } else { "quiet" }, "elevator=noop"];
|
||||
let cmdline = cmdline_options.join(" ");
|
||||
|
||||
let mac = MacAddr6::random()
|
||||
.to_string()
|
||||
.replace('-', ":")
|
||||
.to_lowercase();
|
||||
let mut mac = MacAddr6::random();
|
||||
mac.set_local(true);
|
||||
let mac = mac.to_string().replace('-', ":");
|
||||
let config = DomainConfig {
|
||||
backend_domid: 0,
|
||||
name: &name,
|
||||
|
@ -1,4 +1,3 @@
|
||||
pub mod autoloop;
|
||||
pub mod ctl;
|
||||
pub mod image;
|
||||
pub mod shared;
|
||||
|
@ -1,14 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct LaunchNetwork {
|
||||
pub link: String,
|
||||
pub ipv4: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct LaunchInfo {
|
||||
pub network: Option<LaunchNetwork>,
|
||||
pub env: Option<Vec<String>>,
|
||||
pub run: Option<Vec<String>>,
|
||||
}
|
@ -64,7 +64,7 @@ impl XenCall {
|
||||
|
||||
pub fn hypercall(&self, op: c_ulong, arg: [c_ulong; 5]) -> Result<c_long> {
|
||||
trace!(
|
||||
"call fd={} hypercall op={:#x}, arg={:?}",
|
||||
"call fd={} hypercall op={:#x} arg={:?}",
|
||||
self.handle.as_raw_fd(),
|
||||
op,
|
||||
arg
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::os::fd::AsRawFd;
|
||||
use std::panic::UnwindSafe;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use std::{panic, thread};
|
||||
|
||||
@ -73,14 +74,10 @@ impl NetworkBackend {
|
||||
}
|
||||
|
||||
pub fn run(mut self) -> Result<()> {
|
||||
let interface = self.interface.clone();
|
||||
let result = panic::catch_unwind(move || self.run_maybe_panic());
|
||||
|
||||
if result.is_err() {
|
||||
return Err(anyhow!(
|
||||
"network backend for interface {} encountered an error and is now shutdown",
|
||||
interface
|
||||
));
|
||||
return Err(anyhow!("network backend has terminated"));
|
||||
}
|
||||
|
||||
result.unwrap()
|
||||
@ -109,7 +106,7 @@ impl NetworkBackend {
|
||||
|
||||
impl NetworkService {
|
||||
pub async fn watch(&mut self) -> Result<()> {
|
||||
let mut spawned: Vec<String> = Vec::new();
|
||||
let spawned: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::new()));
|
||||
let (connection, handle, _) = rtnetlink::new_connection()?;
|
||||
tokio::spawn(connection);
|
||||
loop {
|
||||
@ -131,25 +128,33 @@ impl NetworkService {
|
||||
continue;
|
||||
}
|
||||
|
||||
if spawned.contains(&name) {
|
||||
if let Ok(spawns) = spawned.lock() {
|
||||
if spawns.contains(&name) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(error) = self.add_network_backend(&name).await {
|
||||
if let Err(error) = self.add_network_backend(&name, spawned.clone()).await {
|
||||
warn!(
|
||||
"failed to initialize network backend for interface {}: {}",
|
||||
name, error
|
||||
);
|
||||
}
|
||||
|
||||
spawned.push(name);
|
||||
if let Ok(mut spawns) = spawned.lock() {
|
||||
spawns.push(name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_network_backend(&mut self, interface: &str) -> Result<()> {
|
||||
async fn add_network_backend(
|
||||
&mut self,
|
||||
interface: &str,
|
||||
spawned: Arc<Mutex<Vec<String>>>,
|
||||
) -> Result<()> {
|
||||
let interface = interface.to_string();
|
||||
let mut network = NetworkBackend::new(&interface, &[&self.network])?;
|
||||
info!("initializing network backend for interface {}", interface);
|
||||
@ -163,6 +168,12 @@ impl NetworkService {
|
||||
interface, error
|
||||
);
|
||||
}
|
||||
|
||||
if let Ok(mut spawns) = spawned.lock() {
|
||||
if let Some(position) = spawns.iter().position(|x| *x == interface) {
|
||||
spawns.remove(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user