mount: Close devices before doing mount

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-07-18 20:47:47 -04:00
parent 573d635b2c
commit 9058835b97
2 changed files with 9 additions and 2 deletions

View File

@ -4,6 +4,8 @@ use crate::errcode::bch_errcode;
use crate::path_to_cstr; use crate::path_to_cstr;
use anyhow::anyhow; use anyhow::anyhow;
pub use crate::bcachefs::bch2_free_super;
pub fn read_super_opts( pub fn read_super_opts(
path: &std::path::Path, path: &std::path::Path,
mut opts: bch_opts, mut opts: bch_opts,

View File

@ -321,7 +321,7 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> {
// Grab the udev information once // Grab the udev information once
let udev_info = udev_bcachefs_info()?; let udev_info = udev_bcachefs_info()?;
let (devices, sbs) = if let Some(("UUID" | "OLD_BLKID_UUID", uuid)) = cli.dev.split_once('=') { let (devices, mut sbs) = if let Some(("UUID" | "OLD_BLKID_UUID", uuid)) = cli.dev.split_once('=') {
devs_str_sbs_from_uuid(&udev_info, uuid)? devs_str_sbs_from_uuid(&udev_info, uuid)?
} else if cli.dev.contains(':') { } else if cli.dev.contains(':') {
// If the device string contains ":" we will assume the user knows the // If the device string contains ":" we will assume the user knows the
@ -343,11 +343,16 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> {
ensure!(!sbs.is_empty(), "No device(s) to mount specified"); ensure!(!sbs.is_empty(), "No device(s) to mount specified");
let first_sb = sbs[0]; let first_sb = &sbs[0];
if unsafe { bcachefs::bch2_sb_is_encrypted(first_sb.sb) } { if unsafe { bcachefs::bch2_sb_is_encrypted(first_sb.sb) } {
handle_unlock(cli, &first_sb)?; handle_unlock(cli, &first_sb)?;
} }
for sb in &mut sbs {
unsafe { bch_bindgen::sb_io::bch2_free_super(sb); }
}
drop(sbs);
if let Some(mountpoint) = cli.mountpoint.as_deref() { if let Some(mountpoint) = cli.mountpoint.as_deref() {
info!( info!(
"mounting with params: device: {}, target: {}, options: {}", "mounting with params: device: {}, target: {}, options: {}",