-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from containers/rootfs-fixes
--rootfs fixes
- Loading branch information
Showing
7 changed files
with
183 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
use std::ffi::OsStr; | ||
use std::path::PathBuf; | ||
use std::process::{Command, Stdio}; | ||
|
||
use anyhow::{ensure, Result}; | ||
use camino::Utf8PathBuf; | ||
use serde::Deserialize; | ||
|
||
use crate::util::{crun, ensure_unmounted}; | ||
|
||
pub fn delete(args: &liboci_cli::Delete, raw_args: &[impl AsRef<OsStr>]) -> Result<()> { | ||
// get container root path | ||
|
||
// the container might not exist because creation failed midway through, so we ignore errors | ||
let root_path = get_root_path(&args.container_id).ok(); | ||
|
||
// actually delete the container | ||
|
||
crun(raw_args)?; | ||
|
||
// clean up crun-vm mounts so that user doesn't have to deal with them when they decide to | ||
// delete crun-vm's state/private directory | ||
|
||
if let Some(root_path) = root_path { | ||
let private_dir_path: Utf8PathBuf = root_path | ||
.canonicalize()? | ||
.parent() | ||
.unwrap() | ||
.to_path_buf() | ||
.try_into()?; | ||
|
||
let image_dir_path = private_dir_path.join("root/crun-vm/image"); | ||
let image_file_path = image_dir_path.join("image"); | ||
|
||
ensure_unmounted(image_file_path)?; | ||
ensure_unmounted(image_dir_path)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn get_root_path(container_id: &str) -> Result<Utf8PathBuf> { | ||
let output = Command::new("crun") | ||
.arg("state") | ||
.arg(container_id) | ||
.stderr(Stdio::inherit()) | ||
.output()?; | ||
|
||
ensure!(output.status.success()); | ||
|
||
#[derive(Deserialize)] | ||
struct ContainerState { | ||
rootfs: PathBuf, | ||
} | ||
|
||
let state: ContainerState = serde_json::from_slice(&output.stdout)?; | ||
|
||
Ok(state.rootfs.try_into()?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pub mod create; | ||
pub mod delete; | ||
pub mod exec; |
Oops, something went wrong.