Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add descriptors.json when creating checkpoint #1511

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/libcontainer/src/container/container_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ use libcgroups::common::CgroupSetup::{Hybrid, Legacy};
#[cfg(feature = "v1")]
use libcgroups::common::DEFAULT_CGROUP_ROOT;
use oci_spec::runtime::Spec;
use std::fs::{self, File};
use std::io::Write;
use std::os::unix::io::AsRawFd;

const CRIU_CHECKPOINT_LOG_FILE: &str = "dump.log";
const DESCRIPTORS_JSON: &str = "descriptors.json";

impl Container {
pub fn checkpoint(&mut self, opts: &CheckpointOptions) -> Result<()> {
Expand Down Expand Up @@ -88,9 +91,24 @@ impl Container {
criu.set_work_dir_fd(work_dir.as_raw_fd());
}

let pid: i32 = self.pid().unwrap().into();

// Remember original stdin, stdout, stderr for container restore.
let mut descriptors = Vec::new();
for n in 0..3 {
let link_path = match fs::read_link(format!("/proc/{}/fd/{}", pid, n)) {
Ok(lp) => lp.into_os_string().into_string().unwrap(),
Err(..) => "/dev/null".to_string(),
};
descriptors.push(link_path);
}
let descriptors_json_path = opts.image_path.join(DESCRIPTORS_JSON);
let mut descriptors_json = File::create(descriptors_json_path)?;
write!(descriptors_json, "{}", serde_json::to_string(&descriptors)?)?;

criu.set_log_file(CRIU_CHECKPOINT_LOG_FILE.to_string());
criu.set_log_level(4);
criu.set_pid(self.pid().unwrap().into());
criu.set_pid(pid);
criu.set_leave_running(opts.leave_running);
criu.set_ext_unix_sk(opts.ext_unix_sk);
criu.set_shell_job(opts.shell_job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ fn checkpoint(
));
}

if !Path::new(&checkpoint_dir.join("descriptors.json")).exists() {
return TestResult::Failed(anyhow::anyhow!(
"resulting checkpoint does not seem to be complete. {:?}/descriptors.json is missing",
&checkpoint_dir,
));
}

let dump_log = match work_path {
Some(wp) => Path::new(wp).join("dump.log"),
_ => checkpoint_dir.join("dump.log"),
Expand Down