Skip to content

Commit 44d33a3

Browse files
committed
hidpipe: merge hidpipe project into muvm
Merge hidpipe project into muvm, with hidpipe-server operating as a thread inside the main muvm binary, and hidpipe-client getting renamed to muvm-hidpipe (and it's still autostarted by muvm-guest). This simplifies the lifecycle management for hidpipe, ensuring it's tied to the microVM lifetime. Co-developed-by: Sasha Finkelstein <[email protected]> Signed-off-by: Sergio Lopez <[email protected]>
1 parent 8b49072 commit 44d33a3

9 files changed

Lines changed: 1059 additions & 20 deletions

File tree

.github/workflows/code_quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
components: rustfmt, clippy
3030

3131
- name: Install packages
32-
run: sudo apt-get update && sudo apt-get -y install libclang-dev
32+
run: sudo apt-get update && sudo apt-get -y install libclang-dev libudev-dev
3333

3434
- name: Download libkrun.h
3535
run: sudo curl -o /usr/include/libkrun.h https://raw.githubusercontent.com/containers/libkrun/refs/heads/main/include/libkrun.h

Cargo.lock

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/muvm/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ anyhow = { version = "1.0.82", default-features = false, features = ["std"] }
1313
bpaf = { version = "0.9.11", default-features = false, features = [] }
1414
byteorder = { version = "1.5.0", default-features = false, features = ["std"] }
1515
env_logger = { version = "0.11.3", default-features = false, features = ["auto-color", "humantime", "unstable-kv"] }
16+
input-linux = { version = "0.7.0", default-features = false, features = [] }
17+
input-linux-sys = { version = "0.9.0", default-features = false, features = [] }
1618
krun-sys = { path = "../krun-sys", version = "1.9.1", default-features = false, features = [] }
1719
log = { version = "0.4.21", default-features = false, features = ["kv"] }
1820
nix = { version = "0.29.0", default-features = false, features = ["user"] }
@@ -23,6 +25,7 @@ serde_json = { version = "1.0.117", default-features = false, features = ["std"]
2325
tempfile = { version = "3.10.1", default-features = false, features = [] }
2426
tokio = { version = "1.38.0", default-features = false, features = ["io-util", "macros", "net", "process", "rt-multi-thread", "sync"] }
2527
tokio-stream = { version = "0.1.15", default-features = false, features = ["net", "sync"] }
28+
udev = { version = "0.9.0", default-features = false, features = [] }
2629
uuid = { version = "1.10.0", default-features = false, features = ["serde", "std", "v7"] }
2730

2831
[features]
@@ -37,6 +40,10 @@ path = "src/bin/muvm.rs"
3740
name = "muvm-guest"
3841
path = "src/guest/bin/muvm-guest.rs"
3942

43+
[[bin]]
44+
name = "muvm-hidpipe"
45+
path = "src/hidpipe/bin/muvm-hidpipe.rs"
46+
4047
[[bin]]
4148
name = "muvm-server"
4249
path = "src/server/bin/muvm-server.rs"

crates/muvm/src/bin/muvm.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use log::debug;
1515
use muvm::cli_options::options;
1616
use muvm::cpu::{get_fallback_cores, get_performance_cores};
1717
use muvm::env::{find_muvm_exec, prepare_env_vars};
18+
use muvm::hidpipe_server::spawn_hidpipe_server;
1819
use muvm::launch::{launch_or_lock, LaunchResult};
1920
use muvm::monitor::spawn_monitor;
2021
use muvm::net::{connect_to_passt, start_passt};
@@ -297,19 +298,19 @@ fn main() -> Result<()> {
297298
}
298299
}
299300
let hidpipe_path = Path::new(&run_path).join("hidpipe");
300-
if hidpipe_path.exists() {
301-
let hidpipe_path = CString::new(
302-
hidpipe_path
303-
.to_str()
304-
.expect("hidpipe_path should not contain invalid UTF-8"),
305-
)
306-
.context("Failed to process `hidpipe` path as it contains NUL character")?;
307-
// SAFETY: `hidpipe_path` is a pointer to a `CString` with long enough lifetime.
308-
let err = unsafe { krun_add_vsock_port(ctx_id, 3334, hidpipe_path.as_ptr()) };
309-
if err < 0 {
310-
let err = Errno::from_raw_os_error(-err);
311-
return Err(err).context("Failed to configure vsock for hidpipe socket");
312-
}
301+
spawn_hidpipe_server(hidpipe_path.clone()).context("Failed to spawn hidpipe thread")?;
302+
let hidpipe_path = CString::new(
303+
hidpipe_path
304+
.to_str()
305+
.expect("hidpipe_path should not contain invalid UTF-8"),
306+
)
307+
.context("Failed to process `hidpipe` path as it contains NUL character")?;
308+
309+
// SAFETY: `hidpipe_path` is a pointer to a `CString` with long enough lifetime.
310+
let err = unsafe { krun_add_vsock_port(ctx_id, 3334, hidpipe_path.as_ptr()) };
311+
if err < 0 {
312+
let err = Errno::from_raw_os_error(-err);
313+
return Err(err).context("Failed to configure vsock for hidpipe socket");
313314
}
314315
}
315316

crates/muvm/src/guest/bin/muvm-guest.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use muvm::guest::sommelier::exec_sommelier;
1414
use muvm::guest::user::setup_user;
1515
#[cfg(feature = "x11bridge")]
1616
use muvm::guest::x11::setup_x11_forwarding;
17-
use muvm::utils::env::find_in_path;
1817
use rustix::process::{getrlimit, setrlimit, Resource};
1918

2019
fn main() -> Result<()> {
@@ -57,11 +56,10 @@ fn main() -> Result<()> {
5756

5857
configure_network()?;
5958

60-
if let Some(hidpipe_client_path) = find_in_path("hidpipe-client")? {
61-
Command::new(hidpipe_client_path)
62-
.arg(format!("{}", options.uid))
63-
.spawn()?;
64-
}
59+
Command::new("muvm-hidpipe")
60+
.arg(format!("{}", options.uid))
61+
.spawn()
62+
.context("Failed to execute `muvm-hidpipe` as child process")?;
6563

6664
// Before switching to the user, start another instance of muvm-server to serve
6765
// launch requests as root.

0 commit comments

Comments
 (0)