119 Commits

Author SHA1 Message Date
koverstreet
0a3e0e6582
Merge pull request #413 from beviu/systemd-ask-password
Improve systemd-ask-password integration
2025-09-21 15:55:04 -04:00
beviu
69cb6428ba
key: Pass --keyname and --accept-cached to systemd-ask-password
Before asking for a passphrase, mount.bcachefs searches for an existing
key in the keyring containing a passphrase for the filesystem. This
means that the user only has to enter the passphrase once when mounting
the filesystem multiple times.

However, if the key appears in between the check and the time when
systemd-ask-password queries the user for a password, the existing key
will not be reused. Also, when multiple instances of mount.bcachefs
are started in parallel for the same filesystem (such as during boot),
each of them will see that the key is not in the keyring and start an
instance of systemd-ask-password, meaning that the user will be queried
multiple times.

Fix the race condition by passing the --keyname and --accept-cached
options to systemd-ask-password which also makes it try itself to
retreive a cached password from the keyring before querying the user
for a password.
2025-09-21 21:42:56 +02:00
beviu
e5f4be87a8
key: Try systemd-ask-password when stdin is /dev/null
When mount.bcachefs is started with stdin set to /dev/null (such as when
it is started by systemd during boot), try to use systemd-ask-password
to ask for the passphrase.
2025-09-21 21:42:56 +02:00
beviu
b5f23b00cd
Use bcache_fs_open_fallible in BcachefsHandle::open
Also, as long as the path is valid, bcache_fs_open{,fallible} do not
do anything unsafe so BcachefsHandle::open does not need to be marked
unsafe.
2025-09-20 22:38:18 +02:00
Kent Overstreet
e65dd86e41 bcachefs undump
Some checks failed
build / bcachefs-tools-deb (ubuntu-24.04) (push) Has been cancelled
build / bcachefs-tools-rpm (push) Has been cancelled
build / bcachefs-tools-msrv (push) Has been cancelled
Nix Flake actions / nix-matrix (push) Has been cancelled
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Has been cancelled
Add our own version of 'qemu-img convert', which doesn't have the l1
table size limit or require fixing our missing reflink table.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-09-01 15:11:56 -04:00
Kent Overstreet
da8f1d04e3 Plumb subvol v2 ioctls with proper error messages
Some checks failed
build / bcachefs-tools-deb (ubuntu-24.04) (push) Has been cancelled
build / bcachefs-tools-rpm (push) Has been cancelled
build / bcachefs-tools-msrv (push) Has been cancelled
Nix Flake actions / nix-matrix (push) Has been cancelled
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Has been cancelled
update-flake-lock / lockfile (push) Has been cancelled
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-08-28 20:06:04 -04:00
NewbieOrange
34f9eeba1d mount: try to mount even if module is not loaded
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-08-27 19:22:37 -04:00
Kent Overstreet
c12d7b3315 Commands called with no arguments now print usage
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-08-27 18:47:54 -04:00
Kent Overstreet
530e8ade4e device_scan now uses no_version_check
Some checks failed
build / bcachefs-tools-deb (ubuntu-24.04) (push) Has been cancelled
build / bcachefs-tools-rpm (push) Has been cancelled
build / bcachefs-tools-msrv (push) Has been cancelled
Nix Flake actions / nix-matrix (push) Has been cancelled
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Has been cancelled
Fix a compatibility issue - old tools can now mount newer filesystems
with incompatible features, even if they can't do anything else with
them.

cmd_show_super now uses no_version_check as well.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-08-08 19:35:16 -04:00
Kent Overstreet
6704e252ef cmd_show_super: Look up and print names of member devices
bch2_sb_to_text_with_names(): print device paths and models of each
member.

Fixes: https://github.com/koverstreet/bcachefs/issues/801
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-08-02 13:22:13 -04:00
Kent Overstreet
6eda7d1831 get_or_split_cmdline_devs() now scans for component devices
Fix accidental splitbrain issues caused by writing to only some of a
filesystem's devices: now, all subcommands that take member devices will
scan for all members before opening.

Fixes: https://github.com/koverstreet/bcachefs/issues/924
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-08-01 18:35:33 -04:00
Kent Overstreet
c97bc37ae8 device_scan.rs
Pull out the code for scanning for component devices into a separate
module with a nicer interface.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-08-01 18:35:33 -04:00
Kent Overstreet
c2f3e4c99c Implement dump_stack()
Rust has this in the standard library - nice.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-07-13 09:19:28 -04:00
Kent Overstreet
60ec05df84 bcachefs recovery-passes
New subcommand for scheduling or descheduling recovery passes on an
unmounted filesystem.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-07-06 12:29:26 -04:00
Kent Overstreet
ffd8765ec6 mount: check if bcachefs module is loaded
Some checks failed
Nix Flake actions / nix-matrix (push) Has been cancelled
build / bcachefs-tools-deb (ubuntu-22.04) (push) Has been cancelled
build / bcachefs-tools-deb (ubuntu-24.04) (push) Has been cancelled
build / bcachefs-tools-rpm (push) Has been cancelled
build / bcachefs-tools-msrv (push) Has been cancelled
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Has been cancelled
update-flake-lock / lockfile (push) Has been cancelled
This lets us print out a more useful error.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-06-25 14:01:22 -04:00
Kent Overstreet
45f6fe0a14 cmd_image_create
Some checks failed
build / bcachefs-tools-deb (ubuntu-22.04) (push) Has been cancelled
build / bcachefs-tools-deb (ubuntu-24.04) (push) Has been cancelled
build / bcachefs-tools-rpm (push) Has been cancelled
build / bcachefs-tools-msrv (push) Has been cancelled
Nix Flake actions / nix-matrix (push) Has been cancelled
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Has been cancelled
Add a tool for creating small image files.

