Merge pull request #6673 from Tim-Zhang/upgrade-ttrpc-protobuf

Bump ttrpc to 0.7.2 and protobuf to 3.2.0
This commit is contained in:
Fupan Li 2023-04-20 10:13:43 +08:00 committed by GitHub
commit a7b4b69230
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 1025 additions and 974 deletions

87
src/agent/Cargo.lock generated
View File

@ -819,7 +819,7 @@ dependencies = [
"opentelemetry", "opentelemetry",
"procfs", "procfs",
"prometheus", "prometheus",
"protobuf", "protobuf 3.2.0",
"protocols", "protocols",
"regex", "regex",
"rtnetlink", "rtnetlink",
@ -1431,7 +1431,7 @@ dependencies = [
"memchr", "memchr",
"parking_lot 0.12.1", "parking_lot 0.12.1",
"procfs", "procfs",
"protobuf", "protobuf 2.27.1",
"thiserror", "thiserror",
] ]
@ -1491,9 +1491,16 @@ name = "protobuf"
version = "2.27.1" version = "2.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96"
[[package]]
name = "protobuf"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e"
dependencies = [ dependencies = [
"serde", "once_cell",
"serde_derive", "protobuf-support",
"thiserror",
] ]
[[package]] [[package]]
@ -1502,17 +1509,47 @@ version = "2.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.27.1",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure" name = "protobuf-codegen"
version = "2.27.1" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen", "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]] [[package]]
@ -1521,7 +1558,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"ttrpc", "ttrpc",
"ttrpc-codegen", "ttrpc-codegen",
] ]
@ -1705,7 +1742,7 @@ dependencies = [
"nix 0.24.2", "nix 0.24.2",
"oci", "oci",
"path-absolutize", "path-absolutize",
"protobuf", "protobuf 3.2.0",
"protocols", "protocols",
"regex", "regex",
"rlimit", "rlimit",
@ -2217,9 +2254,9 @@ dependencies = [
[[package]] [[package]]
name = "ttrpc" name = "ttrpc"
version = "0.6.1" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"byteorder", "byteorder",
@ -2227,8 +2264,8 @@ dependencies = [
"libc", "libc",
"log", "log",
"nix 0.23.1", "nix 0.23.1",
"protobuf", "protobuf 3.2.0",
"protobuf-codegen-pure", "protobuf-codegen 3.2.0",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-vsock", "tokio-vsock",
@ -2236,28 +2273,28 @@ dependencies = [
[[package]] [[package]]
name = "ttrpc-codegen" name = "ttrpc-codegen"
version = "0.2.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.27.1",
"protobuf-codegen", "protobuf-codegen 3.2.0",
"protobuf-codegen-pure", "protobuf-support",
"ttrpc-compiler", "ttrpc-compiler",
] ]
[[package]] [[package]]
name = "ttrpc-compiler" name = "ttrpc-compiler"
version = "0.4.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2978ed3fa047d8fd55cbeb4d4a61d461fb3021a90c9618519c73ce7e5bb66c15" checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647"
dependencies = [ dependencies = [
"derive-new", "derive-new",
"prost", "prost",
"prost-build", "prost-build",
"prost-types", "prost-types",
"protobuf", "protobuf 2.27.1",
"protobuf-codegen", "protobuf-codegen 2.27.1",
"tempfile", "tempfile",
] ]

View File

@ -10,8 +10,8 @@ oci = { path = "../libs/oci" }
rustjail = { path = "rustjail" } rustjail = { path = "rustjail" }
protocols = { path = "../libs/protocols", features = ["async"] } protocols = { path = "../libs/protocols", features = ["async"] }
lazy_static = "1.3.0" lazy_static = "1.3.0"
ttrpc = { version = "0.6.0", features = ["async"], default-features = false } ttrpc = { version = "0.7.1", features = ["async"], default-features = false }
protobuf = "2.27.0" protobuf = "3.2.0"
libc = "0.2.58" libc = "0.2.58"
nix = "0.24.2" nix = "0.24.2"
capctl = "0.2.0" capctl = "0.2.0"

View File

@ -18,7 +18,7 @@ scopeguard = "1.0.0"
capctl = "0.2.0" capctl = "0.2.0"
lazy_static = "1.3.0" lazy_static = "1.3.0"
libc = "0.2.58" libc = "0.2.58"
protobuf = "2.27.0" protobuf = "3.2.0"
slog = "2.5.2" slog = "2.5.2"
slog-scope = "4.1.2" slog-scope = "4.1.2"
scan_fmt = "0.2.6" scan_fmt = "0.2.6"

View File

@ -27,7 +27,7 @@ use oci::{
LinuxNetwork, LinuxPids, LinuxResources, LinuxNetwork, LinuxPids, LinuxResources,
}; };
use protobuf::{CachedSize, RepeatedField, SingularPtrField, UnknownFields}; use protobuf::MessageField;
use protocols::agent::{ use protocols::agent::{
BlkioStats, BlkioStatsEntry, CgroupStats, CpuStats, CpuUsage, HugetlbStats, MemoryData, BlkioStats, BlkioStatsEntry, CgroupStats, CpuStats, CpuUsage, HugetlbStats, MemoryData,
MemoryStats, PidsStats, ThrottlingData, MemoryStats, PidsStats, ThrottlingData,
@ -50,7 +50,7 @@ macro_rules! get_controller_or_return_singular_none {
($cg:ident) => { ($cg:ident) => {
match $cg.controller_of() { match $cg.controller_of() {
Some(c) => c, 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 throttling_data = get_cpu_stats(&self.cgroup);
let cpu_stats = SingularPtrField::some(CpuStats { let cpu_stats = MessageField::some(CpuStats {
cpu_usage, cpu_usage,
throttling_data, throttling_data,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}); });
// Memorystats // Memorystats
@ -160,8 +159,7 @@ impl CgroupManager for Manager {
pids_stats, pids_stats,
blkio_stats, blkio_stats,
hugetlb_stats, hugetlb_stats,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}) })
} }
@ -446,14 +444,14 @@ fn set_memory_resources(cg: &cgroups::Cgroup, memory: &LinuxMemory, update: bool
let memstat = get_memory_stats(cg) let memstat = get_memory_stats(cg)
.into_option() .into_option()
.ok_or_else(|| anyhow!("failed to get the cgroup memory stats"))?; .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 // 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 // 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 // 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 // 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. // 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)?; mem_controller.set_memswap_limit(swap)?;
set_resource!(mem_controller, set_limit, memory, limit); set_resource!(mem_controller, set_limit, memory, limit);
} else { } else {
@ -657,21 +655,20 @@ lazy_static! {
}; };
} }
fn get_cpu_stats(cg: &cgroups::Cgroup) -> SingularPtrField<ThrottlingData> { fn get_cpu_stats(cg: &cgroups::Cgroup) -> MessageField<ThrottlingData> {
let cpu_controller: &CpuController = get_controller_or_return_singular_none!(cg); let cpu_controller: &CpuController = get_controller_or_return_singular_none!(cg);
let stat = cpu_controller.cpu().stat; let stat = cpu_controller.cpu().stat;
let h = lines_to_map(&stat); let h = lines_to_map(&stat);
SingularPtrField::some(ThrottlingData { MessageField::some(ThrottlingData {
periods: *h.get("nr_periods").unwrap_or(&0), periods: *h.get("nr_periods").unwrap_or(&0),
throttled_periods: *h.get("nr_throttled").unwrap_or(&0), throttled_periods: *h.get("nr_throttled").unwrap_or(&0),
throttled_time: *h.get("throttled_time").unwrap_or(&0), throttled_time: *h.get("throttled_time").unwrap_or(&0),
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}) })
} }
fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField<CpuUsage> { fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> MessageField<CpuUsage> {
if let Some(cpuacct_controller) = cg.controller_of::<CpuAcctController>() { if let Some(cpuacct_controller) = cg.controller_of::<CpuAcctController>() {
let cpuacct = cpuacct_controller.cpuacct(); let cpuacct = cpuacct_controller.cpuacct();
@ -685,13 +682,12 @@ fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField<CpuUsage> {
let percpu_usage = line_to_vec(&cpuacct.usage_percpu); let percpu_usage = line_to_vec(&cpuacct.usage_percpu);
return SingularPtrField::some(CpuUsage { return MessageField::some(CpuUsage {
total_usage, total_usage,
percpu_usage, percpu_usage,
usage_in_kernelmode, usage_in_kernelmode,
usage_in_usermode, usage_in_usermode,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}); });
} }
@ -704,17 +700,16 @@ fn get_cpuacct_stats(cg: &cgroups::Cgroup) -> SingularPtrField<CpuUsage> {
let total_usage = *h.get("usage_usec").unwrap_or(&0); let total_usage = *h.get("usage_usec").unwrap_or(&0);
let percpu_usage = vec![]; let percpu_usage = vec![];
SingularPtrField::some(CpuUsage { MessageField::some(CpuUsage {
total_usage, total_usage,
percpu_usage, percpu_usage,
usage_in_kernelmode, usage_in_kernelmode,
usage_in_usermode, usage_in_usermode,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}) })
} }
fn get_memory_stats(cg: &cgroups::Cgroup) -> SingularPtrField<MemoryStats> { fn get_memory_stats(cg: &cgroups::Cgroup) -> MessageField<MemoryStats> {
let memory_controller: &MemController = get_controller_or_return_singular_none!(cg); let memory_controller: &MemController = get_controller_or_return_singular_none!(cg);
// cache from memory stat // cache from memory stat
@ -726,52 +721,48 @@ fn get_memory_stats(cg: &cgroups::Cgroup) -> SingularPtrField<MemoryStats> {
let use_hierarchy = value == 1; let use_hierarchy = value == 1;
// get memory data // get memory data
let usage = SingularPtrField::some(MemoryData { let usage = MessageField::some(MemoryData {
usage: memory.usage_in_bytes, usage: memory.usage_in_bytes,
max_usage: memory.max_usage_in_bytes, max_usage: memory.max_usage_in_bytes,
failcnt: memory.fail_cnt, failcnt: memory.fail_cnt,
limit: memory.limit_in_bytes as u64, limit: memory.limit_in_bytes as u64,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}); });
// get swap usage // get swap usage
let memswap = memory_controller.memswap(); let memswap = memory_controller.memswap();
let swap_usage = SingularPtrField::some(MemoryData { let swap_usage = MessageField::some(MemoryData {
usage: memswap.usage_in_bytes, usage: memswap.usage_in_bytes,
max_usage: memswap.max_usage_in_bytes, max_usage: memswap.max_usage_in_bytes,
failcnt: memswap.fail_cnt, failcnt: memswap.fail_cnt,
limit: memswap.limit_in_bytes as u64, limit: memswap.limit_in_bytes as u64,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}); });
// get kernel usage // get kernel usage
let kmem_stat = memory_controller.kmem_stat(); 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, usage: kmem_stat.usage_in_bytes,
max_usage: kmem_stat.max_usage_in_bytes, max_usage: kmem_stat.max_usage_in_bytes,
failcnt: kmem_stat.fail_cnt, failcnt: kmem_stat.fail_cnt,
limit: kmem_stat.limit_in_bytes as u64, limit: kmem_stat.limit_in_bytes as u64,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}); });
SingularPtrField::some(MemoryStats { MessageField::some(MemoryStats {
cache, cache,
usage, usage,
swap_usage, swap_usage,
kernel_usage, kernel_usage,
use_hierarchy, use_hierarchy,
stats: memory.stat.raw, stats: memory.stat.raw,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}) })
} }
fn get_pids_stats(cg: &cgroups::Cgroup) -> SingularPtrField<PidsStats> { fn get_pids_stats(cg: &cgroups::Cgroup) -> MessageField<PidsStats> {
let pid_controller: &PidController = get_controller_or_return_singular_none!(cg); let pid_controller: &PidController = get_controller_or_return_singular_none!(cg);
let current = pid_controller.get_pid_current().unwrap_or(0); let current = pid_controller.get_pid_current().unwrap_or(0);
@ -785,11 +776,10 @@ fn get_pids_stats(cg: &cgroups::Cgroup) -> SingularPtrField<PidsStats> {
}, },
} as u64; } as u64;
SingularPtrField::some(PidsStats { MessageField::some(PidsStats {
current, current,
limit, limit,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}) })
} }
@ -825,8 +815,8 @@ https://github.com/opencontainers/runc/blob/a5847db387ae28c0ca4ebe4beee1a76900c8
Total 0 Total 0
*/ */
fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField<BlkioStatsEntry> { fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> Vec<BlkioStatsEntry> {
let mut m = RepeatedField::new(); let mut m = Vec::new();
if blkiodata.is_empty() { if blkiodata.is_empty() {
return m; return m;
} }
@ -839,16 +829,15 @@ fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField<BlkioStats
minor: d.minor as u64, minor: d.minor as u64,
op: op.clone(), op: op.clone(),
value: d.data, value: d.data,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}); });
} }
m m
} }
fn get_blkio_stat_ioservice(services: &[IoService]) -> RepeatedField<BlkioStatsEntry> { fn get_blkio_stat_ioservice(services: &[IoService]) -> Vec<BlkioStatsEntry> {
let mut m = RepeatedField::new(); let mut m = Vec::new();
if services.is_empty() { if services.is_empty() {
return m; return m;
@ -872,17 +861,16 @@ fn build_blkio_stats_entry(major: i16, minor: i16, op: &str, value: u64) -> Blki
minor: minor as u64, minor: minor as u64,
op: op.to_string(), op: op.to_string(),
value, value,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
} }
} }
fn get_blkio_stats_v2(cg: &cgroups::Cgroup) -> SingularPtrField<BlkioStats> { fn get_blkio_stats_v2(cg: &cgroups::Cgroup) -> MessageField<BlkioStats> {
let blkio_controller: &BlkIoController = get_controller_or_return_singular_none!(cg); let blkio_controller: &BlkIoController = get_controller_or_return_singular_none!(cg);
let blkio = blkio_controller.blkio(); let blkio = blkio_controller.blkio();
let mut resp = BlkioStats::new(); let mut resp = BlkioStats::new();
let mut blkio_stats = RepeatedField::new(); let mut blkio_stats = Vec::new();
let stat = blkio.io_stat; let stat = blkio.io_stat;
for s in stat { for s in stat {
@ -898,10 +886,10 @@ fn get_blkio_stats_v2(cg: &cgroups::Cgroup) -> SingularPtrField<BlkioStats> {
resp.io_service_bytes_recursive = blkio_stats; resp.io_service_bytes_recursive = blkio_stats;
SingularPtrField::some(resp) MessageField::some(resp)
} }
fn get_blkio_stats(cg: &cgroups::Cgroup) -> SingularPtrField<BlkioStats> { fn get_blkio_stats(cg: &cgroups::Cgroup) -> MessageField<BlkioStats> {
if cg.v2() { if cg.v2() {
return get_blkio_stats_v2(cg); return get_blkio_stats_v2(cg);
} }
@ -934,7 +922,7 @@ fn get_blkio_stats(cg: &cgroups::Cgroup) -> SingularPtrField<BlkioStats> {
m.sectors_recursive = get_blkio_stat_blkiodata(&blkio.sectors_recursive); m.sectors_recursive = get_blkio_stat_blkiodata(&blkio.sectors_recursive);
} }
SingularPtrField::some(m) MessageField::some(m)
} }
fn get_hugetlb_stats(cg: &cgroups::Cgroup) -> HashMap<String, HugetlbStats> { fn get_hugetlb_stats(cg: &cgroups::Cgroup) -> HashMap<String, HugetlbStats> {
@ -958,8 +946,7 @@ fn get_hugetlb_stats(cg: &cgroups::Cgroup) -> HashMap<String, HugetlbStats> {
usage, usage,
max_usage, max_usage,
failcnt, failcnt,
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}, },
); );
} }

View File

@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
use protobuf::{CachedSize, SingularPtrField, UnknownFields}; use protobuf::MessageField;
use crate::cgroups::Manager as CgroupManager; use crate::cgroups::Manager as CgroupManager;
use crate::protocols::agent::{BlkioStats, CgroupStats, CpuStats, MemoryStats, PidsStats}; use crate::protocols::agent::{BlkioStats, CgroupStats, CpuStats, MemoryStats, PidsStats};
@ -33,13 +33,12 @@ impl CgroupManager for Manager {
fn get_stats(&self) -> Result<CgroupStats> { fn get_stats(&self) -> Result<CgroupStats> {
Ok(CgroupStats { Ok(CgroupStats {
cpu_stats: SingularPtrField::some(CpuStats::default()), cpu_stats: MessageField::some(CpuStats::default()),
memory_stats: SingularPtrField::some(MemoryStats::new()), memory_stats: MessageField::some(MemoryStats::new()),
pids_stats: SingularPtrField::some(PidsStats::new()), pids_stats: MessageField::some(PidsStats::new()),
blkio_stats: SingularPtrField::some(BlkioStats::new()), blkio_stats: MessageField::some(BlkioStats::new()),
hugetlb_stats: HashMap::new(), hugetlb_stats: HashMap::new(),
unknown_fields: UnknownFields::default(), ..Default::default()
cached_size: CachedSize::default(),
}) })
} }

View File

@ -48,7 +48,7 @@ use nix::unistd::{self, fork, ForkResult, Gid, Pid, Uid, User};
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use protobuf::SingularPtrField; use protobuf::MessageField;
use oci::State as OCIState; use oci::State as OCIState;
use regex::Regex; use regex::Regex;
@ -875,7 +875,7 @@ impl BaseContainer for LinuxContainer {
// what about network interface stats? // what about network interface stats?
Ok(StatsContainerResponse { 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() ..Default::default()
}) })
} }

View File

