Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'bcachefs-2024-06-22' of https://evilpiepirate.org/git/bcachefs

Pull bcachefs fixes from Kent Overstreet:
"Lots of (mostly boring) fixes for syzbot bugs and rare(r) CI bugs.

The LRU_TIME_BITS fix was slightly more involved; we only have 48 bits
for the LRU position (we would prefer 64), so wraparound is possible
for the cached data LRUs on a filesystem that has done sufficient
(petabytes) reads; this is now handled.

One notable user reported bugfix, where we were forgetting to
correctly set the bucket data type, which should have been
BCH_DATA_need_gc_gens instead of BCH_DATA_free; this was causing us to
go emergency read-only on a filesystem that had seen heavy enough use
to see bucket gen wraparoud.

We're now starting to fix simple (safe) errors without requiring user
intervention - i.e. a small incremental step towards full self
healing.

This is currently limited to just certain allocation information
counters, and the error is still logged in the superblock; see that
patch for more information. ("bcachefs: Fix safe errors by default")"

* tag 'bcachefs-2024-06-22' of https://evilpiepirate.org/git/bcachefs: (22 commits)
bcachefs: Move the ei_flags setting to after initialization
bcachefs: Fix a UAF after write_super()
bcachefs: Use bch2_print_string_as_lines for long err
bcachefs: Fix I_NEW warning in race path in bch2_inode_insert()
bcachefs: Replace bare EEXIST with private error codes
bcachefs: Fix missing alloc_data_type_set()
closures: Change BUG_ON() to WARN_ON()
bcachefs: fix alignment of VMA for memory mapped files on THP
bcachefs: Fix safe errors by default
bcachefs: Fix bch2_trans_put()
bcachefs: set_worker_desc() for delete_dead_snapshots
bcachefs: Fix bch2_sb_downgrade_update()
bcachefs: Handle cached data LRU wraparound
bcachefs: Guard against overflowing LRU_TIME_BITS
bcachefs: delete_dead_snapshots() doesn't need to go RW
bcachefs: Fix early init error path in journal code
bcachefs: Check for invalid btree IDs
bcachefs: Fix btree ID bitmasks
bcachefs: Fix shift overflow in read_one_super()
bcachefs: Fix a locking bug in the do_discard_fast() path
...

