Commit Graph

1276 Commits

Author SHA1 Message Date
Raito Bezarius
11d2a45bc0 doc(versioning): document version semantics of this project
It's semantic versioning applied to bcachefs kernel data structures.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-26 21:04:45 -05:00
Raito Bezarius
5787b1c234 feat(bindgen): expose BCH_IOCTL_SUBVOLUME_* on Rust side
As they are functional macro, they need help from our side.
2024-01-26 20:39:08 -05:00
Raito Bezarius
5a1975e528 fix(bindgen): expand the Fix753 workaround for any type and document it
Offer documentation to the poor people who stumble on this and look for a macro generation mechanism
on the Rust side.
2024-01-26 20:39:08 -05:00
Raito Bezarius
234fe664b1 fix(libbcachefs/ioctl): dirfd should be a signed 32 bits integer
`AT_FDCWD` is defined as a macro constant: -100, it works in C… because C.

But in Rust, this will be exposed as a u32 instead of a i32, which is the correct variable type for it.
2024-01-26 20:39:08 -05:00
Kent Overstreet
38b8d01c4c Update bcachefs sources to 481b5f343248 bcachefs: Better error messages for missing inodes in fsck
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-24 17:36:11 -05:00
Thomas Bertschinger
7717a439cf use upstream bindgen; fix packed and aligned types
bcachefs-tools has been using a patched bindgen to work around a
limitation of rustc that prevents compiling structs with
both #[repr(packed(N)] and #[repr(align(N)] attributes. The patch:
e8168ceda507 "codegen: Don't generate conflicting packed() and align()
representation hints." discards the "align" attribute in cases where
bindgen produces a type with both.

This may be correct for some types, but it turns out that for each
bcachefs type with this problem, keeping the "align" attribute and
discarding the "packed" attribute generates a type with the same ABI as
the original C type.

This can be tested automatically by running:
$ cargo test --manifest-path bch_bindgen/Cargo.toml
in the bcachefs-tools tree.

There has been pressure recently to start using upstream bindgen; both
externally, from distribution maintainers who want to build
bcachefs-tools with standard dependencies, and internally, in order to
enable using Rust for bcachefs in-kernel.

This patch updates bcachefs-tools to use upstream bindgen. It works
around the rustc limitation with a post-processing step in the bindgen
build that adjusts the attributes to include "#[repr(C, align(N))]" and
exclude #[repr(packed(N)] only for the 4 types that need it. It also
updates bch_bindgen to format the code with prettyplease so that this
will work even in environments with rustfmt installed.

Some types that had been manually implemented in
bch_bindgen/src/bcachefs.rs are now automatically generated by bindgen,
so that they will be covered by the ABI compatibility testing mentioned
above.

I intentionally targeted the post-processing to the exact 4 types with
the issue currently, so that any changes to bcachefs that result in this
issue appearing for a new type will require manual intervention. I
figured any such changes should require careful consideration.

Ideally, bindgen can be updated to handle situations where "align(N)"
is needed and "packed(N)" can be safely discarded. If a patch for this
is accepted into bindgen, the post-processing hack can be removed.

I update the minimum Rust version to 1.70 as this is needed to build
recent versions of some dependencies.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-23 13:08:12 -05:00
Thomas Bertschinger
505d5aaed2 remove bch_bindgen/Cargo.lock from version control
This is redundant with the root level Cargo.lock. Any changes made to
the bch_bindgen dependencies will be duplicated in both Cargo.lock
files. Removing this from version control will reduce the noise in the
git diffs for such changes.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-23 02:53:45 -05:00
koverstreet
39e109e5f9
Merge pull request #220 from ElvishJerricco/fix-nix-and-docs
Fix nix and docs
2024-01-23 02:53:21 -05:00
Will Fancher
de191cd19c rust: fix docs 2024-01-23 02:38:24 -05:00
Will Fancher
8117fa732b nix: fix build 2024-01-23 02:38:20 -05:00
koverstreet
3da247cd20
Merge pull request #219 from xhebox/master
bch_bindgen: add liburcu paths by pkgconfig
2024-01-21 07:08:23 -05:00
xhe
03122a5888 bch_bindgen: add liburcu paths by pkgconfig
Signed-off-by: xhe <xw897002528@gmail.com>
2024-01-21 19:04:31 +08:00
Kent Overstreet
5e224596cf Remove gag usage
Possibly-fixes: https://github.com/koverstreet/bcachefs-tools/issues/217
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-20 22:32:00 -05:00
Kent Overstreet
b5fd066153 Move c_src dirs back to toplevel
We just wanted c sourcefiles out of the top level, not c source
directories.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-16 17:17:23 -05:00
Faidon Liambotis
06ff8b55b7 rust: bump rpassword to v7.x
Including a tiny API change.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-16 16:30:10 -05:00
Thomas Bertschinger
f5baaf48e3 move Rust sources to top level, C sources into c_src
This moves the Rust sources out of rust_src/ and into the top level.
Running the bcachefs executable out of the development tree is now:

$ ./target/release/bcachefs command
or
$ cargo run --profile release -- command

instead of "./bcachefs command".

Building and installing is still:

$ make && make install

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-16 01:47:05 -05:00
Thomas Bertschinger
fb35dbfdc5 remove library from bcachefs-tools Rust package
When bcachefs was a C program that had some functions implemented in
Rust, it was necessary to make a static library containing the Rust
functions available for the C program to link.

Now that bcachefs is a Rust program, that library is no longer needed.
Instead, the Rust executable links in libbachefs.a.

This patch updates the crate structure to reflect that. The command
functions are moved into their own module.

There could be a need to create a "libbachefs-tools" library in the
future that exposes an API for bcachefs functionality to other
userspace programs. That will be a different, external API as opposed to
the previous library functions which were an internal API for the
bcachefs tool itself.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-16 01:46:58 -05:00
Thomas Bertschinger
0a284fc4ff convert main() from C to Rust
This moves the main() function from C to Rust. It also updates the name
of the Rust package from "bcachefs-rust" to "bcachefs-tools".

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-16 01:46:41 -05:00
Kent Overstreet
249bf7b9d4 cmd_dump: Use buffered IO
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-15 22:15:02 -05:00
Kent Overstreet
807cabc4c9 Prune rust dependencies
pruned via 'cargo machete --fix'

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-15 14:37:07 -05:00
Kent Overstreet
76161e0687 cmd_attr: check for errors from fdopendir()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-15 14:34:54 -05:00
Kent Overstreet
039fd4064a cmd_mount: Use noxcl for opening block devices
We're only reading the superblocks, no need for O_EXCL - and this fixes
mounts failing because we're still holding the devices open.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-15 12:53:52 -05:00
Faidon Liambotis
5ed0dcc001 rust: remove dependency on itertools
The only use for itertools is in parse_mount_options() where we take a
vector, convert it to iterator and then join it. Instead, we can join
the vector directly.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-12 22:53:22 -05:00
Thomas Bertschinger
aefc264401 fix invalid write in pop_cmd()
The memmove() in pop_cmd() reads and writes beyond the end of argv.

This is basically harmless in the current C program; the environment
variable list immediately follows argv so all this does is unnecessarily
copy the beginning of that list.

However, this will become problematic once we start calling C functions
like fs_cmds() from Rust code. Then argv will be a Vec<String> (as
*mut *mut i8) and the memory layout will be different--in particular,
I don't think we can assume that a Vec<String> will be NULL-terminated
like argv always is--, meaning the invalid write could lead to heap
corruption.