@ -82,11 +82,11 @@ pub fn process_grpc_to_oci(p: &grpc::Process) -> oci::Process {
let cap = p.Capabilities.as_ref().unwrap(); let cap = p.Capabilities.as_ref().unwrap();
Some(oci::LinuxCapabilities { Some(oci::LinuxCapabilities {
bounding: cap.Bounding.clone().into_vec(), bounding: cap.Bounding.clone(),
effective: cap.Effective.clone().into_vec(), effective: cap.Effective.clone(),
inheritable: cap.Inheritable.clone().into_vec(), inheritable: cap.Inheritable.clone(),
permitted: cap.Permitted.clone().into_vec(), permitted: cap.Permitted.clone(),
ambient: cap.Ambient.clone().into_vec(), ambient: cap.Ambient.clone(),
}) })
} else { } else {
None None
@ -108,8 +108,8 @@ pub fn process_grpc_to_oci(p: &grpc::Process) -> oci::Process {
terminal: p.Terminal, terminal: p.Terminal,
console_size, console_size,
user, user,
args: p.Args.clone().into_vec(), args: p.Args.clone(),
env: p.Env.clone().into_vec(), env: p.Env.clone(),
cwd: p.Cwd.clone(), cwd: p.Cwd.clone(),
capabilities, capabilities,
rlimits, 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 { fn mount_grpc_to_oci(m: &grpc::Mount) -> oci::Mount {
oci::Mount { oci::Mount {
destination: m.destination.clone(), destination: m.destination.clone(),
r#type: m.field_type.clone(), r#type: m.type_.clone(),
source: m.source.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<oci::Hook> {
for e in h.iter() { for e in h.iter() {
r.push(oci::Hook { r.push(oci::Hook {
path: e.Path.clone(), path: e.Path.clone(),
args: e.Args.clone().into_vec(), args: e.Args.clone(),
env: e.Env.clone().into_vec(), env: e.Env.clone(),
timeout: Some(e.Timeout as i32), 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 mut args = Vec::new();
let errno_ret: u32 = if sys.has_errnoret() { let errno_ret: u32 = if sys.has_errnoret() {
sys.get_errnoret() sys.errnoret()
} else { } else {
libc::EPERM as u32 libc::EPERM as u32
}; };
@ -374,7 +374,7 @@ fn seccomp_grpc_to_oci(sec: &grpc::LinuxSeccomp) -> oci::LinuxSeccomp {
} }
r.push(oci::LinuxSyscall { r.push(oci::LinuxSyscall {
names: sys.Names.clone().into_vec(), names: sys.Names.clone(),
action: sys.Action.clone(), action: sys.Action.clone(),
errno_ret, errno_ret,
args, args,
@ -385,8 +385,8 @@ fn seccomp_grpc_to_oci(sec: &grpc::LinuxSeccomp) -> oci::LinuxSeccomp {
oci::LinuxSeccomp { oci::LinuxSeccomp {
default_action: sec.DefaultAction.clone(), default_action: sec.DefaultAction.clone(),
architectures: sec.Architectures.clone().into_vec(), architectures: sec.Architectures.clone(),
flags: sec.Flags.clone().into_vec(), flags: sec.Flags.clone(),
syscalls, syscalls,
} }
} }
@ -456,8 +456,8 @@ fn linux_grpc_to_oci(l: &grpc::Linux) -> oci::Linux {
devices, devices,
seccomp, seccomp,
rootfs_propagation: l.RootfsPropagation.clone(), rootfs_propagation: l.RootfsPropagation.clone(),
masked_paths: l.MaskedPaths.clone().into_vec(), masked_paths: l.MaskedPaths.clone(),
readonly_paths: l.ReadonlyPaths.clone().into_vec(), readonly_paths: l.ReadonlyPaths.clone(),
mount_label: l.MountLabel.clone(), mount_label: l.MountLabel.clone(),
intel_rdt, intel_rdt,
} }
@ -558,35 +558,30 @@ mod tests {
// All fields specified // All fields specified
grpcproc: grpc::Process { grpcproc: grpc::Process {
Terminal: true, Terminal: true,
ConsoleSize: protobuf::SingularPtrField::<grpc::Box>::some(grpc::Box { ConsoleSize: protobuf::MessageField::<grpc::Box>::some(grpc::Box {
Height: 123, Height: 123,
Width: 456, Width: 456,
..Default::default() ..Default::default()
}), }),
User: protobuf::SingularPtrField::<grpc::User>::some(grpc::User { User: protobuf::MessageField::<grpc::User>::some(grpc::User {
UID: 1234, UID: 1234,
GID: 5678, GID: 5678,
AdditionalGids: Vec::from([910, 1112]), AdditionalGids: Vec::from([910, 1112]),
Username: String::from("username"), Username: String::from("username"),
..Default::default() ..Default::default()
}), }),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([String::from("env")])),
Cwd: String::from("cwd"), Cwd: String::from("cwd"),
Capabilities: protobuf::SingularPtrField::some(grpc::LinuxCapabilities { Capabilities: protobuf::MessageField::some(grpc::LinuxCapabilities {
Bounding: protobuf::RepeatedField::from(Vec::from([String::from("bnd")])), Bounding: Vec::from([String::from("bnd")]),
Effective: protobuf::RepeatedField::from(Vec::from([String::from("eff")])), Effective: Vec::from([String::from("eff")]),
Inheritable: protobuf::RepeatedField::from(Vec::from([String::from( Inheritable: Vec::from([String::from("inher")]),
"inher", Permitted: Vec::from([String::from("perm")]),
)])), Ambient: Vec::from([String::from("amb")]),
Permitted: protobuf::RepeatedField::from(Vec::from([String::from("perm")])),
Ambient: protobuf::RepeatedField::from(Vec::from([String::from("amb")])),
..Default::default() ..Default::default()
}), }),
Rlimits: protobuf::RepeatedField::from(Vec::from([ Rlimits: Vec::from([
grpc::POSIXRlimit { grpc::POSIXRlimit {
Type: String::from("r#type"), Type: String::from("r#type"),
Hard: 123, Hard: 123,
@ -599,7 +594,7 @@ mod tests {
Soft: 1011, Soft: 1011,
..Default::default() ..Default::default()
}, },
])), ]),
NoNewPrivileges: true, NoNewPrivileges: true,
ApparmorProfile: String::from("apparmor profile"), ApparmorProfile: String::from("apparmor profile"),
OOMScoreAdj: 123456, OOMScoreAdj: 123456,
@ -649,7 +644,7 @@ mod tests {
TestData { TestData {
// None ConsoleSize // None ConsoleSize
grpcproc: grpc::Process { grpcproc: grpc::Process {
ConsoleSize: protobuf::SingularPtrField::<grpc::Box>::none(), ConsoleSize: protobuf::MessageField::<grpc::Box>::none(),
OOMScoreAdj: 0, OOMScoreAdj: 0,
..Default::default() ..Default::default()
}, },
@ -662,7 +657,7 @@ mod tests {
TestData { TestData {
// None User // None User
grpcproc: grpc::Process { grpcproc: grpc::Process {
User: protobuf::SingularPtrField::<grpc::User>::none(), User: protobuf::MessageField::<grpc::User>::none(),
OOMScoreAdj: 0, OOMScoreAdj: 0,
..Default::default() ..Default::default()
}, },
@ -680,7 +675,7 @@ mod tests {
TestData { TestData {
// None Capabilities // None Capabilities
grpcproc: grpc::Process { grpcproc: grpc::Process {
Capabilities: protobuf::SingularPtrField::none(), Capabilities: protobuf::MessageField::none(),
OOMScoreAdj: 0, OOMScoreAdj: 0,
..Default::default() ..Default::default()
}, },
@ -781,99 +776,57 @@ mod tests {
TestData { TestData {
// All specified // All specified
grpchooks: grpc::Hooks { grpchooks: grpc::Hooks {
Prestart: protobuf::RepeatedField::from(Vec::from([ Prestart: Vec::from([
grpc::Hook { grpc::Hook {
Path: String::from("prestartpath"), Path: String::from("prestartpath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}, },
grpc::Hook { grpc::Hook {
Path: String::from("prestartpath2"), Path: String::from("prestartpath2"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg3"), String::from("arg4")]),
String::from("arg3"), Env: Vec::from([String::from("env3"), String::from("env4")]),
String::from("arg4"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env3"),
String::from("env4"),
])),
Timeout: 25, Timeout: 25,
..Default::default() ..Default::default()
}, },
])), ]),
Poststart: protobuf::RepeatedField::from(Vec::from([grpc::Hook { Poststart: Vec::from([grpc::Hook {
Path: String::from("poststartpath"), Path: String::from("poststartpath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
Poststop: protobuf::RepeatedField::from(Vec::from([grpc::Hook { Poststop: Vec::from([grpc::Hook {
Path: String::from("poststoppath"), Path: String::from("poststoppath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
CreateRuntime: protobuf::RepeatedField::from(Vec::from([grpc::Hook { CreateRuntime: Vec::from([grpc::Hook {
Path: String::from("createruntimepath"), Path: String::from("createruntimepath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
CreateContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { CreateContainer: Vec::from([grpc::Hook {
Path: String::from("createcontainerpath"), Path: String::from("createcontainerpath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
StartContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { StartContainer: Vec::from([grpc::Hook {
Path: String::from("startcontainerpath"), Path: String::from("startcontainerpath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
..Default::default() ..Default::default()
}, },
result: oci::Hooks { result: oci::Hooks {
@ -926,72 +879,42 @@ mod tests {
TestData { TestData {
// Prestart empty // Prestart empty
grpchooks: grpc::Hooks { grpchooks: grpc::Hooks {
Prestart: protobuf::RepeatedField::from(Vec::from([])), Prestart: Vec::from([]),
Poststart: protobuf::RepeatedField::from(Vec::from([grpc::Hook { Poststart: Vec::from([grpc::Hook {
Path: String::from("poststartpath"), Path: String::from("poststartpath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
Poststop: protobuf::RepeatedField::from(Vec::from([grpc::Hook { Poststop: Vec::from([grpc::Hook {
Path: String::from("poststoppath"), Path: String::from("poststoppath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
CreateRuntime: protobuf::RepeatedField::from(Vec::from([grpc::Hook { CreateRuntime: Vec::from([grpc::Hook {
Path: String::from("createruntimepath"), Path: String::from("createruntimepath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
CreateContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { CreateContainer: Vec::from([grpc::Hook {
Path: String::from("createcontainerpath"), Path: String::from("createcontainerpath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
StartContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook { StartContainer: Vec::from([grpc::Hook {
Path: String::from("startcontainerpath"), Path: String::from("startcontainerpath"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}])), }]),
..Default::default() ..Default::default()
}, },
result: oci::Hooks { result: oci::Hooks {
@ -1063,11 +986,8 @@ mod tests {
grpcmount: grpc::Mount { grpcmount: grpc::Mount {
destination: String::from("destination"), destination: String::from("destination"),
source: String::from("source"), source: String::from("source"),
field_type: String::from("fieldtype"), type_: String::from("fieldtype"),
options: protobuf::RepeatedField::from(Vec::from([ options: Vec::from([String::from("option1"), String::from("option2")]),
String::from("option1"),
String::from("option2"),
])),
..Default::default() ..Default::default()
}, },
result: oci::Mount { result: oci::Mount {
@ -1081,8 +1001,8 @@ mod tests {
grpcmount: grpc::Mount { grpcmount: grpc::Mount {
destination: String::from("destination"), destination: String::from("destination"),
source: String::from("source"), source: String::from("source"),
field_type: String::from("fieldtype"), type_: String::from("fieldtype"),
options: protobuf::RepeatedField::from(Vec::new()), options: Vec::new(),
..Default::default() ..Default::default()
}, },
result: oci::Mount { result: oci::Mount {
@ -1096,8 +1016,8 @@ mod tests {
grpcmount: grpc::Mount { grpcmount: grpc::Mount {
destination: String::new(), destination: String::new(),
source: String::from("source"), source: String::from("source"),
field_type: String::from("fieldtype"), type_: String::from("fieldtype"),
options: protobuf::RepeatedField::from(Vec::from([String::from("option1")])), options: Vec::from([String::from("option1")]),
..Default::default() ..Default::default()
}, },
result: oci::Mount { result: oci::Mount {
@ -1111,8 +1031,8 @@ mod tests {
grpcmount: grpc::Mount { grpcmount: grpc::Mount {
destination: String::from("destination"), destination: String::from("destination"),
source: String::from("source"), source: String::from("source"),
field_type: String::new(), type_: String::new(),
options: protobuf::RepeatedField::from(Vec::from([String::from("option1")])), options: Vec::from([String::from("option1")]),
..Default::default() ..Default::default()
}, },
result: oci::Mount { result: oci::Mount {
@ -1172,27 +1092,15 @@ mod tests {
grpchook: &[ grpchook: &[
grpc::Hook { grpc::Hook {
Path: String::from("path"), Path: String::from("path"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg1"), String::from("arg2")]),
String::from("arg1"), Env: Vec::from([String::from("env1"), String::from("env2")]),
String::from("arg2"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env1"),
String::from("env2"),
])),
Timeout: 10, Timeout: 10,
..Default::default() ..Default::default()
}, },
grpc::Hook { grpc::Hook {
Path: String::from("path2"), Path: String::from("path2"),
Args: protobuf::RepeatedField::from(Vec::from([ Args: Vec::from([String::from("arg3"), String::from("arg4")]),
String::from("arg3"), Env: Vec::from([String::from("env3"), String::from("env4")]),
String::from("arg4"),
])),
Env: protobuf::RepeatedField::from(Vec::from([
String::from("env3"),
String::from("env4"),
])),
Timeout: 20, Timeout: 20,
..Default::default() ..Default::default()
}, },

View File

@ -759,7 +759,7 @@ async fn vfio_pci_device_handler(
device: &Device, device: &Device,
sandbox: &Arc<Mutex<Sandbox>>, sandbox: &Arc<Mutex<Sandbox>>,
) -> Result<SpecUpdate> { ) -> Result<SpecUpdate> {
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 pci_fixups = Vec::<(pci::Address, pci::Address)>::new();
let mut group = None; let mut group = None;
@ -874,9 +874,9 @@ pub async fn add_devices(
async fn add_device(device: &Device, sandbox: &Arc<Mutex<Sandbox>>) -> Result<SpecUpdate> { async fn add_device(device: &Device, sandbox: &Arc<Mutex<Sandbox>>) -> Result<SpecUpdate> {
// log before validation to help with debugging gRPC protocol version differences. // 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: {:?}", 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)); return Err(anyhow!("invalid type for device {:?}", device));
} }
@ -888,7 +888,7 @@ async fn add_device(device: &Device, sandbox: &Arc<Mutex<Sandbox>>) -> Result<Sp
return Err(anyhow!("invalid container path for device {:?}", device)); return Err(anyhow!("invalid container path for device {:?}", device));
} }
match device.field_type.as_str() { match device.type_.as_str() {
DRIVER_BLK_TYPE => virtio_blk_device_handler(device, sandbox).await, DRIVER_BLK_TYPE => virtio_blk_device_handler(device, sandbox).await,
DRIVER_BLK_CCW_TYPE => virtio_blk_ccw_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, DRIVER_MMIO_BLK_TYPE => virtiommio_blk_device_handler(device, sandbox).await,
@ -898,7 +898,7 @@ async fn add_device(device: &Device, sandbox: &Arc<Mutex<Sandbox>>) -> Result<Sp
vfio_pci_device_handler(device, sandbox).await vfio_pci_device_handler(device, sandbox).await
} }
DRIVER_VFIO_AP_TYPE => vfio_ap_device_handler(device, sandbox).await, DRIVER_VFIO_AP_TYPE => vfio_ap_device_handler(device, sandbox).await,
_ => Err(anyhow!("Unknown device type {}", device.field_type)), _ => Err(anyhow!("Unknown device type {}", device.type_)),
} }
} }

View File

@ -211,10 +211,10 @@ async fn ephemeral_storage_handler(
// By now we only support one option field: "fsGroup" which // By now we only support one option field: "fsGroup" which
// isn't an valid mount option, thus we should remove it when // isn't an valid mount option, thus we should remove it when
// do mount. // do mount.
if storage.options.len() > 0 { if !storage.options.is_empty() {
// ephemeral_storage didn't support mount options except fsGroup. // ephemeral_storage didn't support mount options except fsGroup.
let mut new_storage = storage.clone(); let mut new_storage = storage.clone();
new_storage.options = protobuf::RepeatedField::default(); new_storage.options = Default::default();
common_storage_handler(logger, &new_storage)?; common_storage_handler(logger, &new_storage)?;
let opts_vec: Vec<String> = storage.options.to_vec(); let opts_vec: Vec<String> = storage.options.to_vec();
@ -654,7 +654,7 @@ pub fn set_ownership(logger: &Logger, storage: &Storage) -> Result<()> {
if storage.fs_group.is_none() { if storage.fs_group.is_none() {
return Ok(()); return Ok(());
} }
let fs_group = storage.get_fs_group(); let fs_group = storage.fs_group();
let mut read_only = false; let mut read_only = false;
let opts_vec: Vec<String> = storage.options.to_vec(); let opts_vec: Vec<String> = storage.options.to_vec();
@ -671,7 +671,7 @@ pub fn set_ownership(logger: &Logger, storage: &Storage) -> Result<()> {
err err
})?; })?;
if fs_group.group_change_policy == FSGroupChangePolicy::OnRootMismatch if fs_group.group_change_policy == FSGroupChangePolicy::OnRootMismatch.into()
&& metadata.gid() == fs_group.group_id && metadata.gid() == fs_group.group_id
{ {
let mut mask = if read_only { RO_MASK } else { RW_MASK }; let mut mask = if read_only { RO_MASK } else { RW_MASK };
@ -1094,7 +1094,6 @@ fn parse_options(option_list: Vec<String>) -> HashMap<String, String> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use protobuf::RepeatedField;
use protocols::agent::FSGroup; use protocols::agent::FSGroup;
use std::fs::File; use std::fs::File;
use std::fs::OpenOptions; use std::fs::OpenOptions;
@ -2015,9 +2014,8 @@ mod tests {
mount_path: "rw_mount", mount_path: "rw_mount",
fs_group: Some(FSGroup { fs_group: Some(FSGroup {
group_id: 3000, group_id: 3000,
group_change_policy: FSGroupChangePolicy::Always, group_change_policy: FSGroupChangePolicy::Always.into(),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
}), }),
read_only: false, read_only: false,
expected_group_id: 3000, expected_group_id: 3000,
@ -2027,9 +2025,8 @@ mod tests {
mount_path: "ro_mount", mount_path: "ro_mount",
fs_group: Some(FSGroup { fs_group: Some(FSGroup {
group_id: 3000, group_id: 3000,
group_change_policy: FSGroupChangePolicy::OnRootMismatch, group_change_policy: FSGroupChangePolicy::OnRootMismatch.into(),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
}), }),
read_only: true, read_only: true,
expected_group_id: 3000, expected_group_id: 3000,
@ -2049,10 +2046,7 @@ mod tests {
let directory_mode = mount_dir.as_path().metadata().unwrap().permissions().mode(); let directory_mode = mount_dir.as_path().metadata().unwrap().permissions().mode();
let mut storage_data = Storage::new(); let mut storage_data = Storage::new();
if d.read_only { if d.read_only {
storage_data.set_options(RepeatedField::from_slice(&[ storage_data.set_options(vec!["foo".to_string(), "ro".to_string()]);
"foo".to_string(),
"ro".to_string(),
]));
} }
if let Some(fs_group) = d.fs_group.clone() { if let Some(fs_group) = d.fs_group.clone() {
storage_data.set_fs_group(fs_group); storage_data.set_fs_group(fs_group);

View File

@ -7,7 +7,6 @@ use anyhow::{anyhow, Context, Result};
use futures::{future, StreamExt, TryStreamExt}; use futures::{future, StreamExt, TryStreamExt};
use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network}; use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network};
use nix::errno::Errno; use nix::errno::Errno;
use protobuf::RepeatedField;
use protocols::types::{ARPNeighbor, IPAddress, IPFamily, Interface, Route}; use protocols::types::{ARPNeighbor, IPAddress, IPFamily, Interface, Route};
use rtnetlink::{new_connection, packet, IpVersion}; use rtnetlink::{new_connection, packet, IpVersion};
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
@ -83,8 +82,8 @@ impl Handle {
// Add new ip addresses from request // Add new ip addresses from request
for ip_address in &iface.IPAddresses { for ip_address in &iface.IPAddresses {
let ip = IpAddr::from_str(ip_address.get_address())?; let ip = IpAddr::from_str(ip_address.address())?;
let mask = ip_address.get_mask().parse::<u8>()?; let mask = ip_address.mask().parse::<u8>()?;
self.add_addresses(link.index(), std::iter::once(IpNetwork::new(ip, mask)?)) self.add_addresses(link.index(), std::iter::once(IpNetwork::new(ip, mask)?))
.await?; .await?;
@ -152,7 +151,7 @@ impl Handle {
.map(|p| p.try_into()) .map(|p| p.try_into())
.collect::<Result<Vec<IPAddress>>>()?; .collect::<Result<Vec<IPAddress>>>()?;
iface.IPAddresses = RepeatedField::from_vec(ips); iface.IPAddresses = ips;
list.push(iface); list.push(iface);
} }
@ -334,7 +333,7 @@ impl Handle {
// `rtnetlink` offers a separate request builders for different IP versions (IP v4 and v6). // `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. // 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() { let dest_addr = if !route.dest.is_empty() {
Ipv6Network::from_str(&route.dest)? Ipv6Network::from_str(&route.dest)?
} else { } else {
@ -368,9 +367,9 @@ impl Handle {
if Errno::from_i32(message.code.abs()) != Errno::EEXIST { if Errno::from_i32(message.code.abs()) != Errno::EEXIST {
return Err(anyhow!( return Err(anyhow!(
"Failed to add IP v6 route (src: {}, dst: {}, gtw: {},Err: {})", "Failed to add IP v6 route (src: {}, dst: {}, gtw: {},Err: {})",
route.get_source(), route.source(),
route.get_dest(), route.dest(),
route.get_gateway(), route.gateway(),
message message
)); ));
} }
@ -409,9 +408,9 @@ impl Handle {
if Errno::from_i32(message.code.abs()) != Errno::EEXIST { if Errno::from_i32(message.code.abs()) != Errno::EEXIST {
return Err(anyhow!( return Err(anyhow!(
"Failed to add IP v4 route (src: {}, dst: {}, gtw: {},Err: {})", "Failed to add IP v4 route (src: {}, dst: {}, gtw: {},Err: {})",
route.get_source(), route.source(),
route.get_dest(), route.dest(),
route.get_gateway(), route.gateway(),
message message
)); ));
} }
@ -506,7 +505,7 @@ impl Handle {
self.add_arp_neighbor(&neigh).await.map_err(|err| { self.add_arp_neighbor(&neigh).await.map_err(|err| {
anyhow!( anyhow!(
"Failed to add ARP neighbor {}: {:?}", "Failed to add ARP neighbor {}: {:?}",
neigh.get_toIPAddress().get_address(), neigh.toIPAddress().address(),
err err
) )
})?; })?;
@ -725,7 +724,7 @@ impl TryFrom<Address> for IPAddress {
let mask = format!("{}", value.0.header.prefix_len); let mask = format!("{}", value.0.header.prefix_len);
Ok(IPAddress { Ok(IPAddress {
family, family: family.into(),
address, address,
mask, mask,
..Default::default() ..Default::default()

View File

@ -21,17 +21,20 @@ use ttrpc::{
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use cgroups::freezer::FreezerState; use cgroups::freezer::FreezerState;
use oci::{LinuxNamespace, Root, Spec}; use oci::{LinuxNamespace, Root, Spec};
use protobuf::{Message, RepeatedField, SingularPtrField}; use protobuf::{MessageDyn, MessageField};
use protocols::agent::{ use protocols::agent::{
AddSwapRequest, AgentDetails, CopyFileRequest, GetIPTablesRequest, GetIPTablesResponse, AddSwapRequest, AgentDetails, CopyFileRequest, GetIPTablesRequest, GetIPTablesResponse,
GuestDetailsResponse, Interfaces, Metrics, OOMEvent, ReadStreamResponse, Routes, GuestDetailsResponse, Interfaces, Metrics, OOMEvent, ReadStreamResponse, Routes,
SetIPTablesRequest, SetIPTablesResponse, StatsContainerResponse, VolumeStatsRequest, SetIPTablesRequest, SetIPTablesResponse, StatsContainerResponse, VolumeStatsRequest,
WaitProcessResponse, WriteStreamResponse, 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::empty::Empty;
use protocols::health::{ use protocols::health::{
HealthCheckResponse, HealthCheckResponse_ServingStatus, VersionCheckResponse, health_check_response::ServingStatus as HealthCheckResponse_ServingStatus, HealthCheckResponse,
VersionCheckResponse,
}; };
use protocols::types::Interface; use protocols::types::Interface;
use protocols::{agent_ttrpc_async as agent_ttrpc, health_ttrpc_async as health_ttrpc}; 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 if !AGENT_CONFIG
.read() .read()
.await .await
.is_allowed_endpoint($req.descriptor().name()) .is_allowed_endpoint($req.descriptor_dyn().name())
{ {
return Err(ttrpc_error!( return Err(ttrpc_error!(
ttrpc::Code::UNIMPLEMENTED, 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)?; kata_sys_util::validate::verify_id(&cid)?;
let mut oci_spec = req.OCI.clone(); 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 sandbox;
let mut s; let mut s;
@ -785,7 +788,7 @@ impl agent_ttrpc::AgentService for AgentService {
) -> ttrpc::Result<protocols::empty::Empty> { ) -> ttrpc::Result<protocols::empty::Empty> {
trace_rpc_call!(ctx, "pause_container", req); trace_rpc_call!(ctx, "pause_container", req);
is_allowed!(req); is_allowed!(req);
let cid = req.get_container_id(); let cid = req.container_id();
let s = Arc::clone(&self.sandbox); let s = Arc::clone(&self.sandbox);
let mut sandbox = s.lock().await; let mut sandbox = s.lock().await;
@ -809,7 +812,7 @@ impl agent_ttrpc::AgentService for AgentService {
) -> ttrpc::Result<protocols::empty::Empty> { ) -> ttrpc::Result<protocols::empty::Empty> {
trace_rpc_call!(ctx, "resume_container", req); trace_rpc_call!(ctx, "resume_container", req);
is_allowed!(req); is_allowed!(req);
let cid = req.get_container_id(); let cid = req.container_id();
let s = Arc::clone(&self.sandbox); let s = Arc::clone(&self.sandbox);
let mut sandbox = s.lock().await; let mut sandbox = s.lock().await;
@ -964,11 +967,7 @@ impl agent_ttrpc::AgentService for AgentService {
trace_rpc_call!(ctx, "update_routes", req); trace_rpc_call!(ctx, "update_routes", req);
is_allowed!(req); is_allowed!(req);
let new_routes = req let new_routes = req.routes.into_option().map(|r| r.Routes).ok_or_else(|| {
.routes
.into_option()
.map(|r| r.Routes.into_vec())
.ok_or_else(|| {
ttrpc_error!( ttrpc_error!(
ttrpc::Code::INVALID_ARGUMENT, ttrpc::Code::INVALID_ARGUMENT,
"empty update routes request".to_string(), "empty update routes request".to_string(),
@ -992,7 +991,7 @@ impl agent_ttrpc::AgentService for AgentService {
})?; })?;
Ok(protocols::agent::Routes { Ok(protocols::agent::Routes {
Routes: RepeatedField::from_vec(list), Routes: list,
..Default::default() ..Default::default()
}) })
} }
@ -1191,7 +1190,7 @@ impl agent_ttrpc::AgentService for AgentService {
})?; })?;
Ok(protocols::agent::Interfaces { Ok(protocols::agent::Interfaces {
Interfaces: RepeatedField::from_vec(list), Interfaces: list,
..Default::default() ..Default::default()
}) })
} }
@ -1214,7 +1213,7 @@ impl agent_ttrpc::AgentService for AgentService {
.map_err(|e| ttrpc_error!(ttrpc::Code::INTERNAL, format!("list routes: {:?}", e)))?; .map_err(|e| ttrpc_error!(ttrpc::Code::INTERNAL, format!("list routes: {:?}", e)))?;
Ok(protocols::agent::Routes { Ok(protocols::agent::Routes {
Routes: RepeatedField::from_vec(list), Routes: list,
..Default::default() ..Default::default()
}) })
} }
@ -1330,7 +1329,7 @@ impl agent_ttrpc::AgentService for AgentService {
let neighs = req let neighs = req
.neighbors .neighbors
.into_option() .into_option()
.map(|n| n.ARPNeighbors.into_vec()) .map(|n| n.ARPNeighbors)
.ok_or_else(|| { .ok_or_else(|| {
ttrpc_error!( ttrpc_error!(
ttrpc::Code::INVALID_ARGUMENT, ttrpc::Code::INVALID_ARGUMENT,
@ -1414,7 +1413,7 @@ impl agent_ttrpc::AgentService for AgentService {
// to get agent details // to get agent details
let detail = get_agent_details(); let detail = get_agent_details();
resp.agent_details = SingularPtrField::some(detail); resp.agent_details = MessageField::some(detail);
Ok(resp) Ok(resp)
} }
@ -1539,8 +1538,8 @@ impl agent_ttrpc::AgentService for AgentService {
.map(|u| usage_vec.push(u)) .map(|u| usage_vec.push(u))
.map_err(|e| ttrpc_error!(ttrpc::Code::INTERNAL, e))?; .map_err(|e| ttrpc_error!(ttrpc::Code::INTERNAL, e))?;
resp.usage = RepeatedField::from_vec(usage_vec); resp.usage = usage_vec;
resp.volume_condition = SingularPtrField::some(condition); resp.volume_condition = MessageField::some(condition);
Ok(resp) Ok(resp)
} }
@ -1644,7 +1643,7 @@ fn get_volume_capacity_stats(path: &str) -> Result<VolumeUsage> {
usage.total = stat.blocks() * block_size; usage.total = stat.blocks() * block_size;
usage.available = stat.blocks_free() * block_size; usage.available = stat.blocks_free() * block_size;
usage.used = usage.total - usage.available; usage.used = usage.total - usage.available;
usage.unit = VolumeUsage_Unit::BYTES; usage.unit = VolumeUsage_Unit::BYTES.into();
Ok(usage) Ok(usage)
} }
@ -1656,7 +1655,7 @@ fn get_volume_inode_stats(path: &str) -> Result<VolumeUsage> {
usage.total = stat.files(); usage.total = stat.files();
usage.available = stat.files_free(); usage.available = stat.files_free();
usage.used = usage.total - usage.available; usage.used = usage.total - usage.available;
usage.unit = VolumeUsage_Unit::INODES; usage.unit = VolumeUsage_Unit::INODES.into();
Ok(usage) Ok(usage)
} }
@ -1676,14 +1675,12 @@ fn get_agent_details() -> AgentDetails {
detail.set_supports_seccomp(have_seccomp()); detail.set_supports_seccomp(have_seccomp());
detail.init_daemon = unistd::getpid() == Pid::from_raw(1); detail.init_daemon = unistd::getpid() == Pid::from_raw(1);
detail.device_handlers = RepeatedField::new(); detail.device_handlers = Vec::new();
detail.storage_handlers = RepeatedField::from_vec( detail.storage_handlers = STORAGE_HANDLER_LIST
STORAGE_HANDLER_LIST
.to_vec() .to_vec()
.iter() .iter()
.map(|x| x.to_string()) .map(|x| x.to_string())
.collect(), .collect();
);
detail detail
} }
@ -2037,7 +2034,7 @@ fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> {
let mut args = vec!["-v".to_string(), module.name.clone()]; 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()) args.extend(module.parameters.to_vec())
} }

85
src/libs/Cargo.lock generated
View File

@ -703,9 +703,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.9.0" version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
@ -845,9 +845,16 @@ name = "protobuf"
version = "2.27.1" version = "2.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96"
[[package]]
name = "protobuf"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e"
dependencies = [ dependencies = [
"serde", "once_cell",
"serde_derive", "protobuf-support",
"thiserror",
] ]
[[package]] [[package]]
@ -856,17 +863,47 @@ version = "2.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.27.1",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure" name = "protobuf-codegen"
version = "2.27.1" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen", "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]] [[package]]
@ -875,7 +912,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"serde", "serde",
"serde_json", "serde_json",
"ttrpc", "ttrpc",
@ -1314,9 +1351,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]] [[package]]
name = "ttrpc" name = "ttrpc"
version = "0.6.1" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"byteorder", "byteorder",
@ -1324,8 +1361,8 @@ dependencies = [
"libc", "libc",
"log", "log",
"nix 0.23.1", "nix 0.23.1",
"protobuf", "protobuf 3.2.0",
"protobuf-codegen-pure", "protobuf-codegen 3.2.0",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-vsock", "tokio-vsock",
@ -1333,28 +1370,28 @@ dependencies = [
[[package]] [[package]]
name = "ttrpc-codegen" name = "ttrpc-codegen"
version = "0.2.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.27.1",
"protobuf-codegen", "protobuf-codegen 3.2.0",
"protobuf-codegen-pure", "protobuf-support",
"ttrpc-compiler", "ttrpc-compiler",
] ]
[[package]] [[package]]
name = "ttrpc-compiler" name = "ttrpc-compiler"
version = "0.4.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2978ed3fa047d8fd55cbeb4d4a61d461fb3021a90c9618519c73ce7e5bb66c15" checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647"
dependencies = [ dependencies = [
"derive-new", "derive-new",
"prost", "prost",
"prost-build", "prost-build",
"prost-types", "prost-types",
"protobuf", "protobuf 2.27.1",
"protobuf-codegen", "protobuf-codegen 2.27.1",
"tempfile", "tempfile",
] ]

View File

@ -1,11 +1,6 @@
Cargo.lock Cargo.lock
src/agent.rs
src/agent_ttrpc.rs src/*.rs
src/agent_ttrpc_async.rs !src/lib.rs
src/csi.rs !src/trans.rs
src/empty.rs !src/serde_config.rs
src/health.rs
src/health_ttrpc.rs
src/health_ttrpc_async.rs
src/oci.rs
src/types.rs

View File

@ -11,12 +11,13 @@ with-serde = [ "serde", "serde_json" ]
async = ["ttrpc/async", "async-trait"] async = ["ttrpc/async", "async-trait"]
[dependencies] [dependencies]
ttrpc = { version = "0.6.0" } ttrpc = { version = "0.7.1" }
async-trait = { version = "0.1.42", optional = true } 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 = { version = "1.0.130", features = ["derive"], optional = true }
serde_json = { version = "1.0.68", optional = true } serde_json = { version = "1.0.68", optional = true }
oci = { path = "../oci" } oci = { path = "../oci" }
[build-dependencies] [build-dependencies]
ttrpc-codegen = "0.2.0" ttrpc-codegen = "0.4.2"
protobuf = { version = "3.2.0" }

View File

@ -7,7 +7,46 @@ use std::fs::{self, File};
use std::io::{BufRead, BufReader, Read, Write}; use std::io::{BufRead, BufReader, Read, Write};
use std::path::Path; use std::path::Path;
use std::process::exit; 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> { fn replace_text_in_file(file_name: &str, from: &str, to: &str) -> Result<(), std::io::Error> {
let mut src = File::open(file_name)?; 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() ..Default::default()
}; };
let protobuf_options = ProtobufCustomize { let protobuf_options = ProtobufCustomize::default()
serde_derive: Some(true), .gen_mod_rs(false)
..Default::default() .generate_getter(true)
}; .generate_accessors(true);
let out_dir = Path::new("src"); 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) .customize(ttrpc_options)
.rust_protobuf() .rust_protobuf()
.rust_protobuf_customize(protobuf_options) .rust_protobuf_customize(protobuf_options)
.rust_protobuf_customize_callback(GenSerde)
.run()?; .run()?;
let autogen_comment = format!("\n//! Generated by {:?} ({:?})", file!(), module_path!()); let autogen_comment = format!("\n//! Generated by {:?} ({:?})", file!(), module_path!());
@ -147,6 +187,7 @@ fn real_main() -> Result<(), std::io::Error> {
"src", "src",
&[ &[
"protos/google/protobuf/empty.proto", "protos/google/protobuf/empty.proto",
"protos/gogo/protobuf/gogoproto/gogo.proto",
"protos/oci.proto", "protos/oci.proto",
"protos/types.proto", "protos/types.proto",
"protos/csi.proto", "protos/csi.proto",

View File

@ -11,10 +11,19 @@ pub mod agent_ttrpc;
pub mod agent_ttrpc_async; pub mod agent_ttrpc_async;
pub mod csi; pub mod csi;
pub mod empty; pub mod empty;
mod gogo;
pub mod health; pub mod health;
pub mod health_ttrpc; pub mod health_ttrpc;
#[cfg(feature = "async")] #[cfg(feature = "async")]
pub mod health_ttrpc_async; pub mod health_ttrpc_async;
pub mod oci; pub mod oci;
#[cfg(feature = "with-serde")]
mod serde_config;
pub mod trans; pub mod trans;
pub mod types; 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,
};

View File

@ -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::EnumFull, S: serde::Serializer>(
e: &protobuf::EnumOrUnknown<E>,
s: S,
) -> Result<S::Ok, S::Error> {
e.value().serialize(s)
}
pub fn serialize_message_field<E: Serialize, S: serde::Serializer>(
e: &protobuf::MessageField<E>,
s: S,
) -> Result<S::Ok, S::Error> {
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<protobuf::EnumOrUnknown<E>, 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<protobuf::MessageField<E>, 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);
}
}

View File

@ -15,19 +15,19 @@ use oci::{
}; };
// translate from interface to ttprc tools // translate from interface to ttprc tools
fn from_option<F: Sized, T: From<F>>(from: Option<F>) -> ::protobuf::SingularPtrField<T> { fn from_option<F: Sized, T: From<F>>(from: Option<F>) -> protobuf::MessageField<T> {
match from { match from {
Some(f) => ::protobuf::SingularPtrField::from_option(Some(T::from(f))), Some(f) => protobuf::MessageField::from_option(Some(f.into())),
None => ::protobuf::SingularPtrField::none(), None => protobuf::MessageField::none(),
} }
} }
fn from_vec<F: Sized, T: From<F>>(from: Vec<F>) -> ::protobuf::RepeatedField<T> { fn from_vec<F: Sized, T: From<F>>(from: Vec<F>) -> Vec<T> {
let mut to: Vec<T> = vec![]; let mut to: Vec<T> = vec![];
for data in from { for data in from {
to.push(T::from(data)); to.push(data.into());
} }
::protobuf::RepeatedField::from_vec(to) to
} }
impl From<oci::Box> for crate::oci::Box { impl From<oci::Box> for crate::oci::Box {
@ -35,8 +35,7 @@ impl From<oci::Box> for crate::oci::Box {
crate::oci::Box { crate::oci::Box {
Height: from.height, Height: from.height,
Width: from.width, Width: from.width,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -48,8 +47,7 @@ impl From<oci::User> for crate::oci::User {
GID: from.gid, GID: from.gid,
AdditionalGids: from.additional_gids, AdditionalGids: from.additional_gids,
Username: from.username, Username: from.username,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -57,13 +55,12 @@ impl From<oci::User> for crate::oci::User {
impl From<oci::LinuxCapabilities> for crate::oci::LinuxCapabilities { impl From<oci::LinuxCapabilities> for crate::oci::LinuxCapabilities {
fn from(from: LinuxCapabilities) -> Self { fn from(from: LinuxCapabilities) -> Self {
crate::oci::LinuxCapabilities { crate::oci::LinuxCapabilities {
Bounding: from_vec(from.bounding), Bounding: from.bounding,
Effective: from_vec(from.effective), Effective: from.effective,
Inheritable: from_vec(from.inheritable), Inheritable: from.inheritable,
Permitted: from_vec(from.permitted), Permitted: from.permitted,
Ambient: from_vec(from.ambient), Ambient: from.ambient,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -74,8 +71,7 @@ impl From<oci::PosixRlimit> for crate::oci::POSIXRlimit {
Type: from.r#type, Type: from.r#type,
Hard: from.hard, Hard: from.hard,
Soft: from.soft, Soft: from.soft,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -86,8 +82,8 @@ impl From<oci::Process> for crate::oci::Process {
Terminal: from.terminal, Terminal: from.terminal,
ConsoleSize: from_option(from.console_size), ConsoleSize: from_option(from.console_size),
User: from_option(Some(from.user)), User: from_option(Some(from.user)),
Args: from_vec(from.args), Args: from.args,
Env: from_vec(from.env), Env: from.env,
Cwd: from.cwd, Cwd: from.cwd,
Capabilities: from_option(from.capabilities), Capabilities: from_option(from.capabilities),
Rlimits: from_vec(from.rlimits), Rlimits: from_vec(from.rlimits),
@ -95,8 +91,7 @@ impl From<oci::Process> for crate::oci::Process {
ApparmorProfile: from.apparmor_profile, ApparmorProfile: from.apparmor_profile,
OOMScoreAdj: from.oom_score_adj.map_or(0, |t| t as i64), OOMScoreAdj: from.oom_score_adj.map_or(0, |t| t as i64),
SelinuxLabel: from.selinux_label, SelinuxLabel: from.selinux_label,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -109,8 +104,7 @@ impl From<oci::LinuxDeviceCgroup> for crate::oci::LinuxDeviceCgroup {
Major: from.major.map_or(0, |t| t), Major: from.major.map_or(0, |t| t),
Minor: from.minor.map_or(0, |t| t), Minor: from.minor.map_or(0, |t| t),
Access: from.access, Access: from.access,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -125,8 +119,7 @@ impl From<oci::LinuxMemory> for crate::oci::LinuxMemory {
KernelTCP: from.kernel_tcp.map_or(0, |t| t), KernelTCP: from.kernel_tcp.map_or(0, |t| t),
Swappiness: from.swappiness.map_or(0, |t| t), Swappiness: from.swappiness.map_or(0, |t| t),
DisableOOMKiller: from.disable_oom_killer.map_or(false, |t| t), DisableOOMKiller: from.disable_oom_killer.map_or(false, |t| t),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -141,8 +134,7 @@ impl From<oci::LinuxCpu> for crate::oci::LinuxCPU {
RealtimePeriod: from.realtime_period.map_or(0, |t| t), RealtimePeriod: from.realtime_period.map_or(0, |t| t),
Cpus: from.cpus, Cpus: from.cpus,
Mems: from.mems, Mems: from.mems,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -151,8 +143,7 @@ impl From<oci::LinuxPids> for crate::oci::LinuxPids {
fn from(from: LinuxPids) -> Self { fn from(from: LinuxPids) -> Self {
crate::oci::LinuxPids { crate::oci::LinuxPids {
Limit: from.limit, Limit: from.limit,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -165,8 +156,7 @@ impl From<oci::LinuxWeightDevice> for crate::oci::LinuxWeightDevice {
Minor: 0, Minor: 0,
Weight: from.weight.map_or(0, |t| t as u32), Weight: from.weight.map_or(0, |t| t as u32),
LeafWeight: from.leaf_weight.map_or(0, |t| t as u32), LeafWeight: from.leaf_weight.map_or(0, |t| t as u32),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -178,8 +168,7 @@ impl From<oci::LinuxThrottleDevice> for crate::oci::LinuxThrottleDevice {
Major: 0, Major: 0,
Minor: 0, Minor: 0,
Rate: from.rate, Rate: from.rate,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -194,8 +183,7 @@ impl From<oci::LinuxBlockIo> for crate::oci::LinuxBlockIO {
ThrottleWriteBpsDevice: from_vec(from.throttle_write_bps_device), ThrottleWriteBpsDevice: from_vec(from.throttle_write_bps_device),
ThrottleReadIOPSDevice: from_vec(from.throttle_read_iops_device), ThrottleReadIOPSDevice: from_vec(from.throttle_read_iops_device),
ThrottleWriteIOPSDevice: from_vec(from.throttle_write_iops_device), ThrottleWriteIOPSDevice: from_vec(from.throttle_write_iops_device),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -205,8 +193,7 @@ impl From<oci::LinuxHugepageLimit> for crate::oci::LinuxHugepageLimit {
crate::oci::LinuxHugepageLimit { crate::oci::LinuxHugepageLimit {
Pagesize: from.page_size, Pagesize: from.page_size,
Limit: from.limit, Limit: from.limit,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -216,8 +203,7 @@ impl From<oci::LinuxInterfacePriority> for crate::oci::LinuxInterfacePriority {
crate::oci::LinuxInterfacePriority { crate::oci::LinuxInterfacePriority {
Name: from.name, Name: from.name,
Priority: from.priority, Priority: from.priority,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -227,8 +213,7 @@ impl From<oci::LinuxNetwork> for crate::oci::LinuxNetwork {
crate::oci::LinuxNetwork { crate::oci::LinuxNetwork {
ClassID: from.class_id.map_or(0, |t| t), ClassID: from.class_id.map_or(0, |t| t),
Priorities: from_vec(from.priorities), Priorities: from_vec(from.priorities),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -243,8 +228,7 @@ impl From<oci::LinuxResources> for crate::oci::LinuxResources {
BlockIO: from_option(from.block_io), BlockIO: from_option(from.block_io),
HugepageLimits: from_vec(from.hugepage_limits), HugepageLimits: from_vec(from.hugepage_limits),
Network: from_option(from.network), Network: from_option(from.network),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -254,8 +238,7 @@ impl From<oci::Root> for crate::oci::Root {
crate::oci::Root { crate::oci::Root {
Path: from.path, Path: from.path,
Readonly: from.readonly, Readonly: from.readonly,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -265,10 +248,9 @@ impl From<oci::Mount> for crate::oci::Mount {
crate::oci::Mount { crate::oci::Mount {
destination: from.destination, destination: from.destination,
source: from.source, source: from.source,
field_type: from.r#type, type_: from.r#type,
options: from_vec(from.options), options: from.options,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -281,11 +263,10 @@ impl From<oci::Hook> for crate::oci::Hook {
} }
crate::oci::Hook { crate::oci::Hook {
Path: from.path, Path: from.path,
Args: from_vec(from.args), Args: from.args,
Env: from_vec(from.env), Env: from.env,
Timeout: timeout, Timeout: timeout,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -299,8 +280,7 @@ impl From<oci::Hooks> for crate::oci::Hooks {
StartContainer: from_vec(from.start_container), StartContainer: from_vec(from.start_container),
Poststart: from_vec(from.poststart), Poststart: from_vec(from.poststart),
Poststop: from_vec(from.poststop), Poststop: from_vec(from.poststop),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -311,8 +291,7 @@ impl From<oci::LinuxIdMapping> for crate::oci::LinuxIDMapping {
HostID: from.host_id, HostID: from.host_id,
ContainerID: from.container_id, ContainerID: from.container_id,
Size: from.size, Size: from.size,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -322,8 +301,7 @@ impl From<oci::LinuxNamespace> for crate::oci::LinuxNamespace {
crate::oci::LinuxNamespace { crate::oci::LinuxNamespace {
Type: from.r#type, Type: from.r#type,
Path: from.path, Path: from.path,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -338,8 +316,7 @@ impl From<oci::LinuxDevice> for crate::oci::LinuxDevice {
FileMode: from.file_mode.map_or(0, |v| v), FileMode: from.file_mode.map_or(0, |v| v),
UID: from.uid.map_or(0, |v| v), UID: from.uid.map_or(0, |v| v),
GID: from.gid.map_or(0, |v| v), GID: from.gid.map_or(0, |v| v),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -351,8 +328,7 @@ impl From<oci::LinuxSeccompArg> for crate::oci::LinuxSeccompArg {
Value: from.value, Value: from.value,
ValueTwo: from.value_two, ValueTwo: from.value_two,
Op: from.op, Op: from.op,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -360,14 +336,13 @@ impl From<oci::LinuxSeccompArg> for crate::oci::LinuxSeccompArg {
impl From<oci::LinuxSyscall> for crate::oci::LinuxSyscall { impl From<oci::LinuxSyscall> for crate::oci::LinuxSyscall {
fn from(from: LinuxSyscall) -> Self { fn from(from: LinuxSyscall) -> Self {
crate::oci::LinuxSyscall { crate::oci::LinuxSyscall {
Names: from_vec(from.names), Names: from.names,
Action: from.action, Action: from.action,
Args: from_vec(from.args), Args: from_vec(from.args),
ErrnoRet: Some(crate::oci::LinuxSyscall_oneof_ErrnoRet::errnoret( ErrnoRet: Some(crate::oci::linux_syscall::ErrnoRet::Errnoret(
from.errno_ret, from.errno_ret,
)), )),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -376,11 +351,10 @@ impl From<oci::LinuxSeccomp> for crate::oci::LinuxSeccomp {
fn from(from: LinuxSeccomp) -> Self { fn from(from: LinuxSeccomp) -> Self {
crate::oci::LinuxSeccomp { crate::oci::LinuxSeccomp {
DefaultAction: from.default_action, DefaultAction: from.default_action,
Architectures: from_vec(from.architectures), Architectures: from.architectures,
Syscalls: from_vec(from.syscalls), Syscalls: from_vec(from.syscalls),
Flags: from_vec(from.flags), Flags: from.flags,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -389,8 +363,7 @@ impl From<oci::LinuxIntelRdt> for crate::oci::LinuxIntelRdt {
fn from(from: LinuxIntelRdt) -> Self { fn from(from: LinuxIntelRdt) -> Self {
crate::oci::LinuxIntelRdt { crate::oci::LinuxIntelRdt {
L3CacheSchema: from.l3_cache_schema, L3CacheSchema: from.l3_cache_schema,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -407,12 +380,11 @@ impl From<oci::Linux> for crate::oci::Linux {
Devices: from_vec(from.devices), Devices: from_vec(from.devices),
Seccomp: from_option(from.seccomp), Seccomp: from_option(from.seccomp),
RootfsPropagation: from.rootfs_propagation, RootfsPropagation: from.rootfs_propagation,
MaskedPaths: from_vec(from.masked_paths), MaskedPaths: from.masked_paths,
ReadonlyPaths: from_vec(from.readonly_paths), ReadonlyPaths: from.readonly_paths,
MountLabel: from.mount_label, MountLabel: from.mount_label,
IntelRdt: from_option(from.intel_rdt), IntelRdt: from_option(from.intel_rdt),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -430,8 +402,7 @@ impl From<oci::Spec> for crate::oci::Spec {
Linux: from_option(from.linux), Linux: from_option(from.linux),
Solaris: Default::default(), Solaris: Default::default(),
Windows: Default::default(), Windows: Default::default(),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -449,7 +420,7 @@ impl From<crate::oci::Mount> for oci::Mount {
fn from(mut from: crate::oci::Mount) -> Self { fn from(mut from: crate::oci::Mount) -> Self {
let options = from.take_options().to_vec(); let options = from.take_options().to_vec();
Self { Self {
r#type: from.take_field_type(), r#type: from.take_type_(),
destination: from.take_destination(), destination: from.take_destination(),
source: from.take_source(), source: from.take_source(),
options, options,
@ -460,9 +431,9 @@ impl From<crate::oci::Mount> for oci::Mount {
impl From<crate::oci::LinuxIDMapping> for oci::LinuxIdMapping { impl From<crate::oci::LinuxIDMapping> for oci::LinuxIdMapping {
fn from(from: crate::oci::LinuxIDMapping) -> Self { fn from(from: crate::oci::LinuxIDMapping) -> Self {
LinuxIdMapping { LinuxIdMapping {
container_id: from.get_ContainerID(), container_id: from.ContainerID(),
host_id: from.get_HostID(), host_id: from.HostID(),
size: from.get_Size(), size: from.Size(),
} }
} }
} }
@ -470,17 +441,17 @@ impl From<crate::oci::LinuxIDMapping> for oci::LinuxIdMapping {
impl From<crate::oci::LinuxDeviceCgroup> for oci::LinuxDeviceCgroup { impl From<crate::oci::LinuxDeviceCgroup> for oci::LinuxDeviceCgroup {
fn from(mut from: crate::oci::LinuxDeviceCgroup) -> Self { fn from(mut from: crate::oci::LinuxDeviceCgroup) -> Self {
let mut major = None; let mut major = None;
if from.get_Major() > 0 { if from.Major() > 0 {
major = Some(from.get_Major()); major = Some(from.Major());
} }
let mut minor = None; let mut minor = None;
if from.get_Minor() > 0 { if from.Minor() > 0 {
minor = Some(from.get_Minor()) minor = Some(from.Minor())
} }
oci::LinuxDeviceCgroup { oci::LinuxDeviceCgroup {
allow: from.get_Allow(), allow: from.Allow(),
r#type: from.take_Type(), r#type: from.take_Type(),
major, major,
minor, minor,
@ -492,36 +463,36 @@ impl From<crate::oci::LinuxDeviceCgroup> for oci::LinuxDeviceCgroup {
impl From<crate::oci::LinuxMemory> for oci::LinuxMemory { impl From<crate::oci::LinuxMemory> for oci::LinuxMemory {
fn from(from: crate::oci::LinuxMemory) -> Self { fn from(from: crate::oci::LinuxMemory) -> Self {
let mut limit = None; let mut limit = None;
if from.get_Limit() > 0 { if from.Limit() > 0 {
limit = Some(from.get_Limit()); limit = Some(from.Limit());
} }
let mut reservation = None; let mut reservation = None;
if from.get_Reservation() > 0 { if from.Reservation() > 0 {
reservation = Some(from.get_Reservation()); reservation = Some(from.Reservation());
} }
let mut swap = None; let mut swap = None;
if from.get_Swap() > 0 { if from.Swap() > 0 {
swap = Some(from.get_Swap()); swap = Some(from.Swap());
} }
let mut kernel = None; let mut kernel = None;
if from.get_Kernel() > 0 { if from.Kernel() > 0 {
kernel = Some(from.get_Kernel()); kernel = Some(from.Kernel());
} }
let mut kernel_tcp = None; let mut kernel_tcp = None;
if from.get_KernelTCP() > 0 { if from.KernelTCP() > 0 {
kernel_tcp = Some(from.get_KernelTCP()); kernel_tcp = Some(from.KernelTCP());
} }
let mut swappiness = None; let mut swappiness = None;
if from.get_Swappiness() > 0 { if from.Swappiness() > 0 {
swappiness = Some(from.get_Swappiness()); swappiness = Some(from.Swappiness());
} }
let disable_oom_killer = Some(from.get_DisableOOMKiller()); let disable_oom_killer = Some(from.DisableOOMKiller());
oci::LinuxMemory { oci::LinuxMemory {
limit, limit,
@ -538,28 +509,28 @@ impl From<crate::oci::LinuxMemory> for oci::LinuxMemory {
impl From<crate::oci::LinuxCPU> for oci::LinuxCpu { impl From<crate::oci::LinuxCPU> for oci::LinuxCpu {
fn from(mut from: crate::oci::LinuxCPU) -> Self { fn from(mut from: crate::oci::LinuxCPU) -> Self {
let mut shares = None; let mut shares = None;
if from.get_Shares() > 0 { if from.Shares() > 0 {
shares = Some(from.get_Shares()); shares = Some(from.Shares());
} }
let mut quota = None; let mut quota = None;
if from.get_Quota() > 0 { if from.Quota() > 0 {
quota = Some(from.get_Quota()); quota = Some(from.Quota());
} }
let mut period = None; let mut period = None;
if from.get_Period() > 0 { if from.Period() > 0 {
period = Some(from.get_Period()); period = Some(from.Period());
} }
let mut realtime_runtime = None; let mut realtime_runtime = None;
if from.get_RealtimeRuntime() > 0 { if from.RealtimeRuntime() > 0 {
realtime_runtime = Some(from.get_RealtimeRuntime()); realtime_runtime = Some(from.RealtimeRuntime());
} }
let mut realtime_period = None; let mut realtime_period = None;
if from.get_RealtimePeriod() > 0 { if from.RealtimePeriod() > 0 {
realtime_period = Some(from.get_RealtimePeriod()); realtime_period = Some(from.RealtimePeriod());
} }
let cpus = from.take_Cpus(); let cpus = from.take_Cpus();
@ -580,7 +551,7 @@ impl From<crate::oci::LinuxCPU> for oci::LinuxCpu {
impl From<crate::oci::LinuxPids> for oci::LinuxPids { impl From<crate::oci::LinuxPids> for oci::LinuxPids {
fn from(from: crate::oci::LinuxPids) -> Self { fn from(from: crate::oci::LinuxPids) -> Self {
oci::LinuxPids { oci::LinuxPids {
limit: from.get_Limit(), limit: from.Limit(),
} }
} }
} }
@ -588,35 +559,35 @@ impl From<crate::oci::LinuxPids> for oci::LinuxPids {
impl From<crate::oci::LinuxBlockIO> for oci::LinuxBlockIo { impl From<crate::oci::LinuxBlockIO> for oci::LinuxBlockIo {
fn from(from: crate::oci::LinuxBlockIO) -> Self { fn from(from: crate::oci::LinuxBlockIO) -> Self {
let mut weight = None; let mut weight = None;
if from.get_Weight() > 0 { if from.Weight() > 0 {
weight = Some(from.get_Weight() as u16); weight = Some(from.Weight() as u16);
} }
let mut leaf_weight = None; let mut leaf_weight = None;
if from.get_LeafWeight() > 0 { if from.LeafWeight() > 0 {
leaf_weight = Some(from.get_LeafWeight() as u16); leaf_weight = Some(from.LeafWeight() as u16);
} }
let mut weight_device = Vec::new(); let mut weight_device = Vec::new();
for wd in from.get_WeightDevice() { for wd in from.WeightDevice() {
weight_device.push(wd.clone().into()); weight_device.push(wd.clone().into());
} }
let mut throttle_read_bps_device = Vec::new(); 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()); throttle_read_bps_device.push(td.clone().into());
} }
let mut throttle_write_bps_device = Vec::new(); 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()); throttle_write_bps_device.push(td.clone().into());
} }
let mut throttle_read_iops_device = Vec::new(); 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()); throttle_read_iops_device.push(td.clone().into());
} }
let mut throttle_write_iops_device = Vec::new(); 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()); throttle_write_iops_device.push(td.clone().into());
} }
@ -661,7 +632,7 @@ impl From<crate::oci::LinuxInterfacePriority> for oci::LinuxInterfacePriority {
fn from(mut from: crate::oci::LinuxInterfacePriority) -> Self { fn from(mut from: crate::oci::LinuxInterfacePriority) -> Self {
oci::LinuxInterfacePriority { oci::LinuxInterfacePriority {
name: from.take_Name(), name: from.take_Name(),
priority: from.get_Priority(), priority: from.Priority(),
} }
} }
} }
@ -669,11 +640,11 @@ impl From<crate::oci::LinuxInterfacePriority> for oci::LinuxInterfacePriority {
impl From<crate::oci::LinuxNetwork> for oci::LinuxNetwork { impl From<crate::oci::LinuxNetwork> for oci::LinuxNetwork {
fn from(mut from: crate::oci::LinuxNetwork) -> Self { fn from(mut from: crate::oci::LinuxNetwork) -> Self {
let mut class_id = None; let mut class_id = None;
if from.get_ClassID() > 0 { if from.ClassID() > 0 {
class_id = Some(from.get_ClassID()); class_id = Some(from.ClassID());
} }
let mut priorities = Vec::new(); let mut priorities = Vec::new();
for p in from.take_Priorities().to_vec() { for p in from.take_Priorities() {
priorities.push(p.into()) priorities.push(p.into())
} }
@ -688,7 +659,7 @@ impl From<crate::oci::LinuxHugepageLimit> for oci::LinuxHugepageLimit {
fn from(mut from: crate::oci::LinuxHugepageLimit) -> Self { fn from(mut from: crate::oci::LinuxHugepageLimit) -> Self {
oci::LinuxHugepageLimit { oci::LinuxHugepageLimit {
page_size: from.take_Pagesize(), page_size: from.take_Pagesize(),
limit: from.get_Limit(), limit: from.Limit(),
} }
} }
} }
@ -696,7 +667,7 @@ impl From<crate::oci::LinuxHugepageLimit> for oci::LinuxHugepageLimit {
impl From<crate::oci::LinuxResources> for oci::LinuxResources { impl From<crate::oci::LinuxResources> for oci::LinuxResources {
fn from(mut from: crate::oci::LinuxResources) -> Self { fn from(mut from: crate::oci::LinuxResources) -> Self {
let mut devices = Vec::new(); let mut devices = Vec::new();
for d in from.take_Devices().to_vec() { for d in from.take_Devices() {
devices.push(d.into()); devices.push(d.into());
} }
@ -712,16 +683,16 @@ impl From<crate::oci::LinuxResources> for oci::LinuxResources {
let mut pids = None; let mut pids = None;
if from.has_Pids() { if from.has_Pids() {
pids = Some(from.get_Pids().clone().into()) pids = Some(from.Pids().clone().into())
} }
let mut block_io = None; let mut block_io = None;
if from.has_BlockIO() { 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(); let mut hugepage_limits = Vec::new();
for hl in from.get_HugepageLimits() { for hl in from.HugepageLimits() {
hugepage_limits.push(hl.clone().into()); hugepage_limits.push(hl.clone().into());
} }
@ -750,11 +721,11 @@ impl From<crate::oci::LinuxDevice> for oci::LinuxDevice {
oci::LinuxDevice { oci::LinuxDevice {
path: from.take_Path(), path: from.take_Path(),
r#type: from.take_Type(), r#type: from.take_Type(),
major: from.get_Major(), major: from.Major(),
minor: from.get_Minor(), minor: from.Minor(),
file_mode: Some(from.get_FileMode()), file_mode: Some(from.FileMode()),
uid: Some(from.get_UID()), uid: Some(from.UID()),
gid: Some(from.get_GID()), gid: Some(from.GID()),
} }
} }
} }
@ -762,9 +733,9 @@ impl From<crate::oci::LinuxDevice> for oci::LinuxDevice {
impl From<crate::oci::LinuxSeccompArg> for oci::LinuxSeccompArg { impl From<crate::oci::LinuxSeccompArg> for oci::LinuxSeccompArg {
fn from(mut from: crate::oci::LinuxSeccompArg) -> Self { fn from(mut from: crate::oci::LinuxSeccompArg) -> Self {
oci::LinuxSeccompArg { oci::LinuxSeccompArg {
index: from.get_Index() as u32, index: from.Index() as u32,
value: from.get_Value(), value: from.Value(),
value_two: from.get_ValueTwo(), value_two: from.ValueTwo(),
op: from.take_Op(), op: from.take_Op(),
} }
} }
@ -773,14 +744,14 @@ impl From<crate::oci::LinuxSeccompArg> for oci::LinuxSeccompArg {
impl From<crate::oci::LinuxSyscall> for oci::LinuxSyscall { impl From<crate::oci::LinuxSyscall> for oci::LinuxSyscall {
fn from(mut from: crate::oci::LinuxSyscall) -> Self { fn from(mut from: crate::oci::LinuxSyscall) -> Self {
let mut args = Vec::new(); let mut args = Vec::new();
for ag in from.take_Args().to_vec() { for ag in from.take_Args() {
args.push(ag.into()); args.push(ag.into());
} }
oci::LinuxSyscall { oci::LinuxSyscall {
names: from.take_Names().to_vec(), names: from.take_Names().to_vec(),
action: from.take_Action(), action: from.take_Action(),
args, args,
errno_ret: from.get_errnoret(), errno_ret: from.errnoret(),
} }
} }
} }
@ -788,7 +759,7 @@ impl From<crate::oci::LinuxSyscall> for oci::LinuxSyscall {
impl From<crate::oci::LinuxSeccomp> for oci::LinuxSeccomp { impl From<crate::oci::LinuxSeccomp> for oci::LinuxSeccomp {
fn from(mut from: crate::oci::LinuxSeccomp) -> Self { fn from(mut from: crate::oci::LinuxSeccomp) -> Self {
let mut syscalls = Vec::new(); let mut syscalls = Vec::new();
for s in from.take_Syscalls().to_vec() { for s in from.take_Syscalls() {
syscalls.push(s.into()); syscalls.push(s.into());
} }
@ -813,16 +784,16 @@ impl From<crate::oci::LinuxNamespace> for oci::LinuxNamespace {
impl From<crate::oci::Linux> for oci::Linux { impl From<crate::oci::Linux> for oci::Linux {
fn from(mut from: crate::oci::Linux) -> Self { fn from(mut from: crate::oci::Linux) -> Self {
let mut uid_mappings = Vec::new(); 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()) uid_mappings.push(id_map.into())
} }
let mut gid_mappings = Vec::new(); 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()) gid_mappings.push(id_map.into())
} }
let sysctl = from.get_Sysctl().clone(); let sysctl = from.Sysctl().clone();
let mut resources = None; let mut resources = None;
if from.has_Resources() { if from.has_Resources() {
resources = Some(from.take_Resources().into()); resources = Some(from.take_Resources().into());
@ -830,12 +801,12 @@ impl From<crate::oci::Linux> for oci::Linux {
let cgroups_path = from.take_CgroupsPath(); let cgroups_path = from.take_CgroupsPath();
let mut namespaces = Vec::new(); let mut namespaces = Vec::new();
for ns in from.take_Namespaces().to_vec() { for ns in from.take_Namespaces() {
namespaces.push(ns.into()) namespaces.push(ns.into())
} }
let mut devices = Vec::new(); let mut devices = Vec::new();
for d in from.take_Devices().to_vec() { for d in from.take_Devices() {
devices.push(d.into()); devices.push(d.into());
} }
@ -874,8 +845,8 @@ impl From<crate::oci::POSIXRlimit> for oci::PosixRlimit {
fn from(mut from: crate::oci::POSIXRlimit) -> Self { fn from(mut from: crate::oci::POSIXRlimit) -> Self {
oci::PosixRlimit { oci::PosixRlimit {
r#type: from.take_Type(), r#type: from.take_Type(),
hard: from.get_Hard(), hard: from.Hard(),
soft: from.get_Soft(), soft: from.Soft(),
} }
} }
} }
@ -895,8 +866,8 @@ impl From<crate::oci::LinuxCapabilities> for oci::LinuxCapabilities {
impl From<crate::oci::User> for oci::User { impl From<crate::oci::User> for oci::User {
fn from(mut from: crate::oci::User) -> Self { fn from(mut from: crate::oci::User) -> Self {
oci::User { oci::User {
uid: from.get_UID(), uid: from.UID(),
gid: from.get_GID(), gid: from.GID(),
additional_gids: from.take_AdditionalGids().to_vec(), additional_gids: from.take_AdditionalGids().to_vec(),
username: from.take_Username(), username: from.take_Username(),
} }
@ -906,8 +877,8 @@ impl From<crate::oci::User> for oci::User {
impl From<crate::oci::Box> for oci::Box { impl From<crate::oci::Box> for oci::Box {
fn from(from: crate::oci::Box) -> Self { fn from(from: crate::oci::Box) -> Self {
oci::Box { oci::Box {
height: from.get_Height(), height: from.Height(),
width: from.get_Width(), width: from.Width(),
} }
} }
} }
@ -920,22 +891,22 @@ impl From<crate::oci::Process> for oci::Process {
} }
let user = from.take_User().into(); let user = from.take_User().into();
let args = from.take_Args().into_vec(); let args = from.take_Args();
let env = from.take_Env().into_vec(); let env = from.take_Env();
let cwd = from.take_Cwd(); let cwd = from.take_Cwd();
let mut capabilities = None; let mut capabilities = None;
if from.has_Capabilities() { if from.has_Capabilities() {
capabilities = Some(from.take_Capabilities().into()); capabilities = Some(from.take_Capabilities().into());
} }
let mut rlimits = Vec::new(); let mut rlimits = Vec::new();
for rl in from.take_Rlimits().to_vec() { for rl in from.take_Rlimits() {
rlimits.push(rl.into()); rlimits.push(rl.into());
} }
let no_new_privileges = from.get_NoNewPrivileges(); let no_new_privileges = from.NoNewPrivileges();
let apparmor_profile = from.take_ApparmorProfile(); let apparmor_profile = from.take_ApparmorProfile();
let mut oom_score_adj = None; let mut oom_score_adj = None;
if from.get_OOMScoreAdj() != 0 { if from.OOMScoreAdj() != 0 {
oom_score_adj = Some(from.get_OOMScoreAdj() as i32); oom_score_adj = Some(from.OOMScoreAdj() as i32);
} }
let selinux_label = from.take_SelinuxLabel(); let selinux_label = from.take_SelinuxLabel();
@ -959,8 +930,8 @@ impl From<crate::oci::Process> for oci::Process {
impl From<crate::oci::Hook> for oci::Hook { impl From<crate::oci::Hook> for oci::Hook {
fn from(mut from: crate::oci::Hook) -> Self { fn from(mut from: crate::oci::Hook) -> Self {
let mut timeout = None; let mut timeout = None;
if from.get_Timeout() > 0 { if from.Timeout() > 0 {
timeout = Some(from.get_Timeout() as i32); timeout = Some(from.Timeout() as i32);
} }
oci::Hook { oci::Hook {
path: from.take_Path(), path: from.take_Path(),
@ -1020,7 +991,7 @@ impl From<crate::oci::Spec> for oci::Spec {
} }
let mut mounts = Vec::new(); let mut mounts = Vec::new();
for m in from.take_Mounts().into_vec() { for m in from.take_Mounts() {
mounts.push(m.into()) mounts.push(m.into())
} }
@ -1085,7 +1056,7 @@ mod tests {
#[test] #[test]
fn test_from_vec_len_0() { fn test_from_vec_len_0() {
let from: Vec<TestA> = vec![]; let from: Vec<TestA> = vec![];
let to: ::protobuf::RepeatedField<TestB> = from_vec(from.clone()); let to: Vec<TestB> = from_vec(from.clone());
assert_eq!(from.len(), to.len()); assert_eq!(from.len(), to.len());
} }
@ -1094,7 +1065,7 @@ mod tests {
let from: Vec<TestA> = vec![TestA { let from: Vec<TestA> = vec![TestA {
from: "a".to_string(), from: "a".to_string(),
}]; }];
let to: ::protobuf::RepeatedField<TestB> = from_vec(from.clone()); let to: Vec<TestB> = from_vec(from.clone());
assert_eq!(from.len(), to.len()); assert_eq!(from.len(), to.len());
assert_eq!(from[0].from, to[0].to); assert_eq!(from[0].from, to[0].to);

View File

@ -50,7 +50,7 @@ dependencies = [
"logging", "logging",
"nix 0.24.3", "nix 0.24.3",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"protocols", "protocols",
"serde", "serde",
"serde_json", "serde_json",
@ -475,7 +475,7 @@ dependencies = [
"nix 0.24.3", "nix 0.24.3",
"oci", "oci",
"persist", "persist",
"protobuf", "protobuf 3.2.0",
"serde_json", "serde_json",
"slog", "slog",
"slog-scope", "slog-scope",
@ -508,13 +508,14 @@ checksum = "f3ad85c1f65dc7b37604eb0e89748faf0b9653065f2a8ef69f96a687ec1e9279"
[[package]] [[package]]
name = "containerd-shim-protos" name = "containerd-shim-protos"
version = "0.2.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "077ec778a0835d9d85502e8535362130187759b69eddabe2bdb3a68ffb575bd0" checksum = "ef45f1c71aa587d8f657c546d8da38ea04f113dd05da0ef993c4515fa25fbdd1"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"protobuf", "protobuf 3.2.0",
"ttrpc", "ttrpc",
"ttrpc-codegen",
] ]
[[package]] [[package]]
@ -2192,9 +2193,16 @@ name = "protobuf"
version = "2.28.0" version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94"
[[package]]
name = "protobuf"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e"
dependencies = [ dependencies = [
"serde", "once_cell",
"serde_derive", "protobuf-support",
"thiserror",
] ]
[[package]] [[package]]
@ -2203,36 +2211,47 @@ version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.28.0",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure" name = "protobuf-codegen"
version = "2.28.0" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a29399fc94bcd3eeaa951c715f7bea69409b2445356b00519740bcd6ddd865" checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen", "once_cell",
"protobuf 3.2.0",
"protobuf-parse",
"regex",
"tempfile",
"thiserror",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure3" name = "protobuf-parse"
version = "2.28.2" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b351add14db0721ad0842f4858aec11a5088684112ef163fc50f113c63e69b2e" checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen3", "indexmap",
"log",
"protobuf 3.2.0",
"protobuf-support",
"tempfile",
"thiserror",
"which",
] ]
[[package]] [[package]]
name = "protobuf-codegen3" name = "protobuf-support"
version = "2.28.2" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73c5878d0fa872bd7d61782c6aa2d2d56761ba4ed4514eb6992f5f83162f1d2f" checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372"
dependencies = [ dependencies = [
"protobuf", "thiserror",
] ]
[[package]] [[package]]
@ -2241,7 +2260,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"ttrpc", "ttrpc",
"ttrpc-codegen", "ttrpc-codegen",
] ]
@ -2676,7 +2695,7 @@ dependencies = [
"logging", "logging",
"nix 0.24.3", "nix 0.24.3",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"rand 0.8.5", "rand 0.8.5",
"serial_test", "serial_test",
"service", "service",
@ -3136,9 +3155,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]] [[package]]
name = "ttrpc" name = "ttrpc"
version = "0.6.1" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"byteorder", "byteorder",
@ -3146,8 +3165,8 @@ dependencies = [
"libc", "libc",
"log", "log",
"nix 0.23.2", "nix 0.23.2",
"protobuf", "protobuf 3.2.0",
"protobuf-codegen-pure", "protobuf-codegen 3.2.0",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-vsock", "tokio-vsock",
@ -3155,28 +3174,28 @@ dependencies = [
[[package]] [[package]]
name = "ttrpc-codegen" name = "ttrpc-codegen"
version = "0.2.3" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2365c9179ad82b29bda1b0162c7542ab5861a7844abfedd8cfdf8bd7e12358f9" checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.28.0",
"protobuf-codegen-pure3", "protobuf-codegen 3.2.0",
"protobuf-codegen3", "protobuf-support",
"ttrpc-compiler", "ttrpc-compiler",
] ]
[[package]] [[package]]
name = "ttrpc-compiler" name = "ttrpc-compiler"
version = "0.4.3" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed57c2d6669099791507b8b491b2940f2e8975b52a73fe82efad24257d10e9bc" checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647"
dependencies = [ dependencies = [
"derive-new", "derive-new",
"prost", "prost",
"prost-build", "prost-build",
"prost-types", "prost-types",
"protobuf", "protobuf 2.28.0",
"protobuf-codegen3", "protobuf-codegen 2.28.0",
"tempfile", "tempfile",
] ]
@ -3297,7 +3316,7 @@ dependencies = [
"nix 0.24.3", "nix 0.24.3",
"oci", "oci",
"persist", "persist",
"protobuf", "protobuf 3.2.0",
"resource", "resource",
"serde", "serde",
"serde_derive", "serde_derive",

View File

@ -12,12 +12,12 @@ futures = "0.1.27"
anyhow = "1.0.26" anyhow = "1.0.26"
async-trait = "0.1.48" async-trait = "0.1.48"
log = "0.4.14" log = "0.4.14"
protobuf = "2.27.0" protobuf = "3.2.0"
serde = { version = "^1.0", features = ["derive"] } serde = { version = "^1.0", features = ["derive"] }
serde_json = ">=1.0.9" serde_json = ">=1.0.9"
slog = "2.5.2" slog = "2.5.2"
slog-scope = "4.4.0" slog-scope = "4.4.0"
ttrpc = { version = "0.6.1" } ttrpc = { version = "0.7.1" }
tokio = { version = "1.8.0", features = ["fs", "rt"] } tokio = { version = "1.8.0", features = ["fs", "rt"] }
url = "2.2.2" url = "2.2.2"
nix = "0.24.2" nix = "0.24.2"

View File

@ -56,7 +56,7 @@ macro_rules! impl_health_service {
impl HealthService for KataAgent { impl HealthService for KataAgent {
$(async fn $name(&self, req: $req) -> Result<$resp> { $(async fn $name(&self, req: $req) -> Result<$resp> {
let r = req.into(); 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?; let resp = client.$name(new_ttrpc_ctx(timeout * MILLISECOND_TO_NANOSECOND), &r).await?;
Ok(resp.into()) Ok(resp.into())
})* })*
@ -75,7 +75,7 @@ macro_rules! impl_agent {
impl Agent for KataAgent { impl Agent for KataAgent {
$(async fn $name(&self, req: $req) -> Result<$resp> { $(async fn $name(&self, req: $req) -> Result<$resp> {
let r = req.into(); 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 // update new timeout
if let Some(v) = $new_timeout { if let Some(v) = $new_timeout {

View File

@ -30,30 +30,18 @@ use crate::{
OomEventResponse, WaitProcessResponse, WriteStreamResponse, OomEventResponse, WaitProcessResponse, WriteStreamResponse,
}; };
fn from_vec<F: Into<T>, T: Sized>(from: Vec<F>) -> ::protobuf::RepeatedField<T> { fn trans_vec<F: Sized + Clone, T: From<F>>(from: Vec<F>) -> Vec<T> {
let mut to: Vec<T> = vec![]; from.into_iter().map(|f| f.into()).collect()
for data in from {
to.push(data.into());
}
::protobuf::RepeatedField::from_vec(to)
} }
fn into_vec<F: Sized + Clone, T: From<F>>(from: ::protobuf::RepeatedField<F>) -> Vec<T> { fn from_option<F: Sized, T: From<F>>(from: Option<F>) -> protobuf::MessageField<T> {
let mut to: Vec<T> = vec![];
for data in from.to_vec() {
to.push(data.into());
}
to
}
fn from_option<F: Sized, T: From<F>>(from: Option<F>) -> ::protobuf::SingularPtrField<T> {
match from { match from {
Some(f) => ::protobuf::SingularPtrField::from_option(Some(T::from(f))), Some(f) => protobuf::MessageField::from_option(Some(T::from(f))),
None => ::protobuf::SingularPtrField::none(), None => protobuf::MessageField::none(),
} }
} }
fn into_option<F: Into<T>, T: Sized>(from: ::protobuf::SingularPtrField<F>) -> Option<T> { fn into_option<F: Into<T>, T: Sized>(from: protobuf::MessageField<F>) -> Option<T> {
from.into_option().map(|f| f.into()) from.into_option().map(|f| f.into())
} }
@ -84,9 +72,8 @@ impl From<FSGroup> for agent::FSGroup {
Self { Self {
group_id: from.group_id, group_id: from.group_id,
group_change_policy: policy, group_change_policy: policy.into(),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -96,9 +83,8 @@ impl From<StringUser> for agent::StringUser {
Self { Self {
uid: from.uid, uid: from.uid,
gid: from.gid, gid: from.gid,
additionalGids: ::protobuf::RepeatedField::from_vec(from.additional_gids), additionalGids: from.additional_gids,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -107,12 +93,11 @@ impl From<Device> for agent::Device {
fn from(from: Device) -> Self { fn from(from: Device) -> Self {
Self { Self {
id: from.id, id: from.id,
field_type: from.field_type, type_: from.field_type,
vm_path: from.vm_path, vm_path: from.vm_path,
container_path: from.container_path, container_path: from.container_path,
options: from_vec(from.options), options: trans_vec(from.options),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -121,14 +106,13 @@ impl From<Storage> for agent::Storage {
fn from(from: Storage) -> Self { fn from(from: Storage) -> Self {
Self { Self {
driver: from.driver, driver: from.driver,
driver_options: from_vec(from.driver_options), driver_options: trans_vec(from.driver_options),
source: from.source, source: from.source,
fstype: from.fs_type, fstype: from.fs_type,
fs_group: from_option(from.fs_group), fs_group: from_option(from.fs_group),
options: from_vec(from.options), options: trans_vec(from.options),
mount_point: from.mount_point, mount_point: from.mount_point,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -137,9 +121,8 @@ impl From<KernelModule> for agent::KernelModule {
fn from(from: KernelModule) -> Self { fn from(from: KernelModule) -> Self {
Self { Self {
name: from.name, name: from.name,
parameters: from_vec(from.parameters), parameters: trans_vec(from.parameters),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -166,11 +149,10 @@ impl From<types::IPFamily> for IPFamily {
impl From<IPAddress> for types::IPAddress { impl From<IPAddress> for types::IPAddress {
fn from(from: IPAddress) -> Self { fn from(from: IPAddress) -> Self {
Self { Self {
family: from.family.into(), family: protobuf::EnumOrUnknown::new(from.family.into()),
address: from.address, address: from.address,
mask: from.mask, mask: from.mask,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -178,7 +160,7 @@ impl From<IPAddress> for types::IPAddress {
impl From<types::IPAddress> for IPAddress { impl From<types::IPAddress> for IPAddress {
fn from(src: types::IPAddress) -> Self { fn from(src: types::IPAddress) -> Self {
Self { Self {
family: src.family.into(), family: src.family.unwrap().into(),
address: "".to_string(), address: "".to_string(),
mask: "".to_string(), mask: "".to_string(),
} }
@ -190,14 +172,13 @@ impl From<Interface> for types::Interface {
Self { Self {
device: from.device, device: from.device,
name: from.name, name: from.name,
IPAddresses: from_vec(from.ip_addresses), IPAddresses: trans_vec(from.ip_addresses),
mtu: from.mtu, mtu: from.mtu,
hwAddr: from.hw_addr, hwAddr: from.hw_addr,
pciPath: from.pci_addr, pciPath: from.pci_addr,
field_type: from.field_type, type_: from.field_type,
raw_flags: from.raw_flags, raw_flags: from.raw_flags,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -207,11 +188,11 @@ impl From<types::Interface> for Interface {
Self { Self {
device: src.device, device: src.device,
name: src.name, name: src.name,
ip_addresses: into_vec(src.IPAddresses), ip_addresses: trans_vec(src.IPAddresses),
mtu: src.mtu, mtu: src.mtu,
hw_addr: src.hwAddr, hw_addr: src.hwAddr,
pci_addr: src.pciPath, pci_addr: src.pciPath,
field_type: src.field_type, field_type: src.type_,
raw_flags: src.raw_flags, raw_flags: src.raw_flags,
} }
} }
@ -220,7 +201,7 @@ impl From<types::Interface> for Interface {
impl From<agent::Interfaces> for Interfaces { impl From<agent::Interfaces> for Interfaces {
fn from(src: agent::Interfaces) -> Self { fn from(src: agent::Interfaces) -> Self {
Self { Self {
interfaces: into_vec(src.Interfaces), interfaces: trans_vec(src.Interfaces),
} }
} }
} }
@ -233,9 +214,8 @@ impl From<Route> for types::Route {
device: from.device, device: from.device,
source: from.source, source: from.source,
scope: from.scope, scope: from.scope,
family: from.family.into(), family: protobuf::EnumOrUnknown::new(from.family.into()),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -248,7 +228,7 @@ impl From<types::Route> for Route {
device: src.device, device: src.device,
source: src.source, source: src.source,
scope: src.scope, scope: src.scope,
family: src.family.into(), family: src.family.unwrap().into(),
} }
} }
} }
@ -256,9 +236,8 @@ impl From<types::Route> for Route {
impl From<Routes> for agent::Routes { impl From<Routes> for agent::Routes {
fn from(from: Routes) -> Self { fn from(from: Routes) -> Self {
Self { Self {
Routes: from_vec(from.routes), Routes: trans_vec(from.routes),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -266,7 +245,7 @@ impl From<Routes> for agent::Routes {
impl From<agent::Routes> for Routes { impl From<agent::Routes> for Routes {
fn from(src: agent::Routes) -> Self { fn from(src: agent::Routes) -> Self {
Self { Self {
routes: into_vec(src.Routes), routes: trans_vec(src.Routes),
} }
} }
} }
@ -277,12 +256,11 @@ impl From<CreateContainerRequest> for agent::CreateContainerRequest {
container_id: from.process_id.container_id(), container_id: from.process_id.container_id(),
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
string_user: from_option(from.string_user), string_user: from_option(from.string_user),
devices: from_vec(from.devices), devices: trans_vec(from.devices),
storages: from_vec(from.storages), storages: trans_vec(from.storages),
OCI: from_option(from.oci), OCI: from_option(from.oci),
sandbox_pidns: from.sandbox_pidns, sandbox_pidns: from.sandbox_pidns,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -292,8 +270,7 @@ impl From<RemoveContainerRequest> for agent::RemoveContainerRequest {
Self { Self {
container_id: from.container_id, container_id: from.container_id,
timeout: from.timeout, timeout: from.timeout,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -302,8 +279,7 @@ impl From<ContainerID> for agent::StartContainerRequest {
fn from(from: ContainerID) -> Self { fn from(from: ContainerID) -> Self {
Self { Self {
container_id: from.container_id, container_id: from.container_id,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -312,8 +288,7 @@ impl From<ContainerID> for agent::StatsContainerRequest {
fn from(from: ContainerID) -> Self { fn from(from: ContainerID) -> Self {
Self { Self {
container_id: from.container_id, container_id: from.container_id,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -322,8 +297,7 @@ impl From<ContainerID> for agent::PauseContainerRequest {
fn from(from: ContainerID) -> Self { fn from(from: ContainerID) -> Self {
Self { Self {
container_id: from.container_id, container_id: from.container_id,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -332,8 +306,7 @@ impl From<ContainerID> for agent::ResumeContainerRequest {
fn from(from: ContainerID) -> Self { fn from(from: ContainerID) -> Self {
Self { Self {
container_id: from.container_id, container_id: from.container_id,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -344,8 +317,7 @@ impl From<SignalProcessRequest> for agent::SignalProcessRequest {
container_id: from.process_id.container_id(), container_id: from.process_id.container_id(),
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
signal: from.signal, signal: from.signal,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -355,8 +327,7 @@ impl From<WaitProcessRequest> for agent::WaitProcessRequest {
Self { Self {
container_id: from.process_id.container_id(), container_id: from.process_id.container_id(),
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -366,8 +337,7 @@ impl From<UpdateContainerRequest> for agent::UpdateContainerRequest {
Self { Self {
container_id: from.container_id, container_id: from.container_id,
resources: from_option(Some(from.resources)), resources: from_option(Some(from.resources)),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -378,8 +348,7 @@ impl From<WriteStreamRequest> for agent::WriteStreamRequest {
container_id: from.process_id.container_id(), container_id: from.process_id.container_id(),
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
data: from.data, data: from.data,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -402,7 +371,7 @@ impl From<GetIPTablesRequest> for agent::GetIPTablesRequest {
impl From<agent::GetIPTablesResponse> for GetIPTablesResponse { impl From<agent::GetIPTablesResponse> for GetIPTablesResponse {
fn from(from: agent::GetIPTablesResponse) -> Self { fn from(from: agent::GetIPTablesResponse) -> Self {
Self { Self {
data: from.get_data().to_vec(), data: from.data().to_vec(),
} }
} }
} }
@ -420,7 +389,7 @@ impl From<SetIPTablesRequest> for agent::SetIPTablesRequest {
impl From<agent::SetIPTablesResponse> for SetIPTablesResponse { impl From<agent::SetIPTablesResponse> for SetIPTablesResponse {
fn from(from: agent::SetIPTablesResponse) -> Self { fn from(from: agent::SetIPTablesResponse) -> Self {
Self { Self {
data: from.get_data().to_vec(), data: from.data().to_vec(),
} }
} }
} }
@ -432,8 +401,7 @@ impl From<ExecProcessRequest> for agent::ExecProcessRequest {
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
string_user: from_option(from.string_user), string_user: from_option(from.string_user),
process: from_option(from.process), process: from_option(from.process),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -515,14 +483,14 @@ impl From<agent::BlkioStatsEntry> for BlkioStatsEntry {
impl From<agent::BlkioStats> for BlkioStats { impl From<agent::BlkioStats> for BlkioStats {
fn from(src: agent::BlkioStats) -> Self { fn from(src: agent::BlkioStats) -> Self {
Self { Self {
io_service_bytes_recursive: into_vec(src.io_service_bytes_recursive), io_service_bytes_recursive: trans_vec(src.io_service_bytes_recursive),
io_serviced_recursive: into_vec(src.io_serviced_recursive), io_serviced_recursive: trans_vec(src.io_serviced_recursive),
io_queued_recursive: into_vec(src.io_queued_recursive), io_queued_recursive: trans_vec(src.io_queued_recursive),
io_service_time_recursive: into_vec(src.io_service_time_recursive), io_service_time_recursive: trans_vec(src.io_service_time_recursive),
io_wait_time_recursive: into_vec(src.io_wait_time_recursive), io_wait_time_recursive: trans_vec(src.io_wait_time_recursive),
io_merged_recursive: into_vec(src.io_merged_recursive), io_merged_recursive: trans_vec(src.io_merged_recursive),
io_time_recursive: into_vec(src.io_time_recursive), io_time_recursive: trans_vec(src.io_time_recursive),
sectors_recursive: into_vec(src.sectors_recursive), sectors_recursive: trans_vec(src.sectors_recursive),
} }
} }
} }
@ -570,7 +538,7 @@ impl From<agent::StatsContainerResponse> for StatsContainerResponse {
fn from(src: agent::StatsContainerResponse) -> Self { fn from(src: agent::StatsContainerResponse) -> Self {
Self { Self {
cgroup_stats: into_option(src.cgroup_stats), 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<ReadStreamRequest> for agent::ReadStreamRequest {
container_id: from.process_id.container_id(), container_id: from.process_id.container_id(),
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
len: from.len, len: from.len,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -598,8 +565,7 @@ impl From<CloseStdinRequest> for agent::CloseStdinRequest {
Self { Self {
container_id: from.process_id.container_id(), container_id: from.process_id.container_id(),
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -611,8 +577,7 @@ impl From<TtyWinResizeRequest> for agent::TtyWinResizeRequest {
exec_id: from.process_id.exec_id(), exec_id: from.process_id.exec_id(),
row: from.row, row: from.row,
column: from.column, column: from.column,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -621,8 +586,7 @@ impl From<UpdateInterfaceRequest> for agent::UpdateInterfaceRequest {
fn from(from: UpdateInterfaceRequest) -> Self { fn from(from: UpdateInterfaceRequest) -> Self {
Self { Self {
interface: from_option(from.interface), interface: from_option(from.interface),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -630,8 +594,7 @@ impl From<UpdateInterfaceRequest> for agent::UpdateInterfaceRequest {
impl From<Empty> for agent::ListInterfacesRequest { impl From<Empty> for agent::ListInterfacesRequest {
fn from(_: Empty) -> Self { fn from(_: Empty) -> Self {
Self { Self {
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -640,8 +603,7 @@ impl From<UpdateRoutesRequest> for agent::UpdateRoutesRequest {
fn from(from: UpdateRoutesRequest) -> Self { fn from(from: UpdateRoutesRequest) -> Self {
Self { Self {
routes: from_option(from.route), routes: from_option(from.route),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -649,8 +611,7 @@ impl From<UpdateRoutesRequest> for agent::UpdateRoutesRequest {
impl From<Empty> for agent::ListRoutesRequest { impl From<Empty> for agent::ListRoutesRequest {
fn from(_: Empty) -> Self { fn from(_: Empty) -> Self {
Self { Self {
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -663,8 +624,7 @@ impl From<ARPNeighbor> for types::ARPNeighbor {
lladdr: from.ll_addr, lladdr: from.ll_addr,
state: from.state, state: from.state,
flags: from.flags, flags: from.flags,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -672,9 +632,8 @@ impl From<ARPNeighbor> for types::ARPNeighbor {
impl From<ARPNeighbors> for agent::ARPNeighbors { impl From<ARPNeighbors> for agent::ARPNeighbors {
fn from(from: ARPNeighbors) -> Self { fn from(from: ARPNeighbors) -> Self {
Self { Self {
ARPNeighbors: from_vec(from.neighbors), ARPNeighbors: trans_vec(from.neighbors),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -683,8 +642,7 @@ impl From<AddArpNeighborRequest> for agent::AddARPNeighborsRequest {
fn from(from: AddArpNeighborRequest) -> Self { fn from(from: AddArpNeighborRequest) -> Self {
Self { Self {
neighbors: from_option(from.neighbors), neighbors: from_option(from.neighbors),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -693,14 +651,13 @@ impl From<CreateSandboxRequest> for agent::CreateSandboxRequest {
fn from(from: CreateSandboxRequest) -> Self { fn from(from: CreateSandboxRequest) -> Self {
Self { Self {
hostname: from.hostname, hostname: from.hostname,
dns: from_vec(from.dns), dns: trans_vec(from.dns),
storages: from_vec(from.storages), storages: trans_vec(from.storages),
sandbox_pidns: from.sandbox_pidns, sandbox_pidns: from.sandbox_pidns,
sandbox_id: from.sandbox_id, sandbox_id: from.sandbox_id,
guest_hook_path: from.guest_hook_path, guest_hook_path: from.guest_hook_path,
kernel_modules: from_vec(from.kernel_modules), kernel_modules: trans_vec(from.kernel_modules),
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -708,8 +665,7 @@ impl From<CreateSandboxRequest> for agent::CreateSandboxRequest {
impl From<Empty> for agent::DestroySandboxRequest { impl From<Empty> for agent::DestroySandboxRequest {
fn from(_: Empty) -> Self { fn from(_: Empty) -> Self {
Self { Self {
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -720,8 +676,7 @@ impl From<OnlineCPUMemRequest> for agent::OnlineCPUMemRequest {
wait: from.wait, wait: from.wait,
nb_cpus: from.nb_cpus, nb_cpus: from.nb_cpus,
cpu_only: from.cpu_only, cpu_only: from.cpu_only,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -730,8 +685,7 @@ impl From<ReseedRandomDevRequest> for agent::ReseedRandomDevRequest {
fn from(from: ReseedRandomDevRequest) -> Self { fn from(from: ReseedRandomDevRequest) -> Self {
Self { Self {
data: from.data, data: from.data,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -740,8 +694,7 @@ impl From<MemHotplugByProbeRequest> for agent::MemHotplugByProbeRequest {
fn from(from: MemHotplugByProbeRequest) -> Self { fn from(from: MemHotplugByProbeRequest) -> Self {
Self { Self {
memHotplugProbeAddr: from.mem_hotplug_probe_addr, memHotplugProbeAddr: from.mem_hotplug_probe_addr,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -751,8 +704,7 @@ impl From<SetGuestDateTimeRequest> for agent::SetGuestDateTimeRequest {
Self { Self {
Sec: from.sec, Sec: from.sec,
Usec: from.usec, Usec: from.usec,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -762,8 +714,8 @@ impl From<agent::AgentDetails> for AgentDetails {
Self { Self {
version: src.version, version: src.version,
init_daemon: src.init_daemon, init_daemon: src.init_daemon,
device_handlers: into_vec(src.device_handlers), device_handlers: trans_vec(src.device_handlers),
storage_handlers: into_vec(src.storage_handlers), storage_handlers: trans_vec(src.storage_handlers),
supports_seccomp: src.supports_seccomp, supports_seccomp: src.supports_seccomp,
} }
} }
@ -790,8 +742,7 @@ impl From<CopyFileRequest> for agent::CopyFileRequest {
gid: from.gid, gid: from.gid,
offset: from.offset, offset: from.offset,
data: from.data, data: from.data,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -807,8 +758,7 @@ impl From<agent::WaitProcessResponse> for WaitProcessResponse {
impl From<Empty> for agent::GetOOMEventRequest { impl From<Empty> for agent::GetOOMEventRequest {
fn from(_: Empty) -> Self { fn from(_: Empty) -> Self {
Self { Self {
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -817,8 +767,7 @@ impl From<CheckRequest> for health::CheckRequest {
fn from(from: CheckRequest) -> Self { fn from(from: CheckRequest) -> Self {
Self { Self {
service: from.service, service: from.service,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -826,7 +775,7 @@ impl From<CheckRequest> for health::CheckRequest {
impl From<health::HealthCheckResponse> for HealthCheckResponse { impl From<health::HealthCheckResponse> for HealthCheckResponse {
fn from(from: health::HealthCheckResponse) -> Self { fn from(from: health::HealthCheckResponse) -> Self {
Self { Self {
status: from.status as u32, status: from.status.value() as u32,
} }
} }
} }
@ -852,8 +801,7 @@ impl From<VolumeStatsRequest> for agent::VolumeStatsRequest {
fn from(from: VolumeStatsRequest) -> Self { fn from(from: VolumeStatsRequest) -> Self {
Self { Self {
volume_guest_path: from.volume_guest_path, volume_guest_path: from.volume_guest_path,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }
@ -862,8 +810,8 @@ impl From<csi::VolumeStatsResponse> for VolumeStatsResponse {
fn from(from: csi::VolumeStatsResponse) -> Self { fn from(from: csi::VolumeStatsResponse) -> Self {
let result: String = format!( let result: String = format!(
"Usage: {:?} Volume Condition: {:?}", "Usage: {:?} Volume Condition: {:?}",
from.get_usage(), from.usage(),
from.get_volume_condition() from.volume_condition()
); );
Self { data: result } Self { data: result }
} }
@ -874,8 +822,7 @@ impl From<ResizeVolumeRequest> for agent::ResizeVolumeRequest {
Self { Self {
volume_guest_path: from.volume_guest_path, volume_guest_path: from.volume_guest_path,
size: from.size, size: from.size,
unknown_fields: Default::default(), ..Default::default()
cached_size: Default::default(),
} }
} }
} }

View File

@ -10,17 +10,17 @@ license = "Apache-2.0"
[dependencies] [dependencies]
anyhow = "^1.0" anyhow = "^1.0"
async-trait = "0.1.48" 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" lazy_static = "1.4.0"
nix = "0.24.2" nix = "0.24.2"
protobuf = "2.27.0" protobuf = "3.2.0"
serde_json = "1.0.39" serde_json = "1.0.39"
slog = "2.5.2" slog = "2.5.2"
slog-scope = "4.4.0" slog-scope = "4.4.0"
strum = { version = "0.24.0", features = ["derive"] } strum = { version = "0.24.0", features = ["derive"] }
thiserror = "^1.0" thiserror = "^1.0"
tokio = { version = "1.8.0", features = ["rt-multi-thread", "process", "fs"] } tokio = { version = "1.8.0", features = ["rt-multi-thread", "process", "fs"] }
ttrpc = { version = "0.6.1" } ttrpc = { version = "0.7.1" }
persist = {path = "../../persist"} persist = {path = "../../persist"}
agent = { path = "../../agent" } agent = { path = "../../agent" }
kata-sys-util = { path = "../../../../libs/kata-sys-util" } kata-sys-util = { path = "../../../../libs/kata-sys-util" }

View File

@ -151,7 +151,7 @@ impl From<Option<agent::StatsContainerResponse>> for StatsInfo {
} }
if !cg_stats.hugetlb_stats.is_empty() { 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 { for (k, v) in cg_stats.hugetlb_stats {
let mut h = metrics::HugetlbStat::new(); let mut h = metrics::HugetlbStat::new();
h.set_pagesize(k); h.set_pagesize(k);
@ -166,7 +166,7 @@ impl From<Option<agent::StatsContainerResponse>> for StatsInfo {
let net_stats = stats.network_stats; let net_stats = stats.network_stats;
if !net_stats.is_empty() { if !net_stats.is_empty() {
let mut p_net = ::protobuf::RepeatedField::new(); let mut p_net = Vec::new();
for v in net_stats.iter() { for v in net_stats.iter() {
let mut h = metrics::NetworkStat::new(); let mut h = metrics::NetworkStat::new();
h.set_name(v.name.clone()); h.set_name(v.name.clone());
@ -195,10 +195,8 @@ impl From<Option<agent::StatsContainerResponse>> for StatsInfo {
} }
} }
fn copy_blkio_entry( fn copy_blkio_entry(entry: &[agent::BlkioStatsEntry]) -> Vec<metrics::BlkIOEntry> {
entry: &[agent::BlkioStatsEntry], let mut p_entry = Vec::new();
) -> ::protobuf::RepeatedField<metrics::BlkIOEntry> {
let mut p_entry = ::protobuf::RepeatedField::new();
for e in entry.iter() { for e in entry.iter() {
let mut blk = metrics::BlkIOEntry::new(); let mut blk = metrics::BlkIOEntry::new();

View File

@ -16,7 +16,7 @@ use std::{
path::PathBuf, 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 options = from.options.to_vec();
let mut read_only = false; let mut read_only = false;
for o in &options { for o in &options {
@ -29,7 +29,7 @@ fn trans_from_shim_mount(from: api::Mount) -> Mount {
Mount { Mount {
source: from.source.clone(), source: from.source.clone(),
destination: PathBuf::from(&from.target), destination: PathBuf::from(&from.target),
fs_type: from.field_type, fs_type: from.type_.clone(),
options, options,
device_id: None, device_id: None,
host_shared_fs_path: None, host_shared_fs_path: None,
@ -41,19 +41,14 @@ impl TryFrom<api::CreateTaskRequest> for Request {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(from: api::CreateTaskRequest) -> Result<Self> { fn try_from(from: api::CreateTaskRequest) -> Result<Self> {
let options = if from.has_options() { let options = if from.has_options() {
Some(from.get_options().get_value().to_vec()) Some(from.options().value.to_vec())
} else { } else {
None None
}; };
Ok(Request::CreateContainer(ContainerConfig { Ok(Request::CreateContainer(ContainerConfig {
container_id: from.id.clone(), container_id: from.id.clone(),
bundle: from.bundle.clone(), bundle: from.bundle.clone(),
rootfs_mounts: from rootfs_mounts: from.rootfs.iter().map(trans_from_shim_mount).collect(),
.rootfs
.to_vec()
.into_iter()
.map(trans_from_shim_mount)
.collect(),
terminal: from.terminal, terminal: from.terminal,
options, options,
stdin: (!from.stdin.is_empty()).then(|| from.stdin.clone()), stdin: (!from.stdin.is_empty()).then(|| from.stdin.clone()),
@ -84,15 +79,15 @@ impl TryFrom<api::DeleteRequest> for Request {
impl TryFrom<api::ExecProcessRequest> for Request { impl TryFrom<api::ExecProcessRequest> for Request {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(from: api::ExecProcessRequest) -> Result<Self> { fn try_from(from: api::ExecProcessRequest) -> Result<Self> {
let spec = from.get_spec(); let spec = from.spec();
Ok(Request::ExecProcess(ExecProcessRequest { Ok(Request::ExecProcess(ExecProcessRequest {
process: ContainerProcess::new(&from.id, &from.exec_id).context("new process id")?, process: ContainerProcess::new(&from.id, &from.exec_id).context("new process id")?,
terminal: from.terminal, terminal: from.terminal,
stdin: (!from.stdin.is_empty()).then(|| from.stdin.clone()), stdin: (!from.stdin.is_empty()).then(|| from.stdin.clone()),
stdout: (!from.stdout.is_empty()).then(|| from.stdout.clone()), stdout: (!from.stdout.is_empty()).then(|| from.stdout.clone()),
stderr: (!from.stderr.is_empty()).then(|| from.stderr.clone()), stderr: (!from.stderr.is_empty()).then(|| from.stderr.clone()),
spec_type_url: spec.get_type_url().to_string(), spec_type_url: spec.type_url.to_string(),
spec_value: spec.get_value().to_vec(), spec_value: spec.value.to_vec(),
})) }))
} }
} }
@ -182,7 +177,7 @@ impl TryFrom<api::UpdateTaskRequest> for Request {
fn try_from(from: api::UpdateTaskRequest) -> Result<Self> { fn try_from(from: api::UpdateTaskRequest) -> Result<Self> {
Ok(Request::UpdateContainer(UpdateRequest { Ok(Request::UpdateContainer(UpdateRequest {
container_id: from.id.to_string(), container_id: from.id.to_string(),
value: from.get_resources().get_value().to_vec(), value: from.resources().value.to_vec(),
})) }))
} }
} }

View File

@ -16,24 +16,24 @@ use containerd_shim_protos::api;
use super::{ProcessExitStatus, ProcessStateInfo, ProcessStatus, Response}; use super::{ProcessExitStatus, ProcessStateInfo, ProcessStatus, Response};
use crate::error::Error; use crate::error::Error;
fn system_time_into(time: time::SystemTime) -> ::protobuf::well_known_types::Timestamp { fn system_time_into(time: time::SystemTime) -> ::protobuf::well_known_types::timestamp::Timestamp {
let mut proto_time = ::protobuf::well_known_types::Timestamp::new(); let mut proto_time = ::protobuf::well_known_types::timestamp::Timestamp::new();
proto_time.set_seconds( proto_time.seconds = time
time.duration_since(time::UNIX_EPOCH) .duration_since(time::UNIX_EPOCH)
.unwrap_or_default() .unwrap_or_default()
.as_secs() .as_secs()
.try_into() .try_into()
.unwrap_or_default(), .unwrap_or_default();
);
proto_time proto_time
} }
fn option_system_time_into( fn option_system_time_into(
time: Option<time::SystemTime>, time: Option<time::SystemTime>,
) -> ::protobuf::SingularPtrField<::protobuf::well_known_types::Timestamp> { ) -> protobuf::MessageField<protobuf::well_known_types::timestamp::Timestamp> {
match time { match time {
Some(v) => ::protobuf::SingularPtrField::some(system_time_into(v)), Some(v) => ::protobuf::MessageField::some(system_time_into(v)),
None => ::protobuf::SingularPtrField::none(), None => ::protobuf::MessageField::none(),
} }
} }
@ -66,7 +66,7 @@ impl From<ProcessStateInfo> for api::StateResponse {
id: from.container_id.clone(), id: from.container_id.clone(),
bundle: from.bundle.clone(), bundle: from.bundle.clone(),
pid: from.pid.pid, pid: from.pid.pid,
status: from.status.into(), status: protobuf::EnumOrUnknown::new(from.status.into()),
stdin: from.stdin.unwrap_or_default(), stdin: from.stdin.unwrap_or_default(),
stdout: from.stdout.unwrap_or_default(), stdout: from.stdout.unwrap_or_default(),
stderr: from.stderr.unwrap_or_default(), stderr: from.stderr.unwrap_or_default(),
@ -164,13 +164,13 @@ impl TryFrom<Response> for api::StateResponse {
impl TryFrom<Response> for api::StatsResponse { impl TryFrom<Response> for api::StatsResponse {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(from: Response) -> Result<Self> { fn try_from(from: Response) -> Result<Self> {
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(); let mut response = api::StatsResponse::new();
match from { match from {
Response::StatsContainer(resp) => { Response::StatsContainer(resp) => {
if let Some(value) = resp.value { if let Some(value) = resp.value {
any.set_type_url(value.type_url); any.type_url = value.type_url;
any.set_value(value.value); any.value = value.value;
response.set_stats(any); response.set_stats(any);
} }
Ok(response) Ok(response)
@ -193,8 +193,7 @@ impl TryFrom<Response> for api::PidsResponse {
let mut res = api::PidsResponse::new(); let mut res = api::PidsResponse::new();
p_info.set_pid(resp.pid); p_info.set_pid(resp.pid);
processes.push(p_info); processes.push(p_info);
let v = protobuf::RepeatedField::<api::ProcessInfo>::from_vec(processes); res.set_processes(processes);
res.set_processes(v);
Ok(res) Ok(res)
} }
_ => Err(anyhow!(Error::UnexpectedResponse( _ => Err(anyhow!(Error::UnexpectedResponse(

View File

@ -9,12 +9,12 @@ license = "Apache-2.0"
anyhow = "^1.0" anyhow = "^1.0"
async-trait = "0.1.48" async-trait = "0.1.48"
awaitgroup = "0.6.0" 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" futures = "0.3.19"
lazy_static = "1.4.0" lazy_static = "1.4.0"
libc = ">=0.2.39" libc = ">=0.2.39"
nix = "0.24.2" nix = "0.24.2"
protobuf = "2.27.0" protobuf = "3.2.0"
serde = { version = "1.0.100", features = ["derive"] } serde = { version = "1.0.100", features = ["derive"] }
serde_derive = "1.0.27" serde_derive = "1.0.27"
serde_json = "1.0.82" serde_json = "1.0.82"

View File

@ -11,10 +11,10 @@ async-trait = "0.1.48"
slog = "2.5.2" slog = "2.5.2"
slog-scope = "4.4.0" slog-scope = "4.4.0"
tokio = { version = "1.8.0", features = ["rt-multi-thread"] } tokio = { version = "1.8.0", features = ["rt-multi-thread"] }
ttrpc = { version = "0.6.1" } ttrpc = { version = "0.7.1" }
common = { path = "../runtimes/common" } 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"} logging = { path = "../../../libs/logging"}
shim-interface = { path = "../../../libs/shim-interface" } shim-interface = { path = "../../../libs/shim-interface" }
runtimes = { path = "../runtimes" } runtimes = { path = "../runtimes" }

View File

@ -14,7 +14,7 @@ use std::{
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use common::message::{Action, Event, Message}; use common::message::{Action, Event, Message};
use containerd_shim_protos::{ use containerd_shim_protos::{
protobuf::{well_known_types::Any, Message as ProtobufMessage}, protobuf::{well_known_types::any::Any, Message as ProtobufMessage},
shim_async, shim_async,
}; };
use runtimes::RuntimeHandlerManager; use runtimes::RuntimeHandlerManager;

View File

@ -15,12 +15,12 @@ path = "src/bin/main.rs"
[dependencies] [dependencies]
anyhow = "^1.0" anyhow = "^1.0"
backtrace = {version = ">=0.3.35", features = ["libunwind", "libbacktrace", "std"], default-features = false} 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" go-flag = "0.1.0"
libc = "0.2.108" libc = "0.2.108"
log = "0.4.14" log = "0.4.14"
nix = "0.24.2" nix = "0.24.2"
protobuf = "2.27.0" protobuf = "3.2.0"
sha2 = "=0.9.3" sha2 = "=0.9.3"
slog = {version = "2.5.2", features = ["std", "release_max_level_trace", "max_level_trace"]} slog = {version = "2.5.2", features = ["std", "release_max_level_trace", "max_level_trace"]}
slog-async = "2.5.2" slog-async = "2.5.2"

View File

@ -26,12 +26,12 @@ impl ShimExecutor {
async fn do_cleanup(&self) -> Result<api::DeleteResponse> { async fn do_cleanup(&self) -> Result<api::DeleteResponse> {
let mut rsp = api::DeleteResponse::new(); let mut rsp = api::DeleteResponse::new();
rsp.set_exit_status(128 + libc::SIGKILL as u32); 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() let seconds = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH) .duration_since(std::time::UNIX_EPOCH)
.map_err(Error::SystemTime)? .map_err(Error::SystemTime)?
.as_secs() as i64; .as_secs() as i64;
exited_time.set_seconds(seconds); exited_time.seconds = seconds;
rsp.set_exited_at(exited_time); rsp.set_exited_at(exited_time);
let address = self let address = self

View File

@ -31,9 +31,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.51" version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
[[package]] [[package]]
name = "arc-swap" name = "arc-swap"
@ -114,7 +114,7 @@ checksum = "d7d78656ba01f1b93024b7c3a0467f1608e4be67d725749fdcd7d2c7678fd7a2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -131,7 +131,7 @@ checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -176,7 +176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd9e32d7420c85055e8107e5b2463c4eeefeaac18b52359fe9f9c08a18f342b2" checksum = "fd9e32d7420c85055e8107e5b2463c4eeefeaac18b52359fe9f9c08a18f342b2"
dependencies = [ dependencies = [
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -340,7 +340,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -351,7 +351,7 @@ checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -398,7 +398,7 @@ checksum = "f58dc3c5e468259f19f2d46304a6b28f1c3d034442e14b322d2b850e36f6d5ae"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -527,7 +527,7 @@ dependencies = [
"proc-macro-hack", "proc-macro-hack",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -593,9 +593,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.11.2" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]] [[package]]
name = "heck" name = "heck"
@ -651,9 +651,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.7.0" version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"hashbrown", "hashbrown",
@ -728,7 +728,7 @@ dependencies = [
"logging", "logging",
"nix 0.23.1", "nix 0.23.1",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"protocols", "protocols",
"rand 0.8.4", "rand 0.8.4",
"rustjail", "rustjail",
@ -1084,11 +1084,11 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.34" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1" checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
dependencies = [ dependencies = [
"unicode-xid", "unicode-ident",
] ]
[[package]] [[package]]
@ -1129,7 +1129,7 @@ dependencies = [
"itertools", "itertools",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -1144,31 +1144,68 @@ dependencies = [
[[package]] [[package]]
name = "protobuf" name = "protobuf"
version = "2.27.1" version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" 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 = [ dependencies = [
"serde", "once_cell",
"serde_derive", "protobuf-support",
"thiserror",
] ]
[[package]] [[package]]
name = "protobuf-codegen" name = "protobuf-codegen"
version = "2.27.1" version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aec1632b7c8f2e620343439a7dfd1f3c47b18906c4be58982079911482b5d707" checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.28.0",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure" name = "protobuf-codegen"
version = "2.27.1" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f8122fdb18e55190c796b088a16bdb70cd7acdcd48f7a8b796b58c62e532cc6" checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen", "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]] [[package]]
@ -1176,7 +1213,7 @@ name = "protocols"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"serde", "serde",
"serde_json", "serde_json",
"ttrpc", "ttrpc",
@ -1185,9 +1222,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.10" version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -1347,7 +1384,7 @@ dependencies = [
"nix 0.24.2", "nix 0.24.2",
"oci", "oci",
"path-absolutize", "path-absolutize",
"protobuf", "protobuf 3.2.0",
"protocols", "protocols",
"regex", "regex",
"rlimit", "rlimit",
@ -1386,22 +1423,22 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.132" version = "1.0.160"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008" checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.132" version = "1.0.160"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276" checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.14",
] ]
[[package]] [[package]]
@ -1423,7 +1460,7 @@ checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -1552,6 +1589,17 @@ dependencies = [
"unicode-xid", "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]] [[package]]
name = "take_mut" name = "take_mut"
version = "0.2.2" version = "0.2.2"
@ -1598,7 +1646,7 @@ checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -1645,7 +1693,7 @@ checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -1677,7 +1725,7 @@ checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -1691,43 +1739,43 @@ dependencies = [
[[package]] [[package]]
name = "ttrpc" name = "ttrpc"
version = "0.6.0" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c7d6c992964a013c17814c08d31708d577b0aae44ebadb58755659dd824c2d1" checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"libc", "libc",
"log", "log",
"nix 0.23.1", "nix 0.23.1",
"protobuf", "protobuf 3.2.0",
"protobuf-codegen-pure", "protobuf-codegen 3.2.0",
"thiserror", "thiserror",
] ]
[[package]] [[package]]
name = "ttrpc-codegen" name = "ttrpc-codegen"
version = "0.2.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809eda4e459820237104e4b61d6b41bbe6c9e1ce6adf4057955e6e6722a90408" checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.28.0",
"protobuf-codegen", "protobuf-codegen 3.2.0",
"protobuf-codegen-pure", "protobuf-support",
"ttrpc-compiler", "ttrpc-compiler",
] ]
[[package]] [[package]]
name = "ttrpc-compiler" name = "ttrpc-compiler"
version = "0.4.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2978ed3fa047d8fd55cbeb4d4a61d461fb3021a90c9618519c73ce7e5bb66c15" checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647"
dependencies = [ dependencies = [
"derive-new", "derive-new",
"prost", "prost",
"prost-build", "prost-build",
"prost-types", "prost-types",
"protobuf", "protobuf 2.28.0",
"protobuf-codegen", "protobuf-codegen 2.28.0",
"tempfile", "tempfile",
] ]
@ -1741,6 +1789,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "unicode-ident"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.8.0" version = "1.8.0"
@ -1804,7 +1858,7 @@ dependencies = [
"log", "log",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -1826,7 +1880,7 @@ checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -1981,7 +2035,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex", "regex",
"syn", "syn 1.0.82",
] ]
[[package]] [[package]]
@ -2018,5 +2072,5 @@ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.82",
] ]

View File

@ -27,12 +27,12 @@ logging = { path = "../../libs/logging" }
slog = "2.7.0" slog = "2.7.0"
slog-scope = "4.4.0" slog-scope = "4.4.0"
rand = "0.8.4" rand = "0.8.4"
protobuf = "2.27.0" protobuf = "3.2.0"
nix = "0.23.0" nix = "0.23.0"
libc = "0.2.112" libc = "0.2.112"
# XXX: Must be the same as the version used by the agent # 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 # For parsing timeouts
humantime = "2.1.0" humantime = "2.1.0"

View File

@ -268,8 +268,7 @@ fn root_oci_to_ttrpc(bundle_dir: &str, root: &ociRoot) -> Result<ttrpcRoot> {
let ttrpc_root = ttrpcRoot { let ttrpc_root = ttrpcRoot {
Path: path, Path: path,
Readonly: root.readonly, Readonly: root.readonly,
unknown_fields: protobuf::UnknownFields::new(), ..Default::default()
cached_size: protobuf::CachedSize::default(),
}; };
Ok(ttrpc_root) Ok(ttrpc_root)
@ -281,9 +280,9 @@ fn process_oci_to_ttrpc(p: &ociProcess) -> ttrpcProcess {
let mut b = ttrpcBox::new(); let mut b = ttrpcBox::new();
b.set_Width(s.width); b.set_Width(s.width);
b.set_Height(s.height); 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 { 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) // FIXME: Implement RLimits OCI spec handling (copy from p.rlimits)
//let rlimits = vec![ttrpcPOSIXRlimit::new()]; //let rlimits = vec![ttrpcPOSIXRlimit::new()];
let rlimits = protobuf::RepeatedField::new(); let rlimits = Vec::new();
let capabilities = match &p.capabilities { let capabilities = match &p.capabilities {
Some(c) => { Some(c) => {
let mut gc = ttrpcLinuxCapabilities::new(); let mut gc = ttrpcLinuxCapabilities::new();
gc.set_Bounding(protobuf::RepeatedField::from_slice(&c.bounding)); gc.set_Bounding(c.bounding.clone());
gc.set_Effective(protobuf::RepeatedField::from_slice(&c.effective)); gc.set_Effective(c.effective.clone());
gc.set_Inheritable(protobuf::RepeatedField::from_slice(&c.inheritable)); gc.set_Inheritable(c.inheritable.clone());
gc.set_Permitted(protobuf::RepeatedField::from_slice(&c.permitted)); gc.set_Permitted(c.permitted.clone());
gc.set_Ambient(protobuf::RepeatedField::from_slice(&c.ambient)); 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 { for pair in &p.env {
env.push(pair.to_string()); env.push(pair.to_string());
} }
@ -322,8 +321,8 @@ fn process_oci_to_ttrpc(p: &ociProcess) -> ttrpcProcess {
ttrpcProcess { ttrpcProcess {
Terminal: p.terminal, Terminal: p.terminal,
ConsoleSize: console_size, ConsoleSize: console_size,
User: protobuf::SingularPtrField::some(user), User: protobuf::MessageField::some(user),
Args: protobuf::RepeatedField::from_vec(p.args.clone()), Args: p.args.clone(),
Env: env, Env: env,
Cwd: p.cwd.clone(), Cwd: p.cwd.clone(),
Capabilities: capabilities, Capabilities: capabilities,
@ -332,13 +331,12 @@ fn process_oci_to_ttrpc(p: &ociProcess) -> ttrpcProcess {
ApparmorProfile: p.apparmor_profile.clone(), ApparmorProfile: p.apparmor_profile.clone(),
OOMScoreAdj: oom_score_adj, OOMScoreAdj: oom_score_adj,
SelinuxLabel: p.selinux_label.clone(), SelinuxLabel: p.selinux_label.clone(),
unknown_fields: protobuf::UnknownFields::new(), ..Default::default()
cached_size: protobuf::CachedSize::default(),
} }
} }
fn mount_oci_to_ttrpc(m: &ociMount) -> ttrpcMount { 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 { for op in &m.options {
ttrpc_options.push(op.to_string()); ttrpc_options.push(op.to_string());
} }
@ -346,17 +344,14 @@ fn mount_oci_to_ttrpc(m: &ociMount) -> ttrpcMount {
ttrpcMount { ttrpcMount {
destination: m.destination.clone(), destination: m.destination.clone(),
source: m.source.clone(), source: m.source.clone(),
field_type: m.r#type.clone(), type_: m.r#type.clone(),
options: ttrpc_options, options: ttrpc_options,
unknown_fields: protobuf::UnknownFields::new(), ..Default::default()
cached_size: protobuf::CachedSize::default(),
} }
} }
fn idmaps_oci_to_ttrpc( fn idmaps_oci_to_ttrpc(res: &[oci::LinuxIdMapping]) -> Vec<ttrpcLinuxIDMapping> {
res: &[oci::LinuxIdMapping], let mut ttrpc_idmaps = Vec::new();
) -> protobuf::RepeatedField<ttrpcLinuxIDMapping> {
let mut ttrpc_idmaps = protobuf::RepeatedField::new();
for m in res.iter() { for m in res.iter() {
let mut idmapping = ttrpcLinuxIDMapping::default(); let mut idmapping = ttrpcLinuxIDMapping::default();
idmapping.set_HostID(m.host_id); idmapping.set_HostID(m.host_id);
@ -367,10 +362,8 @@ fn idmaps_oci_to_ttrpc(
ttrpc_idmaps ttrpc_idmaps
} }
fn devices_oci_to_ttrpc( fn devices_oci_to_ttrpc(res: &[oci::LinuxDeviceCgroup]) -> Vec<ttrpcLinuxDeviceCgroup> {
res: &[oci::LinuxDeviceCgroup], let mut ttrpc_devices = Vec::new();
) -> protobuf::RepeatedField<ttrpcLinuxDeviceCgroup> {
let mut ttrpc_devices = protobuf::RepeatedField::new();
for d in res.iter() { for d in res.iter() {
let mut device = ttrpcLinuxDeviceCgroup::default(); let mut device = ttrpcLinuxDeviceCgroup::default();
device.set_Major(d.major.unwrap_or(0)); device.set_Major(d.major.unwrap_or(0));
@ -383,12 +376,10 @@ fn devices_oci_to_ttrpc(
ttrpc_devices ttrpc_devices
} }
fn memory_oci_to_ttrpc( fn memory_oci_to_ttrpc(res: &Option<oci::LinuxMemory>) -> protobuf::MessageField<ttrpcLinuxMemory> {
res: &Option<oci::LinuxMemory>,
) -> protobuf::SingularPtrField<ttrpcLinuxMemory> {
let memory = if res.is_some() { let memory = if res.is_some() {
let mem = res.as_ref().unwrap(); let mem = res.as_ref().unwrap();
protobuf::SingularPtrField::some(ttrpcLinuxMemory { protobuf::MessageField::some(ttrpcLinuxMemory {
Limit: mem.limit.unwrap_or(0), Limit: mem.limit.unwrap_or(0),
Reservation: mem.reservation.unwrap_or(0), Reservation: mem.reservation.unwrap_or(0),
Swap: mem.swap.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), KernelTCP: mem.kernel_tcp.unwrap_or(0),
Swappiness: mem.swappiness.unwrap_or(0), Swappiness: mem.swappiness.unwrap_or(0),
DisableOOMKiller: mem.disable_oom_killer.unwrap_or(false), DisableOOMKiller: mem.disable_oom_killer.unwrap_or(false),
unknown_fields: protobuf::UnknownFields::new(), ..Default::default()
cached_size: protobuf::CachedSize::default(),
}) })
} else { } else {
protobuf::SingularPtrField::none() protobuf::MessageField::none()
}; };
memory memory
} }
fn cpu_oci_to_ttrpc(res: &Option<oci::LinuxCpu>) -> protobuf::SingularPtrField<ttrpcLinuxCPU> { fn cpu_oci_to_ttrpc(res: &Option<oci::LinuxCpu>) -> protobuf::MessageField<ttrpcLinuxCPU> {
match &res { match &res {
Some(s) => { Some(s) => {
let mut cpu = ttrpcLinuxCPU::default(); let mut cpu = ttrpcLinuxCPU::default();
@ -414,27 +404,25 @@ fn cpu_oci_to_ttrpc(res: &Option<oci::LinuxCpu>) -> protobuf::SingularPtrField<t
cpu.set_Period(s.period.unwrap_or(0)); cpu.set_Period(s.period.unwrap_or(0));
cpu.set_RealtimeRuntime(s.realtime_runtime.unwrap_or(0)); cpu.set_RealtimeRuntime(s.realtime_runtime.unwrap_or(0));
cpu.set_RealtimePeriod(s.realtime_period.unwrap_or(0)); cpu.set_RealtimePeriod(s.realtime_period.unwrap_or(0));
protobuf::SingularPtrField::some(cpu) protobuf::MessageField::some(cpu)
} }
None => protobuf::SingularPtrField::none(), None => protobuf::MessageField::none(),
} }
} }
fn pids_oci_to_ttrpc(res: &Option<oci::LinuxPids>) -> protobuf::SingularPtrField<ttrpcLinuxPids> { fn pids_oci_to_ttrpc(res: &Option<oci::LinuxPids>) -> protobuf::MessageField<ttrpcLinuxPids> {
match &res { match &res {
Some(s) => { Some(s) => {
let mut b = ttrpcLinuxPids::new(); let mut b = ttrpcLinuxPids::new();
b.set_Limit(s.limit); 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( fn hugepage_limits_oci_to_ttrpc(res: &[oci::LinuxHugepageLimit]) -> Vec<ttrpcLinuxHugepageLimit> {
res: &[oci::LinuxHugepageLimit], let mut ttrpc_hugepage_limits = Vec::new();
) -> protobuf::RepeatedField<ttrpcLinuxHugepageLimit> {
let mut ttrpc_hugepage_limits = protobuf::RepeatedField::new();
for h in res.iter() { for h in res.iter() {
let mut hugepage_limit = ttrpcLinuxHugepageLimit::default(); let mut hugepage_limit = ttrpcLinuxHugepageLimit::default();
hugepage_limit.set_Limit(h.limit); hugepage_limit.set_Limit(h.limit);
@ -446,28 +434,26 @@ fn hugepage_limits_oci_to_ttrpc(
fn network_oci_to_ttrpc( fn network_oci_to_ttrpc(
res: &Option<oci::LinuxNetwork>, res: &Option<oci::LinuxNetwork>,
) -> protobuf::SingularPtrField<ttrpcLinuxNetwork> { ) -> protobuf::MessageField<ttrpcLinuxNetwork> {
match &res { match &res {
Some(s) => { Some(s) => {
let mut b = ttrpcLinuxNetwork::new(); let mut b = ttrpcLinuxNetwork::new();
b.set_ClassID(s.class_id.unwrap_or(0)); 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() { for pr in s.priorities.iter() {
let mut lip = ttrpcLinuxInterfacePriority::new(); let mut lip = ttrpcLinuxInterfacePriority::new();
lip.set_Name(pr.name.clone()); lip.set_Name(pr.name.clone());
lip.set_Priority(pr.priority); lip.set_Priority(pr.priority);
priorities.push(lip); 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( fn weight_devices_oci_to_ttrpc(res: &[oci::LinuxWeightDevice]) -> Vec<ttrpcLinuxWeightDevice> {
res: &[oci::LinuxWeightDevice], let mut ttrpc_weight_devices = Vec::new();
) -> protobuf::RepeatedField<ttrpcLinuxWeightDevice> {
let mut ttrpc_weight_devices = protobuf::RepeatedField::new();
for dev in res.iter() { for dev in res.iter() {
let mut device = ttrpcLinuxWeightDevice::default(); let mut device = ttrpcLinuxWeightDevice::default();
device.set_Major(dev.blk.major); device.set_Major(dev.blk.major);
@ -489,8 +475,8 @@ fn weight_devices_oci_to_ttrpc(
fn throttle_devices_oci_to_ttrpc( fn throttle_devices_oci_to_ttrpc(
res: &[oci::LinuxThrottleDevice], res: &[oci::LinuxThrottleDevice],
) -> protobuf::RepeatedField<ttrpcLinuxThrottleDevice> { ) -> Vec<ttrpcLinuxThrottleDevice> {
let mut ttrpc_throttle_devices = protobuf::RepeatedField::new(); let mut ttrpc_throttle_devices = Vec::new();
for dev in res.iter() { for dev in res.iter() {
let mut device = ttrpcLinuxThrottleDevice::default(); let mut device = ttrpcLinuxThrottleDevice::default();
device.set_Major(dev.blk.major); device.set_Major(dev.blk.major);
@ -503,7 +489,7 @@ fn throttle_devices_oci_to_ttrpc(
fn block_io_oci_to_ttrpc( fn block_io_oci_to_ttrpc(
res: &Option<oci::LinuxBlockIo>, res: &Option<oci::LinuxBlockIo>,
) -> protobuf::SingularPtrField<ttrpcLinuxBlockIO> { ) -> protobuf::MessageField<ttrpcLinuxBlockIO> {
match &res { match &res {
Some(s) => { Some(s) => {
let mut b = ttrpcLinuxBlockIO::new(); let mut b = ttrpcLinuxBlockIO::new();
@ -529,9 +515,9 @@ fn block_io_oci_to_ttrpc(
b.set_ThrottleWriteIOPSDevice(throttle_devices_oci_to_ttrpc( b.set_ThrottleWriteIOPSDevice(throttle_devices_oci_to_ttrpc(
&s.throttle_write_iops_device, &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, BlockIO: block_io,
HugepageLimits: hugepage_limits, HugepageLimits: hugepage_limits,
Network: network, Network: network,
unknown_fields: protobuf::UnknownFields::new(), ..Default::default()
cached_size: protobuf::CachedSize::default(),
} }
} }
fn namespace_oci_to_ttrpc( fn namespace_oci_to_ttrpc(res: &[oci::LinuxNamespace]) -> Vec<ttrpcLinuxNamespace> {
res: &[oci::LinuxNamespace], let mut ttrpc_namespace = Vec::new();
) -> protobuf::RepeatedField<ttrpcLinuxNamespace> {
let mut ttrpc_namespace = protobuf::RepeatedField::new();
for n in res.iter() { for n in res.iter() {
let mut ns = ttrpcLinuxNamespace::default(); let mut ns = ttrpcLinuxNamespace::default();
ns.set_Path(n.path.clone()); ns.set_Path(n.path.clone());
@ -570,10 +553,8 @@ fn namespace_oci_to_ttrpc(
ttrpc_namespace ttrpc_namespace
} }
fn linux_devices_oci_to_ttrpc( fn linux_devices_oci_to_ttrpc(res: &[oci::LinuxDevice]) -> Vec<ttrpcLinuxDevice> {
res: &[oci::LinuxDevice], let mut ttrpc_linux_devices = Vec::new();
) -> protobuf::RepeatedField<ttrpcLinuxDevice> {
let mut ttrpc_linux_devices = protobuf::RepeatedField::new();
for n in res.iter() { for n in res.iter() {
let mut ld = ttrpcLinuxDevice::default(); let mut ld = ttrpcLinuxDevice::default();
ld.set_FileMode(n.file_mode.unwrap_or(0)); 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 { fn seccomp_oci_to_ttrpc(sec: &oci::LinuxSeccomp) -> ttrpcLinuxSeccomp {
let mut ttrpc_seccomp = ttrpcLinuxSeccomp::default(); let mut ttrpc_seccomp = ttrpcLinuxSeccomp::default();
let mut ttrpc_arch = protobuf::RepeatedField::new(); let mut ttrpc_arch = Vec::new();
for a in &sec.architectures { for a in &sec.architectures {
ttrpc_arch.push(std::string::String::from(a)); ttrpc_arch.push(std::string::String::from(a));
} }
ttrpc_seccomp.set_Architectures(ttrpc_arch); ttrpc_seccomp.set_Architectures(ttrpc_arch);
ttrpc_seccomp.set_DefaultAction(sec.default_action.clone()); 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 { for f in &sec.flags {
ttrpc_flags.push(std::string::String::from(f)); ttrpc_flags.push(std::string::String::from(f));
} }
ttrpc_seccomp.set_Flags(ttrpc_flags); ttrpc_seccomp.set_Flags(ttrpc_flags);
let mut ttrpc_syscalls = protobuf::RepeatedField::new(); let mut ttrpc_syscalls = Vec::new();
for sys in &sec.syscalls { for sys in &sec.syscalls {
let mut ttrpc_sys = ttrpcLinuxSyscall::default(); let mut ttrpc_sys = ttrpcLinuxSyscall::default();
ttrpc_sys.set_Action(sys.action.clone()); 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 { for arg in &sys.args {
let mut a = ttrpcLinuxSeccompArg::default(); let mut a = ttrpcLinuxSeccompArg::default();
a.set_Index(arg.index as u64); 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 { let ttrpc_linux_resources = match &l.resources {
Some(s) => { Some(s) => {
let b = resources_oci_to_ttrpc(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); 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 { let ttrpc_seccomp = match &l.seccomp {
Some(s) => { Some(s) => {
let b = seccomp_oci_to_ttrpc(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 { let ttrpc_intel_rdt = match &l.intel_rdt {
Some(s) => { Some(s) => {
let b = intel_rdt_oci_to_ttrpc(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 { ttrpcLinux {
@ -665,38 +646,37 @@ fn linux_oci_to_ttrpc(l: &ociLinux) -> ttrpcLinux {
Devices: ttrpc_linux_devices, Devices: ttrpc_linux_devices,
Seccomp: ttrpc_seccomp, Seccomp: ttrpc_seccomp,
RootfsPropagation: l.rootfs_propagation.clone(), RootfsPropagation: l.rootfs_propagation.clone(),
MaskedPaths: protobuf::RepeatedField::from_slice(&l.masked_paths), MaskedPaths: l.masked_paths.clone(),
ReadonlyPaths: protobuf::RepeatedField::from_slice(&l.readonly_paths), ReadonlyPaths: l.readonly_paths.clone(),
MountLabel: l.mount_label.clone(), MountLabel: l.mount_label.clone(),
IntelRdt: ttrpc_intel_rdt, IntelRdt: ttrpc_intel_rdt,
unknown_fields: protobuf::UnknownFields::new(), ..Default::default()
cached_size: protobuf::CachedSize::default(),
} }
} }
fn oci_to_ttrpc(bundle_dir: &str, cid: &str, oci: &ociSpec) -> Result<ttrpcSpec> { fn oci_to_ttrpc(bundle_dir: &str, cid: &str, oci: &ociSpec) -> Result<ttrpcSpec> {
let process = match &oci.process { let process = match &oci.process {
Some(p) => protobuf::SingularPtrField::some(process_oci_to_ttrpc(p)), Some(p) => protobuf::MessageField::some(process_oci_to_ttrpc(p)),
None => protobuf::SingularPtrField::none(), None => protobuf::MessageField::none(),
}; };
let root = match &oci.root { let root = match &oci.root {
Some(r) => { Some(r) => {
let ttrpc_root = root_oci_to_ttrpc(bundle_dir, 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 { for m in &oci.mounts {
mounts.push(mount_oci_to_ttrpc(m)); mounts.push(mount_oci_to_ttrpc(m));
} }
let linux = match &oci.linux { let linux = match &oci.linux {
Some(l) => protobuf::SingularPtrField::some(linux_oci_to_ttrpc(l)), Some(l) => protobuf::MessageField::some(linux_oci_to_ttrpc(l)),
None => protobuf::SingularPtrField::none(), None => protobuf::MessageField::none(),
}; };
if cid.len() < MIN_HOSTNAME_LEN as usize { if cid.len() < MIN_HOSTNAME_LEN as usize {
@ -713,13 +693,12 @@ fn oci_to_ttrpc(bundle_dir: &str, cid: &str, oci: &ociSpec) -> Result<ttrpcSpec>
Root: root, Root: root,
Hostname: hostname, Hostname: hostname,
Mounts: mounts, Mounts: mounts,
Hooks: protobuf::SingularPtrField::none(), Hooks: protobuf::MessageField::none(),
Annotations: HashMap::new(), Annotations: HashMap::new(),
Linux: linux, Linux: linux,
Solaris: protobuf::SingularPtrField::none(), Solaris: protobuf::MessageField::none(),
Windows: protobuf::SingularPtrField::none(), Windows: protobuf::MessageField::none(),
unknown_fields: protobuf::UnknownFields::new(), ..Default::default()
cached_size: protobuf::CachedSize::default(),
}; };
Ok(ttrpc_spec) Ok(ttrpc_spec)

View File

@ -13,7 +13,7 @@ dependencies = [
"logging", "logging",
"nix 0.24.3", "nix 0.24.3",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"protocols", "protocols",
"serde", "serde",
"serde_json", "serde_json",
@ -657,7 +657,6 @@ dependencies = [
"test-utils", "test-utils",
"thiserror", "thiserror",
"tokio", "tokio",
"ttrpc",
"url", "url",
"vmm-sys-util", "vmm-sys-util",
] ]
@ -1108,9 +1107,16 @@ name = "protobuf"
version = "2.28.0" version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94"
[[package]]
name = "protobuf"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e"
dependencies = [ dependencies = [
"serde", "once_cell",
"serde_derive", "protobuf-support",
"thiserror",
] ]
[[package]] [[package]]
@ -1119,27 +1125,47 @@ version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.28.0",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure" name = "protobuf-codegen"
version = "2.28.0" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a29399fc94bcd3eeaa951c715f7bea69409b2445356b00519740bcd6ddd865" checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen", "once_cell",
"protobuf 3.2.0",
"protobuf-parse",
"regex",
"tempfile",
"thiserror",
] ]
[[package]] [[package]]
name = "protobuf-codegen-pure3" name = "protobuf-parse"
version = "2.28.1" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0a3cf0a7de7570cb67bfb9a9a585b5841b49790a1be0ef104340a2110b91135" checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49"
dependencies = [ dependencies = [
"protobuf", "anyhow",
"protobuf-codegen", "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]] [[package]]
@ -1148,7 +1174,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"oci", "oci",
"protobuf", "protobuf 3.2.0",
"ttrpc", "ttrpc",
"ttrpc-codegen", "ttrpc-codegen",
] ]
@ -1771,9 +1797,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]] [[package]]
name = "ttrpc" name = "ttrpc"
version = "0.6.1" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ecfff459a859c6ba6668ff72b34c2f1d94d9d58f7088414c2674ad0f31cc7d8" checksum = "a35f22a2964bea14afee161665bb260b83cb48e665e0260ca06ec0e775c8b06c"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"byteorder", "byteorder",
@ -1781,8 +1807,8 @@ dependencies = [
"libc", "libc",
"log", "log",
"nix 0.23.2", "nix 0.23.2",
"protobuf", "protobuf 3.2.0",
"protobuf-codegen-pure", "protobuf-codegen 3.2.0",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-vsock", "tokio-vsock",
@ -1790,28 +1816,28 @@ dependencies = [
[[package]] [[package]]
name = "ttrpc-codegen" name = "ttrpc-codegen"
version = "0.2.2" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df80affc2cf8c589172b05ba2b8e8a88722ebf4e28b86604615497a8b6fb78c0" checksum = "94d7f7631d7a9ebed715a47cd4cb6072cbc7ae1d4ec01598971bbec0024340c2"
dependencies = [ dependencies = [
"protobuf", "protobuf 2.28.0",
"protobuf-codegen", "protobuf-codegen 3.2.0",
"protobuf-codegen-pure3", "protobuf-support",
"ttrpc-compiler", "ttrpc-compiler",
] ]
[[package]] [[package]]
name = "ttrpc-compiler" name = "ttrpc-compiler"
version = "0.4.2" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8db19ce6af25713061dd805d6733b6f0c45904bd63526ce5d2568c858b7edc71" checksum = "ec3cb5dbf1f0865a34fe3f722290fe776cacb16f50428610b779467b76ddf647"
dependencies = [ dependencies = [
"derive-new", "derive-new",
"prost", "prost",
"prost-build", "prost-build",
"prost-types", "prost-types",
"protobuf", "protobuf 2.28.0",
"protobuf-codegen", "protobuf-codegen 2.28.0",
"tempfile", "tempfile",
] ]

View File

@ -37,7 +37,6 @@ libc = "0.2.138"
slog = "2.7.0" slog = "2.7.0"
slog-scope = "4.4.0" slog-scope = "4.4.0"
hyper = "0.14.20" hyper = "0.14.20"
ttrpc = "0.6.0"
tokio = "1.8.0" tokio = "1.8.0"
[target.'cfg(target_arch = "s390x")'.dependencies] [target.'cfg(target_arch = "s390x")'.dependencies]

View File

@ -289,7 +289,6 @@ dependencies = [
"opentelemetry 0.14.0", "opentelemetry 0.14.0",
"opentelemetry-jaeger", "opentelemetry-jaeger",
"privdrop", "privdrop",
"protobuf",
"serde", "serde",
"serde_json", "serde_json",
"slog", "slog",
@ -527,12 +526,6 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "protobuf"
version = "2.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96"
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.10" version = "1.0.10"

View File

@ -23,7 +23,6 @@ serde_json = "1.0.44"
anyhow = "1.0.31" anyhow = "1.0.31"
opentelemetry = { version = "0.14.0", features=["serialize"] } opentelemetry = { version = "0.14.0", features=["serialize"] }
opentelemetry-jaeger = "0.13.0" opentelemetry-jaeger = "0.13.0"
protobuf = "2.27.0"
tracing-opentelemetry = "0.16.0" tracing-opentelemetry = "0.16.0"
tracing = "0.1.29" tracing = "0.1.29"
tracing-subscriber = "0.3.3" tracing-subscriber = "0.3.3"