mount: add much more error info using chain_err

Make the return error  much more specifically by
chain much more error info.

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
fupan.lfp 2020-08-31 10:00:56 +08:00
parent be2f7e6ad9
commit fd8f3ee951
2 changed files with 8 additions and 6 deletions

View File

@ -272,7 +272,8 @@ fn local_storage_handler(
return Ok("".to_string());
}
fs::create_dir_all(&storage.mount_point)?;
fs::create_dir_all(&storage.mount_point)
.chain_err(|| format!("failed to create dir all {:?}", &storage.mount_point))?;
let opts_vec: Vec<String> = storage.options.to_vec();
@ -328,7 +329,8 @@ fn virtio_blk_storage_handler(
// If hot-plugged, get the device node path based on the PCI address else
// use the virt path provided in Storage Source
if storage.source.starts_with("/dev") {
let metadata = fs::metadata(&storage.source)?;
let metadata = fs::metadata(&storage.source)
.chain_err(|| format!("get metadata on file {:?}", &storage.source))?;
let mode = metadata.permissions().mode();
if mode & libc::S_IFBLK == 0 {
@ -631,7 +633,7 @@ pub fn cgroups_mount(logger: &Logger) -> Result<()> {
pub fn remove_mounts(mounts: &Vec<String>) -> Result<()> {
for m in mounts.iter() {
mount::umount(m.as_str())?;
mount::umount(m.as_str()).chain_err(|| format!("failed to umount {:?}", m))?;
}
Ok(())
}
@ -652,12 +654,12 @@ fn ensure_destination_exists(destination: &str, fs_type: &str) -> Result<()> {
}
};
if !dir.exists() {
fs::create_dir_all(dir)?;
fs::create_dir_all(dir).chain_err(|| format!("create dir all failed on {:?}", dir))?;
}
}
if fs_type != "bind" || d.is_dir() {
fs::create_dir_all(d)?;
fs::create_dir_all(d).chain_err(|| format!("create dir all failed on {:?}", d))?;
} else {
fs::OpenOptions::new().create(true).open(d)?;
}

View File

@ -131,7 +131,7 @@ impl Sandbox {
pub fn remove_sandbox_storage(&self, path: &str) -> Result<()> {
let mounts = vec![path.to_string()];
remove_mounts(&mounts)?;
fs::remove_dir_all(path)?;
fs::remove_dir_all(path).chain_err(|| format!("failed to remove dir {:?}", path))?;
Ok(())
}