Use Option as resource fields, remove the update switch: update_values

Use idiomatic Option::None to represent optional fields.
This enables updates where not all fields need to be specified.

Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
Tim Zhang
2020-11-05 11:18:39 +08:00
parent 0c18b0855e
commit 567cdb43b3
11 changed files with 99 additions and 143 deletions

View File

@@ -453,14 +453,12 @@ impl ControllerInternal for MemController {
// get the resources that apply to this controller
let memres: &MemoryResources = &res.memory;
if memres.update_values {
let _ = self.set_limit(memres.memory_hard_limit);
let _ = self.set_soft_limit(memres.memory_soft_limit);
let _ = self.set_kmem_limit(memres.kernel_memory_limit);
let _ = self.set_memswap_limit(memres.memory_swap_limit);
let _ = self.set_tcp_limit(memres.kernel_tcp_memory_limit);
let _ = self.set_swappiness(memres.swappiness);
}
update!(self, set_limit, memres.memory_hard_limit);
update!(self, set_soft_limit, memres.memory_soft_limit);
update!(self, set_kmem_limit, memres.kernel_memory_limit);
update!(self, set_memswap_limit, memres.memory_swap_limit);
update!(self, set_tcp_limit, memres.kernel_tcp_memory_limit);
update!(self, set_swappiness, memres.swappiness);
Ok(())
}