Data is written out in a reproducible order, sequentially from the
start of the device.

Metadata is initially written to a temporary device, then after writing
out data, the metadata we want to keep (alloc info is left out by
default) is migrated to the real device.

Then, the image file is trimmed to minimum size and the temporary
metadata device dropped.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-06-20 17:16:33 -04:00
Kent Overstreet
f2d9a55b1b cmd_strip_alloc
Add a command for stripping allocation info for a filesystem.

This is primarily to test codepaths used by the new image creation tool.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-06-20 17:16:33 -04:00
Kent Overstreet
4613023c16 Update bcachefs sources to 7f938192650f bcachefs: darray_find(), darray_find_p()
Some checks failed
build / bcachefs-tools-msrv (push) Has been cancelled
Nix Flake actions / nix-matrix (push) Has been cancelled
build / bcachefs-tools-deb (ubuntu-22.04) (push) Has been cancelled
build / bcachefs-tools-deb (ubuntu-24.04) (push) Has been cancelled
build / bcachefs-tools-rpm (push) Has been cancelled
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Has been cancelled
update-flake-lock / lockfile (push) Has been cancelled
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-29 20:18:40 -04:00
Kent Overstreet
adb8bdd53d cmd_list: Don't run any fsck/upgrades
Some checks are pending
build / bcachefs-tools-deb (ubuntu-22.04) (push) Waiting to run
build / bcachefs-tools-deb (ubuntu-24.04) (push) Waiting to run
build / bcachefs-tools-rpm (push) Waiting to run
build / bcachefs-tools-msrv (push) Waiting to run
Nix Flake actions / nix-matrix (push) Waiting to run
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Blocked by required conditions
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-29 16:06:57 -04:00
Kent Overstreet
51315289f2 list: Allow for lookups within a particular snapshot
Some checks are pending
build / bcachefs-tools-deb (ubuntu-22.04) (push) Waiting to run
build / bcachefs-tools-deb (ubuntu-24.04) (push) Waiting to run
build / bcachefs-tools-rpm (push) Waiting to run
build / bcachefs-tools-msrv (push) Waiting to run
Nix Flake actions / nix-matrix (push) Waiting to run
Nix Flake actions / ${{ matrix.name }} (${{ matrix.system }}) (push) Blocked by required conditions
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-05-07 15:52:34 -04:00
Kent Overstreet
844721635c Update bcachefs sources to 2f9361370129 bcachefs: Improve opts.degraded
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-04-13 21:10:24 -04:00
Integral
3bfe433d22 bcachefs-tools: make targets of subvolume create/delete required
Some checks are pending
build / bcachefs-tools-deb (ubuntu-22.04) (push) Waiting to run
build / bcachefs-tools-deb (ubuntu-24.04) (push) Waiting to run
build / bcachefs-tools-rpm (push) Waiting to run
build / bcachefs-tools-msrv (push) Waiting to run
Nix-Tests / nix-flake-check (push) Waiting to run
Currently, when no targets are provided for "bcachefs subvolume create" or
"bcachefs subvolume delete", it will exit silently with code 0. Make targets
(arguments) required to solve this problem.

This patch solves issue https://github.com/koverstreet/bcachefs/issues/766.

Signed-off-by: Integral <integral@archlinuxcn.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-03-27 13:58:21 -04:00
Kent Overstreet
941dfd7a29 mount: Parse bcachefs options, and pass them to mount helper
This fixes the migrate test - we need to handle the sb=# option.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-03-25 16:37:26 -04:00
Thomas Mühlbacher
3d972489a8 fix(key): replace c_str macro with c"" literal
According to the MSRV in Cargo.toml, we can use this now.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-03-21 13:08:39 -04:00
Kent Overstreet
64ce740ac6 cmd_recover_super: 'bcachefs recover-super'
Some checks failed
build / bcachefs-tools-deb (ubuntu-22.04) (push) Has been cancelled
build / bcachefs-tools-deb (ubuntu-24.04) (push) Has been cancelled
build / bcachefs-tools-rpm (push) Has been cancelled
build / bcachefs-tools-msrv (push) Has been cancelled
Nix-Tests / nix-flake-check (push) Has been cancelled
New tool for scanning for backup superblocks, to recover when the
primary superblock + sb layout have been overwritten.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2025-03-17 14:28:10 -04:00
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