Support manage-cgroup-mode option for checkpoint#3452
Conversation
4d5a224 to
206dfc1
Compare
utam0k
left a comment
There was a problem hiding this comment.
Is it hard to add the unit or e2e test?
|
I missed that checkpoint tests were implemented in the contest. I have added test cases. |
nayuta723
left a comment
There was a problem hiding this comment.
Thanks! I've left some comments. Please take a look when you have a chance.
crates/liboci-cli/src/checkpoint.rs
Outdated
| @@ -50,8 +50,8 @@ pub struct Checkpoint { | |||
| /// #[clap(long)] | |||
| /// pub pre_dump: bool, | |||
| /// TODO: Cgroups mode | |||
There was a problem hiding this comment.
Please delete TODO comment.
There was a problem hiding this comment.
I would like to put this on hold until #3455 is merged.
There was a problem hiding this comment.
Is the purpose to prevent conflicts? If so, I will leave it as is.
975e4d6 to
d59fa08
Compare
nayuta723
left a comment
There was a problem hiding this comment.
Thanks for the update! I've reviewed your changes and left a few comments. Please take a look when you have a chance.
crates/liboci-cli/src/checkpoint.rs
Outdated
| @@ -50,8 +50,8 @@ pub struct Checkpoint { | |||
| /// #[clap(long)] | |||
| /// pub pre_dump: bool, | |||
| /// TODO: Cgroups mode | |||
There was a problem hiding this comment.
I would like to put this on hold until #3455 is merged.
| let temp_dir = match tempfile::tempdir() { | ||
| Ok(td) => td, | ||
| Err(e) => { | ||
| return TestResult::Failed(anyhow::anyhow!( | ||
| "failed creating temporary directory {:?}", | ||
| e | ||
| )); | ||
| } | ||
| }; | ||
| let image_path = temp_dir.path().join("checkpoint"); | ||
| if let Err(e) = std::fs::create_dir(&image_path) { | ||
| return TestResult::Failed(anyhow::anyhow!( | ||
| "failed creating checkpoint directory ({:?}): {}", | ||
| &image_path, | ||
| e | ||
| )); | ||
| } |
There was a problem hiding this comment.
Please refactor the common logic into a shared function. BTW, is it necessary to create the image_path there?
There was a problem hiding this comment.
Without specifying image_path, we can't control where CRIU writes the image files, and thus can't inspect them.
There was a problem hiding this comment.
I understand that the checkpoint function must have an image_path to operate. If it remains an Option<&Path>, the function should internally generate a default path when None is provided. Alternatively, we could remove the Option and make it a required argument passed from the outside.
I recommend the first approach, as providing a default path internally seems more convenient.
There was a problem hiding this comment.
Ok, I will set the default path.
14f60d7 to
f8d5158
Compare
| let temp_dir = match tempfile::tempdir() { | ||
| Ok(td) => td, | ||
| Err(e) => { | ||
| return TestResult::Failed(anyhow::anyhow!( | ||
| "failed creating temporary directory {:?}", | ||
| e | ||
| )); | ||
| } | ||
| }; | ||
| let image_path = temp_dir.path().join("checkpoint"); | ||
| if let Err(e) = std::fs::create_dir(&image_path) { | ||
| return TestResult::Failed(anyhow::anyhow!( | ||
| "failed creating checkpoint directory ({:?}): {}", | ||
| &image_path, | ||
| e | ||
| )); | ||
| } |
There was a problem hiding this comment.
Without specifying image_path, we can't control where CRIU writes the image files, and thus can't inspect them.
38588c2 to
f00202b
Compare
nayuta723
left a comment
There was a problem hiding this comment.
Apologies for the back-and-forth on my end. I’ve added some nit comments based on the latest implementation strategy. Please check them when you can. Thanks again for your flexibility!
| fn checkpoint( | ||
| project_path: &Path, | ||
| id: &str, | ||
| image_path: Option<&Path>, |
There was a problem hiding this comment.
I’m sorry to backtrack on my previous comment, but I think it’s better to remove the Option after all, as there is processing inside the function that relies on image_path.
| image_path: Option<&Path>, | |
| image_path: &Path, |
| if let Err(e) = setup_network_namespace(project_path, id) { | ||
| return e; | ||
| } | ||
| ) -> Result<(), TestResult> { |
There was a problem hiding this comment.
I’m also sorry to backtrack again, but I think it’s better to remove the Result as well. Requiring the caller to handle errors with match every time feels a bit excessive/clunky in this case.
| ) -> Result<(), TestResult> { | |
| ) -> TestResult { |
42a3daa to
4a38926
Compare
|
Thank you for reviewing, and sorry for the late reply. (I was on vacation.) |
nayuta723
left a comment
There was a problem hiding this comment.
LGTM, Thank you for contributions!
| "full" => Ok(rust_criu::CgMode::FULL), | ||
| "strict" => Ok(rust_criu::CgMode::STRICT), | ||
| "soft" => Ok(rust_criu::CgMode::SOFT), | ||
| _ => Err(anyhow::anyhow!("manage-cgroup-mode: {s}")), |
There was a problem hiding this comment.
| _ => Err(anyhow::anyhow!("manage-cgroup-mode: {s}")), | |
| _ => Err(anyhow::anyhow!("invalid manage-cgroups-mode: {s}")), |
Alternatively, since this is already validated by clap::builder::PossibleValuesParser, I think the following would also be reasonable.
_ => unreachable!("invalid manage-cgroups-mode: {s}"),
| pub shell_job: bool, | ||
| pub tcp_established: bool, | ||
| pub work_path: Option<PathBuf>, | ||
| pub manage_cgroup_mode: rust_criu::CgMode, |
There was a problem hiding this comment.
Overall, I think manage_cgroup_mode should be renamed to manage_cgroups_mode consistently throughout the codebase.
There was a problem hiding this comment.
Good catch, I'll fix it.
75c73a6 to
ba14e65
Compare
Signed-off-by: donkomura <koiru3822fs@gmail.com>
ba14e65 to
2d23f24
Compare
Description
Add support for CRIU's
--manage-cgroup-modeoption in checkpoint command. This primarily affects restore behavior, and with "ignore" mode, cgroup information will not be dumped.Type of Change
Testing
Related Issues
#3394
Additional Context
For detail about the option, see https://criu.org/CGroups.