From 9a0f75d39bdbda1b56c9c460d07bd14cbe9429e4 Mon Sep 17 00:00:00 2001 From: Mauran Date: Mon, 22 Apr 2024 23:27:30 +0200 Subject: [PATCH] chore: lint Signed-off-by: Mauran --- src/vmm/src/args.rs | 2 +- src/vmm/src/lib.rs | 2 +- src/vmm/src/main.rs | 43 ++++++++++++++++++++++++++---------------- src/vmm/src/service.rs | 34 +++++++++++++++++++++------------ 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/vmm/src/args.rs b/src/vmm/src/args.rs index 05978c0..d4e9bcc 100644 --- a/src/vmm/src/args.rs +++ b/src/vmm/src/args.rs @@ -18,7 +18,7 @@ pub enum Commands { Cli(CliArguments), #[command(about = "Run a GRPC server listening for incoming requests.")] Grpc, -} +} /// Run a VMM instance. #[derive(Parser, Debug)] diff --git a/src/vmm/src/lib.rs b/src/vmm/src/lib.rs index 48ffa47..f5df684 100644 --- a/src/vmm/src/lib.rs +++ b/src/vmm/src/lib.rs @@ -6,4 +6,4 @@ pub enum VmmErrors { VmmNew(core::Error), VmmConfigure(core::Error), VmmRun(core::Error), -} \ No newline at end of file +} diff --git a/src/vmm/src/main.rs b/src/vmm/src/main.rs index d003d90..3662646 100644 --- a/src/vmm/src/main.rs +++ b/src/vmm/src/main.rs @@ -1,8 +1,12 @@ use crate::args::{CliArgs, Commands}; use clap::Parser; -use tracing::info; -use vmm::{core::{vmm::VMM}, service::{vmmorchestrator, VmmService}, VmmErrors}; use tonic::transport::Server; +use tracing::info; +use vmm::{ + core::vmm::VMM, + service::{vmmorchestrator, VmmService}, + VmmErrors, +}; mod args; #[tokio::main] @@ -23,27 +27,34 @@ async fn main() -> Result<(), Box> { match args.command { Commands::Grpc => { Server::builder() - .add_service(vmmorchestrator::vmm_service_server::VmmServiceServer::new(vmm_service)) - .serve(addr) - .await?; - + .add_service(vmmorchestrator::vmm_service_server::VmmServiceServer::new( + vmm_service, + )) + .serve(addr) + .await?; } Commands::Cli(cli_args) => { - tracing_subscriber::fmt() - .with_max_level(cli_args.convert_log_to_tracing()) - .init(); + .with_max_level(cli_args.convert_log_to_tracing()) + .init(); // Create a new VMM - let mut vmm = - VMM::new(cli_args.network_host_ip, cli_args.network_host_netmask).map_err(VmmErrors::VmmNew).unwrap(); - - vmm.configure(cli_args.cpus, cli_args.memory, &cli_args.kernel, &cli_args.initramfs) - .map_err(VmmErrors::VmmConfigure).unwrap(); - + let mut vmm = VMM::new(cli_args.network_host_ip, cli_args.network_host_netmask) + .map_err(VmmErrors::VmmNew) + .unwrap(); + + vmm.configure( + cli_args.cpus, + cli_args.memory, + &cli_args.kernel, + &cli_args.initramfs, + ) + .map_err(VmmErrors::VmmConfigure) + .unwrap(); + // Run the VMM vmm.run().map_err(VmmErrors::VmmRun).unwrap(); } } - + Ok(()) } diff --git a/src/vmm/src/service.rs b/src/vmm/src/service.rs index 705f194..bd1dfac 100644 --- a/src/vmm/src/service.rs +++ b/src/vmm/src/service.rs @@ -1,8 +1,15 @@ -use tonic::{transport::Server, Request, Response, Status}; -use crate::core::vmm::{self, VMM}; -use std::{convert::From, net::Ipv4Addr, path::{Path, PathBuf}, process::{Command, Stdio}}; +use self::vmmorchestrator::{ + vmm_service_server::VmmService as VmmServiceTrait, RunVmmRequest, RunVmmResponse, +}; +use crate::core::vmm::VMM; use crate::VmmErrors; -use self::vmmorchestrator::{vmm_service_server::VmmService as VmmServiceTrait, RunVmmRequest, RunVmmResponse}; +use std::{ + convert::From, + net::Ipv4Addr, + path::{Path, PathBuf}, + process::{Command, Stdio}, +}; +use tonic::{Request, Response, Status}; use tracing::{error, info}; pub mod vmmorchestrator { @@ -28,15 +35,17 @@ pub struct VmmService; impl VmmServiceTrait for VmmService { async fn run( &self, - request: Request, + _request: Request, ) -> Result, Status> { let response = vmmorchestrator::RunVmmResponse {}; const HOST_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 0, 1); const HOST_NETMASK: Ipv4Addr = Ipv4Addr::new(255, 255, 0, 0); - + // Check if the kernel is on the system, else build it - if !Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin").exists() { + if !Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin") + .exists() + { info!("Kernel not found, building kernel"); // Execute the script using sh and capture output and error streams let output = Command::new("sh") @@ -51,18 +60,19 @@ impl VmmServiceTrait for VmmService { error!("Script errors: {}", String::from_utf8_lossy(&output.stderr)); }; - let kernel_path = &Path::new("./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin"); - let mut initramfs_path: PathBuf = PathBuf::new(); + let kernel_path = &Path::new( + "./tools/kernel/linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin", + ); + let mut initramfs_path: PathBuf = PathBuf::new(); // Todo - Check if the initramfs for the specified language is on the system, else build it initramfs_path.push("./tools/rootfs/initramfs.img"); // // Create a new VMM - let mut vmm = - VMM::new(HOST_IP, HOST_NETMASK).map_err(VmmErrors::VmmNew)?; + let mut vmm = VMM::new(HOST_IP, HOST_NETMASK).map_err(VmmErrors::VmmNew)?; // Configure the VMM parameters might need to be calculated rather than hardcoded - vmm.configure(1, 512, &kernel_path, &Some(initramfs_path)) + vmm.configure(1, 512, kernel_path, &Some(initramfs_path)) .map_err(VmmErrors::VmmConfigure)?; // Run the VMM vmm.run().map_err(VmmErrors::VmmRun)?;