Commit Graph

59 Commits

Author SHA1 Message Date
Thomas Mühlbacher
c20f323fdb fix(subvol): canonicalize requires path to exist
Which is probably not the case when you want to create a subvolume in
that path.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-10 23:07:27 +02:00
Thomas Mühlbacher
b42b5b4065 fix(subvol): make cmds work with relative paths
`Path::parent()` returns `Some("")` for relative paths with a single
component. The simplest fix is to just canonicalize the paths first.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-09 22:13:11 +02:00
Thomas Mühlbacher
30e16b5e15 fix: avoid addr_of if we already use a reference
It's kind of stupid to use this macro if we have to deref the parameter
first. I was too enthusiastic about using this macro instead of `as`
because it's nicer to read (imo).

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-03 17:05:52 +02:00
Thomas Mühlbacher
fac7cce224 fix: unbreak subvolume commands
This was a stupid mistake by me, "fixing" more than what clippy told me
to. `p` is already a reference and we should not use the addr of it.

Fixes: 96a3462 ("refactor: casting-related `clippy::pedantic` fixes")
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-03 17:05:52 +02:00
koverstreet
e739da5da8
Merge pull request #284 from tmuehlbacher/fix-result-eval
fix: evaluate KeyHandle Result
2024-05-31 11:34:36 -04:00
Thomas Mühlbacher
96a346254d refactor: casting-related clippy::pedantic fixes
Prefer using `ptr::addr_of!()` and `pointer::cast()` instead of raw `as`
where clippy complains and other type casting lints.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-31 12:48:42 +02:00
Thomas Mühlbacher
15e3c90584 refactor: make c_str! simpler, add test
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-31 12:48:42 +02:00
Thomas Mühlbacher
0ca3233518 refactor: change some fn type sigs and simplify
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-31 12:48:42 +02:00
Thomas Mühlbacher
20f7954cdb refactor: treat harmless clippy::pedantic lints
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-31 12:48:42 +02:00
Thomas Mühlbacher
9ec185437d fix: evaluate KeyHandle Result
This one is sort of bad to have missed, ouch.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-31 03:56:53 +02:00
Thomas Mühlbacher
781ea5d40f fix: minor tweaks for key.rs
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-31 02:30:59 +02:00
Thomas Mühlbacher
31066e17e8 fix: keep compat with MSRV
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-31 02:30:59 +02:00
Thomas Mühlbacher
22495e0d31 feat: rewrite key.rs
- Introduce `KeyHandle` and `Passphrase` types

- Refactor the functions into associated functions

- Add `zeroizing` crate to handle passphrase memory safely

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-30 22:26:06 +02:00
Thomas Mühlbacher
25bce91b4b refactor: rename function again
`bch2_sb_is_encrypted_and_locked()` simply does not check if the fs is
locked. The name is misleading.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-30 22:26:06 +02:00
Thomas Mühlbacher
21b1111b59 refactor: reduce UnlockPolicy boilerplate
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-30 22:26:06 +02:00
Kent Overstreet
c3c7dacab2 mount: minor cleanup
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-05-29 17:00:50 -04:00
Thomas Mühlbacher
0e414b462f style: fix one straggler not caught by rustfmt
not sure why this wasn't picked up, maybe different versions of nightly
rustfmt?
2024-05-27 19:30:26 -04:00
Kent Overstreet
aa985e6a44 Format with rustfmt
Note that we're using struct/enum align options, which require nightly.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-05-26 20:38:08 -04:00
Thomas Mühlbacher
5b216318b8 check_for_key before ask_for_passphrase
let's always first check if there is already a key in the keyring
available before we try to get the key from some more involved means.

Fixes: #261
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-05-26 13:32:56 -04:00
Thomas Mühlbacher
3882d1b1e4 refactor: manually fix remaining clippy lints
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-22 22:33:40 +02:00
Thomas Mühlbacher
3488d4f15f refactor: cargo clippy --fix
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-05-22 22:33:40 +02:00
Thomas Bertschinger
3ac510f6a4 add "bkey-type" option to list command
Only bkeys of the specified type will be printed.

Also, this reworks the error type in bch_bindgen to be able to
represent other kinds of error than just "invalid btree id".

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-05-09 17:29:08 -04:00
Tony Asleson
128b569155 mount: Make udev_bcachefs_info more idiomatic
Signed-off-by: Tony Asleson <tasleson@redhat.com>
2024-05-07 12:20:49 -05:00
Tony Asleson
3d63b901c6 Handle mount with FS with 1 device
If the user passes a single device node during the mount and
we have no information for it in the udev db, we read up the
super block.  When we do this, if the FS only has 1 block device
we will simply go ahead and do the mount instead of walking
all the block devices and reading up super blocks looking for
devices with a matching FS UUID.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
2024-05-07 12:20:49 -05:00
Tony Asleson
761ef99f91 Add env. variable BCACHEFS_BLOCK_SCAN
Introduce an env. variable for users that have a broken blkid which
renders the udev db as incomplete.  Only checks for the existence
of the variable, not its value.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
2024-05-07 12:20:49 -05:00
Tony Asleson
1fb1898b24 mount: Leverage udev db
If the udev database contains information about bcachefs, utilize it.
Otherwise, resort to traversing block devices and checking for
bcachefs super blocks.

