1. 22 Oct, 2023 40 commits
    • Kent Overstreet's avatar
      bcachefs: Fix copy_to_user() usage in flush_buf() · f7f6943a
      Kent Overstreet authored
      copy_to_user() returns the number of bytes successfully copied - not an
      errcode.
      Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      f7f6943a
    • Brian Foster's avatar
      bcachefs: fix race between journal entry close and pin set · 3e55189b
      Brian Foster authored
      bcachefs freeze testing via fstests generic/390 occasionally
      reproduces the following BUG from bch2_fs_read_only():
      
        BUG_ON(atomic_long_read(&c->btree_key_cache.nr_dirty));
      
      This indicates that one or more dirty key cache keys still exist
      after the attempt to flush and quiesce the fs. The sequence that
      leads to this problem actually occurs on unfreeze (ro->rw), and
      looks something like the following:
      
      - Task A begins a transaction commit and acquires journal_res for
        the current seq. This transaction intends to perform key cache
        insertion.
      - Task B begins a bch2_journal_flush() via bch2_sync_fs(). This ends
        up in journal_entry_want_write(), which closes the current journal
        entry and drops the reference to the pin list created on entry open.
        The pin put pops the front of the journal via fast reclaim since the
        reference count has dropped to 0.
      - Task A attempts to set the journal pin for the associated cached
        key, but bch2_journal_pin_set() skips the pin insert because the
        seq of the transaction reservation is behind the front of the pin
        list fifo.
      
      The end result is that the pin associated with the cached key is not
      added, which prevents a subsequent reclaim from processing the key
      and thus leaves it dangling at freeze time. The fundamental cause of
      this problem is that the front of the journal is allowed to pop
      before a transaction with outstanding reservation on the associated
      journal seq is able to add a pin. The count for the pin list
      associated with the seq drops to zero and is prematurely reclaimed
      as a result.
      
      The logical fix for this problem lies in how the journal buffer is
      managed in similar scenarios where the entry might have been closed
      before a transaction with outstanding reservations happens to be
      committed.
      
      When a journal entry is opened, the current sequence number is
      bumped, the associated pin list is initialized with a reference
      count of 1, and the journal buffer reference count is bumped (via
      journal_state_inc()). When a journal reservation is acquired, the
      reservation also acquires a reference on the associated buffer. If
      the journal entry is closed in the meantime, it drops both the pin
      and buffer references held by the open entry, but the buffer still
      has references held by outstanding reservation. After the associated
      transaction commits, the reservation release drops the associated
      buffer references and the buffer is written out once the reference
      count has dropped to zero.
      
      The fundamental problem here is that the lifecycle of the pin list
      reference held by an open journal entry is too short to cover the
      processing of transactions with outstanding reservations. The
      simplest way to address this is to expand the pin list reference to
      the lifecycle of the buffer vs. the shorter lifecycle of the open
      journal entry. This ensures the pin list for a seq with outstanding
      reservation cannot be popped and reclaimed before all outstanding
      reservations have been released, even if the associated journal
      entry has been closed for further reservations.
      
      Move the pin put from journal entry close to where final processing
      of the journal buffer occurs. Create a duplicate helper to cover the
      case where the caller doesn't already hold the journal lock. This
      allows generic/390 to pass reliably.
      Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      3e55189b
    • Brian Foster's avatar
      bcachefs: prepare journal buf put to handle pin put · fc08031b
      Brian Foster authored
      bcachefs freeze testing has uncovered some raciness between journal
      entry open/close and pin list reference count management. The
      details of the problem are described in a separate patch. In
      preparation for the associated fix, refactor the journal buffer put
      path a bit to allow it to eventually handle dropping the pin list
      reference currently held by an open journal entry.
      
      Retain the journal write dispatch helper since the closure code is
      inlined and we don't want to increase the amount of inline code in
      the transaction commit path, but rename the function to reflect
      the purpose of final processing of the journal buffer.
      Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      fc08031b
    • Brian Foster's avatar
      bcachefs: refactor pin put helpers · 92b63f5b
      Brian Foster authored
      We have a couple journal pin put helpers to handle cases where the
      journal lock is already held or not. Refactor the helpers to lock
      and reclaim from the highest level and open code the reclaim from
      the one caller of the internal variant. The latter call will be
      moved into the journal buf release helper in a later patch.
      Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      92b63f5b
    • Dan Carpenter's avatar
      bcachefs: snapshot: Add missing assignment in bch2_delete_dead_snapshots() · d67a72bf
      Dan Carpenter authored
      This code accidentally left out the "ret = " assignment so the errors
      from for_each_btree_key2() are not checked.
      
      Fixes: 53534482a250 ("bcachefs: for_each_btree_key2()")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      d67a72bf
    • Dan Carpenter's avatar
      bcachefs: fs-ioctl: Fix copy_to_user() error code · 1f12900a
      Dan Carpenter authored
      The copy_to_user() function returns the number of bytes that it wasn't
      able to copy but we want to return -EFAULT to the user.
      
      Fixes: e0750d947352 ("bcachefs: Initial commit")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      1f12900a
    • Dan Carpenter's avatar
      bcachefs: acl: Add missing check in bch2_acl_chmod() · b6c22147
      Dan Carpenter authored
      The "ret = bkey_err(k);" assignment was accidentally left out so the
      call to bch2_btree_iter_peek_slot() is not checked for errors.
      
      Fixes: 53306e096d91 ("bcachefs: Always check for transaction restarts")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      b6c22147
    • Dan Carpenter's avatar
      bcachefs: acl: Uninitialized variable in bch2_acl_chmod() · e9a0a26e
      Dan Carpenter authored
      The clean up code at the end of the function uses "acl" so it needs
      to be initialized to NULL.
      
      Fixes: 53306e096d91 ("bcachefs: Always check for transaction restarts")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      e9a0a26e
    • Nick Desaulniers's avatar
      bcachefs: Fix -Wself-assign · 265cc423
      Nick Desaulniers authored
      Fixes the following observed error reported by Nathan on IRC.
      
        fs/bcachefs/io_misc.c:467:6: error: explicitly assigning value of
        variable of type 'int' to itself [-Werror,-Wself-assign]
          467 |         ret = ret;
              |         ~~~ ^ ~~~
      Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      265cc423
    • Jiapeng Chong's avatar
      bcachefs: Remove duplicate include · 3b59fbec
      Jiapeng Chong authored
      ./fs/bcachefs/btree_update.h: journal.h is included more than once.
      Reported-by: default avatarAbaci Robot <abaci@linux.alibaba.com>
      Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6573Signed-off-by: default avatarJiapeng Chong <jiapeng.chong@linux.alibaba.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      3b59fbec
    • Dan Carpenter's avatar
      bcachefs: fix error checking in bch2_fs_alloc() · 867c1fe0
      Dan Carpenter authored
      There is a typo here where it uses ";" instead of "?:".  The result is
      that bch2_fs_fs_io_direct_init() is called unconditionally and the errors
      from it are not checked.
      
      Fixes: 0060c68159fc ("bcachefs: Split up fs-io.[ch]")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
      867c1fe0
    • Dan Carpenter's avatar
      bcachefs: chardev: fix an integer overflow (32 bit only) · 4ba985b8
      Dan Carpenter authored
      On 32 bit systems, "sizeof(*arg) + replica_entries_bytes" can have an
      integer overflow leading to memory corruption.  Use size_add() to
      prevent this.
      
      Fixes: b44dd3797034 ("bcachefs: Redo filesystem usage ioctls")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      4ba985b8
    • Dan Carpenter's avatar
      bcachefs: chardev: return -EFAULT if copy_to_user() fails · 301e0237
      Dan Carpenter authored
      The copy_to_user() function returns the number of bytes remaining but
      we want to return -EFAULT to the user.
      
      Fixes: e0750d947352 ("bcachefs: Initial commit")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      301e0237
    • Kent Overstreet's avatar
      bcachefs: Change bucket_lock() to use bit_spin_lock() · 8c2d82a6
      Kent Overstreet authored
      bucket_lock() previously open coded a spinlock, because we need to cram
      a spinlock into a single byte.
      
      But it turns out not all archs support xchg() on a single byte; since we
      need struct bucket to be small, this means we have to play fun games
      with casts and ifdefs for endianness.
      
      This fixes building on 32 bit arm, and likely other architectures.
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      Cc: linux-bcachefs@vger.kernel.org
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      8c2d82a6
    • Kent Overstreet's avatar
      bcachefs: Kill other unreachable() uses · 439c172b
      Kent Overstreet authored
      Per previous commit, bare unreachable() considered harmful, convert to
      BUG()
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      439c172b
    • Josh Poimboeuf's avatar
      bcachefs: Remove undefined behavior in bch2_dev_buckets_reserved() · 3764647b
      Josh Poimboeuf authored
      In general it's a good idea to avoid using bare unreachable() because it
      introduces undefined behavior in compiled code.  In this case it even
      confuses GCC into emitting an empty unused
      bch2_dev_buckets_reserved.part.0() function.
      
      Use BUG() instead, which is nice and defined.  While in theory it should
      never trigger, if something were to go awry and the BCH_WATERMARK_NR
      case were to actually hit, the failure mode is much more robust.
      
      Fixes the following warnings:
      
        vmlinux.o: warning: objtool: bch2_bucket_alloc_trans() falls through to next function bch2_reset_alloc_cursors()
        vmlinux.o: warning: objtool: bch2_dev_buckets_reserved.part.0() is missing an ELF size annotation
      Reported-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      3764647b
    • Christophe JAILLET's avatar
      bcachefs: Remove a redundant and harmless bch2_free_super() call · 0198b235
      Christophe JAILLET authored
      Remove a redundant call to bch2_free_super().
      
      This is harmless because bch2_free_super() has a memset() at its end. So
      a second call would only lead to from kfree(NULL).
      
      Remove the redundant call and only rely on the error handling path.
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      0198b235
    • Christophe JAILLET's avatar
      bcachefs: Fix use-after-free in bch2_dev_add() · 71933fb6
      Christophe JAILLET authored
      If __bch2_dev_attach_bdev() fails, bch2_dev_free() is called twice.
      Once here and another time in the error handling path.
      
      This leads to several use-after-free.
      
      Remove the redundant call and only rely on the error handling path.
      
      Fixes: 6a44735653d4 ("bcachefs: Improved superblock-related error messages")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      71933fb6
    • Brian Foster's avatar
      bcachefs: add module description to fix modpost warning · a9737e0b
      Brian Foster authored
      modpost produces the following warning:
      
      WARNING: modpost: missing MODULE_DESCRIPTION() in fs/bcachefs/bcachefs.o
      
      Add a module description for bcachefs.
      Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      a9737e0b
    • Kent Overstreet's avatar
      bcachefs: Heap allocate btree_trans · 6bd68ec2
      Kent Overstreet authored
      We're using more stack than we'd like in a number of functions, and
      btree_trans is the biggest object that we stack allocate.
      
      But we have to do a heap allocatation to initialize it anyways, so
      there's no real downside to heap allocating the entire thing.
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      6bd68ec2
    • Kent Overstreet's avatar
      96dea3d5
    • Yang Li's avatar
      bcachefs: Remove unneeded semicolon · b5e85d4d
      Yang Li authored
      ./fs/bcachefs/btree_gc.c:1249:2-3: Unneeded semicolon
      ./fs/bcachefs/btree_gc.c:1521:2-3: Unneeded semicolon
      ./fs/bcachefs/btree_gc.c:1575:2-3: Unneeded semicolon
      ./fs/bcachefs/counters.c:46:2-3: Unneeded semicolon
      Signed-off-by: default avatarYang Li <yang.lee@linux.alibaba.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      b5e85d4d
    • Kent Overstreet's avatar
      7bba0dc6
    • Nathan Chancellor's avatar
      bcachefs: Fix -Wcompare-distinct-pointer-types in bch2_copygc_get_buckets() · e82f5f40
      Nathan Chancellor authored
      When building bcachefs for 32-bit ARM, there is a warning when using
      max() to compare an expression involving 'size_t' with an 'unsigned
      long' literal:
      
        fs/bcachefs/movinggc.c:159:21: error: comparison of distinct pointer types ('typeof (16UL) *' (aka 'unsigned long *') and 'typeof (buckets_in_flight->nr / 4) *' (aka 'unsigned int *')) [-Werror,-Wcompare-distinct-pointer-types]
          159 |         size_t nr_to_get = max(16UL, buckets_in_flight->nr / 4);
              |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        include/linux/minmax.h:76:19: note: expanded from macro 'max'
           76 | #define max(x, y)       __careful_cmp(x, y, >)
              |                         ^~~~~~~~~~~~~~~~~~~~~~
        include/linux/minmax.h:38:24: note: expanded from macro '__careful_cmp'
           38 |         __builtin_choose_expr(__safe_cmp(x, y), \
              |                               ^~~~~~~~~~~~~~~~
        include/linux/minmax.h:28:4: note: expanded from macro '__safe_cmp'
           28 |                 (__typecheck(x, y) && __no_side_effects(x, y))
              |                  ^~~~~~~~~~~~~~~~~
        include/linux/minmax.h:22:28: note: expanded from macro '__typecheck'
           22 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
              |                    ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
        1 error generated.
      
      On 64-bit architectures, size_t is 'unsigned long', so there is no
      warning when comparing these two expressions. Use max_t(size_t, ...) for
      this situation, eliminating the warning.
      
      Fixes: dd49018737d4 ("bcachefs: Rhashtable based buckets_in_flight for copygc")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      e82f5f40
    • Nathan Chancellor's avatar
      bcachefs: Fix -Wcompare-distinct-pointer-types in do_encrypt() · 53eda6f7
      Nathan Chancellor authored
      When building bcachefs for 32-bit ARM, there is a warning when using
      min() to compare a variable of type 'size_t' with an expression of type
      'unsigned long':
      
        fs/bcachefs/checksum.c:142:22: error: comparison of distinct pointer types ('typeof (len) *' (aka 'unsigned int *') and 'typeof (((1UL) << 12) - offset) *' (aka 'unsigned long *')) [-Werror,-Wcompare-distinct-pointer-types]
          142 |                         unsigned pg_len = min(len, PAGE_SIZE - offset);
              |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
        include/linux/minmax.h:69:19: note: expanded from macro 'min'
           69 | #define min(x, y)       __careful_cmp(x, y, <)
              |                         ^~~~~~~~~~~~~~~~~~~~~~
        include/linux/minmax.h:38:24: note: expanded from macro '__careful_cmp'
           38 |         __builtin_choose_expr(__safe_cmp(x, y), \
              |                               ^~~~~~~~~~~~~~~~
        include/linux/minmax.h:28:4: note: expanded from macro '__safe_cmp'
           28 |                 (__typecheck(x, y) && __no_side_effects(x, y))
              |                  ^~~~~~~~~~~~~~~~~
        include/linux/minmax.h:22:28: note: expanded from macro '__typecheck'
           22 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
              |                    ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
        1 error generated.
      
      On 64-bit architectures, size_t is 'unsigned long', so there is no
      warning when comparing these two expressions. Use min_t(size_t, ...) for
      this situation, eliminating the warning.
      
      Fixes: 1fb50457684f ("bcachefs: Fix memory corruption in encryption path")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      53eda6f7
    • Nathan Chancellor's avatar
      bcachefs: Fix -Wincompatible-function-pointer-types-strict from key_invalid callbacks · 1f70225d
      Nathan Chancellor authored
      When building bcachefs with -Wincompatible-function-pointer-types-strict,
      a clang warning designed to catch issues with mismatched function
      pointer types, which will be fatal at runtime due to kernel Control Flow
      Integrity (kCFI), there are several instances along the lines of:
      
        fs/bcachefs/bkey_methods.c:118:2: error: incompatible function pointer types initializing 'int (*)(const struct bch_fs *, struct bkey_s_c, enum bkey_invalid_flags, struct printbuf *)' with an expression of type 'int (const struct bch_fs *, struct bkey_s_c, unsigned int, struct printbuf *)' [-Werror,-Wincompatible-function-pointer-types-strict]
          118 |         BCH_BKEY_TYPES()
              |         ^~~~~~~~~~~~~~~~
        fs/bcachefs/bcachefs_format.h:342:2: note: expanded from macro 'BCH_BKEY_TYPES'
          342 |         x(deleted,              0)                      \
              |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
        fs/bcachefs/bkey_methods.c:117:41: note: expanded from macro 'x'
          117 | #define x(name, nr) [KEY_TYPE_##name]   = bch2_bkey_ops_##name,
              |                                           ^~~~~~~~~~~~~~~~~~~~
        <scratch space>:206:1: note: expanded from here
          206 | bch2_bkey_ops_deleted
              | ^~~~~~~~~~~~~~~~~~~~~
        fs/bcachefs/bkey_methods.c:34:17: note: expanded from macro 'bch2_bkey_ops_deleted'
           34 |         .key_invalid = deleted_key_invalid,             \
              |                        ^~~~~~~~~~~~~~~~~~~
      
      The flags parameter should be of type 'enum bkey_invalid_flags', not
      'unsigned int'. Adjust the type everywhere so that there is no more
      warning.
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      1f70225d
    • Nathan Chancellor's avatar
      bcachefs: Fix -Wformat in bch2_bucket_gens_invalid() · 0940863f
      Nathan Chancellor authored
      When building bcachefs for 32-bit ARM, there is a compiler warning in
      bch2_bucket_gens_invalid() due to use of an incorrect format specifier:
      
        fs/bcachefs/alloc_background.c:530:10: error: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
          529 |                 prt_printf(err, "bad val size (%lu != %zu)",
              |                                                ~~~
              |                                                %zu
          530 |                        bkey_val_bytes(k.k), sizeof(struct bch_bucket_gens));
              |                        ^~~~~~~~~~~~~~~~~~~
        fs/bcachefs/util.h:223:54: note: expanded from macro 'prt_printf'
          223 | #define prt_printf(_out, ...)           bch2_prt_printf(_out, __VA_ARGS__)
              |                                                               ^~~~~~~~~~~
      
      On 64-bit architectures, size_t is 'unsigned long', so there is no
      warning when using %lu but on 32-bit architectures, size_t is 'unsigned
      int'. Use '%zu', the format specifier for 'size_t', to eliminate the
      warning.
      
      Fixes: 4be0d766a7e9 ("bcachefs: bucket_gens btree")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      0940863f
    • Nathan Chancellor's avatar
      bcachefs: Fix -Wformat in bch2_alloc_v4_invalid() · 14f63ff3
      Nathan Chancellor authored
      When building bcachefs for 32-bit ARM, there is a compiler warning in
      bch2_alloc_v4_invalid() due to use of an incorrect format specifier:
      
        fs/bcachefs/alloc_background.c:246:30: error: format specifies type 'unsigned long' but the argument has type 'unsigned int' [-Werror,-Wformat]
          245 |                 prt_printf(err, "bad val size (%u > %lu)",
              |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              |                                                     %u
          246 |                        alloc_v4_u64s(a.v), bkey_val_u64s(k.k));
              |                        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
        fs/bcachefs/bkey.h:58:27: note: expanded from macro 'bkey_val_u64s'
           58 | #define bkey_val_u64s(_k)       ((_k)->u64s - BKEY_U64s)
              |                                 ^
        fs/bcachefs/util.h:223:54: note: expanded from macro 'prt_printf'
          223 | #define prt_printf(_out, ...)           bch2_prt_printf(_out, __VA_ARGS__)
              |                                                               ^~~~~~~~~~~
      
      This expression is of type 'size_t'. On 64-bit architectures, size_t is
      'unsigned long', so there is no warning when using %lu but on 32-bit
      architectures, size_t is 'unsigned int'. Use '%zu', the format specifier
      for 'size_t' to eliminate the warning.
      
      Fixes: 11be8e8db283 ("bcachefs: New on disk format: Backpointers")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      14f63ff3
    • Nathan Chancellor's avatar
      bcachefs: Fix -Wformat in bch2_btree_key_cache_to_text() · f7ed15eb
      Nathan Chancellor authored
      When building bcachefs for 32-bit ARM, there is a compiler warning in
      bch2_btree_key_cache_to_text() due to use of an incorrect format
      specifier:
      
        fs/bcachefs/btree_key_cache.c:1060:36: error: format specifies type 'size_t' (aka 'unsigned int') but the argument has type 'long' [-Werror,-Wformat]
         1060 |         prt_printf(out, "nr_freed:\t%zu",       atomic_long_read(&c->nr_freed));
              |                                     ~~~         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              |                                     %ld
        fs/bcachefs/util.h:223:54: note: expanded from macro 'prt_printf'
          223 | #define prt_printf(_out, ...)           bch2_prt_printf(_out, __VA_ARGS__)
              |                                                               ^~~~~~~~~~~
        1 error generated.
      
      On 64-bit architectures, size_t is 'unsigned long', so there is no
      warning when using %zu but on 32-bit architectures, size_t is
      'unsigned int'. Use '%lu' to match the other format specifiers used in
      this function for printing values returned from atomic_long_read().
      
      Fixes: 6d799930ce0f ("bcachefs: btree key cache pcpu freedlist")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      f7ed15eb
    • Nathan Chancellor's avatar
      bcachefs: Fix -Wformat in bch2_set_bucket_needs_journal_commit() · fac1250a
      Nathan Chancellor authored
      When building bcachefs for 32-bit ARM, there is a compiler warning in
      bch2_set_bucket_needs_journal_commit() due to a debug print using the
      wrong specifier:
      
        fs/bcachefs/buckets_waiting_for_journal.c:137:30: error: format specifies type 'size_t' (aka 'unsigned int') but the argument has type 'unsigned long' [-Werror,-Wformat]
          136 |         pr_debug("took %zu rehashes, table at %zu/%zu elements",
              |                                                   ~~~
              |                                                   %lu
          137 |                  nr_rehashes, nr_elements, 1UL << b->t->bits);
              |                                            ^~~~~~~~~~~~~~~~~
        include/linux/printk.h:579:26: note: expanded from macro 'pr_debug'
          579 |         dynamic_pr_debug(fmt, ##__VA_ARGS__)
              |                          ~~~    ^~~~~~~~~~~
        include/linux/dynamic_debug.h:270:22: note: expanded from macro 'dynamic_pr_debug'
          270 |                            pr_fmt(fmt), ##__VA_ARGS__)
              |                                   ~~~     ^~~~~~~~~~~
        include/linux/dynamic_debug.h:250:59: note: expanded from macro '_dynamic_func_call'
          250 |         _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
              |                                                                  ^~~~~~~~~~~
        include/linux/dynamic_debug.h:248:65: note: expanded from macro '_dynamic_func_call_cls'
          248 |         __dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)
              |                                                                        ^~~~~~~~~~~
        include/linux/dynamic_debug.h:224:15: note: expanded from macro '__dynamic_func_call_cls'
          224 |                 func(&id, ##__VA_ARGS__);                       \
              |                             ^~~~~~~~~~~
        1 error generated.
      
      On 64-bit architectures, size_t is 'unsigned long', so there is no
      warning when using %zu but on 32-bit architectures, size_t is
      'unsigned int'. Use the correct specifier to resolve the warning.
      
      Fixes: 7a82e75ddaef ("bcachefs: New data structure for buckets waiting on journal commit")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      fac1250a
    • Colin Ian King's avatar
      bcachefs: Fix a handful of spelling mistakes in various messages · 6bf3766b
      Colin Ian King authored
      There are several spelling mistakes in error messages. Fix these.
      Signed-off-by: default avatarColin Ian King <colin.i.king@gmail.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      6bf3766b
    • Colin Ian King's avatar
      bcachefs: remove redundant pointer q · 74c1e422
      Colin Ian King authored
      The pointer q is being assigned a value but it is never read. The
      assignment and pointer are redundant and can be removed.
      Cleans up clang scan build warning:
      
      fs/bcachefs/quota.c:813:2: warning: Value stored to 'q' is never
      read [deadcode.DeadStores]
      Signed-off-by: default avatarColin Ian King <colin.i.king@gmail.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      74c1e422
    • Colin Ian King's avatar
      bcachefs: remove duplicated assignment to variable offset_into_extent · 2a831e4b
      Colin Ian King authored
      Variable offset_into_extent is being assigned to zero and a few
      statements later it is being re-assigned again to the save value.
      The second assignment is redundant and can be removed. Cleans up
      clang-scan build warning:
      
      fs/bcachefs/io.c:2722:3: warning: Value stored to 'offset_into_extent'
      is never read [deadcode.DeadStores]
      Signed-off-by: default avatarColin Ian King <colin.i.king@gmail.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      2a831e4b
    • Colin Ian King's avatar
      bcachefs: remove redundant initializations of variables start_offset and end_offset · c04cbc0d
      Colin Ian King authored
      The variables start_offset and end_offset are being initialized with
      values that are never read, they being re-assigned later on. The
      initializations are redundant and can be removed.
      
      Cleans up clang-scan build warnings:
      fs/bcachefs/fs-io.c:243:11: warning: Value stored to 'start_offset' during
      its initialization is never read [deadcode.DeadStores]
      fs/bcachefs/fs-io.c:244:11: warning: Value stored to 'end_offset' during
      its initialization is never read [deadcode.DeadStores]
      Signed-off-by: default avatarColin Ian King <colin.i.king@gmail.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      c04cbc0d
    • Colin Ian King's avatar
      bcachefs: remove redundant initialization of pointer dst · 519d6c88
      Colin Ian King authored
      The pointer dst is being initialized with a value that is never read,
      it is being re-assigned later on when it is used in a while-loop
      The initialization is redundant and can be removed.
      
      Cleans up clang-scan build warning:
      fs/bcachefs/disk_groups.c:186:30: warning: Value stored to 'dst' during
      its initialization is never read [deadcode.DeadStores]
      Signed-off-by: default avatarColin Ian King <colin.i.king@gmail.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      519d6c88
    • Colin Ian King's avatar
      bcachefs: remove redundant initialization of pointer d · 7cb0e699
      Colin Ian King authored
      The pointer d is being initialized with a value that is never read,
      it is being re-assigned later on when it is used in a for-loop.
      The initialization is redundant and can be removed.
      
      Cleans up clang-scan build warning:
      fs/bcachefs/buckets.c:1303:25: warning: Value stored to 'd' during its
      initialization is never read [deadcode.DeadStores]
      Signed-off-by: default avatarColin Ian King <colin.i.king@gmail.com>
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      7cb0e699
    • Kent Overstreet's avatar
      bcachefs: trace_read_nopromote() · feb5cc39
      Kent Overstreet authored
      Add a tracepoint to print the reason a read wasn't promoted.
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      feb5cc39
    • Kent Overstreet's avatar
      bcachefs: Log finsert/fcollapse operations · f3e374ef
      Kent Overstreet authored
      Now that we have the logged operations btree, we can make
      finsert/fcollapse atomic w.r.t. unclean shutdown as well.
      
      This adds bch_logged_op_finsert to represent the state of an finsert or
      fcollapse, which is a bit more complicated than truncate since we need
      to track our position in the "shift extents" operation.
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      f3e374ef
    • Kent Overstreet's avatar
      bcachefs: Log truncate operations · b030e262
      Kent Overstreet authored
      Previously, we guaranteed atomicity of truncate after unclean shutdown
      with the BCH_INODE_I_SIZE_DIRTY flag - which required a full scan of the
      inodes btree.
      
      Recently the deleted inodes btree was added so that we no longer have to
      scan for deleted inodes, but truncate was unfinished and that change
      left it broken.
      
      This patch uses the new logged operations btree to fix truncate
      atomicity; we now log an operation that can be replayed at the start of
      a truncate.
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      b030e262
    • Kent Overstreet's avatar
      bcachefs: BTREE_ID_logged_ops · aaad530a
      Kent Overstreet authored
      Add a new btree for long running logged operations - i.e. for logging
      operations that we can't do within a single btree transaction, so that
      they can be resumed if we crash.
      
      Keys in the logged operations btree will represent operations in
      progress, with the state of the operation stored in the value.
      Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
      aaad530a