diff --git a/vmm/common/src/lib.rs b/vmm/common/src/lib.rs index 2b5ed4be..9df951d9 100644 --- a/vmm/common/src/lib.rs +++ b/vmm/common/src/lib.rs @@ -21,6 +21,7 @@ pub mod mount; pub mod storage; pub const KUASAR_STATE_DIR: &str = "/run/kuasar/state"; +pub const YOUKI_DIR: &str = "/run/kuasar/youki"; pub const IO_FILE_PREFIX: &str = "io"; pub const STORAGE_FILE_PREFIX: &str = "storage"; diff --git a/vmm/task/Cargo.lock b/vmm/task/Cargo.lock index 61ff1245..15b38853 100644 --- a/vmm/task/Cargo.lock +++ b/vmm/task/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "1.0.2" @@ -11,6 +17,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.71" @@ -36,7 +57,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] @@ -47,7 +68,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] @@ -75,7 +96,7 @@ checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" dependencies = [ "async-trait", "axum-core", - "bitflags", + "bitflags 1.3.2", "bytes 1.4.0", "futures-util", "http", @@ -124,6 +145,18 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "byteorder" version = "1.4.3" @@ -146,6 +179,16 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "caps" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190baaad529bcfbde9e1a19022c42781bdb6ff9de25721abdb8fd98c0807730b" +dependencies = [ + "libc", + "thiserror", +] + [[package]] name = "cc" version = "1.0.79" @@ -176,6 +219,19 @@ dependencies = [ "regex", ] +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets 0.48.0", +] + [[package]] name = "cmake" version = "0.1.50" @@ -208,7 +264,7 @@ dependencies = [ "libc", "log", "nix 0.23.2", - "oci-spec", + "oci-spec 0.5.8", "pin-project-lite", "prost 0.10.4", "prost-types 0.10.1", @@ -238,7 +294,7 @@ dependencies = [ "libc", "log", "nix 0.25.1", - "oci-spec", + "oci-spec 0.5.8", "page_size", "pin-project-lite", "prctl", @@ -265,6 +321,21 @@ dependencies = [ "ttrpc-codegen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "crossbeam" version = "0.8.2" @@ -384,7 +455,16 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3" dependencies = [ - "derive_builder_macro", + "derive_builder_macro 0.11.2", +] + +[[package]] +name = "derive_builder" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" +dependencies = [ + "derive_builder_macro 0.12.0", ] [[package]] @@ -399,13 +479,35 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_builder_core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "derive_builder_macro" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68" dependencies = [ - "derive_builder_core", + "derive_builder_core 0.11.2", + "syn 1.0.109", +] + +[[package]] +name = "derive_builder_macro" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" +dependencies = [ + "derive_builder_core 0.12.0", "syn 1.0.109", ] @@ -436,7 +538,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -458,6 +560,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fixedbitset" version = "0.2.0" @@ -470,6 +578,16 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -516,6 +634,7 @@ dependencies = [ "futures-core", "futures-task", "futures-util", + "num_cpus", ] [[package]] @@ -532,7 +651,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] @@ -661,6 +780,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "http" version = "0.2.9" @@ -743,6 +868,29 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "iana-time-zone" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -776,7 +924,7 @@ checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi 0.3.1", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -812,6 +960,15 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -820,9 +977,55 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.146" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" + +[[package]] +name = "libcgroups" +version = "0.3.0" +source = "git+https://github.com/containers/youki.git#5b6e5b1e14e4e45a83ab2ea1effc0664606aaa2b" +dependencies = [ + "fixedbitset 0.4.2", + "nix 0.27.1", + "oci-spec 0.6.3", + "procfs", + "serde", + "thiserror", + "tracing", +] + +[[package]] +name = "libcontainer" +version = "0.3.0" +source = "git+https://github.com/containers/youki.git#5b6e5b1e14e4e45a83ab2ea1effc0664606aaa2b" +dependencies = [ + "bitflags 2.4.1", + "caps", + "chrono", + "fastrand 2.0.1", + "futures", + "libc", + "libcgroups", + "nix 0.27.1", + "oci-spec 0.6.3", + "once_cell", + "prctl", + "procfs", + "regex", + "rust-criu", + "safe-path", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "linux-raw-sys" @@ -854,9 +1057,9 @@ checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memoffset" @@ -869,18 +1072,18 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" dependencies = [ "autocfg", ] [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" dependencies = [ "autocfg", ] @@ -891,6 +1094,15 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.8" @@ -899,7 +1111,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -927,7 +1139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea993e32c77d87f01236c38f572ecb6c311d592e56a06262a007fd2a6e31253c" dependencies = [ "anyhow", - "bitflags", + "bitflags 1.3.2", "byteorder", "libc", "netlink-packet-core", @@ -992,7 +1204,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", @@ -1005,7 +1217,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", @@ -1018,7 +1230,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", @@ -1031,7 +1243,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", @@ -1044,14 +1256,33 @@ 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", - "pin-utils", "static_assertions", ] +[[package]] +name = "nix" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.4.1", + "cfg-if 1.0.0", + "libc", + "memoffset 0.9.0", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.15.0" @@ -1063,21 +1294,25 @@ dependencies = [ ] [[package]] -name = "num_threads" -version = "0.1.6" +name = "oci-spec" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +checksum = "98135224dd4faeb24c05a2fac911ed53ea6b09ecb09d7cada1cb79963ab2ee34" dependencies = [ - "libc", + "derive_builder 0.11.2", + "getset", + "serde", + "serde_json", + "thiserror", ] [[package]] name = "oci-spec" -version = "0.5.8" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98135224dd4faeb24c05a2fac911ed53ea6b09ecb09d7cada1cb79963ab2ee34" +checksum = "95e7c5a234613dd98d240891270925718736701c2dbce9c5587567133cf8220f" dependencies = [ - "derive_builder", + "derive_builder 0.12.0", "getset", "serde", "serde_json", @@ -1097,7 +1332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ae859aa07428ca9a929b936690f8b12dc5f11dd8c6992a18ca93919f28bc177" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1130,7 +1365,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.48.0", ] [[package]] @@ -1200,7 +1435,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] @@ -1228,7 +1463,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "059a34f111a9dee2ce1ac2826a68b24601c4298cfeb1a587c3cb493d5ab46f52" dependencies = [ "libc", - "nix 0.26.2", + "nix 0.27.1", ] [[package]] @@ -1267,13 +1502,28 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.59" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] +[[package]] +name = "procfs" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943ca7f9f29bab5844ecd8fdb3992c5969b6622bb9609b9502fef9b4310e3f1f" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "chrono", + "flate2", + "hex", + "lazy_static", + "rustix 0.36.16", +] + [[package]] name = "prost" version = "0.8.0" @@ -1448,9 +1698,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.28" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -1491,14 +1741,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.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -1507,9 +1769,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rtnetlink" @@ -1539,7 +1801,7 @@ dependencies = [ "libc", "log", "nix 0.25.1", - "oci-spec", + "oci-spec 0.5.8", "os_pipe", "path-absolutize", "rand", @@ -1553,18 +1815,44 @@ dependencies = [ "uuid", ] +[[package]] +name = "rust-criu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4737b28406b3395359f485127073117a11cedc8942738b69ba6ab9a79432acbc" +dependencies = [ + "anyhow", + "libc", + "protobuf 3.2.0", + "protobuf-codegen 3.2.0", +] + +[[package]] +name = "rustix" +version = "0.36.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6da3636faa25820d8648e0e31c5d519bbb01f72fdf57131f0f5f7da5fed36eab" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.45.0", +] + [[package]] name = "rustix" version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", - "linux-raw-sys", - "windows-sys", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", ] [[package]] @@ -1573,6 +1861,15 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +[[package]] +name = "safe-path" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "980abdd3220aa19b67ca3ea07b173ca36383f18ae48cde696d90c8af39447ffb" +dependencies = [ + "libc", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -1596,7 +1893,7 @@ checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] @@ -1691,9 +1988,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.18" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -1714,10 +2011,10 @@ checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" dependencies = [ "autocfg", "cfg-if 1.0.0", - "fastrand", + "fastrand 1.9.0", "redox_syscall", - "rustix", - "windows-sys", + "rustix 0.37.19", + "windows-sys 0.48.0", ] [[package]] @@ -1731,33 +2028,48 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] name = "time" -version = "0.3.7" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "004cbc98f30fa233c61a38bc77e96a9106e65c88f2d3bef182ae952027e5753d" +checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" dependencies = [ - "libc", - "num_threads", "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + +[[package]] +name = "time-macros" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" +dependencies = [ + "time-core", ] [[package]] @@ -1776,7 +2088,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1797,7 +2109,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] @@ -1919,7 +2231,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", @@ -1946,11 +2258,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if 1.0.0", "log", "pin-project-lite", "tracing-attributes", @@ -1959,20 +2270,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.24" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.38", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] @@ -2095,12 +2406,13 @@ dependencies = [ "ipnetwork", "lazy_static", "libc", + "libcontainer", "log", "netlink-packet-core", "netlink-packet-route", "netlink-sys 0.7.0", "nix 0.25.1", - "oci-spec", + "oci-spec 0.5.8", "pin-project-lite", "rtnetlink", "runc", @@ -2140,6 +2452,60 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.38", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + [[package]] name = "which" version = "4.4.0" @@ -2182,13 +2548,46 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af6041b3f84485c21b57acdc0fee4f4f0c93f426053dc05fa5d6fc262537bbff" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", ] [[package]] @@ -2197,51 +2596,93 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.0" diff --git a/vmm/task/Cargo.toml b/vmm/task/Cargo.toml index 943290df..241cbffb 100644 --- a/vmm/task/Cargo.toml +++ b/vmm/task/Cargo.toml @@ -12,7 +12,7 @@ vmm-common = {path = "../common"} log = "0.4" nix = "0.25" libc = "0.2.95" -time = { version = "=0.3.7", features = ["serde", "std"] } +time = { version = "=0.3.23", features = ["serde", "std"] } serde = { version = "1.0.133", features = ["derive"] } serde_json = "1.0.74" oci-spec = "0.5.4" @@ -36,3 +36,4 @@ ttrpc = { version = "0.7", features = ["async"] } containerd-shim = { git="https://github.com/kuasar-io/rust-extensions.git", features=["async"] } runc = { git="https://github.com/kuasar-io/rust-extensions.git", features=["async"] } +libcontainer = { git="https://github.com/containers/youki.git", version="0.3.0", default-features = false, features=["v1"]} diff --git a/vmm/task/src/container.rs b/vmm/task/src/container.rs index 8ac89465..0c745c74 100644 --- a/vmm/task/src/container.rs +++ b/vmm/task/src/container.rs @@ -15,7 +15,11 @@ limitations under the License. */ use std::{ - convert::TryFrom, os::unix::prelude::ExitStatusExt, path::Path, process::ExitStatus, sync::Arc, + convert::TryFrom, + os::unix::prelude::ExitStatusExt, + path::{Path, PathBuf}, + process::ExitStatus, + sync::Arc, }; use async_trait::async_trait; @@ -41,18 +45,22 @@ use containerd_shim::{ util::read_spec, ExitSignal, }; +use libcontainer::{ + container::{builder::ContainerBuilder, Container}, + signal::Signal, + syscall::syscall::SyscallType, +}; use log::{debug, error}; use nix::{sys::signalfd::signal::kill, unistd::Pid}; use oci_spec::runtime::{LinuxResources, Process, Spec}; -use runc::{options::GlobalOpts, Runc, Spawner}; +use runc::Spawner; use serde::Deserialize; use tokio::{ - fs::File, - io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, BufReader}, + io::{AsyncRead, AsyncReadExt}, process::Command, sync::Mutex, }; -use vmm_common::{mount::get_mount_type, storage::Storage, KUASAR_STATE_DIR}; +use vmm_common::{mount::get_mount_type, storage::Storage, KUASAR_STATE_DIR, YOUKI_DIR}; use crate::{ device::rescan_pci_bus, @@ -81,14 +89,12 @@ pub(crate) struct KuasarFactory { } pub struct KuasarExecFactory { - runtime: Runc, bundle: String, io_uid: u32, io_gid: u32, } pub struct KuasarExecLifecycle { - runtime: Runc, bundle: String, container_id: String, io_uid: u32, @@ -98,7 +104,6 @@ pub struct KuasarExecLifecycle { } pub struct KuasarInitLifecycle { - runtime: Runc, opts: Options, bundle: String, exit_signal: Arc, @@ -114,7 +119,7 @@ pub struct Log { impl ContainerFactory for KuasarFactory { async fn create( &self, - ns: &str, + _ns: &str, req: &CreateTaskRequest, ) -> containerd_shim::Result { rescan_pci_bus().await?; @@ -139,18 +144,9 @@ impl ContainerFactory for KuasarFactory { if opts.compute_size() > 0 { debug!("create options: {:?}", &opts); } - let runtime = opts.binary_name.as_str(); // As the rootfs is already mounted when handling the storage, the root in spec is one of the // storage mount point. so no need to mount rootfs anymore - let runc = create_runc( - runtime, - ns, - &bundle, - &opts, - Some(Arc::new(ShimExecutor::default())), - )?; - let id = req.id(); let stdio = match read_io(&bundle, req.id(), None).await { @@ -162,11 +158,7 @@ impl ContainerFactory for KuasarFactory { // that needs to be converted to the serial file path let stdio = convert_stdio(&stdio).await?; - let mut init = InitProcess::new( - id, - stdio, - KuasarInitLifecycle::new(runc.clone(), opts.clone(), &bundle), - ); + let mut init = InitProcess::new(id, stdio, KuasarInitLifecycle::new(opts.clone(), &bundle)); self.do_create(&mut init).await?; let container = KuasarContainer { @@ -174,7 +166,6 @@ impl ContainerFactory for KuasarFactory { bundle: bundle.to_string(), init, process_factory: KuasarExecFactory { - runtime: runc, bundle: bundle.to_string(), io_uid: opts.io_uid, io_gid: opts.io_gid, @@ -201,41 +192,45 @@ impl KuasarFactory { let opts = &init.lifecycle.opts; let bundle = &init.lifecycle.bundle; let pid_path = Path::new(bundle).join(INIT_PID_FILE); - let mut no_pivot_root = opts.no_pivot_root; + let mut _no_pivot_root = opts.no_pivot_root; // pivot_root could not work with initramfs + // TODO youki not support no_pivot_root yet match get_mount_type("/") { Ok(m_type) => { if m_type == *"rootfs" { - no_pivot_root = true; + _no_pivot_root = true; } } Err(e) => debug!("get mount type failed {}", e), }; - let mut create_opts = runc::options::CreateOpts::new() - .pid_file(&pid_path) - .no_pivot(no_pivot_root) - .no_new_keyring(opts.no_new_keyring) - .detach(false); + let mut socket_path = PathBuf::new(); let (socket, pio) = if stdio.terminal { let s = ConsoleSocket::new().await?; - create_opts.console_socket = Some(s.path.to_owned()); + socket_path = s.path.to_owned(); (Some(s), None) } else { let pio = create_io(&id, opts.io_uid, opts.io_gid, stdio)?; - create_opts.io = pio.io.as_ref().cloned(); (None, Some(pio)) }; - - let resp = init - .lifecycle - .runtime - .create(&id, bundle, Some(&create_opts)) - .await; + let resp = ContainerBuilder::new(id.to_string(), SyscallType::default()) + .with_pid_file(Some(pid_path.clone())) + .map_err(other_error!(e, "failed to set youki create pid file"))? + .with_console_socket(Some(socket_path)) + .with_root_path(PathBuf::from(YOUKI_DIR)) + .map_err(other_error!(e, "failed to set youki create root path"))? + .as_init(bundle) + .with_systemd(false) + .with_detach(false) + .build(); if let Err(e) = resp { if let Some(s) = socket { s.clean().await; } - return Err(runtime_error(bundle, e, "OCI runtime create failed").await); + return Err(other!( + "youki create container {} failed {}", + id.to_string(), + e + )); } copy_io_or_console(init, socket, pio, init.lifecycle.exit_signal.clone()).await?; let pid = read_file_to_str(pid_path).await?.parse::()?; @@ -244,33 +239,6 @@ impl KuasarFactory { } } -// runtime_error will read the OCI runtime logfile retrieving OCI runtime error -pub async fn runtime_error(bundle: &str, e: runc::error::Error, msg: &str) -> Error { - let mut rt_msg = String::new(); - match File::open(Path::new(bundle).join("log.json")).await { - Err(err) => other!("{}: unable to open OCI runtime log file){}", msg, err), - Ok(file) => { - let mut lines = BufReader::new(file).lines(); - while let Ok(Some(line)) = lines.next_line().await { - // Retrieve the last runtime error - match serde_json::from_str::(&line) { - Err(err) => return other!("{}: unable to parse log msg: {}", msg, err), - Ok(log) => { - if log.level == "error" { - rt_msg = log.msg.trim().to_string(); - } - } - } - } - if !rt_msg.is_empty() { - other!("{}: {}", msg, rt_msg) - } else { - other!("{}: (no OCI runtime error in logfile) {}", msg, e) - } - } - } -} - #[async_trait] impl ProcessFactory for KuasarExecFactory { async fn create(&self, req: &ExecProcessRequest) -> Result { @@ -290,7 +258,6 @@ impl ProcessFactory for KuasarExecFactory { wait_chan_tx: vec![], console: None, lifecycle: Arc::from(KuasarExecLifecycle { - runtime: self.runtime.clone(), bundle: self.bundle.to_string(), container_id: req.id.to_string(), io_uid: self.io_uid, @@ -305,10 +272,12 @@ impl ProcessFactory for KuasarExecFactory { #[async_trait] impl ProcessLifecycle for KuasarInitLifecycle { async fn start(&self, p: &mut InitProcess) -> containerd_shim::Result<()> { - self.runtime - .start(p.id.as_str()) - .await - .map_err(other_error!(e, "failed start"))?; + let mut container = Container::load(PathBuf::from(YOUKI_DIR).join(p.id.as_str())) + .map_err(other_error!(e, "youki load container error"))?; + + container + .start() + .map_err(other_error!(e, "youki start container error"))?; p.state = Status::RUNNING; Ok(()) } @@ -319,23 +288,26 @@ impl ProcessLifecycle for KuasarInitLifecycle { signal: u32, all: bool, ) -> containerd_shim::Result<()> { - self.runtime - .kill( - p.id.as_str(), - signal, - Some(&runc::options::KillOpts { all }), - ) - .await + let mut container = Container::load(PathBuf::from(YOUKI_DIR).join(p.id.as_str())) + .map_err(other_error!(e, "youki load container error"))?; + + let kill_signal: Signal = + signal.to_string().as_str().try_into().map_err(|e| { + Error::Other(format!("kill signal {} transfer error: {}", signal, e)) + })?; + + container + .kill(kill_signal, all) + .map_err(other_error!(e, "youki kill container error")) .map_err(|e| check_kill_error(e.to_string())) } async fn delete(&self, p: &mut InitProcess) -> containerd_shim::Result<()> { - self.runtime - .delete( - p.id.as_str(), - Some(&runc::options::DeleteOpts { force: true }), - ) - .await + let mut container = Container::load(PathBuf::from(YOUKI_DIR).join(p.id.as_str())) + .map_err(other_error!(e, "youki load container error"))?; + + container + .delete(true) .or_else(|e| { if !e.to_string().to_lowercase().contains("does not exist") { Err(e) @@ -343,7 +315,7 @@ impl ProcessLifecycle for KuasarInitLifecycle { Ok(()) } }) - .map_err(other_error!(e, "failed delete"))?; + .map_err(other_error!(e, "youki delete container error"))?; self.exit_signal.signal(); Ok(()) } @@ -381,15 +353,14 @@ impl ProcessLifecycle for KuasarInitLifecycle { } async fn ps(&self, p: &InitProcess) -> Result> { - let pids = self - .runtime - .ps(&p.id) - .await - .map_err(other_error!(e, "failed to execute runc ps"))?; - Ok(pids + let container = Container::load(PathBuf::from(YOUKI_DIR).join(p.id.as_str())) + .map_err(other_error!(e, "youki load container error"))?; + + Ok(container + .pid() .iter() .map(|&x| ProcessInfo { - pid: x as u32, + pid: x.as_raw() as u32, ..Default::default() }) .collect()) @@ -397,14 +368,13 @@ impl ProcessLifecycle for KuasarInitLifecycle { } impl KuasarInitLifecycle { - pub fn new(runtime: Runc, opts: Options, bundle: &str) -> Self { + pub fn new(opts: Options, bundle: &str) -> Self { let work_dir = Path::new(bundle).join("work"); let mut opts = opts; if opts.criu_path().is_empty() { opts.criu_path = work_dir.to_string_lossy().to_string(); } Self { - runtime, opts, bundle: bundle.to_string(), exit_signal: Default::default(), @@ -417,32 +387,47 @@ impl ProcessLifecycle for KuasarExecLifecycle { async fn start(&self, p: &mut ExecProcess) -> containerd_shim::Result<()> { rescan_pci_bus().await?; let pid_path = Path::new(self.bundle.as_str()).join(format!("{}.pid", &p.id)); - let mut exec_opts = runc::options::ExecOpts { - io: None, - pid_file: Some(pid_path.to_owned()), - console_socket: None, - detach: true, - }; + let mut socket_path = PathBuf::new(); let (socket, pio) = if p.stdio.terminal { let s = ConsoleSocket::new().await?; - exec_opts.console_socket = Some(s.path.to_owned()); + socket_path = s.path.to_owned(); (Some(s), None) } else { let pio = create_io(&p.id, self.io_uid, self.io_gid, &p.stdio)?; - exec_opts.io = pio.io.as_ref().cloned(); (None, Some(pio)) }; + + let probe_path = format!("{}/{}-process.json", self.bundle, &p.id); + let spec_str = serde_json::to_string(&self.spec) + .map_err(other_error!(e, "failed to marshall exec spec to string"))?; + tokio::fs::write(&probe_path, &spec_str) + .await + .map_err(other_error!(e, "failed to write spec to process.json"))?; + //TODO checkpoint support - let exec_result = self - .runtime - .exec(&self.container_id, &self.spec, Some(&exec_opts)) - .await; + let exec_result = ContainerBuilder::new(self.container_id.clone(), SyscallType::default()) + .with_root_path(PathBuf::from(YOUKI_DIR)) + .map_err(other_error!(e, "failed to set youki root path"))? + .with_console_socket(Some(socket_path)) + .with_pid_file(Some(pid_path.clone())) + .map_err(other_error!(e, "failed to set process pid file"))? + .as_tenant() + .with_detach(true) + .with_process(Some(&probe_path)) + .build(); if let Err(e) = exec_result { if let Some(s) = socket { s.clean().await; } - return Err(other!("failed to start runc exec: {}", e)); + let _ = tokio::fs::remove_file(&probe_path).await; + return Err(other!( + "youki exec container {} failed {}", + self.container_id, + e + )); } + let _ = tokio::fs::remove_file(&probe_path).await; + copy_io_or_console(p, socket, pio, p.lifecycle.exit_signal.clone()).await?; let pid = read_file_to_str(pid_path).await?.parse::()?; p.pid = pid; @@ -502,44 +487,6 @@ fn get_spec_from_request( } } -const DEFAULT_RUNC_ROOT: &str = "/run/containerd/runc"; -const DEFAULT_COMMAND: &str = "runc"; - -pub fn create_runc( - runtime: &str, - namespace: &str, - bundle: impl AsRef, - opts: &Options, - spawner: Option>, -) -> containerd_shim::Result { - let runtime = if runtime.is_empty() { - DEFAULT_COMMAND - } else { - runtime - }; - let root = opts.root.as_str(); - let root = Path::new(if root.is_empty() { - DEFAULT_RUNC_ROOT - } else { - root - }) - .join(namespace); - - let log = bundle.as_ref().join("log.json"); - let mut gopts = GlobalOpts::default() - .command(runtime) - .root(root) - .log(log) - .log_json() - .systemd_cgroup(opts.systemd_cgroup); - if let Some(s) = spawner { - gopts.custom_spawner(s); - } - gopts - .build() - .map_err(other_error!(e, "unable to create runc instance")) -} - #[derive(Default, Debug)] pub struct ShimExecutor {} diff --git a/vmm/task/src/main.rs b/vmm/task/src/main.rs index 713fe1c0..91681b86 100644 --- a/vmm/task/src/main.rs +++ b/vmm/task/src/main.rs @@ -35,7 +35,9 @@ use nix::{ unistd::Pid, }; use signal_hook_tokio::Signals; -use vmm_common::{api::sandbox_ttrpc::create_sandbox_service, mount::mount, KUASAR_STATE_DIR}; +use vmm_common::{ + api::sandbox_ttrpc::create_sandbox_service, mount::mount, KUASAR_STATE_DIR, YOUKI_DIR, +}; use crate::{ config::TaskConfig, @@ -154,6 +156,10 @@ async fn main() { } } + tokio::fs::create_dir_all(YOUKI_DIR) + .await + .expect("failed to create youki dir"); + // Start ttrpc server let mut server = start_ttrpc_server() .await