diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index 8a352fae0a..d5c557a3da 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -819,7 +819,7 @@ dependencies = [ "opentelemetry", "procfs", "prometheus", - "protobuf", + "protobuf 3.2.0", "protocols", "regex", "rtnetlink", @@ -1431,7 +1431,7 @@ dependencies = [ "memchr", "parking_lot 0.12.1", "procfs", - "protobuf", + "protobuf 2.27.1", "thiserror", ] @@ -1491,9 +1491,16 @@ name = "protobuf" version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" + +[[package]] +name = "protobuf" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" dependencies = [ - "serde", - "serde_derive", + "once_cell", + "protobuf-support", + "thiserror", ] [[package]] @@ -1502,17 +1509,47 @@ version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" dependencies = [ - "protobuf", + "protobuf 2.27.1", ] [[package]] -name = "protobuf-codegen-pure" -version = "2.27.1" +name = "protobuf-codegen" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" +checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901" dependencies = [ - "protobuf", - "protobuf-codegen", + "anyhow", + "once_cell", + "protobuf 3.2.0", + "protobuf-parse", + "regex", + "tempfile", + "thiserror", +] + +[[package]] +name = "protobuf-parse" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" +dependencies = [ + "anyhow", + "indexmap", + "log", + "protobuf 3.2.0", + "protobuf-support", + "tempfile", + "thiserror", + "which", +] + +[[package]] +name = "protobuf-support" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" +dependencies = [ + "thiserror", ] [[package]] @@ -1521,7 +1558,7 @@ version = "0.1.0" dependencies = [ "async-trait", "oci", - "protobuf", + "protobuf 3.2.0", "ttrpc", "ttrpc-codegen", ] @@ -1705,7 +1742,7 @@ dependencies = [ "nix 0.24.2", "oci", "path-absolutize", - "protobuf", + "protobuf 3.2.0", "protocols", "regex", "rlimit", @@ -2217,9 +2254,9 @@ dependencies = [ [[package]] name = "ttrpc" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" +checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c" dependencies = [ "async-trait", "byteorder", @@ -2227,8 +2264,8 @@ dependencies = [ "libc", "log", "nix 0.23.1", - "protobuf", - "protobuf-codegen-pure", + "protobuf 3.2.0", + "protobuf-codegen 3.2.0", "thiserror", "tokio", "tokio-vsock", @@ -2236,28 +2273,28 @@ dependencies = [ [[package]] name = "ttrpc-codegen" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" +checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2" dependencies = [ - "protobuf", - "protobuf-codegen", - "protobuf-codegen-pure", + "protobuf 2.27.1", + "protobuf-codegen 3.2.0", + "protobuf-support", "ttrpc-compiler", ] [[package]] name = "ttrpc-compiler" -version = "0.4.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2978ed3fa047d8fd55cbeb4d4a61d461fb3021a90c9618519c73ce7e5bb66c15" +checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647" dependencies = [ "derive-new", "prost", "prost-build", "prost-types", - "protobuf", - "protobuf-codegen", + "protobuf 2.27.1", + "protobuf-codegen 2.27.1", "tempfile", ] diff --git a/src/agent/Cargo.toml b/src/agent/Cargo.toml index 4b4a71c8fe..d8ba20db35 100644 --- a/src/agent/Cargo.toml +++ b/src/agent/Cargo.toml @@ -10,8 +10,8 @@ oci = { path = "../libs/oci" } rustjail = { path = "rustjail" } protocols = { path = "../libs/protocols", features = ["async"] } lazy_static = "1.3.0" -ttrpc = { version = "0.6.0", features = ["async"], default-features = false } -protobuf = "2.27.0" +ttrpc = { version = "0.7.1", features = ["async"], default-features = false } +protobuf = "3.2.0" libc = "0.2.58" nix = "0.24.2" capctl = "0.2.0" diff --git a/src/agent/rustjail/Cargo.toml b/src/agent/rustjail/Cargo.toml index 8c9c2230d6..19602bee2b 100644 --- a/src/agent/rustjail/Cargo.toml +++ b/src/agent/rustjail/Cargo.toml @@ -18,7 +18,7 @@ scopeguard = "1.0.0" capctl = "0.2.0" lazy_static = "1.3.0" libc = "0.2.58" -protobuf = "2.27.0" +protobuf = "3.2.0" slog = "2.5.2" slog-scope = "4.1.2" scan_fmt = "0.2.6" diff --git a/src/agent/rustjail/src/cgroups/fs/mod.rs b/src/agent/rustjail/src/cgroups/fs/mod.rs index 6eaa9870df..fc023ac61a 100644 --- a/src/agent/rustjail/src/cgroups/fs/mod.rs +++ b/src/agent/rustjail/src/cgroups/fs/mod.rs @@ -27,7 +27,7 @@ use oci::{ LinuxNetwork, LinuxPids, LinuxResources, }; -use protobuf::{CachedSize, RepeatedField, SingularPtrField, UnknownFields}; +use protobuf::MessageField; use protocols::agent::{ BlkioStats, BlkioStatsEntry, CgroupStats, CpuStats, CpuUsage, HugetlbStats, MemoryData, MemoryStats, PidsStats, ThrottlingData, @@ -50,7 +50,7 @@ macro_rules! get_controller_or_return_singular_none { ($cg:ident) => { match $cg.controller_of() { Some(c) => c, - None => return SingularPtrField::none(), + None => return MessageField::none(), } }; } @@ -134,11 +134,10 @@ impl CgroupManager for Manager { let throttling_data = get_cpu_stats(&self.cgroup); - let cpu_stats = SingularPtrField::some(CpuStats { + let cpu_stats = MessageField::some(CpuStats { cpu_usage, throttling_data, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }); // Memorystats @@ -160,8 +159,7 @@ impl CgroupManager for Manager { pids_stats, blkio_stats, hugetlb_stats, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }) } @@ -446,14 +444,14 @@ fn set_memory_resources(cg: &cgroups::Cgroup, memory: &LinuxMemory, update: bool let memstat = get_memory_stats(cg) .into_option() .ok_or_else(|| anyhow!("failed to get the cgroup memory stats"))?; - let memusage = memstat.get_usage(); + let memusage = memstat.usage(); // When update memory limit, the kernel would check the current memory limit // set against the new swap setting, if the current memory limit is large than // the new swap, then set limit first, otherwise the kernel would complain and // refused to set; on the other hand, if the current memory limit is smaller than // the new swap, then we should set the swap first and then set the memor limit. - if swap == -1 || memusage.get_limit() < swap as u64 { + if swap == -1 || memusage.limit() < swap as u64 { mem_controller.set_memswap_limit(swap)?; set_resource!(mem_controller, set_limit, memory, limit); } else { @@ -657,21 +655,20 @@ lazy_static! { }; } -fn get_cpu_stats(cg: &cgroups::Cgroup) -> SingularPtrField { +fn get_cpu_stats(cg: &cgroups::Cgroup) -> MessageField { let cpu_controller: &CpuController = get_controller_or_return_singular_none!(cg); let stat = cpu_controller.cpu().stat; let h = lines_to_map(&stat); - SingularPtrField::some(ThrottlingData { + MessageField::some(ThrottlingData { periods: *h.get("nr_periods").unwrap_or(&0), throttled_periods: *h.get("nr_throttled").unwrap_or(&0), throttled_time: *h.get("throttled_time").unwrap_or(&0), - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }) } -fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField { +fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> MessageField { if let Some(cpuacct_controller) = cg.controller_of::() { let cpuacct = cpuacct_controller.cpuacct(); @@ -685,13 +682,12 @@ fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField { let percpu_usage = line_to_vec(&cpuacct.usage_percpu); - return SingularPtrField::some(CpuUsage { + return MessageField::some(CpuUsage { total_usage, percpu_usage, usage_in_kernelmode, usage_in_usermode, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }); } @@ -704,17 +700,16 @@ fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField { let total_usage = *h.get("usage_usec").unwrap_or(&0); let percpu_usage = vec![]; - SingularPtrField::some(CpuUsage { + MessageField::some(CpuUsage { total_usage, percpu_usage, usage_in_kernelmode, usage_in_usermode, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }) } -fn get_memory_stats(cg: &cgroups::Cgroup) -> SingularPtrField { +fn get_memory_stats(cg: &cgroups::Cgroup) -> MessageField { let memory_controller: &MemController = get_controller_or_return_singular_none!(cg); // cache from memory stat @@ -726,52 +721,48 @@ fn get_memory_stats(cg: &cgroups::Cgroup) -> SingularPtrField { let use_hierarchy = value == 1; // get memory data - let usage = SingularPtrField::some(MemoryData { + let usage = MessageField::some(MemoryData { usage: memory.usage_in_bytes, max_usage: memory.max_usage_in_bytes, failcnt: memory.fail_cnt, limit: memory.limit_in_bytes as u64, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }); // get swap usage let memswap = memory_controller.memswap(); - let swap_usage = SingularPtrField::some(MemoryData { + let swap_usage = MessageField::some(MemoryData { usage: memswap.usage_in_bytes, max_usage: memswap.max_usage_in_bytes, failcnt: memswap.fail_cnt, limit: memswap.limit_in_bytes as u64, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }); // get kernel usage let kmem_stat = memory_controller.kmem_stat(); - let kernel_usage = SingularPtrField::some(MemoryData { + let kernel_usage = MessageField::some(MemoryData { usage: kmem_stat.usage_in_bytes, max_usage: kmem_stat.max_usage_in_bytes, failcnt: kmem_stat.fail_cnt, limit: kmem_stat.limit_in_bytes as u64, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }); - SingularPtrField::some(MemoryStats { + MessageField::some(MemoryStats { cache, usage, swap_usage, kernel_usage, use_hierarchy, stats: memory.stat.raw, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }) } -fn get_pids_stats(cg: &cgroups::Cgroup) -> SingularPtrField { +fn get_pids_stats(cg: &cgroups::Cgroup) -> MessageField { let pid_controller: &PidController = get_controller_or_return_singular_none!(cg); let current = pid_controller.get_pid_current().unwrap_or(0); @@ -785,11 +776,10 @@ fn get_pids_stats(cg: &cgroups::Cgroup) -> SingularPtrField { }, } as u64; - SingularPtrField::some(PidsStats { + MessageField::some(PidsStats { current, limit, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }) } @@ -825,8 +815,8 @@ https://github.com/opencontainers/runc/blob/a5847db387ae28c0ca4ebe4beee1a76900c8 Total 0 */ -fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField { - let mut m = RepeatedField::new(); +fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> Vec { + let mut m = Vec::new(); if blkiodata.is_empty() { return m; } @@ -839,16 +829,15 @@ fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField RepeatedField { - let mut m = RepeatedField::new(); +fn get_blkio_stat_ioservice(services: &[IoService]) -> Vec { + let mut m = Vec::new(); if services.is_empty() { return m; @@ -872,17 +861,16 @@ fn build_blkio_stats_entry(major: i16, minor: i16, op: &str, value: u64) -> Blki minor: minor as u64, op: op.to_string(), value, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() } } -fn get_blkio_stats_v2(cg: &cgroups::Cgroup) -> SingularPtrField { +fn get_blkio_stats_v2(cg: &cgroups::Cgroup) -> MessageField { let blkio_controller: &BlkIoController = get_controller_or_return_singular_none!(cg); let blkio = blkio_controller.blkio(); let mut resp = BlkioStats::new(); - let mut blkio_stats = RepeatedField::new(); + let mut blkio_stats = Vec::new(); let stat = blkio.io_stat; for s in stat { @@ -898,10 +886,10 @@ fn get_blkio_stats_v2(cg: &cgroups::Cgroup) -> SingularPtrField { resp.io_service_bytes_recursive = blkio_stats; - SingularPtrField::some(resp) + MessageField::some(resp) } -fn get_blkio_stats(cg: &cgroups::Cgroup) -> SingularPtrField { +fn get_blkio_stats(cg: &cgroups::Cgroup) -> MessageField { if cg.v2() { return get_blkio_stats_v2(cg); } @@ -934,7 +922,7 @@ fn get_blkio_stats(cg: &cgroups::Cgroup) -> SingularPtrField { m.sectors_recursive = get_blkio_stat_blkiodata(&blkio.sectors_recursive); } - SingularPtrField::some(m) + MessageField::some(m) } fn get_hugetlb_stats(cg: &cgroups::Cgroup) -> HashMap { @@ -958,8 +946,7 @@ fn get_hugetlb_stats(cg: &cgroups::Cgroup) -> HashMap { usage, max_usage, failcnt, - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }, ); } diff --git a/src/agent/rustjail/src/cgroups/mock.rs b/src/agent/rustjail/src/cgroups/mock.rs index 3bcc99955c..8ac77c63b2 100644 --- a/src/agent/rustjail/src/cgroups/mock.rs +++ b/src/agent/rustjail/src/cgroups/mock.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -use protobuf::{CachedSize, SingularPtrField, UnknownFields}; +use protobuf::MessageField; use crate::cgroups::Manager as CgroupManager; use crate::protocols::agent::{BlkioStats, CgroupStats, CpuStats, MemoryStats, PidsStats}; @@ -33,13 +33,12 @@ impl CgroupManager for Manager { fn get_stats(&self) -> Result { Ok(CgroupStats { - cpu_stats: SingularPtrField::some(CpuStats::default()), - memory_stats: SingularPtrField::some(MemoryStats::new()), - pids_stats: SingularPtrField::some(PidsStats::new()), - blkio_stats: SingularPtrField::some(BlkioStats::new()), + cpu_stats: MessageField::some(CpuStats::default()), + memory_stats: MessageField::some(MemoryStats::new()), + pids_stats: MessageField::some(PidsStats::new()), + blkio_stats: MessageField::some(BlkioStats::new()), hugetlb_stats: HashMap::new(), - unknown_fields: UnknownFields::default(), - cached_size: CachedSize::default(), + ..Default::default() }) } diff --git a/src/agent/rustjail/src/container.rs b/src/agent/rustjail/src/container.rs index 60b936557d..b1d7499cd9 100644 --- a/src/agent/rustjail/src/container.rs +++ b/src/agent/rustjail/src/container.rs @@ -48,7 +48,7 @@ use nix::unistd::{self, fork, ForkResult, Gid, Pid, Uid, User}; use std::os::unix::fs::MetadataExt; use std::os::unix::io::AsRawFd; -use protobuf::SingularPtrField; +use protobuf::MessageField; use oci::State as OCIState; use regex::Regex; @@ -875,7 +875,7 @@ impl BaseContainer for LinuxContainer { // what about network interface stats? Ok(StatsContainerResponse { - cgroup_stats: SingularPtrField::some(self.cgroup_manager.as_ref().get_stats()?), + cgroup_stats: MessageField::some(self.cgroup_manager.as_ref().get_stats()?), ..Default::default() }) } diff --git a/src/agent/rustjail/src/lib.rs b/src/agent/rustjail/src/lib.rs index 18ee0c3335..de91f81bb1 100644 --- a/src/agent/rustjail/src/lib.rs +++ b/src/agent/rustjail/src/lib.rs @@ -82,11 +82,11 @@ pub fn process_grpc_to_oci(p: &grpc::Process) -> oci::Process { let cap = p.Capabilities.as_ref().unwrap(); Some(oci::LinuxCapabilities { - bounding: cap.Bounding.clone().into_vec(), - effective: cap.Effective.clone().into_vec(), - inheritable: cap.Inheritable.clone().into_vec(), - permitted: cap.Permitted.clone().into_vec(), - ambient: cap.Ambient.clone().into_vec(), + bounding: cap.Bounding.clone(), + effective: cap.Effective.clone(), + inheritable: cap.Inheritable.clone(), + permitted: cap.Permitted.clone(), + ambient: cap.Ambient.clone(), }) } else { None @@ -108,8 +108,8 @@ pub fn process_grpc_to_oci(p: &grpc::Process) -> oci::Process { terminal: p.Terminal, console_size, user, - args: p.Args.clone().into_vec(), - env: p.Env.clone().into_vec(), + args: p.Args.clone(), + env: p.Env.clone(), cwd: p.Cwd.clone(), capabilities, rlimits, @@ -130,9 +130,9 @@ fn root_grpc_to_oci(root: &grpc::Root) -> oci::Root { fn mount_grpc_to_oci(m: &grpc::Mount) -> oci::Mount { oci::Mount { destination: m.destination.clone(), - r#type: m.field_type.clone(), + r#type: m.type_.clone(), source: m.source.clone(), - options: m.options.clone().into_vec(), + options: m.options.clone(), } } @@ -143,8 +143,8 @@ fn hook_grpc_to_oci(h: &[grpcHook]) -> Vec { for e in h.iter() { r.push(oci::Hook { path: e.Path.clone(), - args: e.Args.clone().into_vec(), - env: e.Env.clone().into_vec(), + args: e.Args.clone(), + env: e.Env.clone(), timeout: Some(e.Timeout as i32), }); } @@ -359,7 +359,7 @@ fn seccomp_grpc_to_oci(sec: &grpc::LinuxSeccomp) -> oci::LinuxSeccomp { let mut args = Vec::new(); let errno_ret: u32 = if sys.has_errnoret() { - sys.get_errnoret() + sys.errnoret() } else { libc::EPERM as u32 }; @@ -374,7 +374,7 @@ fn seccomp_grpc_to_oci(sec: &grpc::LinuxSeccomp) -> oci::LinuxSeccomp { } r.push(oci::LinuxSyscall { - names: sys.Names.clone().into_vec(), + names: sys.Names.clone(), action: sys.Action.clone(), errno_ret, args, @@ -385,8 +385,8 @@ fn seccomp_grpc_to_oci(sec: &grpc::LinuxSeccomp) -> oci::LinuxSeccomp { oci::LinuxSeccomp { default_action: sec.DefaultAction.clone(), - architectures: sec.Architectures.clone().into_vec(), - flags: sec.Flags.clone().into_vec(), + architectures: sec.Architectures.clone(), + flags: sec.Flags.clone(), syscalls, } } @@ -456,8 +456,8 @@ fn linux_grpc_to_oci(l: &grpc::Linux) -> oci::Linux { devices, seccomp, rootfs_propagation: l.RootfsPropagation.clone(), - masked_paths: l.MaskedPaths.clone().into_vec(), - readonly_paths: l.ReadonlyPaths.clone().into_vec(), + masked_paths: l.MaskedPaths.clone(), + readonly_paths: l.ReadonlyPaths.clone(), mount_label: l.MountLabel.clone(), intel_rdt, } @@ -558,35 +558,30 @@ mod tests { // All fields specified grpcproc: grpc::Process { Terminal: true, - ConsoleSize: protobuf::SingularPtrField::::some(grpc::Box { + ConsoleSize: protobuf::MessageField::::some(grpc::Box { Height: 123, Width: 456, ..Default::default() }), - User: protobuf::SingularPtrField::::some(grpc::User { + User: protobuf::MessageField::::some(grpc::User { UID: 1234, GID: 5678, AdditionalGids: Vec::from([910, 1112]), Username: String::from("username"), ..Default::default() }), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([String::from("env")])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env")]), Cwd: String::from("cwd"), - Capabilities: protobuf::SingularPtrField::some(grpc::LinuxCapabilities { - Bounding: protobuf::RepeatedField::from(Vec::from([String::from("bnd")])), - Effective: protobuf::RepeatedField::from(Vec::from([String::from("eff")])), - Inheritable: protobuf::RepeatedField::from(Vec::from([String::from( - "inher", - )])), - Permitted: protobuf::RepeatedField::from(Vec::from([String::from("perm")])), - Ambient: protobuf::RepeatedField::from(Vec::from([String::from("amb")])), + Capabilities: protobuf::MessageField::some(grpc::LinuxCapabilities { + Bounding: Vec::from([String::from("bnd")]), + Effective: Vec::from([String::from("eff")]), + Inheritable: Vec::from([String::from("inher")]), + Permitted: Vec::from([String::from("perm")]), + Ambient: Vec::from([String::from("amb")]), ..Default::default() }), - Rlimits: protobuf::RepeatedField::from(Vec::from([ + Rlimits: Vec::from([ grpc::POSIXRlimit { Type: String::from("r#type"), Hard: 123, @@ -599,7 +594,7 @@ mod tests { Soft: 1011, ..Default::default() }, - ])), + ]), NoNewPrivileges: true, ApparmorProfile: String::from("apparmor profile"), OOMScoreAdj: 123456, @@ -649,7 +644,7 @@ mod tests { TestData { // None ConsoleSize grpcproc: grpc::Process { - ConsoleSize: protobuf::SingularPtrField::::none(), + ConsoleSize: protobuf::MessageField::::none(), OOMScoreAdj: 0, ..Default::default() }, @@ -662,7 +657,7 @@ mod tests { TestData { // None User grpcproc: grpc::Process { - User: protobuf::SingularPtrField::::none(), + User: protobuf::MessageField::::none(), OOMScoreAdj: 0, ..Default::default() }, @@ -680,7 +675,7 @@ mod tests { TestData { // None Capabilities grpcproc: grpc::Process { - Capabilities: protobuf::SingularPtrField::none(), + Capabilities: protobuf::MessageField::none(), OOMScoreAdj: 0, ..Default::default() }, @@ -781,99 +776,57 @@ mod tests { TestData { // All specified grpchooks: grpc::Hooks { - Prestart: protobuf::RepeatedField::from(Vec::from([ + Prestart: Vec::from([ grpc::Hook { Path: String::from("prestartpath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() }, grpc::Hook { Path: String::from("prestartpath2"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg3"), - String::from("arg4"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env3"), - String::from("env4"), - ])), + Args: Vec::from([String::from("arg3"), String::from("arg4")]), + Env: Vec::from([String::from("env3"), String::from("env4")]), Timeout: 25, ..Default::default() }, - ])), - Poststart: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + ]), + Poststart: Vec::from([grpc::Hook { Path: String::from("poststartpath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - Poststop: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + Poststop: Vec::from([grpc::Hook { Path: String::from("poststoppath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - CreateRuntime: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + CreateRuntime: Vec::from([grpc::Hook { Path: String::from("createruntimepath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - CreateContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + CreateContainer: Vec::from([grpc::Hook { Path: String::from("createcontainerpath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - StartContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + StartContainer: Vec::from([grpc::Hook { Path: String::from("startcontainerpath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), + }]), ..Default::default() }, result: oci::Hooks { @@ -926,72 +879,42 @@ mod tests { TestData { // Prestart empty grpchooks: grpc::Hooks { - Prestart: protobuf::RepeatedField::from(Vec::from([])), - Poststart: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + Prestart: Vec::from([]), + Poststart: Vec::from([grpc::Hook { Path: String::from("poststartpath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - Poststop: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + Poststop: Vec::from([grpc::Hook { Path: String::from("poststoppath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - CreateRuntime: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + CreateRuntime: Vec::from([grpc::Hook { Path: String::from("createruntimepath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - CreateContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + CreateContainer: Vec::from([grpc::Hook { Path: String::from("createcontainerpath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), - StartContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { + }]), + StartContainer: Vec::from([grpc::Hook { Path: String::from("startcontainerpath"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() - }])), + }]), ..Default::default() }, result: oci::Hooks { @@ -1063,11 +986,8 @@ mod tests { grpcmount: grpc::Mount { destination: String::from("destination"), source: String::from("source"), - field_type: String::from("fieldtype"), - options: protobuf::RepeatedField::from(Vec::from([ - String::from("option1"), - String::from("option2"), - ])), + type_: String::from("fieldtype"), + options: Vec::from([String::from("option1"), String::from("option2")]), ..Default::default() }, result: oci::Mount { @@ -1081,8 +1001,8 @@ mod tests { grpcmount: grpc::Mount { destination: String::from("destination"), source: String::from("source"), - field_type: String::from("fieldtype"), - options: protobuf::RepeatedField::from(Vec::new()), + type_: String::from("fieldtype"), + options: Vec::new(), ..Default::default() }, result: oci::Mount { @@ -1096,8 +1016,8 @@ mod tests { grpcmount: grpc::Mount { destination: String::new(), source: String::from("source"), - field_type: String::from("fieldtype"), - options: protobuf::RepeatedField::from(Vec::from([String::from("option1")])), + type_: String::from("fieldtype"), + options: Vec::from([String::from("option1")]), ..Default::default() }, result: oci::Mount { @@ -1111,8 +1031,8 @@ mod tests { grpcmount: grpc::Mount { destination: String::from("destination"), source: String::from("source"), - field_type: String::new(), - options: protobuf::RepeatedField::from(Vec::from([String::from("option1")])), + type_: String::new(), + options: Vec::from([String::from("option1")]), ..Default::default() }, result: oci::Mount { @@ -1172,27 +1092,15 @@ mod tests { grpchook: &[ grpc::Hook { Path: String::from("path"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg1"), - String::from("arg2"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env1"), - String::from("env2"), - ])), + Args: Vec::from([String::from("arg1"), String::from("arg2")]), + Env: Vec::from([String::from("env1"), String::from("env2")]), Timeout: 10, ..Default::default() }, grpc::Hook { Path: String::from("path2"), - Args: protobuf::RepeatedField::from(Vec::from([ - String::from("arg3"), - String::from("arg4"), - ])), - Env: protobuf::RepeatedField::from(Vec::from([ - String::from("env3"), - String::from("env4"), - ])), + Args: Vec::from([String::from("arg3"), String::from("arg4")]), + Env: Vec::from([String::from("env3"), String::from("env4")]), Timeout: 20, ..Default::default() }, diff --git a/src/agent/src/device.rs b/src/agent/src/device.rs index 535a729f60..67d35651bd 100644 --- a/src/agent/src/device.rs +++ b/src/agent/src/device.rs @@ -759,7 +759,7 @@ async fn vfio_pci_device_handler( device: &Device, sandbox: &Arc>, ) -> Result { - let vfio_in_guest = device.field_type != DRIVER_VFIO_PCI_GK_TYPE; + let vfio_in_guest = device.type_ != DRIVER_VFIO_PCI_GK_TYPE; let mut pci_fixups = Vec::<(pci::Address, pci::Address)>::new(); let mut group = None; @@ -874,9 +874,9 @@ pub async fn add_devices( async fn add_device(device: &Device, sandbox: &Arc>) -> Result { // log before validation to help with debugging gRPC protocol version differences. info!(sl!(), "device-id: {}, device-type: {}, device-vm-path: {}, device-container-path: {}, device-options: {:?}", - device.id, device.field_type, device.vm_path, device.container_path, device.options); + device.id, device.type_, device.vm_path, device.container_path, device.options); - if device.field_type.is_empty() { + if device.type_.is_empty() { return Err(anyhow!("invalid type for device {:?}", device)); } @@ -888,7 +888,7 @@ async fn add_device(device: &Device, sandbox: &Arc>) -> Result virtio_blk_device_handler(device, sandbox).await, DRIVER_BLK_CCW_TYPE => virtio_blk_ccw_device_handler(device, sandbox).await, DRIVER_MMIO_BLK_TYPE => virtiommio_blk_device_handler(device, sandbox).await, @@ -898,7 +898,7 @@ async fn add_device(device: &Device, sandbox: &Arc>) -> Result vfio_ap_device_handler(device, sandbox).await, - _ => Err(anyhow!("Unknown device type {}", device.field_type)), + _ => Err(anyhow!("Unknown device type {}", device.type_)), } } diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index bc13a6896f..0eff266f24 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -211,10 +211,10 @@ async fn ephemeral_storage_handler( // By now we only support one option field: "fsGroup" which // isn't an valid mount option, thus we should remove it when // do mount. - if storage.options.len() > 0 { + if !storage.options.is_empty() { // ephemeral_storage didn't support mount options except fsGroup. let mut new_storage = storage.clone(); - new_storage.options = protobuf::RepeatedField::default(); + new_storage.options = Default::default(); common_storage_handler(logger, &new_storage)?; let opts_vec: Vec = storage.options.to_vec(); @@ -654,7 +654,7 @@ pub fn set_ownership(logger: &Logger, storage: &Storage) -> Result<()> { if storage.fs_group.is_none() { return Ok(()); } - let fs_group = storage.get_fs_group(); + let fs_group = storage.fs_group(); let mut read_only = false; let opts_vec: Vec = storage.options.to_vec(); @@ -671,7 +671,7 @@ pub fn set_ownership(logger: &Logger, storage: &Storage) -> Result<()> { err })?; - if fs_group.group_change_policy == FSGroupChangePolicy::OnRootMismatch + if fs_group.group_change_policy == FSGroupChangePolicy::OnRootMismatch.into() && metadata.gid() == fs_group.group_id { let mut mask = if read_only { RO_MASK } else { RW_MASK }; @@ -1094,7 +1094,6 @@ fn parse_options(option_list: Vec) -> HashMap { #[cfg(test)] mod tests { use super::*; - use protobuf::RepeatedField; use protocols::agent::FSGroup; use std::fs::File; use std::fs::OpenOptions; @@ -2015,9 +2014,8 @@ mod tests { mount_path: "rw_mount", fs_group: Some(FSGroup { group_id: 3000, - group_change_policy: FSGroupChangePolicy::Always, - unknown_fields: Default::default(), - cached_size: Default::default(), + group_change_policy: FSGroupChangePolicy::Always.into(), + ..Default::default() }), read_only: false, expected_group_id: 3000, @@ -2027,9 +2025,8 @@ mod tests { mount_path: "ro_mount", fs_group: Some(FSGroup { group_id: 3000, - group_change_policy: FSGroupChangePolicy::OnRootMismatch, - unknown_fields: Default::default(), - cached_size: Default::default(), + group_change_policy: FSGroupChangePolicy::OnRootMismatch.into(), + ..Default::default() }), read_only: true, expected_group_id: 3000, @@ -2049,10 +2046,7 @@ mod tests { let directory_mode = mount_dir.as_path().metadata().unwrap().permissions().mode(); let mut storage_data = Storage::new(); if d.read_only { - storage_data.set_options(RepeatedField::from_slice(&[ - "foo".to_string(), - "ro".to_string(), - ])); + storage_data.set_options(vec!["foo".to_string(), "ro".to_string()]); } if let Some(fs_group) = d.fs_group.clone() { storage_data.set_fs_group(fs_group); diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index 29785fc436..f5e9d271b8 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -7,7 +7,6 @@ use anyhow::{anyhow, Context, Result}; use futures::{future, StreamExt, TryStreamExt}; use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network}; use nix::errno::Errno; -use protobuf::RepeatedField; use protocols::types::{ARPNeighbor, IPAddress, IPFamily, Interface, Route}; use rtnetlink::{new_connection, packet, IpVersion}; use std::convert::{TryFrom, TryInto}; @@ -83,8 +82,8 @@ impl Handle { // Add new ip addresses from request for ip_address in &iface.IPAddresses { - let ip = IpAddr::from_str(ip_address.get_address())?; - let mask = ip_address.get_mask().parse::()?; + let ip = IpAddr::from_str(ip_address.address())?; + let mask = ip_address.mask().parse::()?; self.add_addresses(link.index(), std::iter::once(IpNetwork::new(ip, mask)?)) .await?; @@ -152,7 +151,7 @@ impl Handle { .map(|p| p.try_into()) .collect::>>()?; - iface.IPAddresses = RepeatedField::from_vec(ips); + iface.IPAddresses = ips; list.push(iface); } @@ -334,7 +333,7 @@ impl Handle { // `rtnetlink` offers a separate request builders for different IP versions (IP v4 and v6). // This if branch is a bit clumsy because it does almost the same. - if route.get_family() == IPFamily::v6 { + if route.family() == IPFamily::v6 { let dest_addr = if !route.dest.is_empty() { Ipv6Network::from_str(&route.dest)? } else { @@ -368,9 +367,9 @@ impl Handle { if Errno::from_i32(message.code.abs()) != Errno::EEXIST { return Err(anyhow!( "Failed to add IP v6 route (src: {}, dst: {}, gtw: {},Err: {})", - route.get_source(), - route.get_dest(), - route.get_gateway(), + route.source(), + route.dest(), + route.gateway(), message )); } @@ -409,9 +408,9 @@ impl Handle { if Errno::from_i32(message.code.abs()) != Errno::EEXIST { return Err(anyhow!( "Failed to add IP v4 route (src: {}, dst: {}, gtw: {},Err: {})", - route.get_source(), - route.get_dest(), - route.get_gateway(), + route.source(), + route.dest(), + route.gateway(), message )); } @@ -506,7 +505,7 @@ impl Handle { self.add_arp_neighbor(&neigh).await.map_err(|err| { anyhow!( "Failed to add ARP neighbor {}: {:?}", - neigh.get_toIPAddress().get_address(), + neigh.toIPAddress().address(), err ) })?; @@ -725,7 +724,7 @@ impl TryFrom
for IPAddress { let mask = format!("{}", value.0.header.prefix_len); Ok(IPAddress { - family, + family: family.into(), address, mask, ..Default::default() diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 3a927b3b56..4786539040 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -21,17 +21,20 @@ use ttrpc::{ use anyhow::{anyhow, Context, Result}; use cgroups::freezer::FreezerState; use oci::{LinuxNamespace, Root, Spec}; -use protobuf::{Message, RepeatedField, SingularPtrField}; +use protobuf::{MessageDyn, MessageField}; use protocols::agent::{ AddSwapRequest, AgentDetails, CopyFileRequest, GetIPTablesRequest, GetIPTablesResponse, GuestDetailsResponse, Interfaces, Metrics, OOMEvent, ReadStreamResponse, Routes, SetIPTablesRequest, SetIPTablesResponse, StatsContainerResponse, VolumeStatsRequest, WaitProcessResponse, WriteStreamResponse, }; -use protocols::csi::{VolumeCondition, VolumeStatsResponse, VolumeUsage, VolumeUsage_Unit}; +use protocols::csi::{ + volume_usage::Unit as VolumeUsage_Unit, VolumeCondition, VolumeStatsResponse, VolumeUsage, +}; use protocols::empty::Empty; use protocols::health::{ - HealthCheckResponse, HealthCheckResponse_ServingStatus, VersionCheckResponse, + health_check_response::ServingStatus as HealthCheckResponse_ServingStatus, HealthCheckResponse, + VersionCheckResponse, }; use protocols::types::Interface; use protocols::{agent_ttrpc_async as agent_ttrpc, health_ttrpc_async as health_ttrpc}; @@ -124,11 +127,11 @@ macro_rules! is_allowed { if !AGENT_CONFIG .read() .await - .is_allowed_endpoint($req.descriptor().name()) + .is_allowed_endpoint($req.descriptor_dyn().name()) { return Err(ttrpc_error!( ttrpc::Code::UNIMPLEMENTED, - format!("{} is blocked", $req.descriptor().name()), + format!("{} is blocked", $req.descriptor_dyn().name()), )); } }; @@ -151,7 +154,7 @@ impl AgentService { kata_sys_util::validate::verify_id(&cid)?; let mut oci_spec = req.OCI.clone(); - let use_sandbox_pidns = req.get_sandbox_pidns(); + let use_sandbox_pidns = req.sandbox_pidns(); let sandbox; let mut s; @@ -785,7 +788,7 @@ impl agent_ttrpc::AgentService for AgentService { ) -> ttrpc::Result { trace_rpc_call!(ctx, "pause_container", req); is_allowed!(req); - let cid = req.get_container_id(); + let cid = req.container_id(); let s = Arc::clone(&self.sandbox); let mut sandbox = s.lock().await; @@ -809,7 +812,7 @@ impl agent_ttrpc::AgentService for AgentService { ) -> ttrpc::Result { trace_rpc_call!(ctx, "resume_container", req); is_allowed!(req); - let cid = req.get_container_id(); + let cid = req.container_id(); let s = Arc::clone(&self.sandbox); let mut sandbox = s.lock().await; @@ -964,16 +967,12 @@ impl agent_ttrpc::AgentService for AgentService { trace_rpc_call!(ctx, "update_routes", req); is_allowed!(req); - let new_routes = req - .routes - .into_option() - .map(|r| r.Routes.into_vec()) - .ok_or_else(|| { - ttrpc_error!( - ttrpc::Code::INVALID_ARGUMENT, - "empty update routes request".to_string(), - ) - })?; + let new_routes = req.routes.into_option().map(|r| r.Routes).ok_or_else(|| { + ttrpc_error!( + ttrpc::Code::INVALID_ARGUMENT, + "empty update routes request".to_string(), + ) + })?; let mut sandbox = self.sandbox.lock().await; @@ -992,7 +991,7 @@ impl agent_ttrpc::AgentService for AgentService { })?; Ok(protocols::agent::Routes { - Routes: RepeatedField::from_vec(list), + Routes: list, ..Default::default() }) } @@ -1191,7 +1190,7 @@ impl agent_ttrpc::AgentService for AgentService { })?; Ok(protocols::agent::Interfaces { - Interfaces: RepeatedField::from_vec(list), + Interfaces: list, ..Default::default() }) } @@ -1214,7 +1213,7 @@ impl agent_ttrpc::AgentService for AgentService { .map_err(|e| ttrpc_error!(ttrpc::Code::INTERNAL, format!("list routes: {:?}", e)))?; Ok(protocols::agent::Routes { - Routes: RepeatedField::from_vec(list), + Routes: list, ..Default::default() }) } @@ -1330,7 +1329,7 @@ impl agent_ttrpc::AgentService for AgentService { let neighs = req .neighbors .into_option() - .map(|n| n.ARPNeighbors.into_vec()) + .map(|n| n.ARPNeighbors) .ok_or_else(|| { ttrpc_error!( ttrpc::Code::INVALID_ARGUMENT, @@ -1414,7 +1413,7 @@ impl agent_ttrpc::AgentService for AgentService { // to get agent details let detail = get_agent_details(); - resp.agent_details = SingularPtrField::some(detail); + resp.agent_details = MessageField::some(detail); Ok(resp) } @@ -1539,8 +1538,8 @@ impl agent_ttrpc::AgentService for AgentService { .map(|u| usage_vec.push(u)) .map_err(|e| ttrpc_error!(ttrpc::Code::INTERNAL, e))?; - resp.usage = RepeatedField::from_vec(usage_vec); - resp.volume_condition = SingularPtrField::some(condition); + resp.usage = usage_vec; + resp.volume_condition = MessageField::some(condition); Ok(resp) } @@ -1644,7 +1643,7 @@ fn get_volume_capacity_stats(path: &str) -> Result { usage.total = stat.blocks() * block_size; usage.available = stat.blocks_free() * block_size; usage.used = usage.total - usage.available; - usage.unit = VolumeUsage_Unit::BYTES; + usage.unit = VolumeUsage_Unit::BYTES.into(); Ok(usage) } @@ -1656,7 +1655,7 @@ fn get_volume_inode_stats(path: &str) -> Result { usage.total = stat.files(); usage.available = stat.files_free(); usage.used = usage.total - usage.available; - usage.unit = VolumeUsage_Unit::INODES; + usage.unit = VolumeUsage_Unit::INODES.into(); Ok(usage) } @@ -1676,14 +1675,12 @@ fn get_agent_details() -> AgentDetails { detail.set_supports_seccomp(have_seccomp()); detail.init_daemon = unistd::getpid() == Pid::from_raw(1); - detail.device_handlers = RepeatedField::new(); - detail.storage_handlers = RepeatedField::from_vec( - STORAGE_HANDLER_LIST - .to_vec() - .iter() - .map(|x| x.to_string()) - .collect(), - ); + detail.device_handlers = Vec::new(); + detail.storage_handlers = STORAGE_HANDLER_LIST + .to_vec() + .iter() + .map(|x| x.to_string()) + .collect(); detail } @@ -2037,7 +2034,7 @@ fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> { let mut args = vec!["-v".to_string(), module.name.clone()]; - if module.parameters.len() > 0 { + if !module.parameters.is_empty() { args.extend(module.parameters.to_vec()) } diff --git a/src/libs/Cargo.lock b/src/libs/Cargo.lock index 16bdfda6f0..2f03109f8a 100644 --- a/src/libs/Cargo.lock +++ b/src/libs/Cargo.lock @@ -703,9 +703,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.9.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "parking_lot" @@ -845,9 +845,16 @@ name = "protobuf" version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" + +[[package]] +name = "protobuf" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" dependencies = [ - "serde", - "serde_derive", + "once_cell", + "protobuf-support", + "thiserror", ] [[package]] @@ -856,17 +863,47 @@ version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" dependencies = [ - "protobuf", + "protobuf 2.27.1", ] [[package]] -name = "protobuf-codegen-pure" -version = "2.27.1" +name = "protobuf-codegen" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" +checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901" dependencies = [ - "protobuf", - "protobuf-codegen", + "anyhow", + "once_cell", + "protobuf 3.2.0", + "protobuf-parse", + "regex", + "tempfile", + "thiserror", +] + +[[package]] +name = "protobuf-parse" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" +dependencies = [ + "anyhow", + "indexmap", + "log", + "protobuf 3.2.0", + "protobuf-support", + "tempfile", + "thiserror", + "which", +] + +[[package]] +name = "protobuf-support" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" +dependencies = [ + "thiserror", ] [[package]] @@ -875,7 +912,7 @@ version = "0.1.0" dependencies = [ "async-trait", "oci", - "protobuf", + "protobuf 3.2.0", "serde", "serde_json", "ttrpc", @@ -1314,9 +1351,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "ttrpc" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" +checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c" dependencies = [ "async-trait", "byteorder", @@ -1324,8 +1361,8 @@ dependencies = [ "libc", "log", "nix 0.23.1", - "protobuf", - "protobuf-codegen-pure", + "protobuf 3.2.0", + "protobuf-codegen 3.2.0", "thiserror", "tokio", "tokio-vsock", @@ -1333,28 +1370,28 @@ dependencies = [ [[package]] name = "ttrpc-codegen" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" +checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2" dependencies = [ - "protobuf", - "protobuf-codegen", - "protobuf-codegen-pure", + "protobuf 2.27.1", + "protobuf-codegen 3.2.0", + "protobuf-support", "ttrpc-compiler", ] [[package]] name = "ttrpc-compiler" -version = "0.4.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2978ed3fa047d8fd55cbeb4d4a61d461fb3021a90c9618519c73ce7e5bb66c15" +checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647" dependencies = [ "derive-new", "prost", "prost-build", "prost-types", - "protobuf", - "protobuf-codegen", + "protobuf 2.27.1", + "protobuf-codegen 2.27.1", "tempfile", ] diff --git a/src/libs/protocols/.gitignore b/src/libs/protocols/.gitignore index 0a83b1689a..bc7e10bf31 100644 --- a/src/libs/protocols/.gitignore +++ b/src/libs/protocols/.gitignore @@ -1,11 +1,6 @@ Cargo.lock -src/agent.rs -src/agent_ttrpc.rs -src/agent_ttrpc_async.rs -src/csi.rs -src/empty.rs -src/health.rs -src/health_ttrpc.rs -src/health_ttrpc_async.rs -src/oci.rs -src/types.rs + +src/*.rs +!src/lib.rs +!src/trans.rs +!src/serde_config.rs diff --git a/src/libs/protocols/Cargo.toml b/src/libs/protocols/Cargo.toml index 03b9c8b3d5..9c0033d17e 100644 --- a/src/libs/protocols/Cargo.toml +++ b/src/libs/protocols/Cargo.toml @@ -11,12 +11,13 @@ with-serde = [ "serde", "serde_json" ] async = ["ttrpc/async", "async-trait"] [dependencies] -ttrpc = { version = "0.6.0" } +ttrpc = { version = "0.7.1" } async-trait = { version = "0.1.42", optional = true } -protobuf = { version = "2.27.0", features = ["with-serde"] } +protobuf = { version = "3.2.0" } serde = { version = "1.0.130", features = ["derive"], optional = true } serde_json = { version = "1.0.68", optional = true } oci = { path = "../oci" } [build-dependencies] -ttrpc-codegen = "0.2.0" +ttrpc-codegen = "0.4.2" +protobuf = { version = "3.2.0" } diff --git a/src/libs/protocols/build.rs b/src/libs/protocols/build.rs index 8c0341762d..bc34c07a07 100644 --- a/src/libs/protocols/build.rs +++ b/src/libs/protocols/build.rs @@ -7,7 +7,46 @@ use std::fs::{self, File}; use std::io::{BufRead, BufReader, Read, Write}; use std::path::Path; use std::process::exit; -use ttrpc_codegen::{Codegen, Customize, ProtobufCustomize}; + +use protobuf::{ + descriptor::field_descriptor_proto::Type, + reflect::{EnumDescriptor, FieldDescriptor, MessageDescriptor, OneofDescriptor}, +}; +use ttrpc_codegen::{Codegen, Customize, ProtobufCustomize, ProtobufCustomizeCallback}; + +struct GenSerde; + +impl ProtobufCustomizeCallback for GenSerde { + fn message(&self, _message: &MessageDescriptor) -> ProtobufCustomize { + ProtobufCustomize::default().before("#[cfg_attr(feature = \"with-serde\", derive(::serde::Serialize, ::serde::Deserialize))]") + } + + fn enumeration(&self, _enum_type: &EnumDescriptor) -> ProtobufCustomize { + ProtobufCustomize::default().before("#[cfg_attr(feature = \"with-serde\", derive(::serde::Serialize, ::serde::Deserialize))]") + } + + fn oneof(&self, _oneof: &OneofDescriptor) -> ProtobufCustomize { + ProtobufCustomize::default().before("#[cfg_attr(feature = \"with-serde\", derive(::serde::Serialize, ::serde::Deserialize))]") + } + + fn field(&self, field: &FieldDescriptor) -> ProtobufCustomize { + if field.proto().type_() == Type::TYPE_ENUM { + ProtobufCustomize::default().before( + "#[cfg_attr(feature = \"with-serde\", serde(serialize_with = \"crate::serialize_enum_or_unknown\", deserialize_with = \"crate::deserialize_enum_or_unknown\"))]", + ) + } else if field.proto().type_() == Type::TYPE_MESSAGE && field.is_singular() { + ProtobufCustomize::default().before( + "#[cfg_attr(feature = \"with-serde\", serde(serialize_with = \"crate::serialize_message_field\", deserialize_with = \"crate::deserialize_message_field\"))]", + ) + } else { + ProtobufCustomize::default() + } + } + + fn special_field(&self, _message: &MessageDescriptor, _field: &str) -> ProtobufCustomize { + ProtobufCustomize::default().before("#[cfg_attr(feature = \"with-serde\", serde(skip))]") + } +} fn replace_text_in_file(file_name: &str, from: &str, to: &str) -> Result<(), std::io::Error> { let mut src = File::open(file_name)?; @@ -103,10 +142,10 @@ fn codegen(path: &str, protos: &[&str], async_all: bool) -> Result<(), std::io:: ..Default::default() }; - let protobuf_options = ProtobufCustomize { - serde_derive: Some(true), - ..Default::default() - }; + let protobuf_options = ProtobufCustomize::default() + .gen_mod_rs(false) + .generate_getter(true) + .generate_accessors(true); let out_dir = Path::new("src"); @@ -117,6 +156,7 @@ fn codegen(path: &str, protos: &[&str], async_all: bool) -> Result<(), std::io:: .customize(ttrpc_options) .rust_protobuf() .rust_protobuf_customize(protobuf_options) + .rust_protobuf_customize_callback(GenSerde) .run()?; let autogen_comment = format!("\n//! Generated by {:?} ({:?})", file!(), module_path!()); @@ -147,6 +187,7 @@ fn real_main() -> Result<(), std::io::Error> { "src", &[ "protos/google/protobuf/empty.proto", + "protos/gogo/protobuf/gogoproto/gogo.proto", "protos/oci.proto", "protos/types.proto", "protos/csi.proto", diff --git a/src/libs/protocols/src/lib.rs b/src/libs/protocols/src/lib.rs index 0c62b8a933..33f75ca0ea 100644 --- a/src/libs/protocols/src/lib.rs +++ b/src/libs/protocols/src/lib.rs @@ -11,10 +11,19 @@ pub mod agent_ttrpc; pub mod agent_ttrpc_async; pub mod csi; pub mod empty; +mod gogo; pub mod health; pub mod health_ttrpc; #[cfg(feature = "async")] pub mod health_ttrpc_async; pub mod oci; +#[cfg(feature = "with-serde")] +mod serde_config; pub mod trans; pub mod types; + +#[cfg(feature = "with-serde")] +pub use serde_config::{ + deserialize_enum_or_unknown, deserialize_message_field, serialize_enum_or_unknown, + serialize_message_field, +}; diff --git a/src/libs/protocols/src/serde_config.rs b/src/libs/protocols/src/serde_config.rs new file mode 100644 index 0000000000..064379cd16 --- /dev/null +++ b/src/libs/protocols/src/serde_config.rs @@ -0,0 +1,68 @@ +// Copyright (c) 2023 Ant Group +// +// SPDX-License-Identifier: Apache-2.0 +// + +use protobuf::{EnumOrUnknown, MessageField}; +use serde::{Deserialize, Serialize}; + +#[cfg(feature = "with-serde")] +pub fn serialize_enum_or_unknown( + e: &protobuf::EnumOrUnknown, + s: S, +) -> Result { + e.value().serialize(s) +} + +pub fn serialize_message_field( + e: &protobuf::MessageField, + s: S, +) -> Result { + if e.is_some() { + e.as_ref().unwrap().serialize(s) + } else { + s.serialize_unit() + } +} + +pub fn deserialize_enum_or_unknown<'de, E: Deserialize<'de>, D: serde::Deserializer<'de>>( + d: D, +) -> Result, D::Error> { + i32::deserialize(d).map(EnumOrUnknown::from_i32) +} + +pub fn deserialize_message_field<'de, E: Deserialize<'de>, D: serde::Deserializer<'de>>( + d: D, +) -> Result, D::Error> { + Option::deserialize(d).map(MessageField::from_option) +} + +#[cfg(test)] +mod tests { + use crate::agent::{ExecProcessRequest, StringUser}; + use crate::health::{health_check_response::ServingStatus, HealthCheckResponse}; + + #[test] + fn test_serde_for_enum_or_unknown() { + let mut hc = HealthCheckResponse::new(); + hc.set_status(ServingStatus::SERVING); + + let json = serde_json::to_string(&hc).unwrap(); + let from_json: HealthCheckResponse = serde_json::from_str(&json).unwrap(); + + assert_eq!(from_json, hc); + } + + #[test] + fn test_serde_for_message_field() { + let mut epr = ExecProcessRequest::new(); + let mut str_user = StringUser::new(); + str_user.uid = "Someone's id".to_string(); + epr.set_string_user(str_user); + + let json = serde_json::to_string(&epr).unwrap(); + let from_json: ExecProcessRequest = serde_json::from_str(&json).unwrap(); + + assert_eq!(from_json, epr); + } +} diff --git a/src/libs/protocols/src/trans.rs b/src/libs/protocols/src/trans.rs index 1e15147883..db59b7c2aa 100644 --- a/src/libs/protocols/src/trans.rs +++ b/src/libs/protocols/src/trans.rs @@ -15,19 +15,19 @@ use oci::{ }; // translate from interface to ttprc tools -fn from_option>(from: Option) -> ::protobuf::SingularPtrField { +fn from_option>(from: Option) -> protobuf::MessageField { match from { - Some(f) => ::protobuf::SingularPtrField::from_option(Some(T::from(f))), - None => ::protobuf::SingularPtrField::none(), + Some(f) => protobuf::MessageField::from_option(Some(f.into())), + None => protobuf::MessageField::none(), } } -fn from_vec>(from: Vec) -> ::protobuf::RepeatedField { +fn from_vec>(from: Vec) -> Vec { let mut to: Vec = vec![]; for data in from { - to.push(T::from(data)); + to.push(data.into()); } - ::protobuf::RepeatedField::from_vec(to) + to } impl From for crate::oci::Box { @@ -35,8 +35,7 @@ impl From for crate::oci::Box { crate::oci::Box { Height: from.height, Width: from.width, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -48,8 +47,7 @@ impl From for crate::oci::User { GID: from.gid, AdditionalGids: from.additional_gids, Username: from.username, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -57,13 +55,12 @@ impl From for crate::oci::User { impl From for crate::oci::LinuxCapabilities { fn from(from: LinuxCapabilities) -> Self { crate::oci::LinuxCapabilities { - Bounding: from_vec(from.bounding), - Effective: from_vec(from.effective), - Inheritable: from_vec(from.inheritable), - Permitted: from_vec(from.permitted), - Ambient: from_vec(from.ambient), - unknown_fields: Default::default(), - cached_size: Default::default(), + Bounding: from.bounding, + Effective: from.effective, + Inheritable: from.inheritable, + Permitted: from.permitted, + Ambient: from.ambient, + ..Default::default() } } } @@ -74,8 +71,7 @@ impl From for crate::oci::POSIXRlimit { Type: from.r#type, Hard: from.hard, Soft: from.soft, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -86,8 +82,8 @@ impl From for crate::oci::Process { Terminal: from.terminal, ConsoleSize: from_option(from.console_size), User: from_option(Some(from.user)), - Args: from_vec(from.args), - Env: from_vec(from.env), + Args: from.args, + Env: from.env, Cwd: from.cwd, Capabilities: from_option(from.capabilities), Rlimits: from_vec(from.rlimits), @@ -95,8 +91,7 @@ impl From for crate::oci::Process { ApparmorProfile: from.apparmor_profile, OOMScoreAdj: from.oom_score_adj.map_or(0, |t| t as i64), SelinuxLabel: from.selinux_label, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -109,8 +104,7 @@ impl From for crate::oci::LinuxDeviceCgroup { Major: from.major.map_or(0, |t| t), Minor: from.minor.map_or(0, |t| t), Access: from.access, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -125,8 +119,7 @@ impl From for crate::oci::LinuxMemory { KernelTCP: from.kernel_tcp.map_or(0, |t| t), Swappiness: from.swappiness.map_or(0, |t| t), DisableOOMKiller: from.disable_oom_killer.map_or(false, |t| t), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -141,8 +134,7 @@ impl From for crate::oci::LinuxCPU { RealtimePeriod: from.realtime_period.map_or(0, |t| t), Cpus: from.cpus, Mems: from.mems, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -151,8 +143,7 @@ impl From for crate::oci::LinuxPids { fn from(from: LinuxPids) -> Self { crate::oci::LinuxPids { Limit: from.limit, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -165,8 +156,7 @@ impl From for crate::oci::LinuxWeightDevice { Minor: 0, Weight: from.weight.map_or(0, |t| t as u32), LeafWeight: from.leaf_weight.map_or(0, |t| t as u32), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -178,8 +168,7 @@ impl From for crate::oci::LinuxThrottleDevice { Major: 0, Minor: 0, Rate: from.rate, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -194,8 +183,7 @@ impl From for crate::oci::LinuxBlockIO { ThrottleWriteBpsDevice: from_vec(from.throttle_write_bps_device), ThrottleReadIOPSDevice: from_vec(from.throttle_read_iops_device), ThrottleWriteIOPSDevice: from_vec(from.throttle_write_iops_device), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -205,8 +193,7 @@ impl From for crate::oci::LinuxHugepageLimit { crate::oci::LinuxHugepageLimit { Pagesize: from.page_size, Limit: from.limit, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -216,8 +203,7 @@ impl From for crate::oci::LinuxInterfacePriority { crate::oci::LinuxInterfacePriority { Name: from.name, Priority: from.priority, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -227,8 +213,7 @@ impl From for crate::oci::LinuxNetwork { crate::oci::LinuxNetwork { ClassID: from.class_id.map_or(0, |t| t), Priorities: from_vec(from.priorities), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -243,8 +228,7 @@ impl From for crate::oci::LinuxResources { BlockIO: from_option(from.block_io), HugepageLimits: from_vec(from.hugepage_limits), Network: from_option(from.network), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -254,8 +238,7 @@ impl From for crate::oci::Root { crate::oci::Root { Path: from.path, Readonly: from.readonly, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -265,10 +248,9 @@ impl From for crate::oci::Mount { crate::oci::Mount { destination: from.destination, source: from.source, - field_type: from.r#type, - options: from_vec(from.options), - unknown_fields: Default::default(), - cached_size: Default::default(), + type_: from.r#type, + options: from.options, + ..Default::default() } } } @@ -281,11 +263,10 @@ impl From for crate::oci::Hook { } crate::oci::Hook { Path: from.path, - Args: from_vec(from.args), - Env: from_vec(from.env), + Args: from.args, + Env: from.env, Timeout: timeout, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -299,8 +280,7 @@ impl From for crate::oci::Hooks { StartContainer: from_vec(from.start_container), Poststart: from_vec(from.poststart), Poststop: from_vec(from.poststop), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -311,8 +291,7 @@ impl From for crate::oci::LinuxIDMapping { HostID: from.host_id, ContainerID: from.container_id, Size: from.size, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -322,8 +301,7 @@ impl From for crate::oci::LinuxNamespace { crate::oci::LinuxNamespace { Type: from.r#type, Path: from.path, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -338,8 +316,7 @@ impl From for crate::oci::LinuxDevice { FileMode: from.file_mode.map_or(0, |v| v), UID: from.uid.map_or(0, |v| v), GID: from.gid.map_or(0, |v| v), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -351,8 +328,7 @@ impl From for crate::oci::LinuxSeccompArg { Value: from.value, ValueTwo: from.value_two, Op: from.op, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -360,14 +336,13 @@ impl From for crate::oci::LinuxSeccompArg { impl From for crate::oci::LinuxSyscall { fn from(from: LinuxSyscall) -> Self { crate::oci::LinuxSyscall { - Names: from_vec(from.names), + Names: from.names, Action: from.action, Args: from_vec(from.args), - ErrnoRet: Some(crate::oci::LinuxSyscall_oneof_ErrnoRet::errnoret( + ErrnoRet: Some(crate::oci::linux_syscall::ErrnoRet::Errnoret( from.errno_ret, )), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -376,11 +351,10 @@ impl From for crate::oci::LinuxSeccomp { fn from(from: LinuxSeccomp) -> Self { crate::oci::LinuxSeccomp { DefaultAction: from.default_action, - Architectures: from_vec(from.architectures), + Architectures: from.architectures, Syscalls: from_vec(from.syscalls), - Flags: from_vec(from.flags), - unknown_fields: Default::default(), - cached_size: Default::default(), + Flags: from.flags, + ..Default::default() } } } @@ -389,8 +363,7 @@ impl From for crate::oci::LinuxIntelRdt { fn from(from: LinuxIntelRdt) -> Self { crate::oci::LinuxIntelRdt { L3CacheSchema: from.l3_cache_schema, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -407,12 +380,11 @@ impl From for crate::oci::Linux { Devices: from_vec(from.devices), Seccomp: from_option(from.seccomp), RootfsPropagation: from.rootfs_propagation, - MaskedPaths: from_vec(from.masked_paths), - ReadonlyPaths: from_vec(from.readonly_paths), + MaskedPaths: from.masked_paths, + ReadonlyPaths: from.readonly_paths, MountLabel: from.mount_label, IntelRdt: from_option(from.intel_rdt), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -430,8 +402,7 @@ impl From for crate::oci::Spec { Linux: from_option(from.linux), Solaris: Default::default(), Windows: Default::default(), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -449,7 +420,7 @@ impl From for oci::Mount { fn from(mut from: crate::oci::Mount) -> Self { let options = from.take_options().to_vec(); Self { - r#type: from.take_field_type(), + r#type: from.take_type_(), destination: from.take_destination(), source: from.take_source(), options, @@ -460,9 +431,9 @@ impl From for oci::Mount { impl From for oci::LinuxIdMapping { fn from(from: crate::oci::LinuxIDMapping) -> Self { LinuxIdMapping { - container_id: from.get_ContainerID(), - host_id: from.get_HostID(), - size: from.get_Size(), + container_id: from.ContainerID(), + host_id: from.HostID(), + size: from.Size(), } } } @@ -470,17 +441,17 @@ impl From for oci::LinuxIdMapping { impl From for oci::LinuxDeviceCgroup { fn from(mut from: crate::oci::LinuxDeviceCgroup) -> Self { let mut major = None; - if from.get_Major() > 0 { - major = Some(from.get_Major()); + if from.Major() > 0 { + major = Some(from.Major()); } let mut minor = None; - if from.get_Minor() > 0 { - minor = Some(from.get_Minor()) + if from.Minor() > 0 { + minor = Some(from.Minor()) } oci::LinuxDeviceCgroup { - allow: from.get_Allow(), + allow: from.Allow(), r#type: from.take_Type(), major, minor, @@ -492,36 +463,36 @@ impl From for oci::LinuxDeviceCgroup { impl From for oci::LinuxMemory { fn from(from: crate::oci::LinuxMemory) -> Self { let mut limit = None; - if from.get_Limit() > 0 { - limit = Some(from.get_Limit()); + if from.Limit() > 0 { + limit = Some(from.Limit()); } let mut reservation = None; - if from.get_Reservation() > 0 { - reservation = Some(from.get_Reservation()); + if from.Reservation() > 0 { + reservation = Some(from.Reservation()); } let mut swap = None; - if from.get_Swap() > 0 { - swap = Some(from.get_Swap()); + if from.Swap() > 0 { + swap = Some(from.Swap()); } let mut kernel = None; - if from.get_Kernel() > 0 { - kernel = Some(from.get_Kernel()); + if from.Kernel() > 0 { + kernel = Some(from.Kernel()); } let mut kernel_tcp = None; - if from.get_KernelTCP() > 0 { - kernel_tcp = Some(from.get_KernelTCP()); + if from.KernelTCP() > 0 { + kernel_tcp = Some(from.KernelTCP()); } let mut swappiness = None; - if from.get_Swappiness() > 0 { - swappiness = Some(from.get_Swappiness()); + if from.Swappiness() > 0 { + swappiness = Some(from.Swappiness()); } - let disable_oom_killer = Some(from.get_DisableOOMKiller()); + let disable_oom_killer = Some(from.DisableOOMKiller()); oci::LinuxMemory { limit, @@ -538,28 +509,28 @@ impl From for oci::LinuxMemory { impl From for oci::LinuxCpu { fn from(mut from: crate::oci::LinuxCPU) -> Self { let mut shares = None; - if from.get_Shares() > 0 { - shares = Some(from.get_Shares()); + if from.Shares() > 0 { + shares = Some(from.Shares()); } let mut quota = None; - if from.get_Quota() > 0 { - quota = Some(from.get_Quota()); + if from.Quota() > 0 { + quota = Some(from.Quota()); } let mut period = None; - if from.get_Period() > 0 { - period = Some(from.get_Period()); + if from.Period() > 0 { + period = Some(from.Period()); } let mut realtime_runtime = None; - if from.get_RealtimeRuntime() > 0 { - realtime_runtime = Some(from.get_RealtimeRuntime()); + if from.RealtimeRuntime() > 0 { + realtime_runtime = Some(from.RealtimeRuntime()); } let mut realtime_period = None; - if from.get_RealtimePeriod() > 0 { - realtime_period = Some(from.get_RealtimePeriod()); + if from.RealtimePeriod() > 0 { + realtime_period = Some(from.RealtimePeriod()); } let cpus = from.take_Cpus(); @@ -580,7 +551,7 @@ impl From for oci::LinuxCpu { impl From for oci::LinuxPids { fn from(from: crate::oci::LinuxPids) -> Self { oci::LinuxPids { - limit: from.get_Limit(), + limit: from.Limit(), } } } @@ -588,35 +559,35 @@ impl From for oci::LinuxPids { impl From for oci::LinuxBlockIo { fn from(from: crate::oci::LinuxBlockIO) -> Self { let mut weight = None; - if from.get_Weight() > 0 { - weight = Some(from.get_Weight() as u16); + if from.Weight() > 0 { + weight = Some(from.Weight() as u16); } let mut leaf_weight = None; - if from.get_LeafWeight() > 0 { - leaf_weight = Some(from.get_LeafWeight() as u16); + if from.LeafWeight() > 0 { + leaf_weight = Some(from.LeafWeight() as u16); } let mut weight_device = Vec::new(); - for wd in from.get_WeightDevice() { + for wd in from.WeightDevice() { weight_device.push(wd.clone().into()); } let mut throttle_read_bps_device = Vec::new(); - for td in from.get_ThrottleReadBpsDevice() { + for td in from.ThrottleReadBpsDevice() { throttle_read_bps_device.push(td.clone().into()); } let mut throttle_write_bps_device = Vec::new(); - for td in from.get_ThrottleWriteBpsDevice() { + for td in from.ThrottleWriteBpsDevice() { throttle_write_bps_device.push(td.clone().into()); } let mut throttle_read_iops_device = Vec::new(); - for td in from.get_ThrottleReadIOPSDevice() { + for td in from.ThrottleReadIOPSDevice() { throttle_read_iops_device.push(td.clone().into()); } let mut throttle_write_iops_device = Vec::new(); - for td in from.get_ThrottleWriteIOPSDevice() { + for td in from.ThrottleWriteIOPSDevice() { throttle_write_iops_device.push(td.clone().into()); } @@ -661,7 +632,7 @@ impl From for oci::LinuxInterfacePriority { fn from(mut from: crate::oci::LinuxInterfacePriority) -> Self { oci::LinuxInterfacePriority { name: from.take_Name(), - priority: from.get_Priority(), + priority: from.Priority(), } } } @@ -669,11 +640,11 @@ impl From for oci::LinuxInterfacePriority { impl From for oci::LinuxNetwork { fn from(mut from: crate::oci::LinuxNetwork) -> Self { let mut class_id = None; - if from.get_ClassID() > 0 { - class_id = Some(from.get_ClassID()); + if from.ClassID() > 0 { + class_id = Some(from.ClassID()); } let mut priorities = Vec::new(); - for p in from.take_Priorities().to_vec() { + for p in from.take_Priorities() { priorities.push(p.into()) } @@ -688,7 +659,7 @@ impl From for oci::LinuxHugepageLimit { fn from(mut from: crate::oci::LinuxHugepageLimit) -> Self { oci::LinuxHugepageLimit { page_size: from.take_Pagesize(), - limit: from.get_Limit(), + limit: from.Limit(), } } } @@ -696,7 +667,7 @@ impl From for oci::LinuxHugepageLimit { impl From for oci::LinuxResources { fn from(mut from: crate::oci::LinuxResources) -> Self { let mut devices = Vec::new(); - for d in from.take_Devices().to_vec() { + for d in from.take_Devices() { devices.push(d.into()); } @@ -712,16 +683,16 @@ impl From for oci::LinuxResources { let mut pids = None; if from.has_Pids() { - pids = Some(from.get_Pids().clone().into()) + pids = Some(from.Pids().clone().into()) } let mut block_io = None; if from.has_BlockIO() { - block_io = Some(from.get_BlockIO().clone().into()); + block_io = Some(from.BlockIO().clone().into()); } let mut hugepage_limits = Vec::new(); - for hl in from.get_HugepageLimits() { + for hl in from.HugepageLimits() { hugepage_limits.push(hl.clone().into()); } @@ -750,11 +721,11 @@ impl From for oci::LinuxDevice { oci::LinuxDevice { path: from.take_Path(), r#type: from.take_Type(), - major: from.get_Major(), - minor: from.get_Minor(), - file_mode: Some(from.get_FileMode()), - uid: Some(from.get_UID()), - gid: Some(from.get_GID()), + major: from.Major(), + minor: from.Minor(), + file_mode: Some(from.FileMode()), + uid: Some(from.UID()), + gid: Some(from.GID()), } } } @@ -762,9 +733,9 @@ impl From for oci::LinuxDevice { impl From for oci::LinuxSeccompArg { fn from(mut from: crate::oci::LinuxSeccompArg) -> Self { oci::LinuxSeccompArg { - index: from.get_Index() as u32, - value: from.get_Value(), - value_two: from.get_ValueTwo(), + index: from.Index() as u32, + value: from.Value(), + value_two: from.ValueTwo(), op: from.take_Op(), } } @@ -773,14 +744,14 @@ impl From for oci::LinuxSeccompArg { impl From for oci::LinuxSyscall { fn from(mut from: crate::oci::LinuxSyscall) -> Self { let mut args = Vec::new(); - for ag in from.take_Args().to_vec() { + for ag in from.take_Args() { args.push(ag.into()); } oci::LinuxSyscall { names: from.take_Names().to_vec(), action: from.take_Action(), args, - errno_ret: from.get_errnoret(), + errno_ret: from.errnoret(), } } } @@ -788,7 +759,7 @@ impl From for oci::LinuxSyscall { impl From for oci::LinuxSeccomp { fn from(mut from: crate::oci::LinuxSeccomp) -> Self { let mut syscalls = Vec::new(); - for s in from.take_Syscalls().to_vec() { + for s in from.take_Syscalls() { syscalls.push(s.into()); } @@ -813,16 +784,16 @@ impl From for oci::LinuxNamespace { impl From for oci::Linux { fn from(mut from: crate::oci::Linux) -> Self { let mut uid_mappings = Vec::new(); - for id_map in from.take_UIDMappings().to_vec() { + for id_map in from.take_UIDMappings() { uid_mappings.push(id_map.into()) } let mut gid_mappings = Vec::new(); - for id_map in from.take_GIDMappings().to_vec() { + for id_map in from.take_GIDMappings() { gid_mappings.push(id_map.into()) } - let sysctl = from.get_Sysctl().clone(); + let sysctl = from.Sysctl().clone(); let mut resources = None; if from.has_Resources() { resources = Some(from.take_Resources().into()); @@ -830,12 +801,12 @@ impl From for oci::Linux { let cgroups_path = from.take_CgroupsPath(); let mut namespaces = Vec::new(); - for ns in from.take_Namespaces().to_vec() { + for ns in from.take_Namespaces() { namespaces.push(ns.into()) } let mut devices = Vec::new(); - for d in from.take_Devices().to_vec() { + for d in from.take_Devices() { devices.push(d.into()); } @@ -874,8 +845,8 @@ impl From for oci::PosixRlimit { fn from(mut from: crate::oci::POSIXRlimit) -> Self { oci::PosixRlimit { r#type: from.take_Type(), - hard: from.get_Hard(), - soft: from.get_Soft(), + hard: from.Hard(), + soft: from.Soft(), } } } @@ -895,8 +866,8 @@ impl From for oci::LinuxCapabilities { impl From for oci::User { fn from(mut from: crate::oci::User) -> Self { oci::User { - uid: from.get_UID(), - gid: from.get_GID(), + uid: from.UID(), + gid: from.GID(), additional_gids: from.take_AdditionalGids().to_vec(), username: from.take_Username(), } @@ -906,8 +877,8 @@ impl From for oci::User { impl From for oci::Box { fn from(from: crate::oci::Box) -> Self { oci::Box { - height: from.get_Height(), - width: from.get_Width(), + height: from.Height(), + width: from.Width(), } } } @@ -920,22 +891,22 @@ impl From for oci::Process { } let user = from.take_User().into(); - let args = from.take_Args().into_vec(); - let env = from.take_Env().into_vec(); + let args = from.take_Args(); + let env = from.take_Env(); let cwd = from.take_Cwd(); let mut capabilities = None; if from.has_Capabilities() { capabilities = Some(from.take_Capabilities().into()); } let mut rlimits = Vec::new(); - for rl in from.take_Rlimits().to_vec() { + for rl in from.take_Rlimits() { rlimits.push(rl.into()); } - let no_new_privileges = from.get_NoNewPrivileges(); + let no_new_privileges = from.NoNewPrivileges(); let apparmor_profile = from.take_ApparmorProfile(); let mut oom_score_adj = None; - if from.get_OOMScoreAdj() != 0 { - oom_score_adj = Some(from.get_OOMScoreAdj() as i32); + if from.OOMScoreAdj() != 0 { + oom_score_adj = Some(from.OOMScoreAdj() as i32); } let selinux_label = from.take_SelinuxLabel(); @@ -959,8 +930,8 @@ impl From for oci::Process { impl From for oci::Hook { fn from(mut from: crate::oci::Hook) -> Self { let mut timeout = None; - if from.get_Timeout() > 0 { - timeout = Some(from.get_Timeout() as i32); + if from.Timeout() > 0 { + timeout = Some(from.Timeout() as i32); } oci::Hook { path: from.take_Path(), @@ -1020,7 +991,7 @@ impl From for oci::Spec { } let mut mounts = Vec::new(); - for m in from.take_Mounts().into_vec() { + for m in from.take_Mounts() { mounts.push(m.into()) } @@ -1085,7 +1056,7 @@ mod tests { #[test] fn test_from_vec_len_0() { let from: Vec = vec![]; - let to: ::protobuf::RepeatedField = from_vec(from.clone()); + let to: Vec = from_vec(from.clone()); assert_eq!(from.len(), to.len()); } @@ -1094,7 +1065,7 @@ mod tests { let from: Vec = vec![TestA { from: "a".to_string(), }]; - let to: ::protobuf::RepeatedField = from_vec(from.clone()); + let to: Vec = from_vec(from.clone()); assert_eq!(from.len(), to.len()); assert_eq!(from[0].from, to[0].to); diff --git a/src/runtime-rs/Cargo.lock b/src/runtime-rs/Cargo.lock index 89ea2abf1b..a68b485d17 100644 --- a/src/runtime-rs/Cargo.lock +++ b/src/runtime-rs/Cargo.lock @@ -50,7 +50,7 @@ dependencies = [ "logging", "nix 0.24.3", "oci", - "protobuf", + "protobuf 3.2.0", "protocols", "serde", "serde_json", @@ -475,7 +475,7 @@ dependencies = [ "nix 0.24.3", "oci", "persist", - "protobuf", + "protobuf 3.2.0", "serde_json", "slog", "slog-scope", @@ -508,13 +508,14 @@ checksum = "f3ad85c1f65dc7b37604eb0e89748faf0b9653065f2a8ef69f96a687ec1e9279" [[package]] name = "containerd-shim-protos" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077ec778a0835d9d85502e8535362130187759b69eddabe2bdb3a68ffb575bd0" +checksum = "ef45f1c71aa587d8f657c546d8da38ea04f113dd05da0ef993c4515fa25fbdd1" dependencies = [ "async-trait", - "protobuf", + "protobuf 3.2.0", "ttrpc", + "ttrpc-codegen", ] [[package]] @@ -2192,9 +2193,16 @@ name = "protobuf" version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + +[[package]] +name = "protobuf" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" dependencies = [ - "serde", - "serde_derive", + "once_cell", + "protobuf-support", + "thiserror", ] [[package]] @@ -2203,36 +2211,47 @@ version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" dependencies = [ - "protobuf", + "protobuf 2.28.0", ] [[package]] -name = "protobuf-codegen-pure" -version = "2.28.0" +name = "protobuf-codegen" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a29399fc94bcd3eeaa951c715f7bea69409b2445356b00519740bcd6ddd865" +checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901" dependencies = [ - "protobuf", - "protobuf-codegen", + "anyhow", + "once_cell", + "protobuf 3.2.0", + "protobuf-parse", + "regex", + "tempfile", + "thiserror", ] [[package]] -name = "protobuf-codegen-pure3" -version = "2.28.2" +name = "protobuf-parse" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b351add14db0721ad0842f4858aec11a5088684112ef163fc50f113c63e69b2e" +checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" dependencies = [ - "protobuf", - "protobuf-codegen3", + "anyhow", + "indexmap", + "log", + "protobuf 3.2.0", + "protobuf-support", + "tempfile", + "thiserror", + "which", ] [[package]] -name = "protobuf-codegen3" -version = "2.28.2" +name = "protobuf-support" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73c5878d0fa872bd7d61782c6aa2d2d56761ba4ed4514eb6992f5f83162f1d2f" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" dependencies = [ - "protobuf", + "thiserror", ] [[package]] @@ -2241,7 +2260,7 @@ version = "0.1.0" dependencies = [ "async-trait", "oci", - "protobuf", + "protobuf 3.2.0", "ttrpc", "ttrpc-codegen", ] @@ -2676,7 +2695,7 @@ dependencies = [ "logging", "nix 0.24.3", "oci", - "protobuf", + "protobuf 3.2.0", "rand 0.8.5", "serial_test", "service", @@ -3136,9 +3155,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "ttrpc" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" +checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c" dependencies = [ "async-trait", "byteorder", @@ -3146,8 +3165,8 @@ dependencies = [ "libc", "log", "nix 0.23.2", - "protobuf", - "protobuf-codegen-pure", + "protobuf 3.2.0", + "protobuf-codegen 3.2.0", "thiserror", "tokio", "tokio-vsock", @@ -3155,28 +3174,28 @@ dependencies = [ [[package]] name = "ttrpc-codegen" -version = "0.2.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2365c9179ad82b29bda1b0162c7542ab5861a7844abfedd8cfdf8bd7e12358f9" +checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2" dependencies = [ - "protobuf", - "protobuf-codegen-pure3", - "protobuf-codegen3", + "protobuf 2.28.0", + "protobuf-codegen 3.2.0", + "protobuf-support", "ttrpc-compiler", ] [[package]] name = "ttrpc-compiler" -version = "0.4.3" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed57c2d6669099791507b8b491b2940f2e8975b52a73fe82efad24257d10e9bc" +checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647" dependencies = [ "derive-new", "prost", "prost-build", "prost-types", - "protobuf", - "protobuf-codegen3", + "protobuf 2.28.0", + "protobuf-codegen 2.28.0", "tempfile", ] @@ -3297,7 +3316,7 @@ dependencies = [ "nix 0.24.3", "oci", "persist", - "protobuf", + "protobuf 3.2.0", "resource", "serde", "serde_derive", diff --git a/src/runtime-rs/crates/agent/Cargo.toml b/src/runtime-rs/crates/agent/Cargo.toml index 0deca014da..4475c6d47c 100644 --- a/src/runtime-rs/crates/agent/Cargo.toml +++ b/src/runtime-rs/crates/agent/Cargo.toml @@ -12,12 +12,12 @@ futures = "0.1.27" anyhow = "1.0.26" async-trait = "0.1.48" log = "0.4.14" -protobuf = "2.27.0" +protobuf = "3.2.0" serde = { version = "^1.0", features = ["derive"] } serde_json = ">=1.0.9" slog = "2.5.2" slog-scope = "4.4.0" -ttrpc = { version = "0.6.1" } +ttrpc = { version = "0.7.1" } tokio = { version = "1.8.0", features = ["fs", "rt"] } url = "2.2.2" nix = "0.24.2" diff --git a/src/runtime-rs/crates/agent/src/kata/agent.rs b/src/runtime-rs/crates/agent/src/kata/agent.rs index aa0df08571..d06da15ea6 100644 --- a/src/runtime-rs/crates/agent/src/kata/agent.rs +++ b/src/runtime-rs/crates/agent/src/kata/agent.rs @@ -56,7 +56,7 @@ macro_rules! impl_health_service { impl HealthService for KataAgent { $(async fn $name(&self, req: $req) -> Result<$resp> { let r = req.into(); - let (mut client, timeout, _) = self.get_health_client().await.context("get health client")?; + let (client, timeout, _) = self.get_health_client().await.context("get health client")?; let resp = client.$name(new_ttrpc_ctx(timeout * MILLISECOND_TO_NANOSECOND), &r).await?; Ok(resp.into()) })* @@ -75,7 +75,7 @@ macro_rules! impl_agent { impl Agent for KataAgent { $(async fn $name(&self, req: $req) -> Result<$resp> { let r = req.into(); - let (mut client, mut timeout, _) = self.get_agent_client().await.context("get client")?; + let (client, mut timeout, _) = self.get_agent_client().await.context("get client")?; // update new timeout if let Some(v) = $new_timeout { diff --git a/src/runtime-rs/crates/agent/src/kata/trans.rs b/src/runtime-rs/crates/agent/src/kata/trans.rs index 7d33a09923..172095ceb3 100644 --- a/src/runtime-rs/crates/agent/src/kata/trans.rs +++ b/src/runtime-rs/crates/agent/src/kata/trans.rs @@ -30,30 +30,18 @@ use crate::{ OomEventResponse, WaitProcessResponse, WriteStreamResponse, }; -fn from_vec, T: Sized>(from: Vec) -> ::protobuf::RepeatedField { - let mut to: Vec = vec![]; - for data in from { - to.push(data.into()); - } - ::protobuf::RepeatedField::from_vec(to) +fn trans_vec>(from: Vec) -> Vec { + from.into_iter().map(|f| f.into()).collect() } -fn into_vec>(from: ::protobuf::RepeatedField) -> Vec { - let mut to: Vec = vec![]; - for data in from.to_vec() { - to.push(data.into()); - } - to -} - -fn from_option>(from: Option) -> ::protobuf::SingularPtrField { +fn from_option>(from: Option) -> protobuf::MessageField { match from { - Some(f) => ::protobuf::SingularPtrField::from_option(Some(T::from(f))), - None => ::protobuf::SingularPtrField::none(), + Some(f) => protobuf::MessageField::from_option(Some(T::from(f))), + None => protobuf::MessageField::none(), } } -fn into_option, T: Sized>(from: ::protobuf::SingularPtrField) -> Option { +fn into_option, T: Sized>(from: protobuf::MessageField) -> Option { from.into_option().map(|f| f.into()) } @@ -84,9 +72,8 @@ impl From for agent::FSGroup { Self { group_id: from.group_id, - group_change_policy: policy, - unknown_fields: Default::default(), - cached_size: Default::default(), + group_change_policy: policy.into(), + ..Default::default() } } } @@ -96,9 +83,8 @@ impl From for agent::StringUser { Self { uid: from.uid, gid: from.gid, - additionalGids: ::protobuf::RepeatedField::from_vec(from.additional_gids), - unknown_fields: Default::default(), - cached_size: Default::default(), + additionalGids: from.additional_gids, + ..Default::default() } } } @@ -107,12 +93,11 @@ impl From for agent::Device { fn from(from: Device) -> Self { Self { id: from.id, - field_type: from.field_type, + type_: from.field_type, vm_path: from.vm_path, container_path: from.container_path, - options: from_vec(from.options), - unknown_fields: Default::default(), - cached_size: Default::default(), + options: trans_vec(from.options), + ..Default::default() } } } @@ -121,14 +106,13 @@ impl From for agent::Storage { fn from(from: Storage) -> Self { Self { driver: from.driver, - driver_options: from_vec(from.driver_options), + driver_options: trans_vec(from.driver_options), source: from.source, fstype: from.fs_type, fs_group: from_option(from.fs_group), - options: from_vec(from.options), + options: trans_vec(from.options), mount_point: from.mount_point, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -137,9 +121,8 @@ impl From for agent::KernelModule { fn from(from: KernelModule) -> Self { Self { name: from.name, - parameters: from_vec(from.parameters), - unknown_fields: Default::default(), - cached_size: Default::default(), + parameters: trans_vec(from.parameters), + ..Default::default() } } } @@ -166,11 +149,10 @@ impl From for IPFamily { impl From for types::IPAddress { fn from(from: IPAddress) -> Self { Self { - family: from.family.into(), + family: protobuf::EnumOrUnknown::new(from.family.into()), address: from.address, mask: from.mask, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -178,7 +160,7 @@ impl From for types::IPAddress { impl From for IPAddress { fn from(src: types::IPAddress) -> Self { Self { - family: src.family.into(), + family: src.family.unwrap().into(), address: "".to_string(), mask: "".to_string(), } @@ -190,14 +172,13 @@ impl From for types::Interface { Self { device: from.device, name: from.name, - IPAddresses: from_vec(from.ip_addresses), + IPAddresses: trans_vec(from.ip_addresses), mtu: from.mtu, hwAddr: from.hw_addr, pciPath: from.pci_addr, - field_type: from.field_type, + type_: from.field_type, raw_flags: from.raw_flags, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -207,11 +188,11 @@ impl From for Interface { Self { device: src.device, name: src.name, - ip_addresses: into_vec(src.IPAddresses), + ip_addresses: trans_vec(src.IPAddresses), mtu: src.mtu, hw_addr: src.hwAddr, pci_addr: src.pciPath, - field_type: src.field_type, + field_type: src.type_, raw_flags: src.raw_flags, } } @@ -220,7 +201,7 @@ impl From for Interface { impl From for Interfaces { fn from(src: agent::Interfaces) -> Self { Self { - interfaces: into_vec(src.Interfaces), + interfaces: trans_vec(src.Interfaces), } } } @@ -233,9 +214,8 @@ impl From for types::Route { device: from.device, source: from.source, scope: from.scope, - family: from.family.into(), - unknown_fields: Default::default(), - cached_size: Default::default(), + family: protobuf::EnumOrUnknown::new(from.family.into()), + ..Default::default() } } } @@ -248,7 +228,7 @@ impl From for Route { device: src.device, source: src.source, scope: src.scope, - family: src.family.into(), + family: src.family.unwrap().into(), } } } @@ -256,9 +236,8 @@ impl From for Route { impl From for agent::Routes { fn from(from: Routes) -> Self { Self { - Routes: from_vec(from.routes), - unknown_fields: Default::default(), - cached_size: Default::default(), + Routes: trans_vec(from.routes), + ..Default::default() } } } @@ -266,7 +245,7 @@ impl From for agent::Routes { impl From for Routes { fn from(src: agent::Routes) -> Self { Self { - routes: into_vec(src.Routes), + routes: trans_vec(src.Routes), } } } @@ -277,12 +256,11 @@ impl From for agent::CreateContainerRequest { container_id: from.process_id.container_id(), exec_id: from.process_id.exec_id(), string_user: from_option(from.string_user), - devices: from_vec(from.devices), - storages: from_vec(from.storages), + devices: trans_vec(from.devices), + storages: trans_vec(from.storages), OCI: from_option(from.oci), sandbox_pidns: from.sandbox_pidns, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -292,8 +270,7 @@ impl From for agent::RemoveContainerRequest { Self { container_id: from.container_id, timeout: from.timeout, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -302,8 +279,7 @@ impl From for agent::StartContainerRequest { fn from(from: ContainerID) -> Self { Self { container_id: from.container_id, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -312,8 +288,7 @@ impl From for agent::StatsContainerRequest { fn from(from: ContainerID) -> Self { Self { container_id: from.container_id, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -322,8 +297,7 @@ impl From for agent::PauseContainerRequest { fn from(from: ContainerID) -> Self { Self { container_id: from.container_id, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -332,8 +306,7 @@ impl From for agent::ResumeContainerRequest { fn from(from: ContainerID) -> Self { Self { container_id: from.container_id, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -344,8 +317,7 @@ impl From for agent::SignalProcessRequest { container_id: from.process_id.container_id(), exec_id: from.process_id.exec_id(), signal: from.signal, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -355,8 +327,7 @@ impl From for agent::WaitProcessRequest { Self { container_id: from.process_id.container_id(), exec_id: from.process_id.exec_id(), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -366,8 +337,7 @@ impl From for agent::UpdateContainerRequest { Self { container_id: from.container_id, resources: from_option(Some(from.resources)), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -378,8 +348,7 @@ impl From for agent::WriteStreamRequest { container_id: from.process_id.container_id(), exec_id: from.process_id.exec_id(), data: from.data, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -402,7 +371,7 @@ impl From for agent::GetIPTablesRequest { impl From for GetIPTablesResponse { fn from(from: agent::GetIPTablesResponse) -> Self { Self { - data: from.get_data().to_vec(), + data: from.data().to_vec(), } } } @@ -420,7 +389,7 @@ impl From for agent::SetIPTablesRequest { impl From for SetIPTablesResponse { fn from(from: agent::SetIPTablesResponse) -> Self { Self { - data: from.get_data().to_vec(), + data: from.data().to_vec(), } } } @@ -432,8 +401,7 @@ impl From for agent::ExecProcessRequest { exec_id: from.process_id.exec_id(), string_user: from_option(from.string_user), process: from_option(from.process), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -515,14 +483,14 @@ impl From for BlkioStatsEntry { impl From for BlkioStats { fn from(src: agent::BlkioStats) -> Self { Self { - io_service_bytes_recursive: into_vec(src.io_service_bytes_recursive), - io_serviced_recursive: into_vec(src.io_serviced_recursive), - io_queued_recursive: into_vec(src.io_queued_recursive), - io_service_time_recursive: into_vec(src.io_service_time_recursive), - io_wait_time_recursive: into_vec(src.io_wait_time_recursive), - io_merged_recursive: into_vec(src.io_merged_recursive), - io_time_recursive: into_vec(src.io_time_recursive), - sectors_recursive: into_vec(src.sectors_recursive), + io_service_bytes_recursive: trans_vec(src.io_service_bytes_recursive), + io_serviced_recursive: trans_vec(src.io_serviced_recursive), + io_queued_recursive: trans_vec(src.io_queued_recursive), + io_service_time_recursive: trans_vec(src.io_service_time_recursive), + io_wait_time_recursive: trans_vec(src.io_wait_time_recursive), + io_merged_recursive: trans_vec(src.io_merged_recursive), + io_time_recursive: trans_vec(src.io_time_recursive), + sectors_recursive: trans_vec(src.sectors_recursive), } } } @@ -570,7 +538,7 @@ impl From for StatsContainerResponse { fn from(src: agent::StatsContainerResponse) -> Self { Self { cgroup_stats: into_option(src.cgroup_stats), - network_stats: into_vec(src.network_stats), + network_stats: trans_vec(src.network_stats), } } } @@ -581,8 +549,7 @@ impl From for agent::ReadStreamRequest { container_id: from.process_id.container_id(), exec_id: from.process_id.exec_id(), len: from.len, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -598,8 +565,7 @@ impl From for agent::CloseStdinRequest { Self { container_id: from.process_id.container_id(), exec_id: from.process_id.exec_id(), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -611,8 +577,7 @@ impl From for agent::TtyWinResizeRequest { exec_id: from.process_id.exec_id(), row: from.row, column: from.column, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -621,8 +586,7 @@ impl From for agent::UpdateInterfaceRequest { fn from(from: UpdateInterfaceRequest) -> Self { Self { interface: from_option(from.interface), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -630,8 +594,7 @@ impl From for agent::UpdateInterfaceRequest { impl From for agent::ListInterfacesRequest { fn from(_: Empty) -> Self { Self { - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -640,8 +603,7 @@ impl From for agent::UpdateRoutesRequest { fn from(from: UpdateRoutesRequest) -> Self { Self { routes: from_option(from.route), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -649,8 +611,7 @@ impl From for agent::UpdateRoutesRequest { impl From for agent::ListRoutesRequest { fn from(_: Empty) -> Self { Self { - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -663,8 +624,7 @@ impl From for types::ARPNeighbor { lladdr: from.ll_addr, state: from.state, flags: from.flags, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -672,9 +632,8 @@ impl From for types::ARPNeighbor { impl From for agent::ARPNeighbors { fn from(from: ARPNeighbors) -> Self { Self { - ARPNeighbors: from_vec(from.neighbors), - unknown_fields: Default::default(), - cached_size: Default::default(), + ARPNeighbors: trans_vec(from.neighbors), + ..Default::default() } } } @@ -683,8 +642,7 @@ impl From for agent::AddARPNeighborsRequest { fn from(from: AddArpNeighborRequest) -> Self { Self { neighbors: from_option(from.neighbors), - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -693,14 +651,13 @@ impl From for agent::CreateSandboxRequest { fn from(from: CreateSandboxRequest) -> Self { Self { hostname: from.hostname, - dns: from_vec(from.dns), - storages: from_vec(from.storages), + dns: trans_vec(from.dns), + storages: trans_vec(from.storages), sandbox_pidns: from.sandbox_pidns, sandbox_id: from.sandbox_id, guest_hook_path: from.guest_hook_path, - kernel_modules: from_vec(from.kernel_modules), - unknown_fields: Default::default(), - cached_size: Default::default(), + kernel_modules: trans_vec(from.kernel_modules), + ..Default::default() } } } @@ -708,8 +665,7 @@ impl From for agent::CreateSandboxRequest { impl From for agent::DestroySandboxRequest { fn from(_: Empty) -> Self { Self { - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -720,8 +676,7 @@ impl From for agent::OnlineCPUMemRequest { wait: from.wait, nb_cpus: from.nb_cpus, cpu_only: from.cpu_only, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -730,8 +685,7 @@ impl From for agent::ReseedRandomDevRequest { fn from(from: ReseedRandomDevRequest) -> Self { Self { data: from.data, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -740,8 +694,7 @@ impl From for agent::MemHotplugByProbeRequest { fn from(from: MemHotplugByProbeRequest) -> Self { Self { memHotplugProbeAddr: from.mem_hotplug_probe_addr, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -751,8 +704,7 @@ impl From for agent::SetGuestDateTimeRequest { Self { Sec: from.sec, Usec: from.usec, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -762,8 +714,8 @@ impl From for AgentDetails { Self { version: src.version, init_daemon: src.init_daemon, - device_handlers: into_vec(src.device_handlers), - storage_handlers: into_vec(src.storage_handlers), + device_handlers: trans_vec(src.device_handlers), + storage_handlers: trans_vec(src.storage_handlers), supports_seccomp: src.supports_seccomp, } } @@ -790,8 +742,7 @@ impl From for agent::CopyFileRequest { gid: from.gid, offset: from.offset, data: from.data, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -807,8 +758,7 @@ impl From for WaitProcessResponse { impl From for agent::GetOOMEventRequest { fn from(_: Empty) -> Self { Self { - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -817,8 +767,7 @@ impl From for health::CheckRequest { fn from(from: CheckRequest) -> Self { Self { service: from.service, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -826,7 +775,7 @@ impl From for health::CheckRequest { impl From for HealthCheckResponse { fn from(from: health::HealthCheckResponse) -> Self { Self { - status: from.status as u32, + status: from.status.value() as u32, } } } @@ -852,8 +801,7 @@ impl From for agent::VolumeStatsRequest { fn from(from: VolumeStatsRequest) -> Self { Self { volume_guest_path: from.volume_guest_path, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } @@ -862,8 +810,8 @@ impl From for VolumeStatsResponse { fn from(from: csi::VolumeStatsResponse) -> Self { let result: String = format!( "Usage: {:?} Volume Condition: {:?}", - from.get_usage(), - from.get_volume_condition() + from.usage(), + from.volume_condition() ); Self { data: result } } @@ -874,8 +822,7 @@ impl From for agent::ResizeVolumeRequest { Self { volume_guest_path: from.volume_guest_path, size: from.size, - unknown_fields: Default::default(), - cached_size: Default::default(), + ..Default::default() } } } diff --git a/src/runtime-rs/crates/runtimes/common/Cargo.toml b/src/runtime-rs/crates/runtimes/common/Cargo.toml index 78a640e95d..440db14868 100644 --- a/src/runtime-rs/crates/runtimes/common/Cargo.toml +++ b/src/runtime-rs/crates/runtimes/common/Cargo.toml @@ -10,17 +10,17 @@ license = "Apache-2.0" [dependencies] anyhow = "^1.0" async-trait = "0.1.48" -containerd-shim-protos = { version = "0.2.0", features = ["async"]} +containerd-shim-protos = { version = "0.3.0", features = ["async"]} lazy_static = "1.4.0" nix = "0.24.2" -protobuf = "2.27.0" +protobuf = "3.2.0" serde_json = "1.0.39" slog = "2.5.2" slog-scope = "4.4.0" strum = { version = "0.24.0", features = ["derive"] } thiserror = "^1.0" tokio = { version = "1.8.0", features = ["rt-multi-thread", "process", "fs"] } -ttrpc = { version = "0.6.1" } +ttrpc = { version = "0.7.1" } persist = {path = "../../persist"} agent = { path = "../../agent" } kata-sys-util = { path = "../../../../libs/kata-sys-util" } diff --git a/src/runtime-rs/crates/runtimes/common/src/types/trans_from_agent.rs b/src/runtime-rs/crates/runtimes/common/src/types/trans_from_agent.rs index 8877771223..f28f50582b 100644 --- a/src/runtime-rs/crates/runtimes/common/src/types/trans_from_agent.rs +++ b/src/runtime-rs/crates/runtimes/common/src/types/trans_from_agent.rs @@ -151,7 +151,7 @@ impl From> for StatsInfo { } if !cg_stats.hugetlb_stats.is_empty() { - let mut p_huge = ::protobuf::RepeatedField::new(); + let mut p_huge = Vec::new(); for (k, v) in cg_stats.hugetlb_stats { let mut h = metrics::HugetlbStat::new(); h.set_pagesize(k); @@ -166,7 +166,7 @@ impl From> for StatsInfo { let net_stats = stats.network_stats; if !net_stats.is_empty() { - let mut p_net = ::protobuf::RepeatedField::new(); + let mut p_net = Vec::new(); for v in net_stats.iter() { let mut h = metrics::NetworkStat::new(); h.set_name(v.name.clone()); @@ -195,10 +195,8 @@ impl From> for StatsInfo { } } -fn copy_blkio_entry( - entry: &[agent::BlkioStatsEntry], -) -> ::protobuf::RepeatedField { - let mut p_entry = ::protobuf::RepeatedField::new(); +fn copy_blkio_entry(entry: &[agent::BlkioStatsEntry]) -> Vec { + let mut p_entry = Vec::new(); for e in entry.iter() { let mut blk = metrics::BlkIOEntry::new(); diff --git a/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs b/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs index 4d5d7ddf16..29a4a676ce 100644 --- a/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs +++ b/src/runtime-rs/crates/runtimes/common/src/types/trans_from_shim.rs @@ -16,7 +16,7 @@ use std::{ path::PathBuf, }; -fn trans_from_shim_mount(from: api::Mount) -> Mount { +fn trans_from_shim_mount(from: &api::Mount) -> Mount { let options = from.options.to_vec(); let mut read_only = false; for o in &options { @@ -29,7 +29,7 @@ fn trans_from_shim_mount(from: api::Mount) -> Mount { Mount { source: from.source.clone(), destination: PathBuf::from(&from.target), - fs_type: from.field_type, + fs_type: from.type_.clone(), options, device_id: None, host_shared_fs_path: None, @@ -41,19 +41,14 @@ impl TryFrom for Request { type Error = anyhow::Error; fn try_from(from: api::CreateTaskRequest) -> Result { let options = if from.has_options() { - Some(from.get_options().get_value().to_vec()) + Some(from.options().value.to_vec()) } else { None }; Ok(Request::CreateContainer(ContainerConfig { container_id: from.id.clone(), bundle: from.bundle.clone(), - rootfs_mounts: from - .rootfs - .to_vec() - .into_iter() - .map(trans_from_shim_mount) - .collect(), + rootfs_mounts: from.rootfs.iter().map(trans_from_shim_mount).collect(), terminal: from.terminal, options, stdin: (!from.stdin.is_empty()).then(|| from.stdin.clone()), @@ -84,15 +79,15 @@ impl TryFrom for Request { impl TryFrom for Request { type Error = anyhow::Error; fn try_from(from: api::ExecProcessRequest) -> Result { - let spec = from.get_spec(); + let spec = from.spec(); Ok(Request::ExecProcess(ExecProcessRequest { process: ContainerProcess::new(&from.id, &from.exec_id).context("new process id")?, terminal: from.terminal, stdin: (!from.stdin.is_empty()).then(|| from.stdin.clone()), stdout: (!from.stdout.is_empty()).then(|| from.stdout.clone()), stderr: (!from.stderr.is_empty()).then(|| from.stderr.clone()), - spec_type_url: spec.get_type_url().to_string(), - spec_value: spec.get_value().to_vec(), + spec_type_url: spec.type_url.to_string(), + spec_value: spec.value.to_vec(), })) } } @@ -182,7 +177,7 @@ impl TryFrom for Request { fn try_from(from: api::UpdateTaskRequest) -> Result { Ok(Request::UpdateContainer(UpdateRequest { container_id: from.id.to_string(), - value: from.get_resources().get_value().to_vec(), + value: from.resources().value.to_vec(), })) } } diff --git a/src/runtime-rs/crates/runtimes/common/src/types/trans_into_shim.rs b/src/runtime-rs/crates/runtimes/common/src/types/trans_into_shim.rs index 345e02d932..841805bb0e 100644 --- a/src/runtime-rs/crates/runtimes/common/src/types/trans_into_shim.rs +++ b/src/runtime-rs/crates/runtimes/common/src/types/trans_into_shim.rs @@ -16,24 +16,24 @@ use containerd_shim_protos::api; use super::{ProcessExitStatus, ProcessStateInfo, ProcessStatus, Response}; use crate::error::Error; -fn system_time_into(time: time::SystemTime) -> ::protobuf::well_known_types::Timestamp { - let mut proto_time = ::protobuf::well_known_types::Timestamp::new(); - proto_time.set_seconds( - time.duration_since(time::UNIX_EPOCH) - .unwrap_or_default() - .as_secs() - .try_into() - .unwrap_or_default(), - ); +fn system_time_into(time: time::SystemTime) -> ::protobuf::well_known_types::timestamp::Timestamp { + let mut proto_time = ::protobuf::well_known_types::timestamp::Timestamp::new(); + proto_time.seconds = time + .duration_since(time::UNIX_EPOCH) + .unwrap_or_default() + .as_secs() + .try_into() + .unwrap_or_default(); + proto_time } fn option_system_time_into( time: Option, -) -> ::protobuf::SingularPtrField<::protobuf::well_known_types::Timestamp> { +) -> protobuf::MessageField { match time { - Some(v) => ::protobuf::SingularPtrField::some(system_time_into(v)), - None => ::protobuf::SingularPtrField::none(), + Some(v) => ::protobuf::MessageField::some(system_time_into(v)), + None => ::protobuf::MessageField::none(), } } @@ -66,7 +66,7 @@ impl From for api::StateResponse { id: from.container_id.clone(), bundle: from.bundle.clone(), pid: from.pid.pid, - status: from.status.into(), + status: protobuf::EnumOrUnknown::new(from.status.into()), stdin: from.stdin.unwrap_or_default(), stdout: from.stdout.unwrap_or_default(), stderr: from.stderr.unwrap_or_default(), @@ -164,13 +164,13 @@ impl TryFrom for api::StateResponse { impl TryFrom for api::StatsResponse { type Error = anyhow::Error; fn try_from(from: Response) -> Result { - let mut any = ::protobuf::well_known_types::Any::new(); + let mut any = ::protobuf::well_known_types::any::Any::new(); let mut response = api::StatsResponse::new(); match from { Response::StatsContainer(resp) => { if let Some(value) = resp.value { - any.set_type_url(value.type_url); - any.set_value(value.value); + any.type_url = value.type_url; + any.value = value.value; response.set_stats(any); } Ok(response) @@ -193,8 +193,7 @@ impl TryFrom for api::PidsResponse { let mut res = api::PidsResponse::new(); p_info.set_pid(resp.pid); processes.push(p_info); - let v = protobuf::RepeatedField::::from_vec(processes); - res.set_processes(v); + res.set_processes(processes); Ok(res) } _ => Err(anyhow!(Error::UnexpectedResponse( diff --git a/src/runtime-rs/crates/runtimes/virt_container/Cargo.toml b/src/runtime-rs/crates/runtimes/virt_container/Cargo.toml index 6dea5e7628..f3d8d93755 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/Cargo.toml +++ b/src/runtime-rs/crates/runtimes/virt_container/Cargo.toml @@ -9,12 +9,12 @@ license = "Apache-2.0" anyhow = "^1.0" async-trait = "0.1.48" awaitgroup = "0.6.0" -containerd-shim-protos = { version = "0.2.0", features = ["async"]} +containerd-shim-protos = { version = "0.3.0", features = ["async"]} futures = "0.3.19" lazy_static = "1.4.0" libc = ">=0.2.39" nix = "0.24.2" -protobuf = "2.27.0" +protobuf = "3.2.0" serde = { version = "1.0.100", features = ["derive"] } serde_derive = "1.0.27" serde_json = "1.0.82" diff --git a/src/runtime-rs/crates/service/Cargo.toml b/src/runtime-rs/crates/service/Cargo.toml index 82e2c4fbc4..cb414abe3b 100644 --- a/src/runtime-rs/crates/service/Cargo.toml +++ b/src/runtime-rs/crates/service/Cargo.toml @@ -11,10 +11,10 @@ async-trait = "0.1.48" slog = "2.5.2" slog-scope = "4.4.0" tokio = { version = "1.8.0", features = ["rt-multi-thread"] } -ttrpc = { version = "0.6.1" } +ttrpc = { version = "0.7.1" } common = { path = "../runtimes/common" } -containerd-shim-protos = { version = "0.2.0", features = ["async"]} +containerd-shim-protos = { version = "0.3.0", features = ["async"]} logging = { path = "../../../libs/logging"} shim-interface = { path = "../../../libs/shim-interface" } runtimes = { path = "../runtimes" } diff --git a/src/runtime-rs/crates/service/src/manager.rs b/src/runtime-rs/crates/service/src/manager.rs index fe31c179b0..ff0fd997cf 100644 --- a/src/runtime-rs/crates/service/src/manager.rs +++ b/src/runtime-rs/crates/service/src/manager.rs @@ -14,7 +14,7 @@ use std::{ use anyhow::{Context, Result}; use common::message::{Action, Event, Message}; use containerd_shim_protos::{ - protobuf::{well_known_types::Any, Message as ProtobufMessage}, + protobuf::{well_known_types::any::Any, Message as ProtobufMessage}, shim_async, }; use runtimes::RuntimeHandlerManager; diff --git a/src/runtime-rs/crates/shim/Cargo.toml b/src/runtime-rs/crates/shim/Cargo.toml index 76abe1e9fc..84521eb005 100644 --- a/src/runtime-rs/crates/shim/Cargo.toml +++ b/src/runtime-rs/crates/shim/Cargo.toml @@ -15,12 +15,12 @@ path = "src/bin/main.rs" [dependencies] anyhow = "^1.0" backtrace = {version = ">=0.3.35", features = ["libunwind", "libbacktrace", "std"], default-features = false} -containerd-shim-protos = { version = "0.2.0", features = ["async"]} +containerd-shim-protos = { version = "0.3.0", features = ["async"]} go-flag = "0.1.0" libc = "0.2.108" log = "0.4.14" nix = "0.24.2" -protobuf = "2.27.0" +protobuf = "3.2.0" sha2 = "=0.9.3" slog = {version = "2.5.2", features = ["std", "release_max_level_trace", "max_level_trace"]} slog-async = "2.5.2" diff --git a/src/runtime-rs/crates/shim/src/shim_delete.rs b/src/runtime-rs/crates/shim/src/shim_delete.rs index e1053927f6..412fc8be6c 100644 --- a/src/runtime-rs/crates/shim/src/shim_delete.rs +++ b/src/runtime-rs/crates/shim/src/shim_delete.rs @@ -26,12 +26,12 @@ impl ShimExecutor { async fn do_cleanup(&self) -> Result { let mut rsp = api::DeleteResponse::new(); rsp.set_exit_status(128 + libc::SIGKILL as u32); - let mut exited_time = protobuf::well_known_types::Timestamp::new(); + let mut exited_time = protobuf::well_known_types::timestamp::Timestamp::new(); let seconds = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .map_err(Error::SystemTime)? .as_secs() as i64; - exited_time.set_seconds(seconds); + exited_time.seconds = seconds; rsp.set_exited_at(exited_time); let address = self diff --git a/src/tools/agent-ctl/Cargo.lock b/src/tools/agent-ctl/Cargo.lock index 234830c3a6..bfa0177fbd 100644 --- a/src/tools/agent-ctl/Cargo.lock +++ b/src/tools/agent-ctl/Cargo.lock @@ -31,9 +31,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.51" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" +checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "arc-swap" @@ -114,7 +114,7 @@ checksum = "d7d78656ba01f1b93024b7c3a0467f1608e4be67d725749fdcd7d2c7678fd7a2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -131,7 +131,7 @@ checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -176,7 +176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd9e32d7420c85055e8107e5b2463c4eeefeaac18b52359fe9f9c08a18f342b2" dependencies = [ "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -340,7 +340,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -351,7 +351,7 @@ checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -398,7 +398,7 @@ checksum = "f58dc3c5e468259f19f2d46304a6b28f1c3d034442e14b322d2b850e36f6d5ae" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -527,7 +527,7 @@ dependencies = [ "proc-macro-hack", "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -593,9 +593,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" @@ -651,9 +651,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.7.0" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", @@ -728,7 +728,7 @@ dependencies = [ "logging", "nix 0.23.1", "oci", - "protobuf", + "protobuf 3.2.0", "protocols", "rand 0.8.4", "rustjail", @@ -1084,11 +1084,11 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.34" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1129,7 +1129,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -1144,31 +1144,68 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.27.1" +version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + +[[package]] +name = "protobuf" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" dependencies = [ - "serde", - "serde_derive", + "once_cell", + "protobuf-support", + "thiserror", ] [[package]] name = "protobuf-codegen" -version = "2.27.1" +version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" +checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" dependencies = [ - "protobuf", + "protobuf 2.28.0", ] [[package]] -name = "protobuf-codegen-pure" -version = "2.27.1" +name = "protobuf-codegen" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" +checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901" dependencies = [ - "protobuf", - "protobuf-codegen", + "anyhow", + "once_cell", + "protobuf 3.2.0", + "protobuf-parse", + "regex", + "tempfile", + "thiserror", +] + +[[package]] +name = "protobuf-parse" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" +dependencies = [ + "anyhow", + "indexmap", + "log", + "protobuf 3.2.0", + "protobuf-support", + "tempfile", + "thiserror", + "which", +] + +[[package]] +name = "protobuf-support" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" +dependencies = [ + "thiserror", ] [[package]] @@ -1176,7 +1213,7 @@ name = "protocols" version = "0.1.0" dependencies = [ "oci", - "protobuf", + "protobuf 3.2.0", "serde", "serde_json", "ttrpc", @@ -1185,9 +1222,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.10" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -1347,7 +1384,7 @@ dependencies = [ "nix 0.24.2", "oci", "path-absolutize", - "protobuf", + "protobuf 3.2.0", "protocols", "regex", "rlimit", @@ -1386,22 +1423,22 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.132" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.132" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.14", ] [[package]] @@ -1423,7 +1460,7 @@ checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -1552,6 +1589,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syn" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf316d5356ed6847742d036f8a39c3b8435cac10bd528a4bd461928a6ab34d5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "take_mut" version = "0.2.2" @@ -1598,7 +1646,7 @@ checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -1645,7 +1693,7 @@ checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -1677,7 +1725,7 @@ checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] [[package]] @@ -1691,43 +1739,43 @@ dependencies = [ [[package]] name = "ttrpc" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7d6c992964a013c17814c08d31708d577b0aae44ebadb58755659dd824c2d1" +checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c" dependencies = [ "byteorder", "libc", "log", "nix 0.23.1", - "protobuf", - "protobuf-codegen-pure", + "protobuf 3.2.0", + "protobuf-codegen 3.2.0", "thiserror", ] [[package]] name = "ttrpc-codegen" -version = "0.2.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" +checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2" dependencies = [ - "protobuf", - "protobuf-codegen", - "protobuf-codegen-pure", + "protobuf 2.28.0", + "protobuf-codegen 3.2.0", + "protobuf-support", "ttrpc-compiler", ] [[package]] name = "ttrpc-compiler" -version = "0.4.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2978ed3fa047d8fd55cbeb4d4a61d461fb3021a90c9618519c73ce7e5bb66c15" +checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647" dependencies = [ "derive-new", "prost", "prost-build", "prost-types", - "protobuf", - "protobuf-codegen", + "protobuf 2.28.0", + "protobuf-codegen 2.28.0", "tempfile", ] @@ -1741,6 +1789,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + [[package]] name = "unicode-segmentation" version = "1.8.0" @@ -1804,7 +1858,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 1.0.82", "wasm-bindgen-shared", ] @@ -1826,7 +1880,7 @@ checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.82", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1981,7 +2035,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn", + "syn 1.0.82", ] [[package]] @@ -2018,5 +2072,5 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.82", ] diff --git a/src/tools/agent-ctl/Cargo.toml b/src/tools/agent-ctl/Cargo.toml index 25852d83ba..033380396a 100644 --- a/src/tools/agent-ctl/Cargo.toml +++ b/src/tools/agent-ctl/Cargo.toml @@ -27,12 +27,12 @@ logging = { path = "../../libs/logging" } slog = "2.7.0" slog-scope = "4.4.0" rand = "0.8.4" -protobuf = "2.27.0" +protobuf = "3.2.0" nix = "0.23.0" libc = "0.2.112" # XXX: Must be the same as the version used by the agent -ttrpc = { version = "0.6.0" } +ttrpc = { version = "0.7.1" } # For parsing timeouts humantime = "2.1.0" diff --git a/src/tools/agent-ctl/src/utils.rs b/src/tools/agent-ctl/src/utils.rs index 6ba10841b9..59dba46f0f 100644 --- a/src/tools/agent-ctl/src/utils.rs +++ b/src/tools/agent-ctl/src/utils.rs @@ -268,8 +268,7 @@ fn root_oci_to_ttrpc(bundle_dir: &str, root: &ociRoot) -> Result { let ttrpc_root = ttrpcRoot { Path: path, Readonly: root.readonly, - unknown_fields: protobuf::UnknownFields::new(), - cached_size: protobuf::CachedSize::default(), + ..Default::default() }; Ok(ttrpc_root) @@ -281,9 +280,9 @@ fn process_oci_to_ttrpc(p: &ociProcess) -> ttrpcProcess { let mut b = ttrpcBox::new(); b.set_Width(s.width); b.set_Height(s.height); - protobuf::SingularPtrField::some(b) + protobuf::MessageField::some(b) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), }; let oom_score_adj: i64 = match p.oom_score_adj { @@ -298,23 +297,23 @@ fn process_oci_to_ttrpc(p: &ociProcess) -> ttrpcProcess { // FIXME: Implement RLimits OCI spec handling (copy from p.rlimits) //let rlimits = vec![ttrpcPOSIXRlimit::new()]; - let rlimits = protobuf::RepeatedField::new(); + let rlimits = Vec::new(); let capabilities = match &p.capabilities { Some(c) => { let mut gc = ttrpcLinuxCapabilities::new(); - gc.set_Bounding(protobuf::RepeatedField::from_slice(&c.bounding)); - gc.set_Effective(protobuf::RepeatedField::from_slice(&c.effective)); - gc.set_Inheritable(protobuf::RepeatedField::from_slice(&c.inheritable)); - gc.set_Permitted(protobuf::RepeatedField::from_slice(&c.permitted)); - gc.set_Ambient(protobuf::RepeatedField::from_slice(&c.ambient)); + gc.set_Bounding(c.bounding.clone()); + gc.set_Effective(c.effective.clone()); + gc.set_Inheritable(c.inheritable.clone()); + gc.set_Permitted(c.permitted.clone()); + gc.set_Ambient(c.ambient.clone()); - protobuf::SingularPtrField::some(gc) + protobuf::MessageField::some(gc) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), }; - let mut env = protobuf::RepeatedField::new(); + let mut env = Vec::new(); for pair in &p.env { env.push(pair.to_string()); } @@ -322,8 +321,8 @@ fn process_oci_to_ttrpc(p: &ociProcess) -> ttrpcProcess { ttrpcProcess { Terminal: p.terminal, ConsoleSize: console_size, - User: protobuf::SingularPtrField::some(user), - Args: protobuf::RepeatedField::from_vec(p.args.clone()), + User: protobuf::MessageField::some(user), + Args: p.args.clone(), Env: env, Cwd: p.cwd.clone(), Capabilities: capabilities, @@ -332,13 +331,12 @@ fn process_oci_to_ttrpc(p: &ociProcess) -> ttrpcProcess { ApparmorProfile: p.apparmor_profile.clone(), OOMScoreAdj: oom_score_adj, SelinuxLabel: p.selinux_label.clone(), - unknown_fields: protobuf::UnknownFields::new(), - cached_size: protobuf::CachedSize::default(), + ..Default::default() } } fn mount_oci_to_ttrpc(m: &ociMount) -> ttrpcMount { - let mut ttrpc_options = protobuf::RepeatedField::new(); + let mut ttrpc_options = Vec::new(); for op in &m.options { ttrpc_options.push(op.to_string()); } @@ -346,17 +344,14 @@ fn mount_oci_to_ttrpc(m: &ociMount) -> ttrpcMount { ttrpcMount { destination: m.destination.clone(), source: m.source.clone(), - field_type: m.r#type.clone(), + type_: m.r#type.clone(), options: ttrpc_options, - unknown_fields: protobuf::UnknownFields::new(), - cached_size: protobuf::CachedSize::default(), + ..Default::default() } } -fn idmaps_oci_to_ttrpc( - res: &[oci::LinuxIdMapping], -) -> protobuf::RepeatedField { - let mut ttrpc_idmaps = protobuf::RepeatedField::new(); +fn idmaps_oci_to_ttrpc(res: &[oci::LinuxIdMapping]) -> Vec { + let mut ttrpc_idmaps = Vec::new(); for m in res.iter() { let mut idmapping = ttrpcLinuxIDMapping::default(); idmapping.set_HostID(m.host_id); @@ -367,10 +362,8 @@ fn idmaps_oci_to_ttrpc( ttrpc_idmaps } -fn devices_oci_to_ttrpc( - res: &[oci::LinuxDeviceCgroup], -) -> protobuf::RepeatedField { - let mut ttrpc_devices = protobuf::RepeatedField::new(); +fn devices_oci_to_ttrpc(res: &[oci::LinuxDeviceCgroup]) -> Vec { + let mut ttrpc_devices = Vec::new(); for d in res.iter() { let mut device = ttrpcLinuxDeviceCgroup::default(); device.set_Major(d.major.unwrap_or(0)); @@ -383,12 +376,10 @@ fn devices_oci_to_ttrpc( ttrpc_devices } -fn memory_oci_to_ttrpc( - res: &Option, -) -> protobuf::SingularPtrField { +fn memory_oci_to_ttrpc(res: &Option) -> protobuf::MessageField { let memory = if res.is_some() { let mem = res.as_ref().unwrap(); - protobuf::SingularPtrField::some(ttrpcLinuxMemory { + protobuf::MessageField::some(ttrpcLinuxMemory { Limit: mem.limit.unwrap_or(0), Reservation: mem.reservation.unwrap_or(0), Swap: mem.swap.unwrap_or(0), @@ -396,16 +387,15 @@ fn memory_oci_to_ttrpc( KernelTCP: mem.kernel_tcp.unwrap_or(0), Swappiness: mem.swappiness.unwrap_or(0), DisableOOMKiller: mem.disable_oom_killer.unwrap_or(false), - unknown_fields: protobuf::UnknownFields::new(), - cached_size: protobuf::CachedSize::default(), + ..Default::default() }) } else { - protobuf::SingularPtrField::none() + protobuf::MessageField::none() }; memory } -fn cpu_oci_to_ttrpc(res: &Option) -> protobuf::SingularPtrField { +fn cpu_oci_to_ttrpc(res: &Option) -> protobuf::MessageField { match &res { Some(s) => { let mut cpu = ttrpcLinuxCPU::default(); @@ -414,27 +404,25 @@ fn cpu_oci_to_ttrpc(res: &Option) -> protobuf::SingularPtrField protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), } } -fn pids_oci_to_ttrpc(res: &Option) -> protobuf::SingularPtrField { +fn pids_oci_to_ttrpc(res: &Option) -> protobuf::MessageField { match &res { Some(s) => { let mut b = ttrpcLinuxPids::new(); b.set_Limit(s.limit); - protobuf::SingularPtrField::some(b) + protobuf::MessageField::some(b) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), } } -fn hugepage_limits_oci_to_ttrpc( - res: &[oci::LinuxHugepageLimit], -) -> protobuf::RepeatedField { - let mut ttrpc_hugepage_limits = protobuf::RepeatedField::new(); +fn hugepage_limits_oci_to_ttrpc(res: &[oci::LinuxHugepageLimit]) -> Vec { + let mut ttrpc_hugepage_limits = Vec::new(); for h in res.iter() { let mut hugepage_limit = ttrpcLinuxHugepageLimit::default(); hugepage_limit.set_Limit(h.limit); @@ -446,28 +434,26 @@ fn hugepage_limits_oci_to_ttrpc( fn network_oci_to_ttrpc( res: &Option, -) -> protobuf::SingularPtrField { +) -> protobuf::MessageField { match &res { Some(s) => { let mut b = ttrpcLinuxNetwork::new(); b.set_ClassID(s.class_id.unwrap_or(0)); - let mut priorities = protobuf::RepeatedField::new(); + let mut priorities = Vec::new(); for pr in s.priorities.iter() { let mut lip = ttrpcLinuxInterfacePriority::new(); lip.set_Name(pr.name.clone()); lip.set_Priority(pr.priority); priorities.push(lip); } - protobuf::SingularPtrField::some(b) + protobuf::MessageField::some(b) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), } } -fn weight_devices_oci_to_ttrpc( - res: &[oci::LinuxWeightDevice], -) -> protobuf::RepeatedField { - let mut ttrpc_weight_devices = protobuf::RepeatedField::new(); +fn weight_devices_oci_to_ttrpc(res: &[oci::LinuxWeightDevice]) -> Vec { + let mut ttrpc_weight_devices = Vec::new(); for dev in res.iter() { let mut device = ttrpcLinuxWeightDevice::default(); device.set_Major(dev.blk.major); @@ -489,8 +475,8 @@ fn weight_devices_oci_to_ttrpc( fn throttle_devices_oci_to_ttrpc( res: &[oci::LinuxThrottleDevice], -) -> protobuf::RepeatedField { - let mut ttrpc_throttle_devices = protobuf::RepeatedField::new(); +) -> Vec { + let mut ttrpc_throttle_devices = Vec::new(); for dev in res.iter() { let mut device = ttrpcLinuxThrottleDevice::default(); device.set_Major(dev.blk.major); @@ -503,7 +489,7 @@ fn throttle_devices_oci_to_ttrpc( fn block_io_oci_to_ttrpc( res: &Option, -) -> protobuf::SingularPtrField { +) -> protobuf::MessageField { match &res { Some(s) => { let mut b = ttrpcLinuxBlockIO::new(); @@ -529,9 +515,9 @@ fn block_io_oci_to_ttrpc( b.set_ThrottleWriteIOPSDevice(throttle_devices_oci_to_ttrpc( &s.throttle_write_iops_device, )); - protobuf::SingularPtrField::some(b) + protobuf::MessageField::some(b) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), } } @@ -552,15 +538,12 @@ fn resources_oci_to_ttrpc(res: &oci::LinuxResources) -> ttrpcLinuxResources { BlockIO: block_io, HugepageLimits: hugepage_limits, Network: network, - unknown_fields: protobuf::UnknownFields::new(), - cached_size: protobuf::CachedSize::default(), + ..Default::default() } } -fn namespace_oci_to_ttrpc( - res: &[oci::LinuxNamespace], -) -> protobuf::RepeatedField { - let mut ttrpc_namespace = protobuf::RepeatedField::new(); +fn namespace_oci_to_ttrpc(res: &[oci::LinuxNamespace]) -> Vec { + let mut ttrpc_namespace = Vec::new(); for n in res.iter() { let mut ns = ttrpcLinuxNamespace::default(); ns.set_Path(n.path.clone()); @@ -570,10 +553,8 @@ fn namespace_oci_to_ttrpc( ttrpc_namespace } -fn linux_devices_oci_to_ttrpc( - res: &[oci::LinuxDevice], -) -> protobuf::RepeatedField { - let mut ttrpc_linux_devices = protobuf::RepeatedField::new(); +fn linux_devices_oci_to_ttrpc(res: &[oci::LinuxDevice]) -> Vec { + let mut ttrpc_linux_devices = Vec::new(); for n in res.iter() { let mut ld = ttrpcLinuxDevice::default(); ld.set_FileMode(n.file_mode.unwrap_or(0)); @@ -590,22 +571,22 @@ fn linux_devices_oci_to_ttrpc( fn seccomp_oci_to_ttrpc(sec: &oci::LinuxSeccomp) -> ttrpcLinuxSeccomp { let mut ttrpc_seccomp = ttrpcLinuxSeccomp::default(); - let mut ttrpc_arch = protobuf::RepeatedField::new(); + let mut ttrpc_arch = Vec::new(); for a in &sec.architectures { ttrpc_arch.push(std::string::String::from(a)); } ttrpc_seccomp.set_Architectures(ttrpc_arch); ttrpc_seccomp.set_DefaultAction(sec.default_action.clone()); - let mut ttrpc_flags = protobuf::RepeatedField::new(); + let mut ttrpc_flags = Vec::new(); for f in &sec.flags { ttrpc_flags.push(std::string::String::from(f)); } ttrpc_seccomp.set_Flags(ttrpc_flags); - let mut ttrpc_syscalls = protobuf::RepeatedField::new(); + let mut ttrpc_syscalls = Vec::new(); for sys in &sec.syscalls { let mut ttrpc_sys = ttrpcLinuxSyscall::default(); ttrpc_sys.set_Action(sys.action.clone()); - let mut ttrpc_args = protobuf::RepeatedField::new(); + let mut ttrpc_args = Vec::new(); for arg in &sys.args { let mut a = ttrpcLinuxSeccompArg::default(); a.set_Index(arg.index as u64); @@ -632,9 +613,9 @@ fn linux_oci_to_ttrpc(l: &ociLinux) -> ttrpcLinux { let ttrpc_linux_resources = match &l.resources { Some(s) => { let b = resources_oci_to_ttrpc(s); - protobuf::SingularPtrField::some(b) + protobuf::MessageField::some(b) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), }; let ttrpc_namespaces = namespace_oci_to_ttrpc(&l.namespaces); @@ -642,17 +623,17 @@ fn linux_oci_to_ttrpc(l: &ociLinux) -> ttrpcLinux { let ttrpc_seccomp = match &l.seccomp { Some(s) => { let b = seccomp_oci_to_ttrpc(s); - protobuf::SingularPtrField::some(b) + protobuf::MessageField::some(b) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), }; let ttrpc_intel_rdt = match &l.intel_rdt { Some(s) => { let b = intel_rdt_oci_to_ttrpc(s); - protobuf::SingularPtrField::some(b) + protobuf::MessageField::some(b) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), }; ttrpcLinux { @@ -665,38 +646,37 @@ fn linux_oci_to_ttrpc(l: &ociLinux) -> ttrpcLinux { Devices: ttrpc_linux_devices, Seccomp: ttrpc_seccomp, RootfsPropagation: l.rootfs_propagation.clone(), - MaskedPaths: protobuf::RepeatedField::from_slice(&l.masked_paths), - ReadonlyPaths: protobuf::RepeatedField::from_slice(&l.readonly_paths), + MaskedPaths: l.masked_paths.clone(), + ReadonlyPaths: l.readonly_paths.clone(), MountLabel: l.mount_label.clone(), IntelRdt: ttrpc_intel_rdt, - unknown_fields: protobuf::UnknownFields::new(), - cached_size: protobuf::CachedSize::default(), + ..Default::default() } } fn oci_to_ttrpc(bundle_dir: &str, cid: &str, oci: &ociSpec) -> Result { let process = match &oci.process { - Some(p) => protobuf::SingularPtrField::some(process_oci_to_ttrpc(p)), - None => protobuf::SingularPtrField::none(), + Some(p) => protobuf::MessageField::some(process_oci_to_ttrpc(p)), + None => protobuf::MessageField::none(), }; let root = match &oci.root { Some(r) => { let ttrpc_root = root_oci_to_ttrpc(bundle_dir, r)?; - protobuf::SingularPtrField::some(ttrpc_root) + protobuf::MessageField::some(ttrpc_root) } - None => protobuf::SingularPtrField::none(), + None => protobuf::MessageField::none(), }; - let mut mounts = protobuf::RepeatedField::new(); + let mut mounts = Vec::new(); for m in &oci.mounts { mounts.push(mount_oci_to_ttrpc(m)); } let linux = match &oci.linux { - Some(l) => protobuf::SingularPtrField::some(linux_oci_to_ttrpc(l)), - None => protobuf::SingularPtrField::none(), + Some(l) => protobuf::MessageField::some(linux_oci_to_ttrpc(l)), + None => protobuf::MessageField::none(), }; if cid.len() < MIN_HOSTNAME_LEN as usize { @@ -713,13 +693,12 @@ fn oci_to_ttrpc(bundle_dir: &str, cid: &str, oci: &ociSpec) -> Result Root: root, Hostname: hostname, Mounts: mounts, - Hooks: protobuf::SingularPtrField::none(), + Hooks: protobuf::MessageField::none(), Annotations: HashMap::new(), Linux: linux, - Solaris: protobuf::SingularPtrField::none(), - Windows: protobuf::SingularPtrField::none(), - unknown_fields: protobuf::UnknownFields::new(), - cached_size: protobuf::CachedSize::default(), + Solaris: protobuf::MessageField::none(), + Windows: protobuf::MessageField::none(), + ..Default::default() }; Ok(ttrpc_spec) diff --git a/src/tools/kata-ctl/Cargo.lock b/src/tools/kata-ctl/Cargo.lock index 3edafa91d2..6acf131f0d 100644 --- a/src/tools/kata-ctl/Cargo.lock +++ b/src/tools/kata-ctl/Cargo.lock @@ -13,7 +13,7 @@ dependencies = [ "logging", "nix 0.24.3", "oci", - "protobuf", + "protobuf 3.2.0", "protocols", "serde", "serde_json", @@ -657,7 +657,6 @@ dependencies = [ "test-utils", "thiserror", "tokio", - "ttrpc", "url", "vmm-sys-util", ] @@ -1108,9 +1107,16 @@ name = "protobuf" version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + +[[package]] +name = "protobuf" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" dependencies = [ - "serde", - "serde_derive", + "once_cell", + "protobuf-support", + "thiserror", ] [[package]] @@ -1119,27 +1125,47 @@ version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" dependencies = [ - "protobuf", + "protobuf 2.28.0", ] [[package]] -name = "protobuf-codegen-pure" -version = "2.28.0" +name = "protobuf-codegen" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a29399fc94bcd3eeaa951c715f7bea69409b2445356b00519740bcd6ddd865" +checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901" dependencies = [ - "protobuf", - "protobuf-codegen", + "anyhow", + "once_cell", + "protobuf 3.2.0", + "protobuf-parse", + "regex", + "tempfile", + "thiserror", ] [[package]] -name = "protobuf-codegen-pure3" -version = "2.28.1" +name = "protobuf-parse" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0a3cf0a7de7570cb67bfb9a9a585b5841b49790a1be0ef104340a2110b91135" +checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" dependencies = [ - "protobuf", - "protobuf-codegen", + "anyhow", + "indexmap", + "log", + "protobuf 3.2.0", + "protobuf-support", + "tempfile", + "thiserror", + "which", +] + +[[package]] +name = "protobuf-support" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" +dependencies = [ + "thiserror", ] [[package]] @@ -1148,7 +1174,7 @@ version = "0.1.0" dependencies = [ "async-trait", "oci", - "protobuf", + "protobuf 3.2.0", "ttrpc", "ttrpc-codegen", ] @@ -1771,9 +1797,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "ttrpc" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" +checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c" dependencies = [ "async-trait", "byteorder", @@ -1781,8 +1807,8 @@ dependencies = [ "libc", "log", "nix 0.23.2", - "protobuf", - "protobuf-codegen-pure", + "protobuf 3.2.0", + "protobuf-codegen 3.2.0", "thiserror", "tokio", "tokio-vsock", @@ -1790,28 +1816,28 @@ dependencies = [ [[package]] name = "ttrpc-codegen" -version = "0.2.2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df80affc2cf8c589172b05ba2b8e8a88722ebf4e28b86604615497a8b6fb78c0" +checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2" dependencies = [ - "protobuf", - "protobuf-codegen", - "protobuf-codegen-pure3", + "protobuf 2.28.0", + "protobuf-codegen 3.2.0", + "protobuf-support", "ttrpc-compiler", ] [[package]] name = "ttrpc-compiler" -version = "0.4.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8db19ce6af25713061dd805d6733b6f0c45904bd63526ce5d2568c858b7edc71" +checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647" dependencies = [ "derive-new", "prost", "prost-build", "prost-types", - "protobuf", - "protobuf-codegen", + "protobuf 2.28.0", + "protobuf-codegen 2.28.0", "tempfile", ] diff --git a/src/tools/kata-ctl/Cargo.toml b/src/tools/kata-ctl/Cargo.toml index 233f0e3a04..3de3a532a7 100644 --- a/src/tools/kata-ctl/Cargo.toml +++ b/src/tools/kata-ctl/Cargo.toml @@ -37,7 +37,6 @@ libc = "0.2.138" slog = "2.7.0" slog-scope = "4.4.0" hyper = "0.14.20" -ttrpc = "0.6.0" tokio = "1.8.0" [target.'cfg(target_arch = "s390x")'.dependencies] diff --git a/src/tools/trace-forwarder/Cargo.lock b/src/tools/trace-forwarder/Cargo.lock index ce1f994d26..7a6a7c0ac7 100644 --- a/src/tools/trace-forwarder/Cargo.lock +++ b/src/tools/trace-forwarder/Cargo.lock @@ -289,7 +289,6 @@ dependencies = [ "opentelemetry 0.14.0", "opentelemetry-jaeger", "privdrop", - "protobuf", "serde", "serde_json", "slog", @@ -527,12 +526,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "protobuf" -version = "2.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" - [[package]] name = "quote" version = "1.0.10" diff --git a/src/tools/trace-forwarder/Cargo.toml b/src/tools/trace-forwarder/Cargo.toml index fc0b69631e..0b6d3d5502 100644 --- a/src/tools/trace-forwarder/Cargo.toml +++ b/src/tools/trace-forwarder/Cargo.toml @@ -23,7 +23,6 @@ serde_json = "1.0.44" anyhow = "1.0.31" opentelemetry = { version = "0.14.0", features=["serialize"] } opentelemetry-jaeger = "0.13.0" -protobuf = "2.27.0" tracing-opentelemetry = "0.16.0" tracing = "0.1.29" tracing-subscriber = "0.3.3"