Skip to content

Commit

Permalink
Merge pull request #315 from tmuehlbacher/variety-changes
Browse files Browse the repository at this point in the history
Variety changes
  • Loading branch information
koverstreet authored Jul 20, 2024
2 parents 52b9e81 + cdcc241 commit 201b1e8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 66 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ TAGS
cscope*
bcachefs-tools
compile_commands.json
tests/test_helper
tests/__pycache__/

# dot-files that we don't want to ignore
!.gitignore
Expand Down
46 changes: 8 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "bcachefs-tools"
version = "1.9.5"
authors = ["Yuxuan Shui <[email protected]>", "Kayla Firestack <[email protected]>", "Kent Overstreet <[email protected]>" ]
edition = "2021"
rust-version = "1.70"
Expand All @@ -25,11 +24,11 @@ strum = { version = "0.26", features = ["derive"] }
strum_macros = "0.26"
zeroize = { version = "1", features = ["std", "zeroize_derive"] }
rustix = { version = "0.38.34", features = ["termios"] }
owo-colors = "4"

[dependencies.env_logger]
version = "0.10"
default-features = false
features = ["auto-color"]

[profile.release]
strip = "none"
50 changes: 28 additions & 22 deletions src/commands/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ fn mount_inner(

let err = errno::errno().0;

if ret == 0 || (err != libc::EACCES && err != libc::EROFS) || (mountflags & libc::MS_RDONLY) != 0 {
if ret == 0
|| (err != libc::EACCES && err != libc::EROFS)
|| (mountflags & libc::MS_RDONLY) != 0
{
break;
}

Expand Down Expand Up @@ -333,35 +336,38 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> {
// Grab the udev information once
let udev_info = udev_bcachefs_info()?;

let (devices, mut sbs) = if let Some(("UUID" | "OLD_BLKID_UUID", uuid)) = cli.dev.split_once('=') {
devs_str_sbs_from_uuid(&udev_info, uuid)?
} else if cli.dev.contains(':') {
// If the device string contains ":" we will assume the user knows the
// entire list. If they supply a single device it could be either the FS
// only has 1 device or it's only 1 of a number of devices which are
// part of the FS. This appears to be the case when we get called during
// fstab mount processing and the fstab specifies a UUID.

let sbs = cli
.dev
.split(':')
.map(read_super_silent)
.collect::<Result<Vec<_>>>()?;

(cli.dev.clone(), sbs)
} else {
devs_str_sbs_from_device(&udev_info, Path::new(&cli.dev))?
};
let (devices, mut sbs) =
if let Some(("UUID" | "OLD_BLKID_UUID", uuid)) = cli.dev.split_once('=') {
devs_str_sbs_from_uuid(&udev_info, uuid)?
} else if cli.dev.contains(':') {
// If the device string contains ":" we will assume the user knows the
// entire list. If they supply a single device it could be either the FS
// only has 1 device or it's only 1 of a number of devices which are
// part of the FS. This appears to be the case when we get called during
// fstab mount processing and the fstab specifies a UUID.

let sbs = cli
.dev
.split(':')
.map(read_super_silent)
.collect::<Result<Vec<_>>>()?;

(cli.dev.clone(), sbs)
} else {
devs_str_sbs_from_device(&udev_info, Path::new(&cli.dev))?
};

ensure!(!sbs.is_empty(), "No device(s) to mount specified");

let first_sb = &sbs[0];
if unsafe { bcachefs::bch2_sb_is_encrypted(first_sb.sb) } {
handle_unlock(cli, &first_sb)?;
handle_unlock(cli, first_sb)?;
}

for sb in &mut sbs {
unsafe { bch_bindgen::sb_io::bch2_free_super(sb); }
unsafe {
bch_bindgen::sb_io::bch2_free_super(sb);
}
}
drop(sbs);

Expand Down
29 changes: 27 additions & 2 deletions src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::io::Write;

use env_logger::WriteStyle;
use log::LevelFilter;
use log::{Level, LevelFilter};
use owo_colors::{OwoColorize, Style};

pub fn setup(verbose: u8, color: bool) {
let level_filter = match verbose {
0 => LevelFilter::Off,
0 => LevelFilter::Warn,
1 => LevelFilter::Info,
2 => LevelFilter::Debug,
_ => LevelFilter::Trace,
Expand All @@ -19,5 +22,27 @@ pub fn setup(verbose: u8, color: bool) {
.filter_level(level_filter)
.write_style(style)
.parse_env("BCACHEFS_LOG")
.format(move |buf, record| {
let style = if style == WriteStyle::Never {
Style::new()
} else {
match record.level() {
Level::Trace => Style::new().cyan(),
Level::Debug => Style::new().blue(),
Level::Info => Style::new().green(),
Level::Warn => Style::new().yellow(),
Level::Error => Style::new().red().bold(),
}
};

writeln!(
buf,
"[{:<5} {}:{}] {}",
record.level().style(style),
record.file().unwrap(),
record.line().unwrap(),
record.args()
)
})
.init();
}

0 comments on commit 201b1e8

Please sign in to comment.