aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-02-28 06:15:48 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-02-28 06:15:48 -0500
commit8a7e3344fe089b3e2c6c45f00ade217e3d55a958 (patch)
tree801bec15e86816d8c87da17f0ce4f5e21299c0f6
parentdaebbc085d74dc7666dd704f48fa4ed5c0005f75 (diff)
downloadbcachefs-tools-8a7e3344fe089b3e2c6c45f00ade217e3d55a958.tar.gz
rust: Filesystem options now supported
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>
-rw-r--r--rust-src/Cargo.lock7
-rw-r--r--rust-src/bch_bindgen/Cargo.lock7
-rw-r--r--rust-src/bch_bindgen/Cargo.toml1
-rw-r--r--rust-src/bch_bindgen/build.rs2
-rw-r--r--rust-src/bch_bindgen/src/btree.rs2
-rw-r--r--rust-src/bch_bindgen/src/lib.rs2
-rw-r--r--rust-src/bch_bindgen/src/libbcachefs_wrapper.h1
-rw-r--r--rust-src/bch_bindgen/src/opts.rs9
-rw-r--r--rust-src/src/cmd_list.rs22
9 files changed, 47 insertions, 6 deletions
diff --git a/rust-src/Cargo.lock b/rust-src/Cargo.lock
index 46653733..c4dd7f58 100644
--- a/rust-src/Cargo.lock
+++ b/rust-src/Cargo.lock
@@ -81,6 +81,7 @@ dependencies = [
"gag",
"libc",
"memoffset",
+ "paste",
"pkg-config",
"udev",
"uuid",
@@ -596,6 +597,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/rust-src/bch_bindgen/Cargo.lock b/rust-src/bch_bindgen/Cargo.lock
index 82d211b5..b2741976 100644
--- a/rust-src/bch_bindgen/Cargo.lock
+++ b/rust-src/bch_bindgen/Cargo.lock
@@ -48,6 +48,7 @@ dependencies = [
"gag",
"libc",
"memoffset",
+ "paste",
"pkg-config",
"udev",
"uuid",
@@ -440,6 +441,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/rust-src/bch_bindgen/Cargo.toml b/rust-src/bch_bindgen/Cargo.toml
index 9a9b7a98..cb341eef 100644
--- a/rust-src/bch_bindgen/Cargo.toml
+++ b/rust-src/bch_bindgen/Cargo.toml
@@ -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"
diff --git a/rust-src/bch_bindgen/build.rs b/rust-src/bch_bindgen/build.rs
index 8d9986f8..f426316f 100644
--- a/rust-src/bch_bindgen/build.rs
+++ b/rust-src/bch_bindgen/build.rs
@@ -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")
diff --git a/rust-src/bch_bindgen/src/btree.rs b/rust-src/bch_bindgen/src/btree.rs
index 7877b6e2..8ab91aeb 100644
--- a/rust-src/bch_bindgen/src/btree.rs
+++ b/rust-src/bch_bindgen/src/btree.rs
@@ -1,5 +1,3 @@
-#![allow(non_snake_case)]
-
use crate::SPOS_MAX;
use crate::c;
use crate::bkey::BkeySC;
diff --git a/rust-src/bch_bindgen/src/lib.rs b/rust-src/bch_bindgen/src/lib.rs
index bce150a4..3bc21a18 100644
--- a/rust-src/bch_bindgen/src/lib.rs
+++ b/rust-src/bch_bindgen/src/lib.rs
@@ -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::*;
diff --git a/rust-src/bch_bindgen/src/libbcachefs_wrapper.h b/rust-src/bch_bindgen/src/libbcachefs_wrapper.h
index 6332d957..c8990dcc 100644
--- a/rust-src/bch_bindgen/src/libbcachefs_wrapper.h
+++ b/rust-src/bch_bindgen/src/libbcachefs_wrapper.h
@@ -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
index 00000000..e2261993
--- /dev/null
+++ b/rust-src/bch_bindgen/src/opts.rs
@@ -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);
+ }
+ }
+}
diff --git a/rust-src/src/cmd_list.rs b/rust-src/src/cmd_list.rs
index 15f3f71f..c89ba4f0 100644
--- a/rust-src/src/cmd_list.rs
+++ b/rust-src/src/cmd_list.rs
@@ -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)?;