Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : add writer implementation #39

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
105 changes: 102 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 44 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::u32;
use std::{io::Read, os::unix::net::UnixListener, path::Path, thread::sleep, u32};

use clap::Parser;
use vmm::VMM;
use vmm::{devices::Writer, VMM};

#[derive(Parser)]
#[clap(version = "0.1", author = "Polytech Montpellier - DevOps")]
Expand Down Expand Up @@ -29,6 +29,17 @@ struct VMMOpts {
/// Stdout console file path
#[clap(long)]
console: Option<String>,

/// Interface name
#[clap(long)]
net: Option<String>,

/// no-console
#[clap(long)]
no_console: bool,

#[clap(long)]
socket: bool,
}

#[derive(Debug)]
Expand All @@ -43,6 +54,32 @@ pub enum Error {
fn main() -> Result<(), Error> {
let opts: VMMOpts = VMMOpts::parse();

let console = opts.console.unwrap();
if opts.socket {
let path = Path::new(console.as_str());
if std::fs::metadata(path).is_ok() {
std::fs::remove_file(path).unwrap();
}

println!("Socket path: {}", path.to_str().unwrap());

let unix_listener = UnixListener::bind(path).unwrap();

std::thread::spawn(move || {
// read from socket
let (mut stream, _) = unix_listener.accept().unwrap();
let mut buffer = [0; 1024];
loop {
let n = stream.read(&mut buffer).unwrap();
if n == 0 {
break;
}
let s = String::from_utf8_lossy(&buffer[0..n]).to_string();
print!("{}", s);
}
});
}

// Create a new VMM
let mut vmm = VMM::new().map_err(Error::VmmNew)?;

Expand All @@ -55,13 +92,16 @@ fn main() -> Result<(), Error> {
opts.cpus,
opts.memory,
&opts.kernel,
opts.console,
Some(console),
opts.no_console,
opts.initramfs,
opts.net,
opts.socket,
)
.map_err(Error::VmmConfigure)?;

// Run the VMM
vmm.run().map_err(Error::VmmRun)?;
vmm.run(opts.no_console).map_err(Error::VmmRun)?;

Ok(())
}
56 changes: 55 additions & 1 deletion src/vmm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ libc = "0.2.91"
linux-loader = { version = "0.8.1", features = ["bzimage", "elf"] }
vm-memory = { version = "0.10.0", features = ["backend-mmap"] }
vmm-sys-util = "0.11.1"
virtio-bindings = "0.2.0"

# vm-device is not yet published on crates.io.
# To make sure that breaking changes to vm-device are not breaking the
# vm-vcpu build, we're using a fixed revision.
vm-device = { git = "https://github.com/rust-vmm/vm-device", rev = "5847f12" }
vm-device = { git = "https://github.com/lucido-simon/vm-device", rev = "27537ff920fb6b1f8749294c911648d8e44fd5e5" }
virtio-device = { git = "https://github.com/rust-vmm/vm-virtio" }
virtio-queue = { git = "https://github.com/rust-vmm/vm-virtio" }

vm-superio = "0.7.0"

serde_json = "1.0.94"
serde = { version = "1.0.126", features = ["derive"] }
Loading