From 039fd4064af9d6171ae5bf87a199f61e7e3da718 Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kent.overstreet@linux.dev>
Date: Sat, 13 Jan 2024 01:47:33 -0500
Subject: [PATCH] cmd_mount: Use noxcl for opening block devices

We're only reading the superblocks, no need for O_EXCL - and this fixes
mounts failing because we're still holding the devices open.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 rust-src/src/cmd_mount.rs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/rust-src/src/cmd_mount.rs b/rust-src/src/cmd_mount.rs
index 6db109c4..eccfe6d0 100644
--- a/rust-src/src/cmd_mount.rs
+++ b/rust-src/src/cmd_mount.rs
@@ -1,5 +1,5 @@
 use atty::Stream;
-use bch_bindgen::{bcachefs, bcachefs::bch_sb_handle};
+use bch_bindgen::{bcachefs, bcachefs::bch_sb_handle, opt_set};
 use log::{info, debug, error, LevelFilter};
 use clap::{Parser};
 use uuid::Uuid;
@@ -104,7 +104,10 @@ fn read_super_silent(path: &std::path::PathBuf) -> anyhow::Result<bch_sb_handle>
     // Stop libbcachefs from spamming the output
     let _gag = gag::BufferRedirect::stdout().unwrap();
 
-    bch_bindgen::rs::read_super(&path)
+    let mut opts = bcachefs::bch_opts::default();
+    opt_set!(opts, noexcl, 1);
+
+    bch_bindgen::rs::read_super_opts(&path, opts)
 }
 
 fn get_devices_by_uuid(uuid: Uuid) -> anyhow::Result<Vec<(PathBuf, bch_sb_handle)>> {
@@ -188,7 +191,7 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
 
         for dev in opt.dev.split(':') {
             let dev = PathBuf::from(dev);
-            sbs.push(bch_bindgen::rs::read_super(&dev)?);
+            sbs.push(read_super_silent(&dev)?);
         }
 
         (opt.dev, sbs)