aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Fougner <fougner89@gmail.com>2023-01-16 17:08:52 +0100
committerAlexander Fougner <fougner89@gmail.com>2023-01-18 06:47:46 +0100
commit8accfdc3c596bfe5cbd10dac3f1650192981eb17 (patch)
treee93535eb6ded70806cc7518fb453448d569abaa1
parent20aecb42d8d1c869b17b38b979b9f2f7cbd2ca34 (diff)
downloadbcachefs-tools-8accfdc3c596bfe5cbd10dac3f1650192981eb17.tar.gz
rust: replace tracing with logger
tracing framework is a overengineered for simple mount helper. Add a few very barebone logging macros to allow configurable verbosity and colorized output with a small footprint. Signed-off-by: Alexander Fougner <fougner89@gmail.com>
-rw-r--r--rust-src/bch_bindgen/Cargo.lock4
-rw-r--r--rust-src/bch_bindgen/Cargo.toml4
-rw-r--r--rust-src/bch_bindgen/src/lib.rs2
-rw-r--r--rust-src/bch_bindgen/src/log.rs57
-rw-r--r--rust-src/bch_bindgen/src/rs.rs18
-rw-r--r--rust-src/mount/Cargo.lock315
-rw-r--r--rust-src/mount/Cargo.toml9
-rw-r--r--rust-src/mount/src/filesystem.rs36
-rw-r--r--rust-src/mount/src/key.rs8
-rw-r--r--rust-src/mount/src/lib.rs19
-rw-r--r--rust-src/mount/src/main.rs26
11 files changed, 154 insertions, 344 deletions
diff --git a/rust-src/bch_bindgen/Cargo.lock b/rust-src/bch_bindgen/Cargo.lock
index 7485b9be..747fe730 100644
--- a/rust-src/bch_bindgen/Cargo.lock
+++ b/rust-src/bch_bindgen/Cargo.lock
@@ -191,9 +191,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
-version = "7.1.2"
+version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c"
+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
diff --git a/rust-src/bch_bindgen/Cargo.toml b/rust-src/bch_bindgen/Cargo.toml
index 7a619117..ce15fe0a 100644
--- a/rust-src/bch_bindgen/Cargo.toml
+++ b/rust-src/bch_bindgen/Cargo.toml
@@ -9,14 +9,14 @@ crate-type = ["lib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-tracing = "0.1.26"
+chrono = "0.4"
+colored = "2"
anyhow = "1.0"
udev = "0.7.0"
uuid = "1.2.2"
bitfield = "0.14.0"
memoffset = "0.8.0"
byteorder = "1.3"
-tracing-attributes = "0.1.15"
libc = "0.2.69"
gag = "1.0.0"
diff --git a/rust-src/bch_bindgen/src/lib.rs b/rust-src/bch_bindgen/src/lib.rs
index dc8bcf4a..c54786aa 100644
--- a/rust-src/bch_bindgen/src/lib.rs
+++ b/rust-src/bch_bindgen/src/lib.rs
@@ -1,7 +1,7 @@
pub mod bcachefs;
pub mod keyutils;
+pub mod log;
pub mod rs;
-
pub mod c {
pub use crate::bcachefs::*;
}
diff --git a/rust-src/bch_bindgen/src/log.rs b/rust-src/bch_bindgen/src/log.rs
new file mode 100644
index 00000000..32927f16
--- /dev/null
+++ b/rust-src/bch_bindgen/src/log.rs
@@ -0,0 +1,57 @@
+use std::sync::atomic::{AtomicU8, Ordering};
+
+pub const MUTE: u8 = 0;
+pub const ERROR: u8 = 1;
+pub const INFO: u8 = 2;
+pub const DEBUG: u8 = 3;
+
+// error level by default
+pub static VERBOSE: AtomicU8 = AtomicU8::new(ERROR);
+
+#[inline]
+pub fn set_verbose_level(level: u8) {
+ VERBOSE.store(level, Ordering::SeqCst);
+}
+
+pub fn max_level() -> u8 {
+ VERBOSE.load(Ordering::SeqCst)
+}
+
+#[macro_export]
+macro_rules! info {
+ ($($arg:tt)*) => {
+ if 2 <= $crate::log::max_level() {
+ println!("{} {} {}",
+ " INFO".green(),
+ format!("{}:", module_path!()).bright_black(),
+ format_args!($($arg)*)
+ );
+ }
+ }
+}
+
+#[macro_export]
+macro_rules! debug {
+ ($($arg:tt)*) => {
+ if 3 <= $crate::log::max_level() {
+ println!("{} {} {}",
+ "DEBUG".bright_blue(),
+ format!("{}:", module_path!()).bright_black(),
+ format_args!($($arg)*)
+ );
+ }
+ }
+}
+
+#[macro_export]
+macro_rules! error {
+ ($($arg:tt)*) => {
+ if 1 <= $crate::log::max_level() {
+ println!("{} {} {}",
+ "ERROR".bright_red(),
+ format!("{}:", module_path!()).bright_black(),
+ format_args!($($arg)*)
+ );
+ }
+ }
+}
diff --git a/rust-src/bch_bindgen/src/rs.rs b/rust-src/bch_bindgen/src/rs.rs
index 7a3a3eaf..4f5dbcc0 100644
--- a/rust-src/bch_bindgen/src/rs.rs
+++ b/rust-src/bch_bindgen/src/rs.rs
@@ -1,4 +1,6 @@
use crate::bcachefs;
+use crate::{error, info};
+use colored::Colorize;
pub const SUPERBLOCK_MAGIC: uuid::Uuid =
uuid::Uuid::from_u128(0x_c68573f6_4e1a_45ca_8265_f57f48ba6d81);
@@ -13,27 +15,22 @@ pub enum ReadSuperErr {
type RResult<T> = std::io::Result<std::io::Result<T>>;
-#[tracing_attributes::instrument(skip(opts))]
pub fn read_super_opts(
path: &std::path::Path,
mut opts: bcachefs::bch_opts,
) -> RResult<bcachefs::bch_sb_handle> {
- // let devp = camino::Utf8Path::from_path(devp).unwrap();
-
use std::os::unix::ffi::OsStrExt;
let path = std::ffi::CString::new(path.as_os_str().as_bytes())?;
let mut sb = std::mem::MaybeUninit::zeroed();
- // use gag::{BufferRedirect};
- // // Stop libbcachefs from spamming the output
- // let gag = BufferRedirect::stderr().unwrap();
- // tracing::trace!("entering libbcachefs");
-
let ret =
unsafe { crate::bcachefs::bch2_read_super(path.as_ptr(), &mut opts, sb.as_mut_ptr()) };
- tracing::trace!(%ret);
+ println!("{}", ret);
+ info!("something");
+ error!("an error");
+ String::from("something").bright_black();
match -ret {
libc::EACCES => Err(std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
@@ -45,7 +42,7 @@ pub fn read_super_opts(
"Not a BCacheFS SuperBlock",
))),
code => {
- tracing::debug!(msg = "BCacheFS return error code", ?code);
+ println!("BCacheFS return error code: {}", code);
Ok(Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to Read SuperBlock",
@@ -54,7 +51,6 @@ pub fn read_super_opts(
}
}
-#[tracing_attributes::instrument]
pub fn read_super(path: &std::path::Path) -> RResult<bcachefs::bch_sb_handle> {
let opts = bcachefs::bch_opts::default(); //unsafe {std::mem::MaybeUninit::zeroed().assume_init()};
read_super_opts(path, opts)
diff --git a/rust-src/mount/Cargo.lock b/rust-src/mount/Cargo.lock
index 4731b7ea..8561f281 100644
--- a/rust-src/mount/Cargo.lock
+++ b/rust-src/mount/Cargo.lock
@@ -12,30 +12,23 @@ dependencies = [
]
[[package]]
-name = "android_system_properties"
-version = "0.1.5"
+name = "anyhow"
+version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
-dependencies = [
- "libc",
-]
+checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
[[package]]
-name = "ansi_term"
-version = "0.12.1"
+name = "atty"
+version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
+ "hermit-abi 0.1.19",
+ "libc",
"winapi",
]
[[package]]
-name = "anyhow"
-version = "1.0.68"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
-
-[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -46,6 +39,7 @@ name = "bcachefs-mount"
version = "0.3.1"
dependencies = [
"anyhow",
+ "atty",
"bch_bindgen",
"byteorder",
"camino",
@@ -117,12 +111,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
-name = "bumpalo"
-version = "3.11.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
-
-[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -156,18 +144,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
-name = "chrono"
-version = "0.4.23"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
-dependencies = [
- "iana-time-zone",
- "num-integer",
- "num-traits",
- "winapi",
-]
-
-[[package]]
name = "clang-sys"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -216,66 +192,6 @@ dependencies = [
]
[[package]]
-name = "codespan-reporting"
-version = "0.11.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
-dependencies = [
- "termcolor",
- "unicode-width",
-]
-
-[[package]]
-name = "core-foundation-sys"
-version = "0.8.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
-
-[[package]]
-name = "cxx"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "51d1075c37807dcf850c379432f0df05ba52cc30f279c5cfc43cc221ce7f8579"
-dependencies = [
- "cc",
- "cxxbridge-flags",
- "cxxbridge-macro",
- "link-cplusplus",
-]
-
-[[package]]
-name = "cxx-build"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5044281f61b27bc598f2f6647d480aed48d2bf52d6eb0b627d84c0361b17aa70"
-dependencies = [
- "cc",
- "codespan-reporting",
- "once_cell",
- "proc-macro2",
- "quote",
- "scratch",
- "syn",
-]
-
-[[package]]
-name = "cxxbridge-flags"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61b50bc93ba22c27b0d31128d2d130a0a6b3d267ae27ef7e4fae2167dfe8781c"
-
-[[package]]
-name = "cxxbridge-macro"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "39e61fda7e62115119469c7b3591fd913ecca96fb766cfd3f2e2502ab7bc87a5"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "either"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -358,35 +274,20 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
-version = "0.2.6"
+version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
-name = "iana-time-zone"
-version = "0.1.53"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
-dependencies = [
- "android_system_properties",
- "core-foundation-sys",
- "iana-time-zone-haiku",
- "js-sys",
- "wasm-bindgen",
- "winapi",
-]
-
-[[package]]
-name = "iana-time-zone-haiku"
-version = "0.1.1"
+name = "hermit-abi"
+version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
+checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
- "cxx",
- "cxx-build",
+ "libc",
]
[[package]]
@@ -414,7 +315,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189"
dependencies = [
- "hermit-abi",
+ "hermit-abi 0.2.6",
"io-lifetimes",
"rustix",
"windows-sys",
@@ -430,21 +331,6 @@ dependencies = [
]
[[package]]
-name = "itoa"
-version = "1.0.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
-
-[[package]]
-name = "js-sys"
-version = "0.3.60"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
-dependencies = [
- "wasm-bindgen",
-]
-
-[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -473,15 +359,6 @@ dependencies = [
]
[[package]]
-name = "link-cplusplus"
-version = "1.0.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
-dependencies = [
- "cc",
-]
-
-[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -497,15 +374,6 @@ dependencies = [
]
[[package]]
-name = "matchers"
-version = "0.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
-dependencies = [
- "regex-automata",
-]
-
-[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -528,31 +396,22 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
-version = "7.1.2"
+version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c"
+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
-name = "num-integer"
-version = "0.1.45"
+name = "nu-ansi-term"
+version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
+checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
- "autocfg",
- "num-traits",
-]
-
-[[package]]
-name = "num-traits"
-version = "0.2.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
-dependencies = [
- "autocfg",
+ "overload",
+ "winapi",
]
[[package]]
@@ -568,6 +427,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
+name = "overload"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
+
+[[package]]
name = "parse-display"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -673,15 +538,6 @@ dependencies = [
]
[[package]]
-name = "regex-automata"
-version = "0.1.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
-dependencies = [
- "regex-syntax",
-]
-
-[[package]]
name = "regex-syntax"
version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -727,35 +583,6 @@ dependencies = [
]
[[package]]
-name = "ryu"
-version = "1.0.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
-
-[[package]]
-name = "scratch"
-version = "1.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
-
-[[package]]
-name = "serde"
-version = "1.0.152"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
-
-[[package]]
-name = "serde_json"
-version = "1.0.91"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
-dependencies = [
- "itoa",
- "ryu",
- "serde",
-]
-
-[[package]]
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -900,35 +727,17 @@ dependencies = [
]
[[package]]
-name = "tracing-serde"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
-dependencies = [
- "serde",
- "tracing-core",
-]
-
-[[package]]
name = "tracing-subscriber"
-version = "0.2.25"
+version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71"
+checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
dependencies = [
- "ansi_term",
- "chrono",
- "lazy_static",
- "matchers",
- "regex",
- "serde",
- "serde_json",
+ "nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
- "tracing",
"tracing-core",
"tracing-log",
- "tracing-serde",
]
[[package]]
@@ -949,12 +758,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
-name = "unicode-width"
-version = "0.1.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
-
-[[package]]
name = "uuid"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -973,60 +776,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
-name = "wasm-bindgen"
-version = "0.2.83"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
-dependencies = [
- "cfg-if",
- "wasm-bindgen-macro",
-]
-
-[[package]]
-name = "wasm-bindgen-backend"
-version = "0.2.83"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
-dependencies = [
- "bumpalo",
- "log",
- "once_cell",
- "proc-macro2",
- "quote",
- "syn",
- "wasm-bindgen-shared",
-]
-
-[[package]]
-name = "wasm-bindgen-macro"
-version = "0.2.83"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
-dependencies = [
- "quote",
- "wasm-bindgen-macro-support",
-]
-
-[[package]]
-name = "wasm-bindgen-macro-support"
-version = "0.2.83"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "wasm-bindgen-backend",
- "wasm-bindgen-shared",
-]
-
-[[package]]
-name = "wasm-bindgen-shared"
-version = "0.2.83"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
-
-[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/rust-src/mount/Cargo.toml b/rust-src/mount/Cargo.toml
index b167408d..40113945 100644
--- a/rust-src/mount/Cargo.toml
+++ b/rust-src/mount/Cargo.toml
@@ -7,10 +7,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-tracing = "0.1.26"
-tracing-log = "0.1.2"
-tracing-subscriber = "0.2.20"
-tracing-attributes = "0.1.15"
+atty = "0.2.14"
+log = "0.4"
+chrono = "0.4"
+colored = "2"
clap = { version = "4.0.32", features = ["derive", "wrap_help"] }
anyhow = "1.0"
libc = "0.2.69"
@@ -23,6 +23,5 @@ parse-display = "0.1"
errno = "0.2"
either = "1.5"
rpassword = "4"
-camino = "1.0.5"
bch_bindgen = { path = "../bch_bindgen" }
byteorder = "1.3"
diff --git a/rust-src/mount/src/filesystem.rs b/rust-src/mount/src/filesystem.rs
index 430d3c64..f47319c9 100644
--- a/rust-src/mount/src/filesystem.rs
+++ b/rust-src/mount/src/filesystem.rs
@@ -1,7 +1,8 @@
extern "C" {
pub static stdout: *mut libc::FILE;
}
-
+use bch_bindgen::{debug, info};
+use colored::Colorize;
use getset::{CopyGetters, Getters};
use std::path::PathBuf;
#[derive(Getters, CopyGetters)]
@@ -62,14 +63,14 @@ impl FileSystem {
target: impl AsRef<std::path::Path>,
options: impl AsRef<str>,
) -> anyhow::Result<()> {
- tracing::info_span!("mount").in_scope(|| {
- let src = self.device_string();
- let (data, mountflags) = parse_mount_options(options);
- // let fstype = c_str!("bcachefs");
-
- tracing::info!(msg="mounting bcachefs filesystem", target=%target.as_ref().display());
- mount_inner(src, target, "bcachefs", mountflags, data)
- })
+ let src = self.device_string();
+ let (data, mountflags) = parse_mount_options(options);
+
+ info!(
+ "mounting bcachefs filesystem, {}",
+ target.as_ref().display()
+ );
+ mount_inner(src, target, "bcachefs", mountflags, data)
}
}
@@ -100,8 +101,7 @@ fn mount_inner(
let fstype = fstype.as_c_str().to_bytes_with_nul().as_ptr() as *const c_char;
let ret = {
- let _entered = tracing::info_span!("libc::mount").entered();
- tracing::info!("mounting filesystem");
+ info!("mounting filesystem");
// REQUIRES: CAP_SYS_ADMIN
unsafe { libc::mount(src, target, fstype, mountflags, data) }
};
@@ -113,10 +113,9 @@ fn mount_inner(
/// Parse a comma-separated mount options and split out mountflags and filesystem
/// specific options.
-#[tracing_attributes::instrument(skip(options))]
fn parse_mount_options(options: impl AsRef<str>) -> (Option<String>, u64) {
use either::Either::*;
- tracing::debug!(msg="parsing mount options", options=?options.as_ref());
+ debug!("parsing mount options: {}", options.as_ref());
let (opts, flags) = options
.as_ref()
.split(",")
@@ -160,9 +159,8 @@ use bch_bindgen::bcachefs;
use std::collections::HashMap;
use uuid::Uuid;
-#[tracing_attributes::instrument]
pub fn probe_filesystems() -> anyhow::Result<HashMap<Uuid, FileSystem>> {
- tracing::trace!("enumerating udev devices");
+ debug!("enumerating udev devices");
let mut udev = udev::Enumerator::new()?;
udev.match_subsystem("block")?; // find kernel block devices
@@ -177,7 +175,7 @@ pub fn probe_filesystems() -> anyhow::Result<HashMap<Uuid, FileSystem>> {
match get_super_block_uuid(&pathbuf)? {
Ok((uuid_key, superblock)) => {
let fs = fs_map.entry(uuid_key).or_insert_with(|| {
- tracing::info!(msg="found bcachefs pool", uuid=?uuid_key);
+ info!("found bcachefs pool: {}", uuid_key);
FileSystem::new(superblock)
});
@@ -185,12 +183,12 @@ pub fn probe_filesystems() -> anyhow::Result<HashMap<Uuid, FileSystem>> {
}
Err(e) => {
- tracing::debug!(inner2_error=?e);
+ debug!("{}", e);
}
}
}
- tracing::info!(msg = "found filesystems", count = fs_map.len());
+ info!("found {} filesystems", fs_map.len());
Ok(fs_map)
}
@@ -212,7 +210,7 @@ fn get_super_block_uuid(
drop(gag);
let uuid = (&super_block).sb().uuid();
- tracing::debug!(found="bcachefs superblock", devnode=?path, ?uuid);
+ debug!("bcachefs superblock path={} uuid={}", path.display(), uuid);
Ok(Ok((uuid, super_block)))
}
diff --git a/rust-src/mount/src/key.rs b/rust-src/mount/src/key.rs
index 454e641e..a49baa68 100644
--- a/rust-src/mount/src/key.rs
+++ b/rust-src/mount/src/key.rs
@@ -1,4 +1,5 @@
-use tracing::info;
+use bch_bindgen::info;
+use colored::Colorize;
fn check_for_key(key_name: &std::ffi::CStr) -> anyhow::Result<bool> {
use bch_bindgen::keyutils::{self, keyctl_search};
@@ -7,7 +8,7 @@ fn check_for_key(key_name: &std::ffi::CStr) -> anyhow::Result<bool> {
let key_id = unsafe { keyctl_search(keyutils::KEY_SPEC_USER_KEYRING, key_type, key_name, 0) };
if key_id > 0 {
- info!("Key has became avaiable");
+ info!("Key has became available");
Ok(true)
} else if errno::errno().0 != libc::ENOKEY {
Err(crate::ErrnoError(errno::errno()).into())
@@ -83,12 +84,11 @@ fn ask_for_key(fs: &FileSystem) -> anyhow::Result<()> {
}
}
-#[tracing_attributes::instrument]
pub fn prepare_key(fs: &FileSystem, password: crate::KeyLocation) -> anyhow::Result<()> {
use crate::KeyLocation::*;
use anyhow::anyhow;
- tracing::info!(msg = "checking if key exists for filesystem");
+ info!("checking if key exists for filesystem {}", fs.uuid());
match password {
Fail => Err(anyhow!("no key available")),
Wait => Ok(wait_for_key(fs.uuid())?),
diff --git a/rust-src/mount/src/lib.rs b/rust-src/mount/src/lib.rs
index f2964561..68acde03 100644
--- a/rust-src/mount/src/lib.rs
+++ b/rust-src/mount/src/lib.rs
@@ -1,4 +1,5 @@
use anyhow::anyhow;
+use atty::Stream;
use clap::Parser;
use uuid::Uuid;
@@ -69,6 +70,14 @@ fn parse_fstab_uuid(uuid_raw: &str) -> Result<Uuid, uuid::Error> {
return Uuid::parse_str(&uuid);
}
+fn stdout_isatty() -> &'static str {
+ if atty::is(Stream::Stdout) {
+ "true"
+ } else {
+ "false"
+ }
+}
+
/// Mount a bcachefs filesystem by its UUID.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
@@ -85,7 +94,7 @@ pub struct Cli {
/// External UUID of the bcachefs filesystem
///
/// Accepts the UUID as is or as fstab style UUID=<UUID>
- #[arg(value_parser=parse_fstab_uuid)]
+ #[arg(value_parser = parse_fstab_uuid)]
pub uuid: uuid::Uuid,
/// Where the filesystem should be mounted. If not set, then the filesystem
@@ -96,11 +105,17 @@ pub struct Cli {
/// Mount options
#[arg(short, default_value = "")]
pub options: String,
+
+ /// Force color on/off. Default: autodetect tty
+ #[arg(short, long, action = clap::ArgAction::Set, default_value=stdout_isatty())]
+ pub colorize: bool,
+
+ #[arg(short = 'v', long, action = clap::ArgAction::Count)]
+ pub verbose: u8,
}
pub mod filesystem;
pub mod key;
-
// pub fn mnt_in_use()
#[test]
diff --git a/rust-src/mount/src/main.rs b/rust-src/mount/src/main.rs
index 3e4cee89..66ec8acc 100644
--- a/rust-src/mount/src/main.rs
+++ b/rust-src/mount/src/main.rs
@@ -1,34 +1,30 @@
+use bcachefs_mount::Cli;
+use bch_bindgen::{error, info};
use clap::Parser;
+use colored::Colorize;
fn main() {
- // convert existing log statements to tracing events
- // tracing_log::LogTracer::init().expect("logtracer init failed!");
- // format tracing log data to env_logger like stdout
- tracing_subscriber::fmt::init();
-
- if let Err(e) = crate::main_inner() {
- tracing::error!(fatal_error = ?e);
+ let opt = Cli::parse();
+ bch_bindgen::log::set_verbose_level(opt.verbose + bch_bindgen::log::ERROR);
+ colored::control::set_override(opt.colorize);
+ if let Err(e) = crate::main_inner(opt) {
+ error!("Fatal error: {}", e);
}
}
-#[tracing_attributes::instrument("main")]
-pub fn main_inner() -> anyhow::Result<()> {
- use bcachefs_mount::{filesystem, key, Cli};
+pub fn main_inner(opt: Cli) -> anyhow::Result<()> {
+ use bcachefs_mount::{filesystem, key};
unsafe {
libc::setvbuf(filesystem::stdout, std::ptr::null_mut(), libc::_IONBF, 0);
// libc::fflush(filesystem::stdout);
}
- let opt = Cli::parse();
-
- tracing::trace!(?opt);
-
let fss = filesystem::probe_filesystems()?;
let fs = fss
.get(&opt.uuid)
.ok_or_else(|| anyhow::anyhow!("filesystem was not found"))?;
- tracing::info!(msg="found filesystem", %fs);
+ info!("found filesystem {}", fs);
if fs.encrypted() {
let key = opt
.key_location