From 34f9eeba1df78d94f862f268e9d05101ad1dea17 Mon Sep 17 00:00:00 2001 From: NewbieOrange Date: Tue, 26 Aug 2025 21:32:31 +0800 Subject: mount: try to mount even if module is not loaded Signed-off-by: Kent Overstreet --- src/commands/mount.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/commands/mount.rs b/src/commands/mount.rs index d0fd7168..71bc2bd4 100644 --- a/src/commands/mount.rs +++ b/src/commands/mount.rs @@ -218,23 +218,19 @@ pub struct Cli { verbose: u8, } -fn require_bcachefs_module() { +fn check_bcachefs_module() -> bool { let path = Path::new("/sys/module/bcachefs"); - if !path.exists() { + path.exists() || { let _ = std::process::Command::new("modprobe") .arg("bcachefs") .status(); - - if !path.exists() { - error!("bcachefs module not loaded?"); - std::process::exit(1); - } + path.exists() } } pub fn mount(mut argv: Vec, symlink_cmd: Option<&str>) -> std::process::ExitCode { - require_bcachefs_module(); + let module_loaded = check_bcachefs_module(); // If the bcachefs tool is being called as "bcachefs mount dev ..." (as opposed to via a // symlink like "/usr/sbin/mount.bcachefs dev ...", then we need to pop the 0th argument @@ -252,6 +248,9 @@ pub fn mount(mut argv: Vec, symlink_cmd: Option<&str>) -> std::process:: Ok(_) => std::process::ExitCode::SUCCESS, Err(e) => { error!("Mount failed: {e}"); + if !module_loaded { + error!("bcachefs module not loaded?"); + } std::process::ExitCode::FAILURE } } -- cgit v1.2.3