diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-11-27 08:14:51 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-12-27 11:38:33 -0500 |
commit | 3a2c4ac98642179c4eb8354cc13201a139a5c496 (patch) | |
tree | 69dc581a95865b42405a72b2c281388826bf52d6 | |
parent | ae8a3640308ef9282e8b0094e9a22d3bd43a5efa (diff) |
bcachefs: return errors correctly from gc
-rw-r--r-- | fs/bcachefs/btree_gc.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index cab8a5c1e2f1..4595bfb87a52 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -122,12 +122,10 @@ static void ptr_gen_recalc_oldest(struct bch_fs *c, *max_stale = max(*max_stale, ptr_stale(ca, ptr)); } -static u8 ptr_gens_recalc_oldest(struct bch_fs *c, - enum bkey_type type, - struct bkey_s_c k) +static void ptr_gens_recalc_oldest(struct bch_fs *c, enum bkey_type type, + struct bkey_s_c k, u8 *max_stale) { const struct bch_extent_ptr *ptr; - u8 max_stale = 0; switch (type) { case BKEY_TYPE_BTREE: @@ -138,7 +136,7 @@ static u8 ptr_gens_recalc_oldest(struct bch_fs *c, struct bkey_s_c_extent e = bkey_s_c_to_extent(k); extent_for_each_ptr(e, ptr) - ptr_gen_recalc_oldest(c, ptr, &max_stale); + ptr_gen_recalc_oldest(c, ptr, max_stale); break; } } @@ -151,14 +149,12 @@ static u8 ptr_gens_recalc_oldest(struct bch_fs *c, for (ptr = s.v->ptrs; ptr < s.v->ptrs + s.v->nr_blocks; ptr++) - ptr_gen_recalc_oldest(c, ptr, &max_stale); + ptr_gen_recalc_oldest(c, ptr, max_stale); } } default: break; } - - return max_stale; } static int ptr_gen_check(struct bch_fs *c, @@ -241,7 +237,8 @@ static int ptr_gens_check(struct bch_fs *c, enum bkey_type type, * For runtime mark and sweep: */ static int bch2_gc_mark_key(struct bch_fs *c, enum bkey_type type, - struct bkey_s_c k, bool initial) + struct bkey_s_c k, + u8 *max_stale, bool initial) { struct gc_pos pos = { 0 }; unsigned flags = @@ -273,20 +270,21 @@ static int bch2_gc_mark_key(struct bch_fs *c, enum bkey_type type, bch2_mark_key(c, type, k, true, k.k->size, pos, NULL, 0, flags); - ret = ptr_gens_recalc_oldest(c, type, k); + ptr_gens_recalc_oldest(c, type, k, max_stale); fsck_err: return ret; } static int btree_gc_mark_node(struct bch_fs *c, struct btree *b, - bool initial) + u8 *max_stale, bool initial) { enum bkey_type type = btree_node_type(b); struct btree_node_iter iter; struct bkey unpacked; struct bkey_s_c k; - u8 stale = 0; - int ret; + int ret = 0; + + *max_stale = 0; if (!bkey_type_needs_gc(type)) return 0; @@ -295,14 +293,12 @@ static int btree_gc_mark_node(struct bch_fs *c, struct btree *b, &unpacked) { bch2_bkey_debugcheck(c, b, k); - ret = bch2_gc_mark_key(c, type, k, initial); - if (ret < 0) - return ret; - - stale = max_t(u8, stale, ret); + ret = bch2_gc_mark_key(c, type, k, max_stale, initial); + if (ret) + break; } - return stale; + return ret; } static int bch2_gc_btree(struct bch_fs *c, enum btree_id btree_id, @@ -312,7 +308,7 @@ static int bch2_gc_btree(struct bch_fs *c, enum btree_id btree_id, struct btree *b; struct range_checks r; unsigned depth = bkey_type_needs_gc(btree_id) ? 0 : 1; - unsigned max_stale; + u8 max_stale; int ret = 0; gc_pos_set(c, gc_pos_btree(btree_id, POS_MIN, 0)); @@ -334,7 +330,9 @@ static int bch2_gc_btree(struct bch_fs *c, enum btree_id btree_id, bch2_verify_btree_nr_keys(b); - max_stale = btree_gc_mark_node(c, b, initial); + ret = btree_gc_mark_node(c, b, &max_stale, initial); + if (ret) + break; gc_pos_set(c, gc_pos_btree_node(b)); @@ -355,7 +353,7 @@ static int bch2_gc_btree(struct bch_fs *c, enum btree_id btree_id, bch2_btree_iter_cond_resched(&iter); } - ret = bch2_btree_iter_unlock(&iter); + ret = bch2_btree_iter_unlock(&iter) ?: ret; if (ret) return ret; @@ -363,8 +361,8 @@ static int bch2_gc_btree(struct bch_fs *c, enum btree_id btree_id, b = c->btree_roots[btree_id].b; if (!btree_node_fake(b)) - bch2_gc_mark_key(c, BKEY_TYPE_BTREE, - bkey_i_to_s_c(&b->key), initial); + bch2_gc_mark_key(c, BKEY_TYPE_BTREE, bkey_i_to_s_c(&b->key), + &max_stale, initial); gc_pos_set(c, gc_pos_btree_root(b->btree_id)); mutex_unlock(&c->btree_root_lock); @@ -381,6 +379,7 @@ static int bch2_gc_btrees(struct bch_fs *c, struct list_head *journal, bool initial) { enum btree_id ids[BTREE_ID_NR]; + u8 max_stale; unsigned i; for (i = 0; i < BTREE_ID_NR; i++) @@ -405,8 +404,9 @@ static int bch2_gc_btrees(struct bch_fs *c, struct list_head *journal, for_each_jset_key(k, n, j, &r->j) { if (type == bkey_type(j->level, j->btree_id)) { ret = bch2_gc_mark_key(c, type, - bkey_i_to_s_c(k), initial); - if (ret < 0) + bkey_i_to_s_c(k), + &max_stale, initial); + if (ret) return ret; } } |