aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTruongSinh Tran-Nguyen <i@truongsinh.pro>2023-04-26 10:15:12 -0700
committerKent Overstreet <kent.overstreet@linux.dev>2023-04-26 17:46:23 -0400
commit9ee211eacad51bce6858ca9b9755b6c9eb253f2e (patch)
tree13b7f55bb984c88d1534c96722f366792ab6a178
parent47ec3ed6edb90c1117d0c79c382f03a3ed87c5ca (diff)
downloadbcachefs-tools-9ee211eacad51bce6858ca9b9755b6c9eb253f2e.tar.gz
feat(cmd_mount): Add support for magic keyword `OLD_BLKID_UUID`
This commit enhances mount sub command by allowing it to accept `OLD_BLKID_UUID=xxx` as the device, enabling whole fs mounting without relying on colon-separated devices. Using colon-separated devices in fstab is discouraged due to potential device reference issues after reboot. Additionally, using `UUID=xxx` in fstab or with `mount -t bcachefs` is currently infeasible as it depends on blkid, which prior to v2.39, does not recognize bcachefs. This update enables mounting via fstab using `OLD_BLKID_UUID=xxx` as obtained from `bcachefs show-super` "External UUID". Signed-off-by: TruongSinh Tran-Nguyen <i@truongsinh.pro>
-rw-r--r--rust-src/src/cmd_mount.rs44
1 files changed, 33 insertions, 11 deletions
diff --git a/rust-src/src/cmd_mount.rs b/rust-src/src/cmd_mount.rs
index af370ef6..0150ffd5 100644
--- a/rust-src/src/cmd_mount.rs
+++ b/rust-src/src/cmd_mount.rs
@@ -1,9 +1,8 @@
use atty::Stream;
use bch_bindgen::{bcachefs, bcachefs::bch_sb_handle};
-use log::{info, warn, debug, error, trace, LevelFilter};
+use log::{info, debug, error, LevelFilter};
use clap::Parser;
use uuid::Uuid;
-use std::convert::TryInto;
use std::path::PathBuf;
use crate::key;
use crate::key::KeyLoc;
@@ -161,17 +160,31 @@ struct Cli {
verbose: u8,
}
+fn devs_str_sbs_from_uuid(uuid: String) -> anyhow::Result<(String, Vec<bch_sb_handle>)> {
+ debug!("enumerating devices with UUID {}", uuid);
+
+ let devs_sbs = Uuid::parse_str(&uuid)
+ .map(|uuid| get_devices_by_uuid(uuid))??;
+
+ let devs_str = devs_sbs
+ .iter()
+ .map(|(dev, _)| dev.to_str().unwrap())
+ .collect::<Vec<_>>()
+ .join(":");
+
+ let sbs: Vec<bch_sb_handle> = devs_sbs.iter().map(|(_, sb)| *sb).collect();
+
+ Ok((devs_str, sbs))
+
+}
+
fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
let (devs, sbs) = if opt.dev.starts_with("UUID=") {
let uuid = opt.dev.replacen("UUID=", "", 1);
- let uuid = Uuid::parse_str(&uuid)?;
- let devs_sbs = get_devices_by_uuid(uuid)?;
-
- let devs_strs: Vec<_> = devs_sbs.iter().map(|(dev, _)| dev.clone().into_os_string().into_string().unwrap()).collect();
- let devs_str = devs_strs.join(":");
- let sbs = devs_sbs.iter().map(|(_, sb)| *sb).collect();
-
- (devs_str, sbs)
+ devs_str_sbs_from_uuid(uuid)?
+ } else if opt.dev.starts_with("OLD_BLKID_UUID=") {
+ let uuid = opt.dev.replacen("OLD_BLKID_UUID=", "", 1);
+ devs_str_sbs_from_uuid(uuid)?
} else {
let mut sbs = Vec::new();
@@ -183,7 +196,9 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
(opt.dev, sbs)
};
- if unsafe { bcachefs::bch2_sb_is_encrypted(sbs[0].sb) } {
+ if sbs.len() == 0 {
+ Err(anyhow::anyhow!("No device found from specified parameters"))?;
+ } else if unsafe { bcachefs::bch2_sb_is_encrypted(sbs[0].sb) } {
let key = opt
.key_location
.0
@@ -192,6 +207,13 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
key::prepare_key(&sbs[0], key)?;
}
+ info!(
+ "mounting with params: device: {}, target: {}, options: {}",
+ devs,
+ &opt.mountpoint.to_string_lossy(),
+ &opt.options
+ );
+
mount(devs, &opt.mountpoint, &opt.options)?;
Ok(())
}