]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
rust: Filesystem options now supported
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 28 Feb 2023 11:15:48 +0000 (06:15 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 28 Feb 2023 11:15:48 +0000 (06:15 -0500)
This implements opt_set!(), which works exactly the same as the C
version and allows filesystem options to be specified in Rust code.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
rust-src/Cargo.lock
rust-src/bch_bindgen/Cargo.lock
rust-src/bch_bindgen/Cargo.toml
rust-src/bch_bindgen/build.rs
rust-src/bch_bindgen/src/btree.rs
rust-src/bch_bindgen/src/lib.rs
rust-src/bch_bindgen/src/libbcachefs_wrapper.h
rust-src/bch_bindgen/src/opts.rs [new file with mode: 0644]
rust-src/src/cmd_list.rs

index 4665373382107f7ec6ff33b92658cfa614ebeddc..c4dd7f58c704203818d43dc7129c8c0485d40de1 100644 (file)
@@ -81,6 +81,7 @@ dependencies = [
  "gag",
  "libc",
  "memoffset",
+ "paste",
  "pkg-config",
  "udev",
  "uuid",
@@ -595,6 +596,12 @@ dependencies = [
  "syn",
 ]
 
+[[package]]
+name = "paste"
+version = "1.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba"
+
 [[package]]
 name = "peeking_take_while"
 version = "0.1.2"
index 82d211b557c55268c977d4fdeb33c88b9faa5c12..b27419766e7b094d972df929be92d8058db531de 100644 (file)
@@ -48,6 +48,7 @@ dependencies = [
  "gag",
  "libc",
  "memoffset",
+ "paste",
  "pkg-config",
  "udev",
  "uuid",
@@ -439,6 +440,12 @@ version = "1.17.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
 
+[[package]]
+name = "paste"
+version = "1.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba"
+
 [[package]]
 name = "peeking_take_while"
 version = "0.1.2"
index 9a9b7a98fee5ff5312cd4773a669c7fbb5b9f59d..cb341eef5a12d193eea68402bef5dd558f503cc1 100644 (file)
@@ -20,6 +20,7 @@ byteorder = "1.3"
 libc = "0.2.69"
 gag = "1.0.0"
 bitflags = "1.3.2"
+paste = "1.0.11"
 
 [build-dependencies]
 pkg-config = "0.3"
index 8d9986f8f19a68a586a7fce11362d2d358f3b9c9..f426316f42fff1237fbcb67d6a857706f8e80f77 100644 (file)
@@ -54,6 +54,8 @@ fn main() {
         .allowlist_var("BTREE_ITER.*")
         .blocklist_item("bch2_bkey_ops")
         .allowlist_type("bch_.*")
+        .allowlist_type("fsck_err_opts")
+        .rustified_enum("fsck_err_opts")
         .allowlist_type("nonce")
         .no_debug("bch_replicas_padded")
         .newtype_enum("bch_kdf_types")
index 7877b6e23423535857c50b8c845ce931af16d014..8ab91aeb864e77e94bcd6971334f33ee86c78bcb 100644 (file)
@@ -1,5 +1,3 @@
-#![allow(non_snake_case)]
-
 use crate::SPOS_MAX;
 use crate::c;
 use crate::bkey::BkeySC;
index bce150a4b9c4d5495f90508a51764ba382b28881..3bc21a18e0281070a9824cd5434cd6e7eafc5a1b 100644 (file)
@@ -6,6 +6,8 @@ pub mod keyutils;
 pub mod log;
 pub mod rs;
 pub mod fs;
+pub mod opts;
+pub use paste::paste;
 
 pub mod c {
     pub use crate::bcachefs::*;
index 6332d9576a144afe154ab14c076e56dba6225c15..c8990dccf519abc6bb4b3c5d557ac9b66462fa14 100644 (file)
@@ -3,6 +3,7 @@
 #include "../libbcachefs/bcachefs_format.h"
 #include "../libbcachefs/btree_iter.h"
 #include "../libbcachefs/errcode.h"
+#include "../libbcachefs/error.h"
 #include "../libbcachefs/opts.h"
 #include "../libbcachefs.h"
 #include "../crypto.h"
diff --git a/rust-src/bch_bindgen/src/opts.rs b/rust-src/bch_bindgen/src/opts.rs
new file mode 100644 (file)
index 0000000..e226199
--- /dev/null
@@ -0,0 +1,9 @@
+#[macro_export]
+macro_rules! opt_set {
+    ($opts:ident, $n:ident, $v:expr) => {
+        bch_bindgen::paste! {
+            $opts.$n = $v;
+            $opts.[<set_ $n _defined>](1);
+        }
+    }
+}
index 15f3f71fae83afa2f422c8f20b97c7333f91d22c..c89ba4f068158d8af48f6c7f377731d0ece43454 100644 (file)
@@ -1,6 +1,7 @@
 use atty::Stream;
 use bch_bindgen::error;
 use bch_bindgen::bcachefs;
+use bch_bindgen::opt_set;
 use bch_bindgen::fs::Fs;
 use bch_bindgen::btree::BtreeTrans;
 use bch_bindgen::btree::BtreeIter;
@@ -22,7 +23,6 @@ fn list_keys(fs: &Fs, opt: Cli) -> anyhow::Result<()> {
         }
 
         println!("{}", k.to_text(fs));
-
         iter.advance();
     }
 
@@ -92,15 +92,29 @@ struct Cli {
     colorize:   bool,
    
     /// Verbose mode
-    #[arg(short, long, action = clap::ArgAction::Count)]
-    verbose:    u8,
+    #[arg(short, long)]
+    verbose:    bool,
 
     #[arg(required(true))]
     devices:    Vec<std::path::PathBuf>,
 }
 
 fn cmd_list_inner(opt: Cli) -> anyhow::Result<()> {
-    let fs_opts: bcachefs::bch_opts = Default::default();
+    let mut fs_opts: bcachefs::bch_opts = Default::default();
+
+    opt_set!(fs_opts, nochanges,        1);
+    opt_set!(fs_opts, norecovery,       1);
+    opt_set!(fs_opts, degraded,         1);
+    opt_set!(fs_opts, errors,           bcachefs::bch_error_actions::BCH_ON_ERROR_continue as u8);
+
+    if opt.fsck {
+        opt_set!(fs_opts, fix_errors,   bcachefs::fsck_err_opts::FSCK_OPT_YES as u8);
+        opt_set!(fs_opts, norecovery,   0);
+    }
+
+    if opt.verbose {
+        opt_set!(fs_opts, verbose,      1);
+    }
 
     let fs = Fs::open(&opt.devices, fs_opts)?;