ksud: restore stock mount after overlay mount. close #233

This commit is contained in:
tiann
2023-02-21 20:21:34 +08:00
parent 237e477876
commit b76d973f3a
4 changed files with 115 additions and 1 deletions

View File

@@ -18,6 +18,19 @@ fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) -> Result<()> {
warn!("partition: {partition} is a symlink");
return Ok(());
}
// handle stock mounts under /partition, we should restore the mount point after overlay
let stock_mount = mount::StockMount::new(&format!("/{partition}/"))
.with_context(|| format!("get stock mount of partition: {partition} failed"))?;
let result = stock_mount.umount();
if result.is_err() {
let remount_result = stock_mount.remount();
if remount_result.is_err() {
log::error!("remount stock mount of failed: {:?}", remount_result);
}
bail!("umount stock mount of failed: {:?}", result);
}
// add /partition as the lowerest dir
let lowest_dir = format!("/{partition}");
lowerdir.push(lowest_dir.clone());
@@ -25,7 +38,18 @@ fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) -> Result<()> {
let lowerdir = lowerdir.join(":");
info!("partition: {partition} lowerdir: {lowerdir}");
mount::mount_overlay(&lowerdir, &lowest_dir)
let result = mount::mount_overlay(&lowerdir, &lowest_dir);
if result.is_ok() && stock_mount.remount().is_err() {
// if mount overlay ok but stock remount failed, we should umount overlay
warn!("remount stock mount of failed, umount overlay {lowest_dir} now");
if mount::umount_dir(&lowest_dir).is_err() {
warn!("umount overlay {lowest_dir} failed");
}
}
result
}
pub fn mount_systemlessly(module_dir: &str) -> Result<()> {