summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2025-08-01 18:33:22 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2025-08-01 18:35:33 -0400
commit6eda7d18318ad48e4e49515ed55f20230b670ed9 (patch)
treed342e6b708ffe152fa8bf3ac1f2c79fa4ea581ef /src
parentc97bc37ae8a7849df1c5edd14f25b0bd8bd913dd (diff)
get_or_split_cmdline_devs() now scans for component devices
Fix accidental splitbrain issues caused by writing to only some of a filesystem's devices: now, all subcommands that take member devices will scan for all members before opening. Fixes: https://github.com/koverstreet/bcachefs/issues/924 Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'src')
-rw-r--r--src/device_scan.rs24
-rw-r--r--src/rust_to_c.h6
2 files changed, 30 insertions, 0 deletions
diff --git a/src/device_scan.rs b/src/device_scan.rs
index 4bed2d13..fda2d460 100644
--- a/src/device_scan.rs
+++ b/src/device_scan.rs
@@ -1,4 +1,5 @@
use std::{
+ ffi::{CStr, CString, c_char},
collections::HashMap,
env,
path::{Path, PathBuf},
@@ -171,3 +172,26 @@ pub fn joined_device_str(sbs: &Vec<(PathBuf, bch_sb_handle)>) -> String {
.collect::<Vec<_>>()
.join(":")
}
+
+pub fn scan_devices(device: &String, opts: &bch_opts) -> Result<String> {
+ let mut sbs = scan_sbs(device, opts)?;
+
+ for sb in &mut sbs {
+ unsafe {
+ bch_bindgen::sb_io::bch2_free_super(&mut sb.1);
+ }
+ }
+
+ Ok(joined_device_str(&sbs))
+}
+
+#[no_mangle]
+pub extern "C" fn bch2_scan_devices(device: *const c_char) -> *mut c_char {
+ let device = unsafe { CStr::from_ptr(device) };
+ let device = device.to_str().unwrap().to_string();
+
+ let opts = bch_bindgen::opts::parse_mount_opts(None, None, true)
+ .unwrap_or_default();
+
+ CString::new(scan_devices(&device, &opts).unwrap()).unwrap().into_raw()
+}
diff --git a/src/rust_to_c.h b/src/rust_to_c.h
new file mode 100644
index 00000000..4f23e1dd
--- /dev/null
+++ b/src/rust_to_c.h
@@ -0,0 +1,6 @@
+#ifndef _BCACHEFS_TOOLS_RUST_TO_C_H
+#define _BCACHEFS_TOOLS_RUST_TO_C_H
+
+char *bch2_scan_devices(char *);
+
+#endif /* _BCACHEFS_TOOLS_RUST_TO_C_H */