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>
This commit is contained in:
Kent Overstreet 2023-02-28 06:15:48 -05:00
parent daebbc085d
commit 8a7e3344fe
9 changed files with 47 additions and 6 deletions

7
rust-src/Cargo.lock generated
View 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"

View 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"

View 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"

View 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")

View File

@ -1,5 +1,3 @@
#![allow(non_snake_case)]
use crate::SPOS_MAX;
use crate::c;
use crate::bkey::BkeySC;

View 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::*;

View 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"

View File

@ -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);
}
}
}

View 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)?;