+472 -355
+61 -15
fs/bcachefs/alloc_background.c
··· 259 259 "invalid data type (got %u should be %u)", 260 260 a.v->data_type, alloc_data_type(*a.v, a.v->data_type)); 261 261 262 + for (unsigned i = 0; i < 2; i++) 263 + bkey_fsck_err_on(a.v->io_time[i] > LRU_TIME_MAX, 264 + c, err, 265 + alloc_key_io_time_bad, 266 + "invalid io_time[%s]: %llu, max %llu", 267 + i == READ ? "read" : "write", 268 + a.v->io_time[i], LRU_TIME_MAX); 269 + 262 270 switch (a.v->data_type) { 263 271 case BCH_DATA_free: 264 272 case BCH_DATA_need_gc_gens: ··· 765 757 alloc_data_type_set(new_a, new_a->data_type); 766 758 767 759 if (bch2_bucket_sectors_total(*new_a) > bch2_bucket_sectors_total(*old_a)) { 768 - new_a->io_time[READ] = max_t(u64, 1, atomic64_read(&c->io_clock[READ].now)); 769 - new_a->io_time[WRITE]= max_t(u64, 1, atomic64_read(&c->io_clock[WRITE].now)); 760 + new_a->io_time[READ] = bch2_current_io_time(c, READ); 761 + new_a->io_time[WRITE]= bch2_current_io_time(c, WRITE); 770 762 SET_BCH_ALLOC_V4_NEED_INC_GEN(new_a, true); 771 763 SET_BCH_ALLOC_V4_NEED_DISCARD(new_a, true); 772 764 } ··· 776 768 !bch2_bucket_is_open_safe(c, new.k->p.inode, new.k->p.offset)) { 777 769 new_a->gen++; 778 770 SET_BCH_ALLOC_V4_NEED_INC_GEN(new_a, false); 771 + alloc_data_type_set(new_a, new_a->data_type); 779 772 } 780 773 781 774 if (old_a->data_type != new_a->data_type || ··· 790 781 791 782 if (new_a->data_type == BCH_DATA_cached && 792 783 !new_a->io_time[READ]) 793 - new_a->io_time[READ] = max_t(u64, 1, atomic64_read(&c->io_clock[READ].now)); 784 + new_a->io_time[READ] = bch2_current_io_time(c, READ); 794 785 795 786 u64 old_lru = alloc_lru_idx_read(*old_a); 796 787 u64 new_lru = alloc_lru_idx_read(*new_a); ··· 891 882 closure_wake_up(&c->freelist_wait); 892 883 893 884 if (statechange(a->data_type == BCH_DATA_need_discard) && 894 - !bch2_bucket_is_open(c, new.k->p.inode, new.k->p.offset) && 885 + !bch2_bucket_is_open_safe(c, new.k->p.inode, new.k->p.offset) && 895 886 bucket_flushed(new_a)) 896 887 bch2_discard_one_bucket_fast(c, new.k->p); 897 888 ··· 1588 1579 if (ret) 1589 1580 goto err; 1590 1581 1591 - a_mut->v.io_time[READ] = atomic64_read(&c->io_clock[READ].now); 1582 + a_mut->v.io_time[READ] = bch2_current_io_time(c, READ); 1592 1583 ret = bch2_trans_update(trans, alloc_iter, 1593 1584 &a_mut->k_i, BTREE_TRIGGER_norun); 1594 1585 if (ret) ··· 1643 1634 mutex_lock(&c->discard_buckets_in_flight_lock); 1644 1635 darray_for_each(c->discard_buckets_in_flight, i) 1645 1636 if (bkey_eq(*i, bucket)) { 1646 - ret = -EEXIST; 1637 + ret = -BCH_ERR_EEXIST_discard_in_flight_add; 1647 1638 goto out; 1648 1639 } 1649 1640 ··· 1797 1788 } 1798 1789 1799 1790 SET_BCH_ALLOC_V4_NEED_DISCARD(&a->v, false); 1800 - alloc_data_type_set(&a->v, a->v.data_type); 1801 1791 write: 1792 + alloc_data_type_set(&a->v, a->v.data_type); 1793 + 1802 1794 ret = bch2_trans_update(trans, &iter, &a->k_i, 0) ?: 1803 1795 bch2_trans_commit(trans, NULL, NULL, 1804 1796 BCH_WATERMARK_btree| ··· 1985 1975 a->v.data_type = 0; 1986 1976 a->v.dirty_sectors = 0; 1987 1977 a->v.cached_sectors = 0; 1988 - a->v.io_time[READ] = atomic64_read(&c->io_clock[READ].now); 1989 - a->v.io_time[WRITE] = atomic64_read(&c->io_clock[WRITE].now); 1978 + a->v.io_time[READ] = bch2_current_io_time(c, READ); 1979 + a->v.io_time[WRITE] = bch2_current_io_time(c, WRITE); 1990 1980 1991 1981 ret = bch2_trans_commit(trans, NULL, NULL, 1992 1982 BCH_WATERMARK_btree| ··· 2021 2011 goto out; 2022 2012 } 2023 2013 2014 + static struct bkey_s_c next_lru_key(struct btree_trans *trans, struct btree_iter *iter, 2015 + struct bch_dev *ca, bool *wrapped) 2016 + { 2017 + struct bkey_s_c k; 2018 + again: 2019 + k = bch2_btree_iter_peek_upto(iter, lru_pos(ca->dev_idx, U64_MAX, LRU_TIME_MAX)); 2020 + if (!k.k && !*wrapped) { 2021 + bch2_btree_iter_set_pos(iter, lru_pos(ca->dev_idx, 0, 0)); 2022 + *wrapped = true; 2023 + goto again; 2024 + } 2025 + 2026 + return k; 2027 + } 2028 + 2024 2029 static void bch2_do_invalidates_work(struct work_struct *work) 2025 2030 { 2026 2031 struct bch_fs *c = container_of(work, struct bch_fs, invalidate_work); ··· 2049 2024 for_each_member_device(c, ca) { 2050 2025 s64 nr_to_invalidate = 2051 2026 should_invalidate_buckets(ca, bch2_dev_usage_read(ca)); 2027 + struct btree_iter iter; 2028 + bool wrapped = false; 2052 2029 2053 - ret = for_each_btree_key_upto(trans, iter, BTREE_ID_lru, 2054 - lru_pos(ca->dev_idx, 0, 0), 2055 - lru_pos(ca->dev_idx, U64_MAX, LRU_TIME_MAX), 2056 - BTREE_ITER_intent, k, 2057 - invalidate_one_bucket(trans, &iter, k, &nr_to_invalidate)); 2030 + bch2_trans_iter_init(trans, &iter, BTREE_ID_lru, 2031 + lru_pos(ca->dev_idx, 0, 2032 + ((bch2_current_io_time(c, READ) + U32_MAX) & 2033 + LRU_TIME_MAX)), 0); 2034 + 2035 + while (true) { 2036 + bch2_trans_begin(trans); 2037 + 2038 + struct bkey_s_c k = next_lru_key(trans, &iter, ca, &wrapped); 2039 + ret = bkey_err(k); 2040 + if (bch2_err_matches(ret, BCH_ERR_transaction_restart)) 2041 + continue; 2042 + if (ret) 2043 + break; 2044 + if (!k.k) 2045 + break; 2046 + 2047 + ret = invalidate_one_bucket(trans, &iter, k, &nr_to_invalidate); 2048 + if (ret) 2049 + break; 2050 + 2051 + bch2_btree_iter_advance(&iter); 2052 + } 2053 + bch2_trans_iter_exit(trans, &iter); 2058 2054 2059 2055 if (ret < 0) { 2060 2056 bch2_dev_put(ca); ··· 2250 2204 if (ret) 2251 2205 return ret; 2252 2206 2253 - now = atomic64_read(&c->io_clock[rw].now); 2207 + now = bch2_current_io_time(c, rw); 2254 2208 if (a->v.io_time[rw] == now) 2255 2209 goto out; 2256 2210
+7 -1
fs/bcachefs/alloc_background.h
··· 141 141 !bch2_bucket_sectors_fragmented(ca, a)) 142 142 return 0; 143 143 144 - u64 d = bch2_bucket_sectors_dirty(a); 144 + /* 145 + * avoid overflowing LRU_TIME_BITS on a corrupted fs, when 146 + * bucket_sectors_dirty is (much) bigger than bucket_size 147 + */ 148 + u64 d = min(bch2_bucket_sectors_dirty(a), 149 + ca->mi.bucket_size); 150 + 145 151 return div_u64(d * (1ULL << 31), ca->mi.bucket_size); 146 152 } 147 153
+5
fs/bcachefs/bcachefs.h
··· 1214 1214 return timespec_to_bch2_time(c, now); 1215 1215 } 1216 1216 1217 + static inline u64 bch2_current_io_time(const struct bch_fs *c, int rw) 1218 + { 1219 + return max(1ULL, (u64) atomic64_read(&c->io_clock[rw].now) & LRU_TIME_MAX); 1220 + } 1221 + 1217 1222 static inline struct stdio_redirect *bch2_fs_stdio_redirect(struct bch_fs *c) 1218 1223 { 1219 1224 struct stdio_redirect *stdio = c->stdio;
+9 -4
fs/bcachefs/bcachefs_format.h
··· 476 476 477 477 #define LRU_ID_STRIPES (1U << 16) 478 478 479 + #define LRU_TIME_BITS 48 480 + #define LRU_TIME_MAX ((1ULL << LRU_TIME_BITS) - 1) 481 + 479 482 /* Optional/variable size superblock sections: */ 480 483 481 484 struct bch_sb_field { ··· 990 987 991 988 #define BCH_ERROR_ACTIONS() \ 992 989 x(continue, 0) \ 993 - x(ro, 1) \ 994 - x(panic, 2) 990 + x(fix_safe, 1) \ 991 + x(panic, 2) \ 992 + x(ro, 3) 995 993 996 994 enum bch_error_actions { 997 995 #define x(t, n) BCH_ON_ERROR_##t = n, ··· 1386 1382 1387 1383 /* 1388 1384 * Maximum number of btrees that we will _ever_ have under the current scheme, 1389 - * where we refer to them with bitfields 1385 + * where we refer to them with 64 bit bitfields - and we also need a bit for 1386 + * the interior btree node type: 1390 1387 */ 1391 - #define BTREE_ID_NR_MAX 64 1388 + #define BTREE_ID_NR_MAX 63 1392 1389 1393 1390 static inline bool btree_id_is_alloc(enum btree_id id) 1394 1391 {
+1 -1
fs/bcachefs/bkey.c
··· 1064 1064 { 1065 1065 const struct bkey_format *f = bkey_packed(k) ? _f : &bch2_bkey_format_current; 1066 1066 u8 *l = k->key_start; 1067 - u8 *h = (u8 *) (k->_data + f->key_u64s) - 1; 1067 + u8 *h = (u8 *) ((u64 *) k->_data + f->key_u64s) - 1; 1068 1068 1069 1069 while (l < h) { 1070 1070 swap(*l, *h);
+5 -1
fs/bcachefs/bkey_methods.c
··· 398 398 for (i = 0; i < nr_compat; i++) 399 399 switch (!write ? i : nr_compat - 1 - i) { 400 400 case 0: 401 - if (big_endian != CPU_BIG_ENDIAN) 401 + if (big_endian != CPU_BIG_ENDIAN) { 402 402 bch2_bkey_swab_key(f, k); 403 + } else if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) { 404 + bch2_bkey_swab_key(f, k); 405 + bch2_bkey_swab_key(f, k); 406 + } 403 407 break; 404 408 case 1: 405 409 if (version < bcachefs_metadata_version_bkey_renumber)
+2 -1
fs/bcachefs/bkey_methods.h
··· 129 129 struct bkey_packed *k) 130 130 { 131 131 if (version < bcachefs_metadata_version_current || 132 - big_endian != CPU_BIG_ENDIAN) 132 + big_endian != CPU_BIG_ENDIAN || 133 + IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) 133 134 __bch2_bkey_compat(level, btree_id, version, 134 135 big_endian, write, f, k); 135 136
+8 -3
fs/bcachefs/btree_iter.c
··· 3161 3161 list_add_done: 3162 3162 seqmutex_unlock(&c->btree_trans_lock); 3163 3163 got_trans: 3164 + trans->ref.closure_get_happened = false; 3164 3165 trans->c = c; 3165 3166 trans->last_begin_time = local_clock(); 3166 3167 trans->fn_idx = fn_idx; ··· 3236 3235 trans_for_each_update(trans, i) 3237 3236 __btree_path_put(trans->paths + i->path, true); 3238 3237 trans->nr_updates = 0; 3239 - trans->locking_wait.task = NULL; 3240 3238 3241 3239 check_btree_paths_leaked(trans); 3242 3240 ··· 3256 3256 if (unlikely(trans->journal_replay_not_finished)) 3257 3257 bch2_journal_keys_put(c); 3258 3258 3259 + /* 3260 + * trans->ref protects trans->locking_wait.task, btree_paths arary; used 3261 + * by cycle detector 3262 + */ 3263 + closure_sync(&trans->ref); 3264 + trans->locking_wait.task = NULL; 3265 + 3259 3266 unsigned long *paths_allocated = trans->paths_allocated; 3260 3267 trans->paths_allocated = NULL; 3261 3268 trans->paths = NULL; ··· 3280 3273 trans = this_cpu_xchg(c->btree_trans_bufs->trans, trans); 3281 3274 3282 3275 if (trans) { 3283 - closure_sync(&trans->ref); 3284 - 3285 3276 seqmutex_lock(&c->btree_trans_lock); 3286 3277 list_del(&trans->list); 3287 3278 seqmutex_unlock(&c->btree_trans_lock);
+8 -8
fs/bcachefs/btree_types.h
··· 761 761 762 762 static inline bool btree_node_type_is_extents(enum btree_node_type type) 763 763 { 764 - const unsigned mask = 0 764 + const u64 mask = 0 765 765 #define x(name, nr, flags, ...) |((!!((flags) & BTREE_ID_EXTENTS)) << (nr + 1)) 766 766 BCH_BTREE_IDS() 767 767 #undef x 768 768 ; 769 769 770 - return (1U << type) & mask; 770 + return BIT_ULL(type) & mask; 771 771 } 772 772 773 773 static inline bool btree_id_is_extents(enum btree_id btree) ··· 777 777 778 778 static inline bool btree_type_has_snapshots(enum btree_id id) 779 779 { 780 - const unsigned mask = 0 780 + const u64 mask = 0 781 781 #define x(name, nr, flags, ...) |((!!((flags) & BTREE_ID_SNAPSHOTS)) << nr) 782 782 BCH_BTREE_IDS() 783 783 #undef x 784 784 ; 785 785 786 - return (1U << id) & mask; 786 + return BIT_ULL(id) & mask; 787 787 } 788 788 789 789 static inline bool btree_type_has_snapshot_field(enum btree_id id) 790 790 { 791 - const unsigned mask = 0 791 + const u64 mask = 0 792 792 #define x(name, nr, flags, ...) |((!!((flags) & (BTREE_ID_SNAPSHOT_FIELD|BTREE_ID_SNAPSHOTS))) << nr) 793 793 BCH_BTREE_IDS() 794 794 #undef x 795 795 ; 796 796 797 - return (1U << id) & mask; 797 + return BIT_ULL(id) & mask; 798 798 } 799 799 800 800 static inline bool btree_type_has_ptrs(enum btree_id id) 801 801 { 802 - const unsigned mask = 0 802 + const u64 mask = 0 803 803 #define x(name, nr, flags, ...) |((!!((flags) & BTREE_ID_DATA)) << nr) 804 804 BCH_BTREE_IDS() 805 805 #undef x 806 806 ; 807 807 808 - return (1U << id) & mask; 808 + return BIT_ULL(id) & mask; 809 809 } 810 810 811 811 struct btree_root {
+3
fs/bcachefs/errcode.h
··· 116 116 x(ENOENT, ENOENT_dev_idx_not_found) \ 117 117 x(ENOTEMPTY, ENOTEMPTY_dir_not_empty) \ 118 118 x(ENOTEMPTY, ENOTEMPTY_subvol_not_empty) \ 119 + x(EEXIST, EEXIST_str_hash_set) \ 120 + x(EEXIST, EEXIST_discard_in_flight_add) \ 121 + x(EEXIST, EEXIST_subvolume_create) \ 119 122 x(0, open_buckets_empty) \ 120 123 x(0, freelist_empty) \ 121 124 x(BCH_ERR_freelist_empty, no_buckets_found) \
+18 -1
fs/bcachefs/error.c
··· 15 15 switch (c->opts.errors) { 16 16 case BCH_ON_ERROR_continue: 17 17 return false; 18 + case BCH_ON_ERROR_fix_safe: 18 19 case BCH_ON_ERROR_ro: 19 20 if (bch2_fs_emergency_read_only(c)) 20 21 bch_err(c, "inconsistency detected - emergency read only at journal seq %llu", ··· 192 191 prt_str(out, "ing"); 193 192 } 194 193 194 + static const u8 fsck_flags_extra[] = { 195 + #define x(t, n, flags) [BCH_FSCK_ERR_##t] = flags, 196 + BCH_SB_ERRS() 197 + #undef x 198 + }; 199 + 195 200 int bch2_fsck_err(struct bch_fs *c, 196 201 enum bch_fsck_flags flags, 197 202 enum bch_sb_error_id err, ··· 209 202 struct printbuf buf = PRINTBUF, *out = &buf; 210 203 int ret = -BCH_ERR_fsck_ignore; 211 204 const char *action_orig = "fix?", *action = action_orig; 205 + 206 + if (!WARN_ON(err >= ARRAY_SIZE(fsck_flags_extra))) 207 + flags |= fsck_flags_extra[err]; 212 208 213 209 if ((flags & FSCK_CAN_FIX) && 214 210 test_bit(err, c->sb.errors_silent)) ··· 275 265 prt_printf(out, bch2_log_msg(c, "")); 276 266 #endif 277 267 278 - if (!test_bit(BCH_FS_fsck_running, &c->flags)) { 268 + if ((flags & FSCK_CAN_FIX) && 269 + (flags & FSCK_AUTOFIX) && 270 + (c->opts.errors == BCH_ON_ERROR_continue || 271 + c->opts.errors == BCH_ON_ERROR_fix_safe)) { 272 + prt_str(out, ", "); 273 + prt_actioning(out, action); 274 + ret = -BCH_ERR_fsck_fix; 275 + } else if (!test_bit(BCH_FS_fsck_running, &c->flags)) { 279 276 if (c->opts.errors != BCH_ON_ERROR_continue || 280 277 !(flags & (FSCK_CAN_FIX|FSCK_CAN_IGNORE))) { 281 278 prt_str(out, ", shutting down");
-7
fs/bcachefs/error.h
··· 108 108 char *last_msg; 109 109 }; 110 110 111 - enum bch_fsck_flags { 112 - FSCK_CAN_FIX = 1 << 0, 113 - FSCK_CAN_IGNORE = 1 << 1, 114 - FSCK_NEED_FSCK = 1 << 2, 115 - FSCK_NO_RATELIMIT = 1 << 3, 116 - }; 117 - 118 111 #define fsck_err_count(_c, _err) bch2_sb_err_count(_c, BCH_FSCK_ERR_##_err) 119 112 120 113 __printf(4, 5) __cold
+1 -1
fs/bcachefs/fs-ioctl.c
··· 373 373 } 374 374 375 375 if (dst_dentry->d_inode) { 376 - error = -EEXIST; 376 + error = -BCH_ERR_EEXIST_subvolume_create; 377 377 goto err3; 378 378 } 379 379
+14 -7
fs/bcachefs/fs.c
··· 188 188 BUG_ON(!old); 189 189 190 190 if (unlikely(old != inode)) { 191 + /* 192 + * bcachefs doesn't use I_NEW; we have no use for it since we 193 + * only insert fully created inodes in the inode hash table. But 194 + * discard_new_inode() expects it to be set... 195 + */ 196 + inode->v.i_flags |= I_NEW; 191 197 discard_new_inode(&inode->v); 192 198 inode = old; 193 199 } else { ··· 201 195 list_add(&inode->ei_vfs_inode_list, &c->vfs_inodes_list); 202 196 mutex_unlock(&c->vfs_inodes_lock); 203 197 /* 204 - * we really don't want insert_inode_locked2() to be setting 205 - * I_NEW... 198 + * Again, I_NEW makes no sense for bcachefs. This is only needed 199 + * for clearing I_NEW, but since the inode was already fully 200 + * created and initialized we didn't actually want 201 + * inode_insert5() to set it for us. 206 202 */ 207 203 unlock_new_inode(&inode->v); 208 204 } ··· 1165 1157 .read_iter = bch2_read_iter, 1166 1158 .write_iter = bch2_write_iter, 1167 1159 .mmap = bch2_mmap, 1160 + .get_unmapped_area = thp_get_unmapped_area, 1168 1161 .fsync = bch2_fsync, 1169 1162 .splice_read = filemap_splice_read, 1170 1163 .splice_write = iter_file_splice_write, ··· 1497 1488 bch2_iget5_set(&inode->v, &inum); 1498 1489 bch2_inode_update_after_write(trans, inode, bi, ~0); 1499 1490 1500 - if (BCH_SUBVOLUME_SNAP(subvol)) 1501 - set_bit(EI_INODE_SNAPSHOT, &inode->ei_flags); 1502 - else 1503 - clear_bit(EI_INODE_SNAPSHOT, &inode->ei_flags); 1504 - 1505 1491 inode->v.i_blocks = bi->bi_sectors; 1506 1492 inode->v.i_ino = bi->bi_inum; 1507 1493 inode->v.i_rdev = bi->bi_dev; ··· 1507 1503 inode->ei_quota_reserved = 0; 1508 1504 inode->ei_qid = bch_qid(bi); 1509 1505 inode->ei_subvol = inum.subvol; 1506 + 1507 + if (BCH_SUBVOLUME_SNAP(subvol)) 1508 + set_bit(EI_INODE_SNAPSHOT, &inode->ei_flags); 1510 1509 1511 1510 inode->v.i_mapping->a_ops = &bch_address_space_operations; 1512 1511
+3
fs/bcachefs/journal.c
··· 1167 1167 1168 1168 void bch2_fs_journal_stop(struct journal *j) 1169 1169 { 1170 + if (!test_bit(JOURNAL_running, &j->flags)) 1171 + return; 1172 + 1170 1173 bch2_journal_reclaim_stop(j); 1171 1174 bch2_journal_flush_all_pins(j); 1172 1175
+8 -5
fs/bcachefs/journal_io.c
··· 1967 1967 struct journal *j = container_of(w, struct journal, buf[w->idx]); 1968 1968 struct bch_fs *c = container_of(j, struct bch_fs, journal); 1969 1969 struct bch_replicas_padded replicas; 1970 - struct printbuf journal_debug_buf = PRINTBUF; 1971 1970 unsigned nr_rw_members = 0; 1972 1971 int ret; 1973 1972 ··· 2010 2011 } 2011 2012 2012 2013 if (ret) { 2013 - __bch2_journal_debug_to_text(&journal_debug_buf, j); 2014 + struct printbuf buf = PRINTBUF; 2015 + buf.atomic++; 2016 + 2017 + prt_printf(&buf, bch2_fmt(c, "Unable to allocate journal write: %s"), 2018 + bch2_err_str(ret)); 2019 + __bch2_journal_debug_to_text(&buf, j); 2014 2020 spin_unlock(&j->lock); 2015 - bch_err(c, "Unable to allocate journal write:\n%s", 2016 - journal_debug_buf.buf); 2017 - printbuf_exit(&journal_debug_buf); 2021 + bch2_print_string_as_lines(KERN_ERR, buf.buf); 2022 + printbuf_exit(&buf); 2018 2023 goto err; 2019 2024 } 2020 2025
-3
fs/bcachefs/lru.h
··· 2 2 #ifndef _BCACHEFS_LRU_H 3 3 #define _BCACHEFS_LRU_H 4 4 5 - #define LRU_TIME_BITS 48 6 - #define LRU_TIME_MAX ((1ULL << LRU_TIME_BITS) - 1) 7 - 8 5 static inline u64 lru_pos_id(struct bpos pos) 9 6 { 10 7 return pos.inode >> LRU_TIME_BITS;
+1 -1
fs/bcachefs/opts.h
··· 137 137 x(errors, u8, \ 138 138 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ 139 139 OPT_STR(bch2_error_actions), \ 140 - BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \ 140 + BCH_SB_ERROR_ACTION, BCH_ON_ERROR_fix_safe, \ 141 141 NULL, "Action to take on filesystem error") \ 142 142 x(metadata_replicas, u8, \ 143 143 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
+9 -3
fs/bcachefs/recovery.c
··· 326 326 case BCH_JSET_ENTRY_btree_root: { 327 327 struct btree_root *r; 328 328 329 + if (fsck_err_on(entry->btree_id >= BTREE_ID_NR_MAX, 330 + c, invalid_btree_id, 331 + "invalid btree id %u (max %u)", 332 + entry->btree_id, BTREE_ID_NR_MAX)) 333 + return 0; 334 + 329 335 while (entry->btree_id >= c->btree_roots_extra.nr + BTREE_ID_NR) { 330 336 ret = darray_push(&c->btree_roots_extra, (struct btree_root) { NULL }); 331 337 if (ret) ··· 421 415 atomic64_set(&c->io_clock[clock->rw].now, le64_to_cpu(clock->time)); 422 416 } 423 417 } 424 - 418 + fsck_err: 425 419 return ret; 426 420 } 427 421 ··· 664 658 if (check_version_upgrade(c)) 665 659 write_sb = true; 666 660 661 + c->recovery_passes_explicit |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0])); 662 + 667 663 if (write_sb) 668 664 bch2_write_super(c); 669 - 670 - c->recovery_passes_explicit |= bch2_recovery_passes_from_stable(le64_to_cpu(ext->recovery_passes_required[0])); 671 665 mutex_unlock(&c->sb_lock); 672 666 673 667 if (c->opts.fsck && IS_ENABLED(CONFIG_BCACHEFS_DEBUG))
+1 -1
fs/bcachefs/sb-downgrade.c
··· 228 228 229 229 dst = (void *) &darray_top(table); 230 230 dst->version = cpu_to_le16(src->version); 231 - dst->recovery_passes[0] = cpu_to_le64(src->recovery_passes); 231 + dst->recovery_passes[0] = cpu_to_le64(bch2_recovery_passes_to_stable(src->recovery_passes)); 232 232 dst->recovery_passes[1] = 0; 233 233 dst->nr_errors = cpu_to_le16(src->nr_errors); 234 234 for (unsigned i = 0; i < src->nr_errors; i++)
+286 -273
fs/bcachefs/sb-errors_format.h
··· 2 2 #ifndef _BCACHEFS_SB_ERRORS_FORMAT_H 3 3 #define _BCACHEFS_SB_ERRORS_FORMAT_H 4 4 5 - #define BCH_SB_ERRS() \ 6 - x(clean_but_journal_not_empty, 0) \ 7 - x(dirty_but_no_journal_entries, 1) \ 8 - x(dirty_but_no_journal_entries_post_drop_nonflushes, 2) \ 9 - x(sb_clean_journal_seq_mismatch, 3) \ 10 - x(sb_clean_btree_root_mismatch, 4) \ 11 - x(sb_clean_missing, 5) \ 12 - x(jset_unsupported_version, 6) \ 13 - x(jset_unknown_csum, 7) \ 14 - x(jset_last_seq_newer_than_seq, 8) \ 15 - x(jset_past_bucket_end, 9) \ 16 - x(jset_seq_blacklisted, 10) \ 17 - x(journal_entries_missing, 11) \ 18 - x(journal_entry_replicas_not_marked, 12) \ 19 - x(journal_entry_past_jset_end, 13) \ 20 - x(journal_entry_replicas_data_mismatch, 14) \ 21 - x(journal_entry_bkey_u64s_0, 15) \ 22 - x(journal_entry_bkey_past_end, 16) \ 23 - x(journal_entry_bkey_bad_format, 17) \ 24 - x(journal_entry_bkey_invalid, 18) \ 25 - x(journal_entry_btree_root_bad_size, 19) \ 26 - x(journal_entry_blacklist_bad_size, 20) \ 27 - x(journal_entry_blacklist_v2_bad_size, 21) \ 28 - x(journal_entry_blacklist_v2_start_past_end, 22) \ 29 - x(journal_entry_usage_bad_size, 23) \ 30 - x(journal_entry_data_usage_bad_size, 24) \ 31 - x(journal_entry_clock_bad_size, 25) \ 32 - x(journal_entry_clock_bad_rw, 26) \ 33 - x(journal_entry_dev_usage_bad_size, 27) \ 34 - x(journal_entry_dev_usage_bad_dev, 28) \ 35 - x(journal_entry_dev_usage_bad_pad, 29) \ 36 - x(btree_node_unreadable, 30) \ 37 - x(btree_node_fault_injected, 31) \ 38 - x(btree_node_bad_magic, 32) \ 39 - x(btree_node_bad_seq, 33) \ 40 - x(btree_node_unsupported_version, 34) \ 41 - x(btree_node_bset_older_than_sb_min, 35) \ 42 - x(btree_node_bset_newer_than_sb, 36) \ 43 - x(btree_node_data_missing, 37) \ 44 - x(btree_node_bset_after_end, 38) \ 45 - x(btree_node_replicas_sectors_written_mismatch, 39) \ 46 - x(btree_node_replicas_data_mismatch, 40) \ 47 - x(bset_unknown_csum, 41) \ 48 - x(bset_bad_csum, 42) \ 49 - x(bset_past_end_of_btree_node, 43) \ 50 - x(bset_wrong_sector_offset, 44) \ 51 - x(bset_empty, 45) \ 52 - x(bset_bad_seq, 46) \ 53 - x(bset_blacklisted_journal_seq, 47) \ 54 - x(first_bset_blacklisted_journal_seq, 48) \ 55 - x(btree_node_bad_btree, 49) \ 56 - x(btree_node_bad_level, 50) \ 57 - x(btree_node_bad_min_key, 51) \ 58 - x(btree_node_bad_max_key, 52) \ 59 - x(btree_node_bad_format, 53) \ 60 - x(btree_node_bkey_past_bset_end, 54) \ 61 - x(btree_node_bkey_bad_format, 55) \ 62 - x(btree_node_bad_bkey, 56) \ 63 - x(btree_node_bkey_out_of_order, 57) \ 64 - x(btree_root_bkey_invalid, 58) \ 65 - x(btree_root_read_error, 59) \ 66 - x(btree_root_bad_min_key, 60) \ 67 - x(btree_root_bad_max_key, 61) \ 68 - x(btree_node_read_error, 62) \ 69 - x(btree_node_topology_bad_min_key, 63) \ 70 - x(btree_node_topology_bad_max_key, 64) \ 71 - x(btree_node_topology_overwritten_by_prev_node, 65) \ 72 - x(btree_node_topology_overwritten_by_next_node, 66) \ 73 - x(btree_node_topology_interior_node_empty, 67) \ 74 - x(fs_usage_hidden_wrong, 68) \ 75 - x(fs_usage_btree_wrong, 69) \ 76 - x(fs_usage_data_wrong, 70) \ 77 - x(fs_usage_cached_wrong, 71) \ 78 - x(fs_usage_reserved_wrong, 72) \ 79 - x(fs_usage_persistent_reserved_wrong, 73) \ 80 - x(fs_usage_nr_inodes_wrong, 74) \ 81 - x(fs_usage_replicas_wrong, 75) \ 82 - x(dev_usage_buckets_wrong, 76) \ 83 - x(dev_usage_sectors_wrong, 77) \ 84 - x(dev_usage_fragmented_wrong, 78) \ 85 - x(dev_usage_buckets_ec_wrong, 79) \ 86 - x(bkey_version_in_future, 80) \ 87 - x(bkey_u64s_too_small, 81) \ 88 - x(bkey_invalid_type_for_btree, 82) \ 89 - x(bkey_extent_size_zero, 83) \ 90 - x(bkey_extent_size_greater_than_offset, 84) \ 91 - x(bkey_size_nonzero, 85) \ 92 - x(bkey_snapshot_nonzero, 86) \ 93 - x(bkey_snapshot_zero, 87) \ 94 - x(bkey_at_pos_max, 88) \ 95 - x(bkey_before_start_of_btree_node, 89) \ 96 - x(bkey_after_end_of_btree_node, 90) \ 97 - x(bkey_val_size_nonzero, 91) \ 98 - x(bkey_val_size_too_small, 92) \ 99 - x(alloc_v1_val_size_bad, 93) \ 100 - x(alloc_v2_unpack_error, 94) \ 101 - x(alloc_v3_unpack_error, 95) \ 102 - x(alloc_v4_val_size_bad, 96) \ 103 - x(alloc_v4_backpointers_start_bad, 97) \ 104 - x(alloc_key_data_type_bad, 98) \ 105 - x(alloc_key_empty_but_have_data, 99) \ 106 - x(alloc_key_dirty_sectors_0, 100) \ 107 - x(alloc_key_data_type_inconsistency, 101) \ 108 - x(alloc_key_to_missing_dev_bucket, 102) \ 109 - x(alloc_key_cached_inconsistency, 103) \ 110 - x(alloc_key_cached_but_read_time_zero, 104) \ 111 - x(alloc_key_to_missing_lru_entry, 105) \ 112 - x(alloc_key_data_type_wrong, 106) \ 113 - x(alloc_key_gen_wrong, 107) \ 114 - x(alloc_key_dirty_sectors_wrong, 108) \ 115 - x(alloc_key_cached_sectors_wrong, 109) \ 116 - x(alloc_key_stripe_wrong, 110) \ 117 - x(alloc_key_stripe_redundancy_wrong, 111) \ 118 - x(bucket_sector_count_overflow, 112) \ 119 - x(bucket_metadata_type_mismatch, 113) \ 120 - x(need_discard_key_wrong, 114) \ 121 - x(freespace_key_wrong, 115) \ 122 - x(freespace_hole_missing, 116) \ 123 - x(bucket_gens_val_size_bad, 117) \ 124 - x(bucket_gens_key_wrong, 118) \ 125 - x(bucket_gens_hole_wrong, 119) \ 126 - x(bucket_gens_to_invalid_dev, 120) \ 127 - x(bucket_gens_to_invalid_buckets, 121) \ 128 - x(bucket_gens_nonzero_for_invalid_buckets, 122) \ 129 - x(need_discard_freespace_key_to_invalid_dev_bucket, 123) \ 130 - x(need_discard_freespace_key_bad, 124) \ 131 - x(backpointer_bucket_offset_wrong, 125) \ 132 - x(backpointer_to_missing_device, 126) \ 133 - x(backpointer_to_missing_alloc, 127) \ 134 - x(backpointer_to_missing_ptr, 128) \ 135 - x(lru_entry_at_time_0, 129) \ 136 - x(lru_entry_to_invalid_bucket, 130) \ 137 - x(lru_entry_bad, 131) \ 138 - x(btree_ptr_val_too_big, 132) \ 139 - x(btree_ptr_v2_val_too_big, 133) \ 140 - x(btree_ptr_has_non_ptr, 134) \ 141 - x(extent_ptrs_invalid_entry, 135) \ 142 - x(extent_ptrs_no_ptrs, 136) \ 143 - x(extent_ptrs_too_many_ptrs, 137) \ 144 - x(extent_ptrs_redundant_crc, 138) \ 145 - x(extent_ptrs_redundant_stripe, 139) \ 146 - x(extent_ptrs_unwritten, 140) \ 147 - x(extent_ptrs_written_and_unwritten, 141) \ 148 - x(ptr_to_invalid_device, 142) \ 149 - x(ptr_to_duplicate_device, 143) \ 150 - x(ptr_after_last_bucket, 144) \ 151 - x(ptr_before_first_bucket, 145) \ 152 - x(ptr_spans_multiple_buckets, 146) \ 153 - x(ptr_to_missing_backpointer, 147) \ 154 - x(ptr_to_missing_alloc_key, 148) \ 155 - x(ptr_to_missing_replicas_entry, 149) \ 156 - x(ptr_to_missing_stripe, 150) \ 157 - x(ptr_to_incorrect_stripe, 151) \ 158 - x(ptr_gen_newer_than_bucket_gen, 152) \ 159 - x(ptr_too_stale, 153) \ 160 - x(stale_dirty_ptr, 154) \ 161 - x(ptr_bucket_data_type_mismatch, 155) \ 162 - x(ptr_cached_and_erasure_coded, 156) \ 163 - x(ptr_crc_uncompressed_size_too_small, 157) \ 164 - x(ptr_crc_csum_type_unknown, 158) \ 165 - x(ptr_crc_compression_type_unknown, 159) \ 166 - x(ptr_crc_redundant, 160) \ 167 - x(ptr_crc_uncompressed_size_too_big, 161) \ 168 - x(ptr_crc_nonce_mismatch, 162) \ 169 - x(ptr_stripe_redundant, 163) \ 170 - x(reservation_key_nr_replicas_invalid, 164) \ 171 - x(reflink_v_refcount_wrong, 165) \ 172 - x(reflink_p_to_missing_reflink_v, 166) \ 173 - x(stripe_pos_bad, 167) \ 174 - x(stripe_val_size_bad, 168) \ 175 - x(stripe_sector_count_wrong, 169) \ 176 - x(snapshot_tree_pos_bad, 170) \ 177 - x(snapshot_tree_to_missing_snapshot, 171) \ 178 - x(snapshot_tree_to_missing_subvol, 172) \ 179 - x(snapshot_tree_to_wrong_subvol, 173) \ 180 - x(snapshot_tree_to_snapshot_subvol, 174) \ 181 - x(snapshot_pos_bad, 175) \ 182 - x(snapshot_parent_bad, 176) \ 183 - x(snapshot_children_not_normalized, 177) \ 184 - x(snapshot_child_duplicate, 178) \ 185 - x(snapshot_child_bad, 179) \ 186 - x(snapshot_skiplist_not_normalized, 180) \ 187 - x(snapshot_skiplist_bad, 181) \ 188 - x(snapshot_should_not_have_subvol, 182) \ 189 - x(snapshot_to_bad_snapshot_tree, 183) \ 190 - x(snapshot_bad_depth, 184) \ 191 - x(snapshot_bad_skiplist, 185) \ 192 - x(subvol_pos_bad, 186) \ 193 - x(subvol_not_master_and_not_snapshot, 187) \ 194 - x(subvol_to_missing_root, 188) \ 195 - x(subvol_root_wrong_bi_subvol, 189) \ 196 - x(bkey_in_missing_snapshot, 190) \ 197 - x(inode_pos_inode_nonzero, 191) \ 198 - x(inode_pos_blockdev_range, 192) \ 199 - x(inode_unpack_error, 193) \ 200 - x(inode_str_hash_invalid, 194) \ 201 - x(inode_v3_fields_start_bad, 195) \ 202 - x(inode_snapshot_mismatch, 196) \ 203 - x(inode_unlinked_but_clean, 197) \ 204 - x(inode_unlinked_but_nlink_nonzero, 198) \ 205 - x(inode_checksum_type_invalid, 199) \ 206 - x(inode_compression_type_invalid, 200) \ 207 - x(inode_subvol_root_but_not_dir, 201) \ 208 - x(inode_i_size_dirty_but_clean, 202) \ 209 - x(inode_i_sectors_dirty_but_clean, 203) \ 210 - x(inode_i_sectors_wrong, 204) \ 211 - x(inode_dir_wrong_nlink, 205) \ 212 - x(inode_dir_multiple_links, 206) \ 213 - x(inode_multiple_links_but_nlink_0, 207) \ 214 - x(inode_wrong_backpointer, 208) \ 215 - x(inode_wrong_nlink, 209) \ 216 - x(inode_unreachable, 210) \ 217 - x(deleted_inode_but_clean, 211) \ 218 - x(deleted_inode_missing, 212) \ 219 - x(deleted_inode_is_dir, 213) \ 220 - x(deleted_inode_not_unlinked, 214) \ 221 - x(extent_overlapping, 215) \ 222 - x(extent_in_missing_inode, 216) \ 223 - x(extent_in_non_reg_inode, 217) \ 224 - x(extent_past_end_of_inode, 218) \ 225 - x(dirent_empty_name, 219) \ 226 - x(dirent_val_too_big, 220) \ 227 - x(dirent_name_too_long, 221) \ 228 - x(dirent_name_embedded_nul, 222) \ 229 - x(dirent_name_dot_or_dotdot, 223) \ 230 - x(dirent_name_has_slash, 224) \ 231 - x(dirent_d_type_wrong, 225) \ 232 - x(inode_bi_parent_wrong, 226) \ 233 - x(dirent_in_missing_dir_inode, 227) \ 234 - x(dirent_in_non_dir_inode, 228) \ 235 - x(dirent_to_missing_inode, 229) \ 236 - x(dirent_to_missing_subvol, 230) \ 237 - x(dirent_to_itself, 231) \ 238 - x(quota_type_invalid, 232) \ 239 - x(xattr_val_size_too_small, 233) \ 240 - x(xattr_val_size_too_big, 234) \ 241 - x(xattr_invalid_type, 235) \ 242 - x(xattr_name_invalid_chars, 236) \ 243 - x(xattr_in_missing_inode, 237) \ 244 - x(root_subvol_missing, 238) \ 245 - x(root_dir_missing, 239) \ 246 - x(root_inode_not_dir, 240) \ 247 - x(dir_loop, 241) \ 248 - x(hash_table_key_duplicate, 242) \ 249 - x(hash_table_key_wrong_offset, 243) \ 250 - x(unlinked_inode_not_on_deleted_list, 244) \ 251 - x(reflink_p_front_pad_bad, 245) \ 252 - x(journal_entry_dup_same_device, 246) \ 253 - x(inode_bi_subvol_missing, 247) \ 254 - x(inode_bi_subvol_wrong, 248) \ 255 - x(inode_points_to_missing_dirent, 249) \ 256 - x(inode_points_to_wrong_dirent, 250) \ 257 - x(inode_bi_parent_nonzero, 251) \ 258 - x(dirent_to_missing_parent_subvol, 252) \ 259 - x(dirent_not_visible_in_parent_subvol, 253) \ 260 - x(subvol_fs_path_parent_wrong, 254) \ 261 - x(subvol_root_fs_path_parent_nonzero, 255) \ 262 - x(subvol_children_not_set, 256) \ 263 - x(subvol_children_bad, 257) \ 264 - x(subvol_loop, 258) \ 265 - x(subvol_unreachable, 259) \ 266 - x(btree_node_bkey_bad_u64s, 260) \ 267 - x(btree_node_topology_empty_interior_node, 261) \ 268 - x(btree_ptr_v2_min_key_bad, 262) \ 269 - x(btree_root_unreadable_and_scan_found_nothing, 263) \ 270 - x(snapshot_node_missing, 264) \ 271 - x(dup_backpointer_to_bad_csum_extent, 265) \ 272 - x(btree_bitmap_not_marked, 266) \ 273 - x(sb_clean_entry_overrun, 267) \ 274 - x(btree_ptr_v2_written_0, 268) \ 275 - x(subvol_snapshot_bad, 269) \ 276 - x(subvol_inode_bad, 270) 5 + enum bch_fsck_flags { 6 + FSCK_CAN_FIX = 1 << 0, 7 + FSCK_CAN_IGNORE = 1 << 1, 8 + FSCK_NEED_FSCK = 1 << 2, 9 + FSCK_NO_RATELIMIT = 1 << 3, 10 + FSCK_AUTOFIX = 1 << 4, 11 + }; 12 + 13 + #define BCH_SB_ERRS() \ 14 + x(clean_but_journal_not_empty, 0, 0) \ 15 + x(dirty_but_no_journal_entries, 1, 0) \ 16 + x(dirty_but_no_journal_entries_post_drop_nonflushes, 2, 0) \ 17 + x(sb_clean_journal_seq_mismatch, 3, 0) \ 18 + x(sb_clean_btree_root_mismatch, 4, 0) \ 19 + x(sb_clean_missing, 5, 0) \ 20 + x(jset_unsupported_version, 6, 0) \ 21 + x(jset_unknown_csum, 7, 0) \ 22 + x(jset_last_seq_newer_than_seq, 8, 0) \ 23 + x(jset_past_bucket_end, 9, 0) \ 24 + x(jset_seq_blacklisted, 10, 0) \ 25 + x(journal_entries_missing, 11, 0) \ 26 + x(journal_entry_replicas_not_marked, 12, 0) \ 27 + x(journal_entry_past_jset_end, 13, 0) \ 28 + x(journal_entry_replicas_data_mismatch, 14, 0) \ 29 + x(journal_entry_bkey_u64s_0, 15, 0) \ 30 + x(journal_entry_bkey_past_end, 16, 0) \ 31 + x(journal_entry_bkey_bad_format, 17, 0) \ 32 + x(journal_entry_bkey_invalid, 18, 0) \ 33 + x(journal_entry_btree_root_bad_size, 19, 0) \ 34 + x(journal_entry_blacklist_bad_size, 20, 0) \ 35 + x(journal_entry_blacklist_v2_bad_size, 21, 0) \ 36 + x(journal_entry_blacklist_v2_start_past_end, 22, 0) \ 37 + x(journal_entry_usage_bad_size, 23, 0) \ 38 + x(journal_entry_data_usage_bad_size, 24, 0) \ 39 + x(journal_entry_clock_bad_size, 25, 0) \ 40 + x(journal_entry_clock_bad_rw, 26, 0) \ 41 + x(journal_entry_dev_usage_bad_size, 27, 0) \ 42 + x(journal_entry_dev_usage_bad_dev, 28, 0) \ 43 + x(journal_entry_dev_usage_bad_pad, 29, 0) \ 44 + x(btree_node_unreadable, 30, 0) \ 45 + x(btree_node_fault_injected, 31, 0) \ 46 + x(btree_node_bad_magic, 32, 0) \ 47 + x(btree_node_bad_seq, 33, 0) \ 48 + x(btree_node_unsupported_version, 34, 0) \ 49 + x(btree_node_bset_older_than_sb_min, 35, 0) \ 50 + x(btree_node_bset_newer_than_sb, 36, 0) \ 51 + x(btree_node_data_missing, 37, 0) \ 52 + x(btree_node_bset_after_end, 38, 0) \ 53 + x(btree_node_replicas_sectors_written_mismatch, 39, 0) \ 54 + x(btree_node_replicas_data_mismatch, 40, 0) \ 55 + x(bset_unknown_csum, 41, 0) \ 56 + x(bset_bad_csum, 42, 0) \ 57 + x(bset_past_end_of_btree_node, 43, 0) \ 58 + x(bset_wrong_sector_offset, 44, 0) \ 59 + x(bset_empty, 45, 0) \ 60 + x(bset_bad_seq, 46, 0) \ 61 + x(bset_blacklisted_journal_seq, 47, 0) \ 62 + x(first_bset_blacklisted_journal_seq, 48, 0) \ 63 + x(btree_node_bad_btree, 49, 0) \ 64 + x(btree_node_bad_level, 50, 0) \ 65 + x(btree_node_bad_min_key, 51, 0) \ 66 + x(btree_node_bad_max_key, 52, 0) \ 67 + x(btree_node_bad_format, 53, 0) \ 68 + x(btree_node_bkey_past_bset_end, 54, 0) \ 69 + x(btree_node_bkey_bad_format, 55, 0) \ 70 + x(btree_node_bad_bkey, 56, 0) \ 71 + x(btree_node_bkey_out_of_order, 57, 0) \ 72 + x(btree_root_bkey_invalid, 58, 0) \ 73 + x(btree_root_read_error, 59, 0) \ 74 + x(btree_root_bad_min_key, 60, 0) \ 75 + x(btree_root_bad_max_key, 61, 0) \ 76 + x(btree_node_read_error, 62, 0) \ 77 + x(btree_node_topology_bad_min_key, 63, 0) \ 78 + x(btree_node_topology_bad_max_key, 64, 0) \ 79 + x(btree_node_topology_overwritten_by_prev_node, 65, 0) \ 80 + x(btree_node_topology_overwritten_by_next_node, 66, 0) \ 81 + x(btree_node_topology_interior_node_empty, 67, 0) \ 82 + x(fs_usage_hidden_wrong, 68, FSCK_AUTOFIX) \ 83 + x(fs_usage_btree_wrong, 69, FSCK_AUTOFIX) \ 84 + x(fs_usage_data_wrong, 70, FSCK_AUTOFIX) \ 85 + x(fs_usage_cached_wrong, 71, FSCK_AUTOFIX) \ 86 + x(fs_usage_reserved_wrong, 72, FSCK_AUTOFIX) \ 87 + x(fs_usage_persistent_reserved_wrong, 73, FSCK_AUTOFIX) \ 88 + x(fs_usage_nr_inodes_wrong, 74, FSCK_AUTOFIX) \ 89 + x(fs_usage_replicas_wrong, 75, FSCK_AUTOFIX) \ 90 + x(dev_usage_buckets_wrong, 76, FSCK_AUTOFIX) \ 91 + x(dev_usage_sectors_wrong, 77, FSCK_AUTOFIX) \ 92 + x(dev_usage_fragmented_wrong, 78, FSCK_AUTOFIX) \ 93 + x(dev_usage_buckets_ec_wrong, 79, FSCK_AUTOFIX) \ 94 + x(bkey_version_in_future, 80, 0) \ 95 + x(bkey_u64s_too_small, 81, 0) \ 96 + x(bkey_invalid_type_for_btree, 82, 0) \ 97 + x(bkey_extent_size_zero, 83, 0) \ 98 + x(bkey_extent_size_greater_than_offset, 84, 0) \ 99 + x(bkey_size_nonzero, 85, 0) \ 100 + x(bkey_snapshot_nonzero, 86, 0) \ 101 + x(bkey_snapshot_zero, 87, 0) \ 102 + x(bkey_at_pos_max, 88, 0) \ 103 + x(bkey_before_start_of_btree_node, 89, 0) \ 104 + x(bkey_after_end_of_btree_node, 90, 0) \ 105 + x(bkey_val_size_nonzero, 91, 0) \ 106 + x(bkey_val_size_too_small, 92, 0) \ 107 + x(alloc_v1_val_size_bad, 93, 0) \ 108 + x(alloc_v2_unpack_error, 94, 0) \ 109 + x(alloc_v3_unpack_error, 95, 0) \ 110 + x(alloc_v4_val_size_bad, 96, 0) \ 111 + x(alloc_v4_backpointers_start_bad, 97, 0) \ 112 + x(alloc_key_data_type_bad, 98, 0) \ 113 + x(alloc_key_empty_but_have_data, 99, 0) \ 114 + x(alloc_key_dirty_sectors_0, 100, 0) \ 115 + x(alloc_key_data_type_inconsistency, 101, 0) \ 116 + x(alloc_key_to_missing_dev_bucket, 102, 0) \ 117 + x(alloc_key_cached_inconsistency, 103, 0) \ 118 + x(alloc_key_cached_but_read_time_zero, 104, 0) \ 119 + x(alloc_key_to_missing_lru_entry, 105, 0) \ 120 + x(alloc_key_data_type_wrong, 106, FSCK_AUTOFIX) \ 121 + x(alloc_key_gen_wrong, 107, FSCK_AUTOFIX) \ 122 + x(alloc_key_dirty_sectors_wrong, 108, FSCK_AUTOFIX) \ 123 + x(alloc_key_cached_sectors_wrong, 109, FSCK_AUTOFIX) \ 124 + x(alloc_key_stripe_wrong, 110, FSCK_AUTOFIX) \ 125 + x(alloc_key_stripe_redundancy_wrong, 111, FSCK_AUTOFIX) \ 126 + x(bucket_sector_count_overflow, 112, 0) \ 127 + x(bucket_metadata_type_mismatch, 113, 0) \ 128 + x(need_discard_key_wrong, 114, 0) \ 129 + x(freespace_key_wrong, 115, 0) \ 130 + x(freespace_hole_missing, 116, 0) \ 131 + x(bucket_gens_val_size_bad, 117, 0) \ 132 + x(bucket_gens_key_wrong, 118, 0) \ 133 + x(bucket_gens_hole_wrong, 119, 0) \ 134 + x(bucket_gens_to_invalid_dev, 120, 0) \ 135 + x(bucket_gens_to_invalid_buckets, 121, 0) \ 136 + x(bucket_gens_nonzero_for_invalid_buckets, 122, 0) \ 137 + x(need_discard_freespace_key_to_invalid_dev_bucket, 123, 0) \ 138 + x(need_discard_freespace_key_bad, 124, 0) \ 139 + x(backpointer_bucket_offset_wrong, 125, 0) \ 140 + x(backpointer_to_missing_device, 126, 0) \ 141 + x(backpointer_to_missing_alloc, 127, 0) \ 142 + x(backpointer_to_missing_ptr, 128, 0) \ 143 + x(lru_entry_at_time_0, 129, 0) \ 144 + x(lru_entry_to_invalid_bucket, 130, 0) \ 145 + x(lru_entry_bad, 131, 0) \ 146 + x(btree_ptr_val_too_big, 132, 0) \ 147 + x(btree_ptr_v2_val_too_big, 133, 0) \ 148 + x(btree_ptr_has_non_ptr, 134, 0) \ 149 + x(extent_ptrs_invalid_entry, 135, 0) \ 150 + x(extent_ptrs_no_ptrs, 136, 0) \ 151 + x(extent_ptrs_too_many_ptrs, 137, 0) \ 152 + x(extent_ptrs_redundant_crc, 138, 0) \ 153 + x(extent_ptrs_redundant_stripe, 139, 0) \ 154 + x(extent_ptrs_unwritten, 140, 0) \ 155 + x(extent_ptrs_written_and_unwritten, 141, 0) \ 156 + x(ptr_to_invalid_device, 142, 0) \ 157 + x(ptr_to_duplicate_device, 143, 0) \ 158 + x(ptr_after_last_bucket, 144, 0) \ 159 + x(ptr_before_first_bucket, 145, 0) \ 160 + x(ptr_spans_multiple_buckets, 146, 0) \ 161 + x(ptr_to_missing_backpointer, 147, 0) \ 162 + x(ptr_to_missing_alloc_key, 148, 0) \ 163 + x(ptr_to_missing_replicas_entry, 149, 0) \ 164 + x(ptr_to_missing_stripe, 150, 0) \ 165 + x(ptr_to_incorrect_stripe, 151, 0) \ 166 + x(ptr_gen_newer_than_bucket_gen, 152, 0) \ 167 + x(ptr_too_stale, 153, 0) \ 168 + x(stale_dirty_ptr, 154, 0) \ 169 + x(ptr_bucket_data_type_mismatch, 155, 0) \ 170 + x(ptr_cached_and_erasure_coded, 156, 0) \ 171 + x(ptr_crc_uncompressed_size_too_small, 157, 0) \ 172 + x(ptr_crc_csum_type_unknown, 158, 0) \ 173 + x(ptr_crc_compression_type_unknown, 159, 0) \ 174 + x(ptr_crc_redundant, 160, 0) \ 175 + x(ptr_crc_uncompressed_size_too_big, 161, 0) \ 176 + x(ptr_crc_nonce_mismatch, 162, 0) \ 177 + x(ptr_stripe_redundant, 163, 0) \ 178 + x(reservation_key_nr_replicas_invalid, 164, 0) \ 179 + x(reflink_v_refcount_wrong, 165, 0) \ 180 + x(reflink_p_to_missing_reflink_v, 166, 0) \ 181 + x(stripe_pos_bad, 167, 0) \ 182 + x(stripe_val_size_bad, 168, 0) \ 183 + x(stripe_sector_count_wrong, 169, 0) \ 184 + x(snapshot_tree_pos_bad, 170, 0) \ 185 + x(snapshot_tree_to_missing_snapshot, 171, 0) \ 186 + x(snapshot_tree_to_missing_subvol, 172, 0) \ 187 + x(snapshot_tree_to_wrong_subvol, 173, 0) \ 188 + x(snapshot_tree_to_snapshot_subvol, 174, 0) \ 189 + x(snapshot_pos_bad, 175, 0) \ 190 + x(snapshot_parent_bad, 176, 0) \ 191 + x(snapshot_children_not_normalized, 177, 0) \ 192 + x(snapshot_child_duplicate, 178, 0) \ 193 + x(snapshot_child_bad, 179, 0) \ 194 + x(snapshot_skiplist_not_normalized, 180, 0) \ 195 + x(snapshot_skiplist_bad, 181, 0) \ 196 + x(snapshot_should_not_have_subvol, 182, 0) \ 197 + x(snapshot_to_bad_snapshot_tree, 183, 0) \ 198 + x(snapshot_bad_depth, 184, 0) \ 199 + x(snapshot_bad_skiplist, 185, 0) \ 200 + x(subvol_pos_bad, 186, 0) \ 201 + x(subvol_not_master_and_not_snapshot, 187, 0) \ 202 + x(subvol_to_missing_root, 188, 0) \ 203 + x(subvol_root_wrong_bi_subvol, 189, 0) \ 204 + x(bkey_in_missing_snapshot, 190, 0) \ 205 + x(inode_pos_inode_nonzero, 191, 0) \ 206 + x(inode_pos_blockdev_range, 192, 0) \ 207 + x(inode_unpack_error, 193, 0) \ 208 + x(inode_str_hash_invalid, 194, 0) \ 209 + x(inode_v3_fields_start_bad, 195, 0) \ 210 + x(inode_snapshot_mismatch, 196, 0) \ 211 + x(inode_unlinked_but_clean, 197, 0) \ 212 + x(inode_unlinked_but_nlink_nonzero, 198, 0) \ 213 + x(inode_checksum_type_invalid, 199, 0) \ 214 + x(inode_compression_type_invalid, 200, 0) \ 215 + x(inode_subvol_root_but_not_dir, 201, 0) \ 216 + x(inode_i_size_dirty_but_clean, 202, 0) \ 217 + x(inode_i_sectors_dirty_but_clean, 203, 0) \ 218 + x(inode_i_sectors_wrong, 204, 0) \ 219 + x(inode_dir_wrong_nlink, 205, 0) \ 220 + x(inode_dir_multiple_links, 206, 0) \ 221 + x(inode_multiple_links_but_nlink_0, 207, 0) \ 222 + x(inode_wrong_backpointer, 208, 0) \ 223 + x(inode_wrong_nlink, 209, 0) \ 224 + x(inode_unreachable, 210, 0) \ 225 + x(deleted_inode_but_clean, 211, 0) \ 226 + x(deleted_inode_missing, 212, 0) \ 227 + x(deleted_inode_is_dir, 213, 0) \ 228 + x(deleted_inode_not_unlinked, 214, 0) \ 229 + x(extent_overlapping, 215, 0) \ 230 + x(extent_in_missing_inode, 216, 0) \ 231 + x(extent_in_non_reg_inode, 217, 0) \ 232 + x(extent_past_end_of_inode, 218, 0) \ 233 + x(dirent_empty_name, 219, 0) \ 234 + x(dirent_val_too_big, 220, 0) \ 235 + x(dirent_name_too_long, 221, 0) \ 236 + x(dirent_name_embedded_nul, 222, 0) \ 237 + x(dirent_name_dot_or_dotdot, 223, 0) \ 238 + x(dirent_name_has_slash, 224, 0) \ 239 + x(dirent_d_type_wrong, 225, 0) \ 240 + x(inode_bi_parent_wrong, 226, 0) \ 241 + x(dirent_in_missing_dir_inode, 227, 0) \ 242 + x(dirent_in_non_dir_inode, 228, 0) \ 243 + x(dirent_to_missing_inode, 229, 0) \ 244 + x(dirent_to_missing_subvol, 230, 0) \ 245 + x(dirent_to_itself, 231, 0) \ 246 + x(quota_type_invalid, 232, 0) \ 247 + x(xattr_val_size_too_small, 233, 0) \ 248 + x(xattr_val_size_too_big, 234, 0) \ 249 + x(xattr_invalid_type, 235, 0) \ 250 + x(xattr_name_invalid_chars, 236, 0) \ 251 + x(xattr_in_missing_inode, 237, 0) \ 252 + x(root_subvol_missing, 238, 0) \ 253 + x(root_dir_missing, 239, 0) \ 254 + x(root_inode_not_dir, 240, 0) \ 255 + x(dir_loop, 241, 0) \ 256 + x(hash_table_key_duplicate, 242, 0) \ 257 + x(hash_table_key_wrong_offset, 243, 0) \ 258 + x(unlinked_inode_not_on_deleted_list, 244, 0) \ 259 + x(reflink_p_front_pad_bad, 245, 0) \ 260 + x(journal_entry_dup_same_device, 246, 0) \ 261 + x(inode_bi_subvol_missing, 247, 0) \ 262 + x(inode_bi_subvol_wrong, 248, 0) \ 263 + x(inode_points_to_missing_dirent, 249, 0) \ 264 + x(inode_points_to_wrong_dirent, 250, 0) \ 265 + x(inode_bi_parent_nonzero, 251, 0) \ 266 + x(dirent_to_missing_parent_subvol, 252, 0) \ 267 + x(dirent_not_visible_in_parent_subvol, 253, 0) \ 268 + x(subvol_fs_path_parent_wrong, 254, 0) \ 269 + x(subvol_root_fs_path_parent_nonzero, 255, 0) \ 270 + x(subvol_children_not_set, 256, 0) \ 271 + x(subvol_children_bad, 257, 0) \ 272 + x(subvol_loop, 258, 0) \ 273 + x(subvol_unreachable, 259, 0) \ 274 + x(btree_node_bkey_bad_u64s, 260, 0) \ 275 + x(btree_node_topology_empty_interior_node, 261, 0) \ 276 + x(btree_ptr_v2_min_key_bad, 262, 0) \ 277 + x(btree_root_unreadable_and_scan_found_nothing, 263, 0) \ 278 + x(snapshot_node_missing, 264, 0) \ 279 + x(dup_backpointer_to_bad_csum_extent, 265, 0) \ 280 + x(btree_bitmap_not_marked, 266, 0) \ 281 + x(sb_clean_entry_overrun, 267, 0) \ 282 + x(btree_ptr_v2_written_0, 268, 0) \ 283 + x(subvol_snapshot_bad, 269, 0) \ 284 + x(subvol_inode_bad, 270, 0) \ 285 + x(alloc_key_stripe_sectors_wrong, 271, 0) \ 286 + x(accounting_mismatch, 272, 0) \ 287 + x(accounting_replicas_not_marked, 273, 0) \ 288 + x(invalid_btree_id, 274, 0) \ 289 + x(alloc_key_io_time_bad, 275, 0) 277 290 278 291 enum bch_sb_error_id { 279 - #define x(t, n) BCH_FSCK_ERR_##t = n, 292 + #define x(t, n, ...) BCH_FSCK_ERR_##t = n, 280 293 BCH_SB_ERRS() 281 294 #undef x 282 295 BCH_SB_ERR_MAX
+2 -7
fs/bcachefs/snapshot.c
··· 1565 1565 if (!test_and_clear_bit(BCH_FS_need_delete_dead_snapshots, &c->flags)) 1566 1566 return 0; 1567 1567 1568 - if (!test_bit(BCH_FS_started, &c->flags)) { 1569 - ret = bch2_fs_read_write_early(c); 1570 - bch_err_msg(c, ret, "deleting dead snapshots: error going rw"); 1571 - if (ret) 1572 - return ret; 1573 - } 1574 - 1575 1568 trans = bch2_trans_get(c); 1576 1569 1577 1570 /* ··· 1679 1686 void bch2_delete_dead_snapshots_work(struct work_struct *work) 1680 1687 { 1681 1688 struct bch_fs *c = container_of(work, struct bch_fs, snapshot_delete_work); 1689 + 1690 + set_worker_desc("bcachefs-delete-dead-snapshots/%s", c->name); 1682 1691 1683 1692 bch2_delete_dead_snapshots(c); 1684 1693 bch2_write_ref_put(c, BCH_WRITE_REF_delete_dead_snapshots);
+1 -1
fs/bcachefs/str_hash.h
··· 300 300 if (!found && (flags & STR_HASH_must_replace)) { 301 301 ret = -BCH_ERR_ENOENT_str_hash_set_must_replace; 302 302 } else if (found && (flags & STR_HASH_must_create)) { 303 - ret = -EEXIST; 303 + ret = -BCH_ERR_EEXIST_str_hash_set; 304 304 } else { 305 305 if (!found && slot.path) 306 306 swap(iter, slot);
+4 -3
fs/bcachefs/super-io.c
··· 649 649 650 650 bytes = vstruct_bytes(sb->sb); 651 651 652 - if (bytes > 512ULL << min(BCH_SB_LAYOUT_SIZE_BITS_MAX, sb->sb->layout.sb_max_size_bits)) { 653 - prt_printf(err, "Invalid superblock: too big (got %zu bytes, layout max %lu)", 654 - bytes, 512UL << sb->sb->layout.sb_max_size_bits); 652 + u64 sb_size = 512ULL << min(BCH_SB_LAYOUT_SIZE_BITS_MAX, sb->sb->layout.sb_max_size_bits); 653 + if (bytes > sb_size) { 654 + prt_printf(err, "Invalid superblock: too big (got %zu bytes, layout max %llu)", 655 + bytes, sb_size); 655 656 return -BCH_ERR_invalid_sb_too_big; 656 657 } 657 658
+7 -6
fs/bcachefs/super.c
··· 912 912 bch2_io_clock_init(&c->io_clock[WRITE]) ?: 913 913 bch2_fs_journal_init(&c->journal) ?: 914 914 bch2_fs_replicas_init(c) ?: 915 + bch2_fs_btree_iter_init(c) ?: 915 916 bch2_fs_btree_cache_init(c) ?: 916 917 bch2_fs_btree_key_cache_init(&c->btree_key_cache) ?: 917 - bch2_fs_btree_iter_init(c) ?: 918 918 bch2_fs_btree_interior_update_init(c) ?: 919 919 bch2_fs_buckets_waiting_for_journal_init(c) ?: 920 920 bch2_fs_btree_write_buffer_init(c) ?: ··· 931 931 if (ret) 932 932 goto err; 933 933 934 - for (i = 0; i < c->sb.nr_devices; i++) 935 - if (bch2_member_exists(c->disk_sb.sb, i) && 936 - bch2_dev_alloc(c, i)) { 937 - ret = -EEXIST; 934 + for (i = 0; i < c->sb.nr_devices; i++) { 935 + if (!bch2_member_exists(c->disk_sb.sb, i)) 936 + continue; 937 + ret = bch2_dev_alloc(c, i); 938 + if (ret) 938 939 goto err; 939 - } 940 + } 940 941 941 942 bch2_journal_entry_res_resize(&c->journal, 942 943 &c->btree_root_journal_res,
+8 -2
lib/closure.c
··· 17 17 { 18 18 int r = flags & CLOSURE_REMAINING_MASK; 19 19 20 - BUG_ON(flags & CLOSURE_GUARD_MASK); 21 - BUG_ON(!r && (flags & ~CLOSURE_DESTRUCTOR)); 20 + if (WARN(flags & CLOSURE_GUARD_MASK, 21 + "closure has guard bits set: %x (%u)", 22 + flags & CLOSURE_GUARD_MASK, (unsigned) __fls(r))) 23 + r &= ~CLOSURE_GUARD_MASK; 22 24 23 25 if (!r) { 24 26 smp_acquire__after_ctrl_dep(); 27 + 28 + WARN(flags & ~CLOSURE_DESTRUCTOR, 29 + "closure ref hit 0 with incorrect flags set: %x (%u)", 30 + flags & ~CLOSURE_DESTRUCTOR, (unsigned) __fls(flags)); 25 31 26 32 cl->closure_get_happened = false; 27 33