summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/bkey.c
Commit message (Collapse)AuthorAgeFilesLines
* bcachefs: s/bkey_invalid_flags/bch_validate_flagsKent Overstreet2024-05-091-1/+1
| | | | | | | We're about to start using bch_validate_flags for superblock section validation - it's no longer bkey specific. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch2_bkey_format_field_overflows()Kent Overstreet2024-05-081-8/+5
| | | | | | | | | Fix another shift-by-64 by factoring out a common helper for bch2_bkey_format_invalid() and bformat_needs_redo() (where it was already fixed). Reported-by: syzbot+9833a1d29d4a44361e2c@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Improve move_extent tracepointKent Overstreet2024-01-211-1/+1
| | | | | | | Also print out the data_opts, so that we can see what specifically is being done to an extent. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix W=12 build errorsKent Overstreet2023-10-221-9/+22
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Array bounds fixesKent Overstreet2023-10-221-1/+1
| | | | | | | | | | | It's no longer legal to use a zero size array as a flexible array member - this causes UBSAN to complain. This patch switches our zero size arrays to normal flexible array members when possible, and inserts casts in other places (e.g. where we use the zero size array as a marker partway through an array). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix bkey format calculationKent Overstreet2023-10-221-2/+4
| | | | | | | | For extents, we increase the number of bits of the size field to allow extents to get bigger due to merging - but this code didn't check for overflow. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: BCH_COMPAT_bformat_overflow_done no longer requiredKent Overstreet2023-10-221-15/+39
| | | | | | | | | | | | | | | | Awhile back, we changed bkey_format generation to ensure that the packed representation could never represent fields larger than the unpacked representation. This was to ensure that bkey_packed_successor() always gave a sensible result, but in the current code bkey_packed_successor() is only used in a debug assertion - not for anything important. This kills the requirement that we've gotten rid of those weird bkey formats, and instead changes the assertion to check if we're dealing with an old weird bkey format. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: kill EBUG_ON() redefinition in bkey.cKent Overstreet2023-10-221-9/+8
| | | | | | our debug mode assertions in bkey.c haven't been getting run, whoops Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix shift by 64 in set_inc_field()Kent Overstreet2023-10-221-27/+24
| | | | | | | | | | | | | | | UBSAN was complaining about a shift by 64 in set_inc_field(). This only happened when the value being shifted was 0, so in theory should be harmless - a shift by 64 (or register width) should logically give a result of 0, but CPUs will in practice leave the input unchanged when the number of bits to shift by wraps - and since our input here is 0, the output is still what we want. But, it's still undefined behaviour and we need our UBSAN output to be clean, so it needs to be fixed. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bkey_format helper improvementsKent Overstreet2023-10-221-8/+30
| | | | | | | | | | - add a to_text() method for bkey_format - convert bch2_bkey_format_validate() to modern error message style, where we pass a printbuf for the error string instead of returning a static string Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Use memcpy_u64s_small() for copying keysKent Overstreet2023-10-221-1/+1
| | | | | | | Small performance optimization; an open coded loop is better than rep ; movsq for small copies. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Add some unlikely() annotationsKent Overstreet2023-10-221-3/+3
| | | | | | | | Add a few easy unlikely() optimizations. These are mainly worthwhile because the compiler will (usually) put the branch-not-taken path at the end of the function, meaning better icache utilization. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: extents no longer require special handling for packingKent Overstreet2023-10-221-9/+0
| | | | | | | | | | Extent overwrite used to be handled differently, underneath the journaling layer and within the core btree code. This imposed restrictions on bkey packing/packed formats, which no longer apply. This patch deletes those restrictions. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Inline bch2_bkey_format_add_key()Kent Overstreet2023-10-221-26/+0
| | | | | | | This is only called in two places, and when it's used we use it in a tight loop - it's definitely worth inlining. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: More style fixesKent Overstreet2023-10-221-3/+0
| | | | | | Fixes for various checkpatch errors. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch2_bkey_cmp_packed_inlined()Kent Overstreet2023-10-221-105/+3
| | | | | | | This adds an inlined version of bch2_bkey_cmp_packed(), and uses it in bch2_sort_keys(), where it's part of the inner loop. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Assorted checkpatch fixesKent Overstreet2023-10-221-2/+2
| | | | | | | | | | | | | | | | | checkpatch.pl gives lots of warnings that we don't want - suggested ignore list: ASSIGN_IN_IF UNSPECIFIED_INT - bcachefs coding style prefers single token type names NEW_TYPEDEFS - typedefs are occasionally good FUNCTION_ARGUMENTS - we prefer to look at functions in .c files (hopefully with docbook documentation), not .h file prototypes MULTISTATEMENT_MACRO_USE_DO_WHILE - we have _many_ x-macros and other macros where we can't do this Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: bch2_bkey_packed_to_binary_text()Kent Overstreet2023-10-221-26/+54
| | | | | | | | For debugging the eytzinger search tree code, and low level bkey packing code, it can be helpful to see things in binary: this patch improves our helpers for doing so. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
* bcachefs: Heap allocate printbufsKent Overstreet2023-10-221-4/+5
| | | | | | | | | | | This patch changes printbufs dynamically allocate and reallocate a buffer as needed. Stack usage has become a bit of a problem, and a major cause of that has been static size string buffers on the stack. The most involved part of this refactoring is that printbufs must now be exited with printbuf_exit(). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix shift-by-64 in bch2_bkey_format_validate()Kent Overstreet2023-10-221-10/+10
| | | | | | | | | We need to ensure that packed formats can't represent fields larger than the unpacked format, which is a bit tricky since the calculations can also overflow a u64. This patch fixes a shift and simplifies the overall calculations. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
* bcachefs: Fix for bch2_bkey_pack_pos() not initializing len/version fieldsKent Overstreet2023-10-221-1/+8
| | | | | | | This bug led to push_whiteout() generating whiteouts that failed bch2_bkey_invalid() due to nonzero length fields - oops. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
* bcachefs: Start using bpos.snapshot fieldKent Overstreet2023-10-221-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch starts treating the bpos.snapshot field like part of the key in the btree code: * bpos_successor() and bpos_predecessor() now include the snapshot field * Keys in btrees that will be using snapshots (extents, inodes, dirents and xattrs) now always have their snapshot field set to U32_MAX The btree iterator code gets a new flag, BTREE_ITER_ALL_SNAPSHOTS, that determines whether we're iterating over keys in all snapshots or not - internally, this controlls whether bkey_(successor|predecessor) increment/decrement the snapshot field, or only the higher bits of the key. We add a new member to struct btree_iter, iter->snapshot: when BTREE_ITER_ALL_SNAPSHOTS is not set, iter->pos.snapshot should always equal iter->snapshot, which will be 0 for btrees that don't use snapshots, and alsways U32_MAX for btrees that will use snapshots (until we enable snapshot creation). This patch also introduces a new metadata version number, and compat code for reading from/writing to older versions - this isn't a forced upgrade (yet). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Split out bpos_cmp() and bkey_cmp()Kent Overstreet2023-10-221-4/+4
| | | | | | | | | | | | | | With snapshots, we're going to need to differentiate between comparisons that should and shouldn't include the snapshot field. bpos_cmp is now the comparison function that does include the snapshot field, used by core btree code. Upper level filesystem code generally does _not_ want to compare against the snapshot field - that code wants keys to compare as equal even when one of them is in an ancestor snapshot. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Fix bkey format generation for 32 bit fieldsKent Overstreet2023-10-221-1/+6
| | | | | | | | Having a packed format that can represent a field larger than the unpacked type breaks bkey_packed_successor() assertions - we need to fix this to start using the snapshot filed. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Drop typechecking from bkey_cmp_packed()Kent Overstreet2023-10-221-4/+4
| | | | | | | | This only did anything in two places, and those can just be replaced wiht bkey_cmp_left_packed()). Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Make __bch2_bkey_cmp_packed() smallerKent Overstreet2023-10-221-16/+10
| | | | | | | | We can probably get rid of the version that dispatches based on type checking too. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: More bset.c microoptimizationKent Overstreet2023-10-221-1/+1
| | | | | | | Improve a few paper cuts that've shown up during profiling. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: cmp_int()Kent Overstreet2023-10-221-1/+1
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Improve c version of __bkey_cmp_bitsKent Overstreet2023-10-221-5/+4
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Make bkey types globally uniqueKent Overstreet2023-10-221-1/+1
| | | | | | | | | | this lets us get rid of a lot of extra switch statements - in a lot of places we dispatch on the btree node type, and then the key type, so this is a nice cleanup across a lot of code. Also improve the on disk format versioning stuff. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: revamp to_text methodsKent Overstreet2023-10-221-2/+2
| | | | Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
* bcachefs: Initial commitKent Overstreet2023-10-221-0/+1164
Initially forked from drivers/md/bcache, bcachefs is a new copy-on-write filesystem with every feature you could possibly want. Website: https://bcachefs.org Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>