Also, it doesn't look like full_cmd ever gets used after calling
pop_cmd() so I'm removing it here since it looks unneeded to me.

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-12 15:04:13 -05:00
Kent Overstreet
076216c16b cmd_migrate: Fix fsck invocation
It's now an error to ask for a read_write filesystem with nochanges.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-12 15:04:09 -05:00
Steinar H. Gunderson
b6afe1bed4 init_layout(): fix rounding
block_size is in bytes, not sectors, so when calling round_up(),
we could start rounding up by a way too large size and then overflow
outside the area that migrate allocated for us.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-12 13:09:51 -05:00
koverstreet
2b7fda5aee
Merge pull request #206 from kode54/fix-fsck-service
fix fsck service location
2024-01-12 12:25:48 -05:00
Christopher Snowhill
01b4965104 fix fsck service location
Correctly generate libexecdir based path for the bcachefsck_all
service, like the bcachefsck_all_fail service already does.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2024-01-11 23:55:39 -08:00
Kent Overstreet
f6bdf31843 kill bd_buffered_fd
this gets us back down to a single fd for opening block devices, which
means we can use O_EXCL.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-10 22:27:22 -05:00
Kent Overstreet
226bade565 kill bd_sync_fd
not needed with pwritev2(.., RWF_SYNC), and perhaps we can get down to
one fd and then use O_EXCL for block devices.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-10 22:27:22 -05:00
Kent Overstreet
2007d9b6ce Fix bch2_super_write() alignment
We're about to switch to O_DIRECT only, which means we need to write
with proper alignment.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-10 22:27:22 -05:00
Thomas Bertschinger
9a9af6e9e6 create common entry point for Rust commands
The bcachefs sub-commands that are implemented in Rust (completions,
list, and mount) had separate entrypoints and thus had some differences
in behavior.

This introduces a common entry point for the Rust sub-commands. This
reduces duplicate boilerplate code like parsing argv and setting up
logging, and will facilitate converting more sub-commands to Rust in
the future.

An immediate benefit is that this fixes an issue with `bcachefs list`
not reporting errors:

before:

$ bcachefs list /dev/typo
$ echo $?
0

after:

$ bcachefs list /dev/typo
ERROR - bcachefs_rust::cmd_list: Fatal error: "No such file or directory"
$ echo $?
1

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-07 21:38:31 -05:00
Kent Overstreet
b90031efaa Update bcachefs sources to cbb2e45634dd bcachefs: fix simulateously upgrading & downgrading
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-05 20:00:08 -05:00
Kent Overstreet
ba4c17c12b atomic64_read_acquire() should be inline
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-05 15:11:51 -05:00
Kent Overstreet
e7049c592a cmd_show_super: --field-only 2024-01-05 13:01:34 -05:00
Kent Overstreet
799439a88a Update bcachefs sources to d267e10a43b2 bcachefs: __bch2_sb_field_to_text()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-05 13:01:34 -05:00
Kent Overstreet
605e2311d9 linux header updates
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-05 13:01:34 -05:00
Kent Overstreet
30c4b24b77 fix show_super default fields
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-05 12:07:57 -05:00
Kent Overstreet
a751fe3a3c cmd_reset_counters
Add a subcommand for resetting superblock counters - for automated tests

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-04 19:56:14 -05:00
Kent Overstreet
e51f25af3c fix list_journal for nochanges
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-03 23:14:56 -05:00
Kent Overstreet
1f79cf3825 Update bcachefs sources to 2a6125decb43 bcachefs: bch_sb_field_downgrade
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-03 20:31:37 -05:00
Kent Overstreet
3054e5debb improve do_splice() 2024-01-03 20:30:44 -05:00
Kent Overstreet
378ae738d5 Update bcachefs sources to 5264e9f4d0c0 bcachefs: fix setting version_upgrade_complete 2023-12-30 16:04:21 -05:00
Kent Overstreet
44bf7868e5 fix missing atomic64_read_acquire on 32 bit
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-29 20:16:47 -05:00
Kent Overstreet
9a1e627a5d fix cmd_list for new nochanges semantics
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-27 21:50:46 -05:00
koverstreet
3070f45d96
Merge pull request #196 from Conan-Kudo/spec-libexecdir
packaging: Update RPM spec to use %_libexecdir for libexec files
2023-12-24 09:11:48 -05:00
Neal Gompa
a0398cf66f packaging: Update RPM spec to use %_libexecdir for libexec files 2023-12-24 09:09:56 -05:00
Kent Overstreet
d101ad4a61 Update bcachefs sources to 44ac32df8e0c bcachefs: Split brain detection 2023-12-24 08:48:31 -05:00
koverstreet
d01f3f590c
Merge pull request #195 from Conan-Kudo/use-libexec
Makefile, fsck: Use libexec instead of lib
2023-12-24 08:47:55 -05:00
Neal Gompa
89abdd8727 Makefile, fsck: Use libexec instead of lib
These are executables that need to be installed in a non-path location.
Most distributions now install these into /usr/libexec, and the
path variable for this is LIBEXECDIR, so use that instead.
2023-12-24 08:34:16 -05:00