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

Move in x112virtgpu as muvm-x11bridge #97

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @slp @teohhanhui @alyssarosenzweig @asahilina
* @slp @teohhanhui @alyssarosenzweig @asahilina @WhatAmISupposedToPutHere
32 changes: 24 additions & 8 deletions Cargo.lock

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

12 changes: 9 additions & 3 deletions crates/muvm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "muvm"
version = "0.1.3"
authors = ["Sergio Lopez <slp@redhat.com>", "Teoh Han Hui <teohhanhui@gmail.com>"]
authors = ["Sergio Lopez <slp@redhat.com>", "Teoh Han Hui <teohhanhui@gmail.com>", "Sasha Finkelstein <fnkl.kernel@gmail.com>", "Asahi Lina <lina@asahilina.net>"]
edition = "2021"
rust-version = "1.77.0"
description = "Run programs from your system in a microVM"
Expand All @@ -15,7 +15,7 @@ byteorder = { version = "1.5.0", default-features = false, features = ["std"] }
env_logger = { version = "0.11.3", default-features = false, features = ["auto-color", "humantime", "unstable-kv"] }
krun-sys = { path = "../krun-sys", version = "1.9.1", default-features = false, features = [] }
log = { version = "0.4.21", default-features = false, features = ["kv"] }
nix = { version = "0.28.0", default-features = false, features = ["user"] }
nix = { version = "0.29.0", default-features = false, features = ["user"] }
asahilina marked this conversation as resolved.
Show resolved Hide resolved
procfs = { version = "0.17.0", default-features = false, features = [] }
rustix = { version = "0.38.34", default-features = false, features = ["fs", "mount", "process", "std", "stdio", "system", "use-libc-auxv"] }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
Expand All @@ -26,7 +26,8 @@ tokio-stream = { version = "0.1.15", default-features = false, features = ["net"
uuid = { version = "1.10.0", default-features = false, features = ["serde", "std", "v7"] }

[features]
default = []
x11bridge = ["nix/event", "nix/fs", "nix/ioctl", "nix/mman", "nix/ptrace", "nix/signal", "nix/socket", "nix/uio"]
default = ["x11bridge"]

[[bin]]
name = "muvm"
Expand All @@ -39,3 +40,8 @@ path = "src/guest/bin/muvm-guest.rs"
[[bin]]
name = "muvm-server"
path = "src/server/bin/muvm-server.rs"

[[bin]]
name = "muvm-x11bridge"
path = "src/x11bridge/bin/muvm-x11bridge.rs"
required-features = ["x11bridge"]
1 change: 1 addition & 0 deletions crates/muvm/src/bin/muvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ fn main() -> Result<()> {
);
env.insert("MUVM_SERVER_COOKIE".to_owned(), cookie.to_string());

#[cfg(x11bridge)]
if options.direct_x11 {
let display =
env::var("DISPLAY").context("X11 forwarding requested but DISPLAY is unset")?;
Expand Down
8 changes: 8 additions & 0 deletions crates/muvm/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ pub fn options() -> OptionParser<Options> {
.help("Use direct X11 forwarding instead of sommelier + XWayland")
.switch();

#[cfg(not(feature = "x11bridge"))]
let direct_x11 = direct_x11
.guard(
|x| !*x,
"--direct-x11 requires the `x11bridge` crate feature",
)
.hide();

let command = positional("COMMAND").help("the command you want to execute in the vm");
let command_args = any::<String, _, _>("COMMAND_ARGS", |arg| {
(!["--help", "-h"].contains(&&*arg)).then_some(arg)
Expand Down
8 changes: 7 additions & 1 deletion crates/muvm/src/guest/bin/muvm-guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use muvm::guest::net::configure_network;
use muvm::guest::socket::setup_socket_proxy;
use muvm::guest::sommelier::exec_sommelier;
use muvm::guest::user::setup_user;
#[cfg(feature = "x11bridge")]
use muvm::guest::x11::setup_x11_forwarding;
use muvm::utils::env::find_in_path;
use rustix::process::{getrlimit, setrlimit, Resource};
Expand Down Expand Up @@ -79,7 +80,12 @@ fn main() -> Result<()> {
let pulse_path = pulse_path.join("native");
setup_socket_proxy(pulse_path, 3333)?;

if !setup_x11_forwarding(run_path)? {
#[cfg(feature = "x11bridge")]
let direct_x11 = setup_x11_forwarding(run_path)?;
#[cfg(not(feature = "x11bridge"))]
let direct_x11 = false;

if !direct_x11 {
// Will not return if successful.
exec_sommelier(&options.command, &options.command_args)
.context("Failed to execute sommelier")?;
Expand Down
1 change: 1 addition & 0 deletions crates/muvm/src/guest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pub mod net;
pub mod socket;
pub mod sommelier;
pub mod user;
#[cfg(feature = "x11bridge")]
pub mod x11;
18 changes: 4 additions & 14 deletions crates/muvm/src/guest/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use std::process::Command;
use anyhow::{anyhow, Context, Result};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};

use super::socket::setup_socket_proxy;

use crate::utils::env::find_in_path;
use crate::env::find_muvm_exec;

pub fn setup_x11_forwarding<P>(run_path: P) -> Result<bool>
where
Expand All @@ -26,18 +24,10 @@ where
}
let host_display = &host_display[1..];

let x112virtgpu_path =
find_in_path("x112virtgpu").context("Failed to check existence of `x112virtgpu`")?;

if x112virtgpu_path.is_some() {
let mut cmd = Command::new(x112virtgpu_path.unwrap());
cmd.args(["--listen-display", ":1"]);
let mut cmd = Command::new(find_muvm_exec("muvm-x11bridge")?);
cmd.args(["--listen-display", ":1"]);

cmd.spawn().context("Failed to spawn `x112virtgpu`")?;
} else {
log::error!("x112virtgpu not available, X11 forwarding will operate in socket forwarding mode. This is probably not what you want.");
setup_socket_proxy(Path::new("/tmp/.X11-unix/X1"), 6000)?;
}
cmd.spawn().context("Failed to spawn `muvm-x11bridge`")?;

// SAFETY: Safe if and only if `muvm-guest` program is not multithreaded.
// See https://doc.rust-lang.org/std/env/fn.set_var.html#safety
Expand Down
Loading
Loading