Commit Graph

94 Commits

Author SHA1 Message Date
koverstreet
7210d5c911
Merge pull request #345 from Flowdalic/mount-print-error
mount: print a helpful error message
2024-12-29 16:16:25 -05:00
Malte Schröder
cb8dc1b2ba Allow multiple targets for subvolume delete.
Signed-off-by: Malte Schröder <malte.schroeder@tnxip.de>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-10-25 15:07:49 -04:00
Florian Schmaus
9ed0f3fd72 mount: print a helpful error message
Just returning a failure exit status makes it hard to tell what the
actual issue was. Instead, the mount command now also provides some
textual output.

See https://github.com/koverstreet/bcachefs-tools/issues/308 for an
example where mount does not provide any helpful output, even with
BCACHEFS_LOG=trace enabled.

Signed-off-by: Florian Schmaus <flo@geekplace.eu>
2024-10-25 10:46:26 +02:00
Kent Overstreet
b1e6d1ced2 cmd_mount: Change error message on -EBUSY to match util-linux
This causes xfstests generic/741 to pass

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-10-12 17:20:56 -04:00
Kent Overstreet
d27d4cf7f0 Fix 'fuse' feature conditional compilation
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-10-05 22:49:27 -04:00
Kent Overstreet
7a98f526b5 cmd_list: open with noxcl
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-09-29 22:18:18 -04:00
Jubilee Young
a1122aced2 Remove byteorder dep
This requires something other than literally zero code to replace, but
is another opportunity to deny packagers the fun of experimenting with
replacing crate versions with incompatible patched crate versions.
2024-09-03 00:31:33 -07:00
Kent Overstreet
b00ac20e76 mount: When mounting a single device, make sure we mount the device specified
When mounting a multi device filesystem we have to scan for component
devices from the UUID, but we don't want to scan if it's a single device
filesystem; if the same filesystem is exposed via multiple device nodes
(e.g. dm faulty testing), the scan can pick up the wrong node.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-08-09 03:44:27 -04:00
koverstreet
6958dd8df2
Merge pull request #320 from WhatAmISupposedToPutHere/master
Ask for password via systemd-ask-password
2024-08-02 09:33:46 -04:00
Thomas Mühlbacher
b4db95b16e fix: don't try to convert C command returns to u8
Fixes Rust panics if some C command (like fsck) returns a value bigger
than 255. The process exit code will be mangled but what can we do, it's
less confusing than a panic (that unfortunately doesn't print the return
value).

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-07-30 23:33:09 +02:00
Sasha Finkelstein
54da29d413 mount: Ask for password via systemd-ask-password
This would allow to supply the password via the plymouth password input.
If systemd-ask-password does not exist or fails to start, falls back to
the old-style password request.

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
2024-07-26 20:39:17 +02:00
Kent Overstreet
57cd58db1e mount: Fix UAF in option string handling
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-07-22 11:22:34 -04:00
Thomas Mühlbacher
cdcc241167 refactor: fix clippy lint
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-07-21 01:17:27 +02:00
Thomas Mühlbacher
7c68f2758d style: nix fmt
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-07-21 01:17:27 +02:00
Thomas Mühlbacher
e218119b01 fix(logging): re-enable warn and error by default
Same as it was in most previous releases. Without this, you may not see
any output for certain errors.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-07-21 01:16:28 +02:00
Thomas Mühlbacher
09cde4869d feat(logging): switch to custom file:line format
This mostly tries to be similar to the default `env_logger` format but
instead of using the more vague target in the log message, we instead
put the file name and line number in the log.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-07-21 01:16:28 +02:00
Kent Overstreet
52b9e813bd Rename option commands
set-option	-> set-fs-option
setattr 	-> set-file-option

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-07-20 16:45:08 -04:00
Kent Overstreet
59ccde4a2f mount: Fall back to read-only on -EROFS
this is the mount helper's job, and since we're the mount helper...

fixes: xfstests generic/050

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-07-20 11:33:46 -04:00
Kent Overstreet
9058835b97 mount: Close devices before doing mount
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-07-18 20:48:14 -04:00
Kent Overstreet
07913d1185 logging: kill quiet option
no logging by default, enabled with -v

