From b111fc9c0fd9be7947610baacbe216af74f88932 Mon Sep 17 00:00:00 2001 From: dierbei <1628652790@qq.com> Date: Fri, 11 Aug 2023 13:07:31 +0000 Subject: [PATCH] Sandboxer: Replace features with bin parameter Signed-off-by: dierbei <1628652790@qq.com> --- .gitignore | 2 +- Makefile | 4 +- quark/Cargo.lock | 4 +- vmm/sandbox/Cargo.lock | 392 +++++++++---------- vmm/sandbox/Cargo.toml | 33 +- vmm/sandbox/src/bin/cloud_hypervisor/main.rs | 33 ++ vmm/sandbox/src/bin/qemu/main.rs | 33 ++ vmm/sandbox/src/bin/stratovirt/main.rs | 33 ++ vmm/sandbox/src/cloud_hypervisor/mod.rs | 19 +- vmm/sandbox/src/kata_config.rs | 9 +- vmm/sandbox/src/lib.rs | 70 ++++ vmm/sandbox/src/main.rs | 208 ---------- vmm/sandbox/src/param.rs | 7 + vmm/sandbox/src/qemu/hooks.rs | 2 +- vmm/sandbox/src/qemu/mod.rs | 39 +- vmm/sandbox/src/sandbox.rs | 6 +- vmm/sandbox/src/stratovirt/mod.rs | 29 +- vmm/sandbox/src/utils.rs | 9 + wasm/Cargo.lock | 4 +- wasm/src/sandbox.rs | 8 +- 20 files changed, 490 insertions(+), 454 deletions(-) create mode 100644 vmm/sandbox/src/bin/cloud_hypervisor/main.rs create mode 100644 vmm/sandbox/src/bin/qemu/main.rs create mode 100644 vmm/sandbox/src/bin/stratovirt/main.rs create mode 100644 vmm/sandbox/src/lib.rs delete mode 100644 vmm/sandbox/src/main.rs diff --git a/.gitignore b/.gitignore index 22cac7c7..a3e514ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .idea -bin +/bin .vscode target **/src/api/* diff --git a/Makefile b/Makefile index ffb78e64..a451c071 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,8 @@ SYSTEMD_CONF_DIR := /etc/sysconfig all: vmm quark wasm bin/vmm-sandboxer: - @cd vmm/sandbox && cargo build --release --features=${HYPERVISOR} - @mkdir -p bin && cp vmm/sandbox/target/release/vmm-sandboxer bin/vmm-sandboxer + @cd vmm/sandbox && cargo build --release --bin ${HYPERVISOR} + @mkdir -p bin && cp vmm/sandbox/target/release/${HYPERVISOR} bin/vmm-sandboxer bin/vmm-task: @cd vmm/task && cargo build --release --target=${ARCH}-unknown-linux-musl diff --git a/quark/Cargo.lock b/quark/Cargo.lock index 9a72e2dc..54fca43e 100644 --- a/quark/Cargo.lock +++ b/quark/Cargo.lock @@ -1057,9 +1057,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] diff --git a/vmm/sandbox/Cargo.lock b/vmm/sandbox/Cargo.lock index 4df24072..652fb584 100644 --- a/vmm/sandbox/Cargo.lock +++ b/vmm/sandbox/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" dependencies = [ "gimli", ] @@ -43,9 +43,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.71" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" dependencies = [ "backtrace", ] @@ -53,7 +53,7 @@ dependencies = [ [[package]] name = "api_client" version = "0.1.0" -source = "git+https://github.com/cloud-hypervisor/cloud-hypervisor.git#3f6833b315ec3c4a3a23376c5908944469c3b8c9" +source = "git+https://github.com/cloud-hypervisor/cloud-hypervisor.git#ecf3db5092059656ff2b06154801f2e5547a4a75" dependencies = [ "vmm-sys-util", ] @@ -77,18 +77,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] @@ -116,7 +116,7 @@ checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" dependencies = [ "async-trait", "axum-core", - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "futures-util", "http", @@ -155,15 +155,15 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.67" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", - "miniz_oxide 0.6.2", + "miniz_oxide", "object", "rustc-demangle", ] @@ -180,6 +180,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + [[package]] name = "bumpalo" version = "3.13.0" @@ -219,9 +225,12 @@ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -315,7 +324,7 @@ dependencies = [ "serde_derive", "serde_json", "thiserror", - "time 0.3.21", + "time 0.3.25", "tokio", "tokio-stream", "tonic", @@ -348,7 +357,7 @@ dependencies = [ "signal-hook", "signal-hook-tokio", "thiserror", - "time 0.3.21", + "time 0.3.25", "tokio", "uuid", ] @@ -420,6 +429,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "deranged" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" +dependencies = [ + "serde", +] + [[package]] name = "derive-new" version = "0.5.9" @@ -464,9 +482,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "env_logger" @@ -494,9 +512,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", @@ -515,12 +533,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" [[package]] name = "fixedbitset" @@ -541,7 +556,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" dependencies = [ "crc32fast", - "miniz_oxide 0.7.1", + "miniz_oxide", ] [[package]] @@ -606,7 +621,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] @@ -664,9 +679,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.2" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" [[package]] name = "go-flag" @@ -679,9 +694,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d357c7ae988e7d2182f7d7871d0b963962420b0678b0997ce7de72001aeab782" +checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" dependencies = [ "bytes 1.4.0", "fnv", @@ -728,18 +743,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "hex" @@ -771,9 +777,9 @@ dependencies = [ [[package]] name = "http-range-header" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" +checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" [[package]] name = "httparse" @@ -795,9 +801,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.26" +version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ "bytes 1.4.0", "futures-channel", @@ -831,9 +837,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -868,32 +874,12 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "io-lifetimes" version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.1", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "iovec" version = "0.1.4" @@ -914,15 +900,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.63" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ "wasm-bindgen", ] @@ -935,9 +921,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.146" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "linux-raw-sys" @@ -947,9 +933,9 @@ checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" [[package]] name = "linux-raw-sys" -version = "0.3.8" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" @@ -963,9 +949,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.18" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "matchit" @@ -1003,15 +989,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "miniz_oxide" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -1040,24 +1017,23 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "netlink-packet-core" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e5cf0b54effda4b91615c40ff0fd12d0d4c9a6e0f5116874f03941792ff535a" +checksum = "72724faf704479d67b388da142b186f916188505e7e0b26719019c525882eda4" dependencies = [ "anyhow", "byteorder", - "libc", "netlink-packet-utils", ] [[package]] name = "netlink-packet-route" -version = "0.15.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea993e32c77d87f01236c38f572ecb6c311d592e56a06262a007fd2a6e31253c" +checksum = "f6de2fe935f44cbdfcab77dce2150d68eda75be715cd42d4d6f52b0bd4dcc5b1" dependencies = [ "anyhow", - "bitflags", + "bitflags 1.3.2", "byteorder", "libc", "netlink-packet-core", @@ -1078,9 +1054,9 @@ dependencies = [ [[package]] name = "netlink-proto" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26305d12193227ef7b8227e7d61ae4eaf174607f79bd8eeceff07aacaefde497" +checksum = "842c6770fc4bb33dd902f41829c61ef872b8e38de1405aa0b938b27b8fba12c3" dependencies = [ "bytes 1.4.0", "futures", @@ -1110,7 +1086,7 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -1122,7 +1098,7 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -1135,7 +1111,7 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", @@ -1148,7 +1124,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", "memoffset 0.6.5", @@ -1161,7 +1137,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ "autocfg", - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", "memoffset 0.6.5", @@ -1174,7 +1150,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "libc", "memoffset 0.7.1", @@ -1184,28 +1160,28 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.2", "libc", ] [[package]] name = "object" -version = "0.30.4" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" dependencies = [ "memchr", ] @@ -1274,9 +1250,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "percent-encoding" @@ -1306,29 +1282,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead" +checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" +checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" [[package]] name = "pin-utils" @@ -1349,7 +1325,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "059a34f111a9dee2ce1ac2826a68b24601c4298cfeb1a587c3cb493d5ab46f52" dependencies = [ "libc", - "nix 0.20.0", + "nix 0.26.2", ] [[package]] @@ -1388,9 +1364,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.59" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -1401,13 +1377,13 @@ version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b4030746dfb40582518bebdc6303faef2bedfe787bac3786458bcdcc923b4e8" dependencies = [ - "bitflags", + "bitflags 1.3.2", "byteorder", "chrono", "flate2", "hex", "lazy_static", - "rustix 0.35.13", + "rustix 0.35.14", ] [[package]] @@ -1643,9 +1619,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.28" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -1686,14 +1662,26 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "regex" -version = "1.8.4" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" dependencies = [ "aho-corasick", "memchr", @@ -1702,15 +1690,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "rtnetlink" -version = "0.12.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed7d42da676fdf7e470e2502717587dd1089d8b48d9d1b846dcc3c01072858cb" +checksum = "7a552eb82d19f38c3beed3f786bd23aa434ceb9ac43ab44419ca6d67a7e186c0" dependencies = [ "futures", "log", @@ -1732,13 +1720,13 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.35.13" +version = "0.35.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" +checksum = "6380889b07a03b5ecf1d44dc9ede6fd2145d84b502a2a9ca0b03c48e0cc3220f" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno 0.2.8", - "io-lifetimes 0.7.5", + "io-lifetimes", "libc", "linux-raw-sys 0.0.46", "windows-sys 0.42.0", @@ -1746,23 +1734,22 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.19" +version = "0.38.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" +checksum = "1ee020b1716f0a80e2ace9b03441a749e402e86712f15f16fe8a8f75afac732f" dependencies = [ - "bitflags", - "errno 0.3.1", - "io-lifetimes 1.0.11", + "bitflags 2.3.3", + "errno 0.3.2", "libc", - "linux-raw-sys 0.3.8", + "linux-raw-sys 0.4.5", "windows-sys 0.48.0", ] [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "sandbox-derive" @@ -1776,35 +1763,35 @@ dependencies = [ [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.163" +version = "1.0.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +checksum = "0ea67f183f058fe88a4e3ec6e2788e003840893b91bac4559cabedd00863b3ed" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.163" +version = "1.0.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +checksum = "24e744d7782b686ab3b73267ef05697159cc0e5abbed3f47f9933165e5219036" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ "itoa", "ryu", @@ -1813,9 +1800,9 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" dependencies = [ "libc", "signal-hook-registry", @@ -1853,9 +1840,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "socket2" @@ -1892,9 +1879,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.18" +version = "2.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" dependencies = [ "proc-macro2", "quote", @@ -1909,15 +1896,14 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "tempfile" -version = "3.6.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" dependencies = [ - "autocfg", "cfg-if 1.0.0", "fastrand", "redox_syscall", - "rustix 0.37.19", + "rustix 0.38.6", "windows-sys 0.48.0", ] @@ -1932,22 +1918,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] @@ -1963,10 +1949,11 @@ dependencies = [ [[package]] name = "time" -version = "0.3.21" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" dependencies = [ + "deranged", "serde", "time-core", "time-macros", @@ -1980,20 +1967,21 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" dependencies = [ "time-core", ] [[package]] name = "tokio" -version = "1.28.2" +version = "1.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", + "backtrace", "bytes 1.4.0", "libc", "mio", @@ -2024,7 +2012,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] @@ -2159,7 +2147,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" dependencies = [ - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "futures-core", "futures-util", @@ -2199,13 +2187,13 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", ] [[package]] @@ -2281,9 +2269,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "unicode-segmentation" @@ -2303,9 +2291,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.3.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ "getrandom", ] @@ -2353,6 +2341,7 @@ dependencies = [ "nix 0.26.2", "oci-spec", "os_pipe", + "proc-macro2", "procfs", "prost-types 0.10.1", "protobuf 3.2.0", @@ -2364,7 +2353,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "time 0.3.21", + "time 0.3.25", "tokio", "toml", "ttrpc", @@ -2379,7 +2368,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd64fe09d8e880e600c324e7d664760a17f56e9672b7495a86381b49e4f72f46" dependencies = [ - "bitflags", + "bitflags 1.3.2", "libc", ] @@ -2395,11 +2384,10 @@ dependencies = [ [[package]] name = "want" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "log", "try-lock", ] @@ -2417,9 +2405,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2427,24 +2415,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2452,22 +2440,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.28", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "which" @@ -2546,9 +2534,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ "windows_aarch64_gnullvm 0.48.0", "windows_aarch64_msvc 0.48.0", diff --git a/vmm/sandbox/Cargo.toml b/vmm/sandbox/Cargo.toml index e5d450d5..ab0c208b 100644 --- a/vmm/sandbox/Cargo.toml +++ b/vmm/sandbox/Cargo.toml @@ -7,12 +7,6 @@ edition = "2021" [profile.release] panic = 'abort' -[features] -default = [] -qemu = ["qapi/qmp", "qapi/async-tokio-all", "unshare", "os_pipe"] -cloud_hypervisor = ["api_client"] -stratovirt = ["qapi/qmp", "qapi/async-tokio-all", "unshare", "os_pipe"] - [dependencies] tokio = { version = "1.19.2", features = ["full"] } containerd-sandbox = {git="https://github.com/kuasar-io/rust-extensions.git"} @@ -36,15 +30,28 @@ prost-types = "0.10.1" time = "0.3.5" log = { version = "0.4.17", features = ["std"] } uuid = { version = "1.1.2", features = ["v4"] } -unshare = { version = "0.7.0", optional = true } -os_pipe = { version = "0.9.2", optional = true } -qapi = { version = "0.8.0", features = ["qmp", "async-tokio-all"], optional = true } +unshare = { version = "0.7.0" } +os_pipe = { version = "0.9.2" } +qapi = { version = "0.8.0", features = ["qmp", "async-tokio-all"] } qapi-spec = {version = "0.3.1"} sandbox-derive = { path = "derive" } -api_client = { git = "https://github.com/cloud-hypervisor/cloud-hypervisor.git", optional = true } -rtnetlink = "0.12" -netlink-packet-route = "0.15" -netlink-packet-core = "0.5.0" +api_client = { git = "https://github.com/cloud-hypervisor/cloud-hypervisor.git" } +rtnetlink = "0.13.1" +netlink-packet-route = "0.17.0" +netlink-packet-core = "0.7.0" ttrpc = { version = "0.7", features = ["async"] } protobuf = "3.2" cgroups-rs = "0.3.2" +proc-macro2 = "1.0.66" + +[[bin]] +name = "qemu" +path = "src/bin/qemu/main.rs" + +[[bin]] +name = "cloud_hypervisor" +path = "src/bin/cloud_hypervisor/main.rs" + +[[bin]] +name = "stratovirt" +path = "src/bin/stratovirt/main.rs" diff --git a/vmm/sandbox/src/bin/cloud_hypervisor/main.rs b/vmm/sandbox/src/bin/cloud_hypervisor/main.rs new file mode 100644 index 00000000..38f23476 --- /dev/null +++ b/vmm/sandbox/src/bin/cloud_hypervisor/main.rs @@ -0,0 +1,33 @@ +/* +Copyright 2022 The Kuasar Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +use vmm_sandboxer::{cloud_hypervisor::init_cloud_hypervisor_sandboxer, utils::init_logger}; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + // Initialize sandboxer + let sandboxer = init_cloud_hypervisor_sandboxer().await?; + + // Initialize log + init_logger(sandboxer.log_level()); + + // Run the sandboxer + containerd_sandbox::run("kuasar-sandboxer", sandboxer) + .await + .unwrap(); + + Ok(()) +} diff --git a/vmm/sandbox/src/bin/qemu/main.rs b/vmm/sandbox/src/bin/qemu/main.rs new file mode 100644 index 00000000..f910b7f0 --- /dev/null +++ b/vmm/sandbox/src/bin/qemu/main.rs @@ -0,0 +1,33 @@ +/* +Copyright 2022 The Kuasar Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +use vmm_sandboxer::{qemu::init_qemu_sandboxer, utils::init_logger}; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + // Initialize sandboxer + let sandboxer = init_qemu_sandboxer().await?; + + // Initialize log + init_logger(sandboxer.log_level()); + + // Run the sandboxer + containerd_sandbox::run("kuasar-sandboxer", sandboxer) + .await + .unwrap(); + + Ok(()) +} diff --git a/vmm/sandbox/src/bin/stratovirt/main.rs b/vmm/sandbox/src/bin/stratovirt/main.rs new file mode 100644 index 00000000..224f2587 --- /dev/null +++ b/vmm/sandbox/src/bin/stratovirt/main.rs @@ -0,0 +1,33 @@ +/* +Copyright 2022 The Kuasar Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +use vmm_sandboxer::{stratovirt::init_stratovirt_sandboxer, utils::init_logger}; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + // Initialize sandboxer + let sandboxer = init_stratovirt_sandboxer().await?; + + // Initialize log + init_logger(sandboxer.log_level()); + + // Run the sandboxer + containerd_sandbox::run("kuasar-sandboxer", sandboxer) + .await + .unwrap(); + + Ok(()) +} diff --git a/vmm/sandbox/src/cloud_hypervisor/mod.rs b/vmm/sandbox/src/cloud_hypervisor/mod.rs index 7223b764..2a8648fd 100644 --- a/vmm/sandbox/src/cloud_hypervisor/mod.rs +++ b/vmm/sandbox/src/cloud_hypervisor/mod.rs @@ -30,6 +30,7 @@ use tokio::{ }; use vmm_common::SHARED_DIR_SUFFIX; +use self::{factory::CloudHypervisorVMFactory, hooks::CloudHypervisorHooks}; use crate::{ cloud_hypervisor::{ client::ChClient, @@ -37,8 +38,9 @@ use crate::{ devices::{block::Disk, virtio_net::VirtioNetDevice, CloudHypervisorDevice}, }, device::{BusType, DeviceInfo}, - impl_recoverable, + impl_recoverable, load_config, param::ToCmdLineParams, + sandbox::KuasarSandboxer, utils::{read_std, set_cmd_fd, set_cmd_netns, wait_pid, write_file_atomic}, vm::{Pids, VcpuThreads, VM}, }; @@ -50,6 +52,7 @@ pub mod factory; pub mod hooks; const VCPU_PREFIX: &str = "vcpu"; +pub const CONFIG_CLH_PATH: &str = "/var/lib/kuasar/config_clh.toml"; #[derive(Default, Serialize, Deserialize)] pub struct CloudHypervisorVM { @@ -253,7 +256,7 @@ impl VM for CloudHypervisorVM { } async fn wait_channel(&self) -> Option> { - return self.wait_chan.clone(); + self.wait_chan.clone() } async fn vcpus(&self) -> Result { @@ -338,3 +341,15 @@ fn spawn_wait( } }) } + +pub async fn init_cloud_hypervisor_sandboxer( +) -> Result> { + let (config, persist_dir_path) = + load_config::(CONFIG_CLH_PATH).await?; + let hooks = CloudHypervisorHooks {}; + let mut s = KuasarSandboxer::new(config.sandbox, config.hypervisor, hooks); + if !persist_dir_path.is_empty() { + s.recover(&persist_dir_path).await?; + } + Ok(s) +} diff --git a/vmm/sandbox/src/kata_config.rs b/vmm/sandbox/src/kata_config.rs index 0f0e6f9d..892ea652 100644 --- a/vmm/sandbox/src/kata_config.rs +++ b/vmm/sandbox/src/kata_config.rs @@ -22,11 +22,9 @@ use lazy_static::lazy_static; use serde_derive::Deserialize; use tokio::sync::{RwLock, RwLockReadGuard}; -use crate::{sandbox::SandboxConfig, utils::read_file, vm::ShareFsType}; - -cfg_qemu! { - use crate::qemu::config::QemuVMConfig; -} +use crate::{ + qemu::config::QemuVMConfig, sandbox::SandboxConfig, utils::read_file, vm::ShareFsType, +}; lazy_static! { pub static ref CONFIG: RwLock = { @@ -215,7 +213,6 @@ impl KataConfig { } } -#[cfg(feature = "qemu")] impl Hypervisor { #[allow(clippy::field_reassign_with_default)] pub fn to_qemu_config(&self) -> Result { diff --git a/vmm/sandbox/src/lib.rs b/vmm/sandbox/src/lib.rs new file mode 100644 index 00000000..b2718479 --- /dev/null +++ b/vmm/sandbox/src/lib.rs @@ -0,0 +1,70 @@ +/* +Copyright 2022 The Kuasar Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +use serde::de::DeserializeOwned; + +use crate::{config::Config, sandbox::KuasarSandbox}; + +#[macro_use] +mod device; + +mod cgroup; +mod client; +mod container; +mod io; +mod network; +mod param; +mod storage; +mod vm; + +pub mod cloud_hypervisor; +pub mod config; +pub mod kata_config; +pub mod qemu; +pub mod sandbox; +pub mod stratovirt; +pub mod utils; + +pub const NAMESPACE_PID: &str = "pid"; +pub const NAMESPACE_NET: &str = "network"; +pub const NAMESPACE_MNT: &str = "mount"; +pub const NAMESPACE_CGROUP: &str = "cgroup"; + +async fn load_config( + default_config_path: &str, +) -> anyhow::Result<(Config, String)> { + let os_args: Vec<_> = std::env::args_os().collect(); + let mut config_path = default_config_path.to_string(); + let mut dir_path = String::new(); + for i in 0..os_args.len() { + if os_args[i].to_str().unwrap() == "--config" { + config_path = os_args[i + 1].to_str().unwrap().to_string() + } + if os_args[i].to_str().unwrap() == "--dir" { + dir_path = os_args[i + 1].to_str().unwrap().to_string(); + if !std::path::Path::new(&dir_path).exists() { + tokio::fs::create_dir_all(&dir_path).await.unwrap(); + } + } + } + let path = std::path::Path::new(&config_path); + let config: Config = if path.exists() { + Config::parse(path).await? + } else { + panic!("config file {} not exist", config_path); + }; + Ok((config, dir_path)) +} diff --git a/vmm/sandbox/src/main.rs b/vmm/sandbox/src/main.rs deleted file mode 100644 index 60d81d36..00000000 --- a/vmm/sandbox/src/main.rs +++ /dev/null @@ -1,208 +0,0 @@ -/* -Copyright 2022 The Kuasar Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -use std::{path::Path, str::FromStr}; - -use serde::de::DeserializeOwned; - -use crate::{ - config::Config, - kata_config::KataConfig, - sandbox::{KuasarSandbox, KuasarSandboxer}, -}; - -macro_rules! cfg_qemu { - ($($item:item)*) => { - $( - #[cfg(feature = "qemu")] - #[cfg_attr(docsrs, doc(cfg(feature = "qemu")))] - $item - )* - } -} - -macro_rules! cfg_cloud_hypervisor { - ($($item:item)*) => { - $( - #[cfg(feature = "cloud_hypervisor")] - #[cfg_attr(docsrs, doc(cfg(feature = "cloud_hypervisor")))] - $item - )* - } -} - -macro_rules! cfg_stratovirt { - ($($item:item)*) => { - $( - #[cfg(feature = "stratovirt")] - #[cfg_attr(docsrs, doc(cfg(feature = "stratovirt")))] - $item - )* - } -} - -cfg_qemu! { - use crate::qemu::factory::QemuVMFactory; - use crate::qemu::hooks::QemuHooks; -} - -cfg_cloud_hypervisor! { - use crate::cloud_hypervisor::config::CloudHypervisorVMConfig; - use crate::cloud_hypervisor::factory::CloudHypervisorVMFactory; - use crate::cloud_hypervisor::hooks::CloudHypervisorHooks; -} - -cfg_stratovirt! { - use crate::stratovirt::config::StratoVirtVMConfig; - use crate::stratovirt::factory::StratoVirtVMFactory; - use crate::stratovirt::hooks::StratoVirtHooks; -} - -#[macro_use] -mod device; - -mod cgroup; -mod container; -mod io; -mod kata_config; -mod network; -mod sandbox; -mod storage; -mod utils; -mod vm; - -#[cfg(feature = "qemu")] -mod qemu; - -#[cfg(feature = "stratovirt")] -mod stratovirt; - -mod client; -#[cfg(feature = "cloud_hypervisor")] -mod cloud_hypervisor; -mod config; -mod param; - -pub const NAMESPACE_PID: &str = "pid"; -pub const NAMESPACE_NET: &str = "network"; -pub const NAMESPACE_MNT: &str = "mount"; -pub const NAMESPACE_CGROUP: &str = "cgroup"; - -pub const FS_SHARE_PATH: &str = "shared_fs"; - -pub const CONFIG_STRATOVIRT_PATH: &str = "/var/lib/kuasar/config_stratovirt.toml"; -pub const CONFIG_CLH_PATH: &str = "/var/lib/kuasar/config_clh.toml"; - -#[tokio::main] -async fn main() -> anyhow::Result<()> { - let mut builder = env_logger::Builder::from_default_env(); - builder.format_timestamp_micros(); - - #[cfg(feature = "qemu")] - #[allow(unused_variables)] - let sandboxer: KuasarSandboxer = { - // for compatible of kata config - let config_path = std::env::var("KATA_CONFIG_PATH").unwrap_or_else(|_| { - "/usr/share/defaults/kata-containers/configuration.toml".to_string() - }); - let path = Path::new(&config_path); - if path.exists() { - KataConfig::init(path).await.unwrap(); - } - let vmm_config = KataConfig::hypervisor_config("qemu", |h| h.clone()).await?; - let vmm_config = vmm_config.to_qemu_config()?; - let sandbox_config = KataConfig::sandbox_config("qemu").await?; - let hooks = QemuHooks::new(vmm_config.clone()); - let mut s = KuasarSandboxer::new(sandbox_config, vmm_config, hooks); - - let os_args: Vec<_> = std::env::args_os().collect(); - for i in 0..os_args.len() { - if os_args[i].to_str().unwrap() == "--dir" { - let persist_dir_path = os_args[i + 1].to_str().unwrap().to_string(); - if Path::new(&persist_dir_path).exists() { - s.recover(&persist_dir_path).await.unwrap(); - } - } - } - s - }; - - #[cfg(feature = "stratovirt")] - #[allow(unused_variables)] - let sandboxer: KuasarSandboxer = { - let (config, persist_dir_path) = - load_config::(CONFIG_STRATOVIRT_PATH).await?; - let hooks = StratoVirtHooks::new(config.hypervisor.clone()); - let mut s = KuasarSandboxer::new(config.sandbox, config.hypervisor, hooks); - if !persist_dir_path.is_empty() { - s.recover(&persist_dir_path).await.unwrap(); - } - s - }; - - #[cfg(feature = "cloud_hypervisor")] - #[allow(unused_variables)] - let sandboxer: KuasarSandboxer = { - let (config, persist_dir_path) = - load_config::(CONFIG_CLH_PATH).await?; - let hooks = CloudHypervisorHooks {}; - let mut s = KuasarSandboxer::new(config.sandbox, config.hypervisor, hooks); - if !persist_dir_path.is_empty() { - s.recover(&persist_dir_path).await.unwrap(); - } - s - }; - - // If 'log_level' field isn't set in the config file, keep the log level from the default env - // Otherwise, set the log level configured in the config file - if !sandboxer.log_level().is_empty() { - let log_level = log::LevelFilter::from_str(sandboxer.log_level())?; - builder.filter_level(log_level); - } - builder.init(); - - #[cfg(any(feature = "cloud_hypervisor", feature = "qemu", feature = "stratovirt"))] - containerd_sandbox::run("kuasar-sandboxer", sandboxer) - .await - .unwrap(); - Ok(()) -} - -async fn load_config( - default_config_path: &str, -) -> anyhow::Result<(Config, String)> { - let os_args: Vec<_> = std::env::args_os().collect(); - let mut config_path = default_config_path.to_string(); - let mut dir_path = String::new(); - for i in 0..os_args.len() { - if os_args[i].to_str().unwrap() == "--config" { - config_path = os_args[i + 1].to_str().unwrap().to_string() - } - if os_args[i].to_str().unwrap() == "--dir" { - dir_path = os_args[i + 1].to_str().unwrap().to_string(); - if !Path::new(&dir_path).exists() { - tokio::fs::create_dir_all(&dir_path).await.unwrap(); - } - } - } - let path = Path::new(&config_path); - let config: Config = if path.exists() { - Config::parse(path).await? - } else { - panic!("config file {} not exist", config_path); - }; - Ok((config, dir_path)) -} diff --git a/vmm/sandbox/src/param.rs b/vmm/sandbox/src/param.rs index 19efbac2..efa93196 100644 --- a/vmm/sandbox/src/param.rs +++ b/vmm/sandbox/src/param.rs @@ -41,6 +41,13 @@ impl Property { } } +// visit: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default +impl Default for Property { + fn default() -> Self { + Self::new() + } +} + impl Param { pub fn new(name: &str) -> Param { Param { diff --git a/vmm/sandbox/src/qemu/hooks.rs b/vmm/sandbox/src/qemu/hooks.rs index 9f296726..2e53b604 100644 --- a/vmm/sandbox/src/qemu/hooks.rs +++ b/vmm/sandbox/src/qemu/hooks.rs @@ -51,7 +51,7 @@ impl Hooks for QemuHooks { } } -async fn process_annotation(_sandbox: &mut KuasarSandbox) -> Result<()> { +async fn process_annotation(_sandbox: &KuasarSandbox) -> Result<()> { Ok(()) } diff --git a/vmm/sandbox/src/qemu/mod.rs b/vmm/sandbox/src/qemu/mod.rs index c42eb77e..ddcf58a9 100644 --- a/vmm/sandbox/src/qemu/mod.rs +++ b/vmm/sandbox/src/qemu/mod.rs @@ -37,9 +37,11 @@ use tokio::{ }; use unshare::Fd; +use self::{factory::QemuVMFactory, hooks::QemuHooks}; use crate::{ device::{BusType, DeviceInfo, SlotStatus, Transport}, impl_recoverable, + kata_config::KataConfig, param::ToCmdLineParams, qemu::{ config::QemuConfig, @@ -54,6 +56,7 @@ use crate::{ qmp_client::QmpClient, utils::detect_pid, }, + sandbox::KuasarSandboxer, utils::{read_std, wait_channel, wait_pid}, vm::{BlockDriver, Pids, VcpuThreads, VM}, }; @@ -212,7 +215,7 @@ impl VM for QemuVM { } async fn hot_attach(&mut self, device_info: DeviceInfo) -> Result<(BusType, String)> { - return match device_info { + match device_info { DeviceInfo::Block(blk_info) => { let device = VirtioBlockDevice::new( "", @@ -259,7 +262,7 @@ impl VM for QemuVM { // address is not import for char devices as guest will find the device by the name Ok((BusType::PCI, char_info.name.clone())) } - }; + } } async fn hot_detach(&mut self, id: &str) -> Result<()> { @@ -300,7 +303,7 @@ impl VM for QemuVM { } async fn wait_channel(&self) -> Option> { - return self.wait_chan.clone(); + self.wait_chan.clone() } async fn vcpus(&self) -> Result { @@ -529,3 +532,33 @@ impl QemuVM { } impl_recoverable!(QemuVM); + +pub async fn init_qemu_sandboxer() -> Result> { + // For compatibility with kata config + let config_path = std::env::var("KATA_CONFIG_PATH") + .unwrap_or_else(|_| "/usr/share/defaults/kata-containers/configuration.toml".to_string()); + + let path = std::path::Path::new(&config_path); + if path.exists() { + KataConfig::init(path).await?; + } + + let vmm_config = KataConfig::hypervisor_config("qemu", |h| h.clone()).await?; + let vmm_config = vmm_config.to_qemu_config()?; + let sandbox_config = KataConfig::sandbox_config("qemu").await?; + let hooks = QemuHooks::new(vmm_config.clone()); + let mut s = KuasarSandboxer::new(sandbox_config, vmm_config, hooks); + + // Check for "--dir" argument and recover from persisted directory + let os_args: Vec<_> = std::env::args_os().collect(); + for i in 0..os_args.len() { + if os_args[i].to_str().unwrap() == "--dir" { + let persist_dir_path = os_args[i + 1].to_str().unwrap().to_string(); + if std::path::Path::new(&persist_dir_path).exists() { + s.recover(&persist_dir_path).await?; + } + } + } + + Ok(s) +} diff --git a/vmm/sandbox/src/sandbox.rs b/vmm/sandbox/src/sandbox.rs index 4ee69de8..b4209080 100644 --- a/vmm/sandbox/src/sandbox.rs +++ b/vmm/sandbox/src/sandbox.rs @@ -284,13 +284,13 @@ where } async fn sandbox(&self, id: &str) -> Result>> { - return Ok(self + Ok(self .sandboxes .read() .await .get(id) .ok_or_else(|| Error::NotFound(id.to_string()))? - .clone()); + .clone()) } async fn stop(&self, id: &str, force: bool) -> Result<()> { @@ -384,7 +384,7 @@ where } async fn exit_signal(&self) -> Result> { - return Ok(self.exit_signal.clone()); + Ok(self.exit_signal.clone()) } fn get_data(&self) -> Result { diff --git a/vmm/sandbox/src/stratovirt/mod.rs b/vmm/sandbox/src/stratovirt/mod.rs index b91fd182..65e065fd 100644 --- a/vmm/sandbox/src/stratovirt/mod.rs +++ b/vmm/sandbox/src/stratovirt/mod.rs @@ -38,11 +38,17 @@ use tokio::{ }; use unshare::Fd; -use self::devices::{pcie_rootbus::PcieRootBus, rootport::RootPort, PCIE_ROOTBUS_CAPACITY}; +use self::{ + config::StratoVirtVMConfig, + devices::{pcie_rootbus::PcieRootBus, rootport::RootPort, PCIE_ROOTBUS_CAPACITY}, + factory::StratoVirtVMFactory, + hooks::StratoVirtHooks, +}; use crate::{ device::{Bus, BusType, DeviceInfo, Slot, SlotStatus, Transport}, - impl_recoverable, + impl_recoverable, load_config, param::ToCmdLineParams, + sandbox::KuasarSandboxer, stratovirt::{ config::StratoVirtConfig, devices::{ @@ -67,6 +73,7 @@ mod utils; mod virtiofs; pub(crate) const STRATOVIRT_START_TIMEOUT_IN_SEC: u64 = 10; +pub const CONFIG_STRATOVIRT_PATH: &str = "/var/lib/kuasar/config_stratovirt.toml"; // restart recovery is not supported yet, // so we annotate the StratoVirtVM with Serialize and Deserlize, @@ -209,7 +216,7 @@ impl VM for StratoVirtVM { } async fn hot_attach(&mut self, device_info: DeviceInfo) -> Result<(BusType, String)> { - return match device_info { + match device_info { DeviceInfo::Block(blk_info) => { let device = VirtioBlockDevice::new( "", @@ -234,7 +241,7 @@ impl VM for StratoVirtVM { DeviceInfo::Char(_char_info) => Err(Error::Unimplemented( "hot attach for char device".to_string(), )), - }; + } } async fn hot_detach(&mut self, _id: &str) -> Result<()> { @@ -252,7 +259,7 @@ impl VM for StratoVirtVM { } async fn wait_channel(&self) -> Option> { - return self.wait_chan.clone(); + self.wait_chan.clone() } async fn vcpus(&self) -> Result { @@ -534,3 +541,15 @@ impl StratoVirtVM { } impl_recoverable!(StratoVirtVM); + +pub async fn init_stratovirt_sandboxer( +) -> Result> { + let (config, persist_dir_path) = + load_config::(CONFIG_STRATOVIRT_PATH).await?; + let hooks = StratoVirtHooks::new(config.hypervisor.clone()); + let mut s = KuasarSandboxer::new(config.sandbox, config.hypervisor, hooks); + if !persist_dir_path.is_empty() { + s.recover(&persist_dir_path).await?; + } + Ok(s) +} diff --git a/vmm/sandbox/src/utils.rs b/vmm/sandbox/src/utils.rs index 4c998db3..a0303654 100644 --- a/vmm/sandbox/src/utils.rs +++ b/vmm/sandbox/src/utils.rs @@ -20,6 +20,7 @@ use std::{ prelude::{AsRawFd, FromRawFd, OwnedFd}, }, path::Path, + str::FromStr, time::Duration, }; @@ -472,3 +473,11 @@ pub fn get_sandbox_cgroup_parent_path(data: &SandboxData) -> Option { .and_then(|c| c.linux.as_ref()) .map(|l| l.cgroup_parent.clone()) } + +pub fn init_logger(level: &str) { + let log_level = log::LevelFilter::from_str(level).unwrap_or(log::LevelFilter::Info); + env_logger::Builder::from_default_env() + .format_timestamp_micros() + .filter_level(log_level) + .init(); +} diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index f2c98ecb..e5762771 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -1808,9 +1808,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] diff --git a/wasm/src/sandbox.rs b/wasm/src/sandbox.rs index 923d42cd..ddc13742 100644 --- a/wasm/src/sandbox.rs +++ b/wasm/src/sandbox.rs @@ -88,13 +88,13 @@ impl Sandboxer for WasmSandboxer { } async fn sandbox(&self, id: &str) -> Result>> { - return Ok(self + Ok(self .sandboxes .read() .await .get(id) .ok_or_else(|| Error::NotFound(id.to_string()))? - .clone()); + .clone()) } async fn stop(&self, id: &str, _force: bool) -> Result<()> { @@ -212,9 +212,9 @@ impl Sandbox for WasmSandbox { } async fn container(&self, id: &str) -> Result<&Self::Container> { - return self.containers.get(id).ok_or(Error::NotFound(format!( + self.containers.get(id).ok_or(Error::NotFound(format!( "failed to find container by id {id}" - ))); + ))) } async fn append_container(&mut self, id: &str, option: ContainerOption) -> Result<()> {