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

Retry recover mount once on failure #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn inject(option: Options, injector_config: Vec<InjectorConfig>) -> Result<Mount
}

#[instrument(skip(option, mount_guard))]
fn resume(option: Options, mount_guard: MountInjectionGuard) -> Result<()> {
fn resume(option: Options, mut mount_guard: MountInjectionGuard) -> Result<()> {
info!("disable injection");
mount_guard.disable_injection();

Expand All @@ -128,8 +128,18 @@ fn resume(option: Options, mount_guard: MountInjectionGuard) -> Result<()> {
};

info!("recovering mount");
mount_guard.recover_mount()?;

if let Err(_err) = mount_guard.recover_mount() {
info!("Recover mount failed, re-running replacer and retrying...");
let mut replacer = UnionReplacer::default();
replacer.prepare(&path, &new_path)?;
info!("running replacer again");
let result = replacer.run();
info!("replacer second result: {:?}", result);
if let Err(err) = mount_guard.recover_mount() {
info!("Recover mount failed again...");
return Err(err);
}
}
info!("replacers detached");
info!("recover successfully");

Expand Down
11 changes: 8 additions & 3 deletions src/mount_injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl MountInjectionGuard {
self.hookfs.disable_injection();
}

pub fn recover_mount(mut self) -> Result<()> {
pub fn recover_mount(&mut self) -> Result<()> {
let mount_point = self.original_path.clone();

retry(Fixed::from_millis(500).take(20), || {
Expand All @@ -55,7 +55,7 @@ impl MountInjectionGuard {
.unwrap()?;

let new_path = self.new_path.clone();
let original_path = self.original_path;
let original_path = self.original_path.clone();

let mounts = mount::MountsInfo::parse_mounts()?;

Expand Down Expand Up @@ -130,7 +130,12 @@ impl MountInjector {

std::fs::create_dir_all(new_path.as_path())?;

let args = ["allow_other", "fsname=toda", "default_permissions", "nonempty"];
let args = [
"allow_other",
"fsname=toda",
"default_permissions",
"nonempty",
];
let flags: Vec<_> = args
.iter()
.flat_map(|item| vec![OsStr::new("-o"), OsStr::new(item)])
Expand Down
Loading