V2: Reduce number of places we call read_super_slient in interators

Signed-off-by: Tony Asleson <tasleson@redhat.com>
2024-05-07 12:20:49 -05:00
Thomas Bertschinger
2b8a0f0caf remove redundant "cmd_" prefix from functions in "commands"
It is more idiomatic to use `commands::mount` than
`commands::cmd_mount`.

No functionality changes intended by this patch.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-04-30 21:16:09 -04:00
Tony Asleson
825062222c mount: canonicalize device path for single device node
If we pass a symlink for a single device node we fail to locate the
device node.  Canonicalize the device node before we try to read up
the superblock.

This allows the following to work.
 # bcachefs mount /dev/mapper/vg-thinvolume /mnt/lv_thin

Signed-off-by: Tony Asleson <tasleson@redhat.com>
2024-04-09 15:03:26 -05:00
Kent Overstreet
6e50a9b4fc cmd_list, cmd_list_journal: pass -o very_degraded 2024-03-30 22:09:06 -04:00
Tony Asleson
89b322abb3 mount: Handle multi-device with 1 device node
Instead of requiring the user to supply all the device nodes for a
multi-device FS, allow them to specifiy 1 of them.  We then fetch
the UUID for the FS and then find all the disks on the system that
match this UUID.

This allows me to bring up a bcachefs FS in /etc/fstab by using a
UUID.  This works because it appears the mount command looks up
the UUID, finds an entry in /dev/disk/by-uuid and then passes that
found device node to mount.bcachefs which fails with
`insufficient_devices_to_start` as bcachefs is expecting a list of
devices with a ":" between them.  This behavior is preserved if a
user specifies a list of all the needed device nodes to bring up
the FS.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-03-20 17:02:35 -04:00
Wesley Moore
888321446d
Avoid casting away const when processing C command args 2024-03-13 20:07:07 +10:00
Kent Overstreet
6a41851118 path_to_cstr()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-03-08 16:40:38 -05:00
Roland Vet
16661be294 bch2_sb_is_encrypted{,_and_locked}
Specifically also mention locked

Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-23 08:37:23 +01:00
Roland Vet
817e957697 Apply naming convention: passphrase->unlock->key->decrypt->fs
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-23 08:37:23 +01:00
Roland Vet
b582c9b4b8 Improve error message
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
eaf5575080 Rename sb to block_device
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
ceb9eaa020 Rename password{,_policy}
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
37c0ae2e79 Rename KeyLocation to more appropriate KeyPolicy
Also key_location to key_policy

Improve help description key policy

Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
ceb259b2a3 Typo
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
46ed72461f Rename sbs to block_devices_to_mount
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
b7c43996a1 Rephrase help message
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
911c53266a Remove unnecessary brackets
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
d67643f24c Add decryption by key_file
- Add key_file option to Cli
- Rework decryption flow logic to first attempt key_file
- Read password from file and pass to decrypt_master_key

Explicity specify '-k' for key_location

Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:49 +01:00
Roland Vet
0ff96b2a0f Add fmt::Display for KeyLocation
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:36 +01:00
Roland Vet
86049a1641 Refactor ask_for_key to call new decrypt_master_key
Signed-off-by: Roland Vet <RlndVt@protonmail.com>
2024-02-22 21:12:02 +01:00
Thomas Bertschinger
25e84a9917 rust: use libc::Ioctl type for ioctl() request argument
The second argument to ioctl() can be defined as a different type by
different libc implementations, and can be a different size on different
architectures depending on what type it is defined as. For example,
glibc defines it as `unsigned long` which may have a different size on
32-bit vs. 64-bit architectures, and musl libc defines it as `int`.

The Rust libc crate exposes a type `libc::Ioctl` which is defined as the
appropriate integer type for the given libc implementation. Using this
type for the request argument to `libc::ioctl()` ensures code will
compile correctly regardless of architecture and libc implementation.

Also, because ioctl request numbers are defined to be 32 bits
(regardless of the fact that `unsigned long` might sometimes take 64
bits on some architectures), this patch changes the Rust representation
of the bcachefs ioctl numbers to u32 instead of u64.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-02-20 22:27:19 -05:00
ErrorNoInternet
4327e0681b
feat: add aliases for a few subcommands 2024-02-09 17:37:01 +08:00
ErrorNoInternet
428948e120
refactor: clean up arguments 2024-02-09 17:36:49 +08:00
Alexander Fougner
a95a25dc1d Replace atty with stdlib
is_terminal() is part of rust 1.70 std, no need for isatty

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
2024-02-07 21:27:35 +01:00
Kent Overstreet
bc0a443850 kill dependency on char signedness
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-02-06 23:13:02 -05:00