From 8c851d4747b8068d796b4e38fa69ffb99efb267c Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 30 Nov 2025 14:19:56 -0500 Subject: [PATCH] bindgen: implement Drop for bch_sb_handle Signed-off-by: Kent Overstreet --- bch_bindgen/build.rs | 1 + bch_bindgen/src/bcachefs.rs | 6 ++++++ src/commands/mount.rs | 7 +------ src/device_scan.rs | 8 +------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/bch_bindgen/build.rs b/bch_bindgen/build.rs index 55176c9d..68727f04 100644 --- a/bch_bindgen/build.rs +++ b/bch_bindgen/build.rs @@ -91,6 +91,7 @@ fn main() { .allowlist_type("sb_names") .no_copy("btree_trans") .no_copy("printbuf") + .no_copy("bch_sb_handle") .no_partialeq("bkey") .no_partialeq("bpos") .generate_inline_functions(true) diff --git a/bch_bindgen/src/bcachefs.rs b/bch_bindgen/src/bcachefs.rs index a900914c..e7904ef1 100644 --- a/bch_bindgen/src/bcachefs.rs +++ b/bch_bindgen/src/bcachefs.rs @@ -91,6 +91,12 @@ impl bch_sb_handle { } } +impl Drop for bch_sb_handle { + fn drop(&mut self) { + unsafe { bch2_free_super(&mut *self); } + } +} + // #[repr(u8)] pub enum rhash_lock_head {} pub enum srcu_struct {} diff --git a/src/commands/mount.rs b/src/commands/mount.rs index 0959bdcf..8c55257d 100644 --- a/src/commands/mount.rs +++ b/src/commands/mount.rs @@ -141,7 +141,7 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> { let opts = bch_bindgen::opts::parse_mount_opts(None, optstr.as_deref(), true) .unwrap_or_default(); - let mut sbs = device_scan::scan_sbs(&cli.dev, &opts)?; + let sbs = device_scan::scan_sbs(&cli.dev, &opts)?; ensure!(!sbs.is_empty(), "No device(s) to mount specified"); @@ -152,11 +152,6 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> { handle_unlock(cli, first_sb)?; } - for sb in &mut sbs { - unsafe { - bch_bindgen::sb_io::bch2_free_super(&mut sb.1); - } - } drop(sbs); if let Some(mountpoint) = cli.mountpoint.as_deref() { diff --git a/src/device_scan.rs b/src/device_scan.rs index 41297cd6..4c4dd64d 100644 --- a/src/device_scan.rs +++ b/src/device_scan.rs @@ -172,13 +172,7 @@ pub fn joined_device_str(sbs: &Vec<(PathBuf, bch_sb_handle)>) -> OsString { } pub fn scan_devices(device: &String, opts: &bch_opts) -> Result { - let mut sbs = scan_sbs(device, opts)?; - - for sb in &mut sbs { - unsafe { - bch_bindgen::sb_io::bch2_free_super(&mut sb.1); - } - } + let sbs = scan_sbs(device, opts)?; Ok(joined_device_str(&sbs)) }