logging by default broke fstests

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-07-15 23:20:54 -04:00
Kent Overstreet
2d60567685 fix silly clippy warning
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-07-14 22:16:13 -04:00
Lauri Tirkkonen
7ebd67e63a mount: replace rpassword with rustix::termios
because rpassword unconditionally open()s /dev/tty, it fails with ENXIO
on the console without workarounds like busybox's cttyhack. in contrast,
bcachefs unlock works fine on console, so change the passphrase prompt
logic in mount to be closer to what it is in unlock.

Signed-off-by: Lauri Tirkkonen <lauri@hacktheplanet.fi>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-07-14 21:49:58 -04:00
Thomas Mühlbacher
5cce07e986 feat: use ExitCode over std::process:exit()
Should provide us with better outputs on process failure, also makes
unwinding better and is generally recommended over `exit()`.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-29 00:11:07 +02:00
Thomas Mühlbacher
176d76bceb feat: add --quiet cli argument
To silence log outputs on the CLI.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-28 21:29:47 +02:00
Thomas Mühlbacher
df09682869 feat: use env_logger
Instead of the custom logger impl, which limits the features we can
easily provide for users.

This introduces the `BCACHEFS_LOG` environment variable for setting the
log verbosity. Setting `BCACHEFS_LOG=trace`, e.g. in a test environment,
will yield all log messages.

Also I think it's reasonable to print INFO level logs by default.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-28 21:29:20 +02:00
Thomas Mühlbacher
7a17d429d5 feat(key): make UnlockPolicy::Fail more useful
We already can check if an fs is encrypted with `bcachefs unlock -c`.
With this option we can now instead check if we have a key but not
actually mount by not specifying a mount point. e.g.

```sh
if bcachefs mount -k fail "$blkdev"`; then
    echo "device is unlocked!"
fi
```

Not sure what the original intent for this was. For scenarios where
encryption is simply not supported on principle?

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-26 19:14:45 +02:00
Thomas Mühlbacher
ee5f3719d3 refactor(key): split up unlocking functions
This is more similar to the existing C code, which is already in nice
small chunks.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-26 19:14:45 +02:00
Thomas Mühlbacher
795585e289 refactor: simplify branches for parsing dev
Less repetition and no nested if/else.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-26 19:14:45 +02:00
Thomas Mühlbacher
9bd3ada1d1 feat(mount): make unlock policy optional/explict
This changes the semantics of some arguments related to unlocking and
slightly changes the unlocking logic. Also update help formatting/text.

Instead of defaulting to `UnlockPolicy::Ask`, the argument becomes
optional. That means if it is specified, the user really wants that
specific policy. Similar to how `passphrase_file` also works.

This also extends `UnlockPolicy` to override `isatty` detection.

Fixes: #292
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-26 19:14:45 +02:00
Thomas Mühlbacher
a411e7237f refactor(mount): rename opt => cli
The term option is already used for mount options and the `Option` type.
In other modules it's just called `cli`, so let's do that here as well.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-26 19:14:45 +02:00
Thomas Mühlbacher
cf180e8f34 refactor: rm function param only used for log msg
We lose that bit of info but it's weird to require a parameter simply
because we want to use it for a log message.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-26 19:14:45 +02:00
David Disseldorp
411df4e53f key: use c_long type for keyctl_search() helper fn
The keyctl_search() C function returns a long, which is already
reflected in the KeyHandle._id type. The search_keyring() helper
function currently returns a Result<i64>, which breaks 32-bit builds for
e.g. armv7l:
  error[E0308]: mismatched types
     --> src/key.rs:121:16
      |
  121 |             Ok(key_id)
      |             -- ^^^^^^ expected `i64`, found `i32`
      |             |
      |             arguments to this enum variant are incorrect
...
  error[E0308]: mismatched types
     --> src/key.rs:135:24
      |
  135 |                 _id:   id,
      |                        ^^ expected `i32`, found `i64`

Fix this by changing search_keyring() to return a Result<c_long>.

Fixes: f72ded6a ("fix(key): search for key in all relevant keyrings")
Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-06-20 08:52:12 -04:00
Thomas Mühlbacher
41df701a08 fix(logger): log to stderr
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-18 20:56:25 +02:00
Thomas Mühlbacher
f72ded6a4f fix(key): search for key in all relevant keyrings
Previously, using `bcachefs unlock -k session` would still cause mount
to ask for a passphrase.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-18 20:56:17 +02:00
Thomas Mühlbacher
e4271d7a3e fix(key): remove any newlines from passphrase
To match the behavior of the C code and because there may be newlines
under some conditions.

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
2024-06-18 20:56:15 +02:00
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