Commit eeec2599 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'bcachefs-2023-12-27' of https://evilpiepirate.org/git/bcachefs

Pull bcachefs fixes from Kent Overstreet:
 "Just a few fixes: besides a few one liners, we have a fix for
  snapshots + compression where the extent update path didn't account
  for the fact that with snapshots, we might split an existing extent
  into three, not just two; and a small fixup for promotes which were
  broken by the recent changes in the data update path to correctly take
  into account device durability"

* tag 'bcachefs-2023-12-27' of https://evilpiepirate.org/git/bcachefs:
  bcachefs: Fix promotes
  bcachefs: Fix leakage of internal error code
  bcachefs: Fix insufficient disk reservation with compression + snapshots
  bcachefs: fix BCH_FSCK_ERR enum
parents f5837722 7b474c77
...@@ -186,8 +186,11 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans, ...@@ -186,8 +186,11 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
enum btree_id btree_id = iter->btree_id; enum btree_id btree_id = iter->btree_id;
struct bkey_i *update; struct bkey_i *update;
struct bpos new_start = bkey_start_pos(new.k); struct bpos new_start = bkey_start_pos(new.k);
bool front_split = bkey_lt(bkey_start_pos(old.k), new_start); unsigned front_split = bkey_lt(bkey_start_pos(old.k), new_start);
bool back_split = bkey_gt(old.k->p, new.k->p); unsigned back_split = bkey_gt(old.k->p, new.k->p);
unsigned middle_split = (front_split || back_split) &&
old.k->p.snapshot != new.k->p.snapshot;
unsigned nr_splits = front_split + back_split + middle_split;
int ret = 0, compressed_sectors; int ret = 0, compressed_sectors;
/* /*
...@@ -195,10 +198,9 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans, ...@@ -195,10 +198,9 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
* so that __bch2_trans_commit() can increase our disk * so that __bch2_trans_commit() can increase our disk
* reservation: * reservation:
*/ */
if (((front_split && back_split) || if (nr_splits > 1 &&
((front_split || back_split) && old.k->p.snapshot != new.k->p.snapshot)) &&
(compressed_sectors = bch2_bkey_sectors_compressed(old))) (compressed_sectors = bch2_bkey_sectors_compressed(old)))
trans->extra_journal_res += compressed_sectors; trans->extra_journal_res += compressed_sectors * (nr_splits - 1);
if (front_split) { if (front_split) {
update = bch2_bkey_make_mut_noupdate(trans, old); update = bch2_bkey_make_mut_noupdate(trans, old);
...@@ -216,8 +218,7 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans, ...@@ -216,8 +218,7 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
} }
/* If we're overwriting in a different snapshot - middle split: */ /* If we're overwriting in a different snapshot - middle split: */
if (old.k->p.snapshot != new.k->p.snapshot && if (middle_split) {
(front_split || back_split)) {
update = bch2_bkey_make_mut_noupdate(trans, old); update = bch2_bkey_make_mut_noupdate(trans, old);
if ((ret = PTR_ERR_OR_ZERO(update))) if ((ret = PTR_ERR_OR_ZERO(update)))
return ret; return ret;
......
...@@ -587,7 +587,8 @@ int bch2_data_update_init(struct btree_trans *trans, ...@@ -587,7 +587,8 @@ int bch2_data_update_init(struct btree_trans *trans,
* Increasing replication is an explicit operation triggered by * Increasing replication is an explicit operation triggered by
* rereplicate, currently, so that users don't get an unexpected -ENOSPC * rereplicate, currently, so that users don't get an unexpected -ENOSPC
*/ */
if (durability_have >= io_opts.data_replicas) { if (!(m->data_opts.write_flags & BCH_WRITE_CACHED) &&
durability_have >= io_opts.data_replicas) {
m->data_opts.kill_ptrs |= m->data_opts.rewrite_ptrs; m->data_opts.kill_ptrs |= m->data_opts.rewrite_ptrs;
m->data_opts.rewrite_ptrs = 0; m->data_opts.rewrite_ptrs = 0;
/* if iter == NULL, it's just a promote */ /* if iter == NULL, it's just a promote */
......
...@@ -157,6 +157,7 @@ void bch2_flush_fsck_errs(struct bch_fs *); ...@@ -157,6 +157,7 @@ void bch2_flush_fsck_errs(struct bch_fs *);
#define fsck_err_on(cond, c, _err_type, ...) \ #define fsck_err_on(cond, c, _err_type, ...) \
__fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__) __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
__printf(4, 0)
static inline void bch2_bkey_fsck_err(struct bch_fs *c, static inline void bch2_bkey_fsck_err(struct bch_fs *c,
struct printbuf *err_msg, struct printbuf *err_msg,
enum bch_sb_error_id err_type, enum bch_sb_error_id err_type,
...@@ -167,7 +168,6 @@ static inline void bch2_bkey_fsck_err(struct bch_fs *c, ...@@ -167,7 +168,6 @@ static inline void bch2_bkey_fsck_err(struct bch_fs *c,
va_start(args, fmt); va_start(args, fmt);
prt_vprintf(err_msg, fmt, args); prt_vprintf(err_msg, fmt, args);
va_end(args); va_end(args);
} }
#define bkey_fsck_err(c, _err_msg, _err_type, ...) \ #define bkey_fsck_err(c, _err_msg, _err_type, ...) \
......
...@@ -408,8 +408,10 @@ static int journal_entry_btree_root_validate(struct bch_fs *c, ...@@ -408,8 +408,10 @@ static int journal_entry_btree_root_validate(struct bch_fs *c,
return 0; return 0;
} }
return journal_validate_key(c, jset, entry, 1, entry->btree_id, k, ret = journal_validate_key(c, jset, entry, 1, entry->btree_id, k,
version, big_endian, flags); version, big_endian, flags);
if (ret == FSCK_DELETED_KEY)
ret = 0;
fsck_err: fsck_err:
return ret; return ret;
} }
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
x(btree_node_bkey_out_of_order, 57) \ x(btree_node_bkey_out_of_order, 57) \
x(btree_root_bkey_invalid, 58) \ x(btree_root_bkey_invalid, 58) \
x(btree_root_read_error, 59) \ x(btree_root_read_error, 59) \
x(btree_root_bad_min_key, 50) \ x(btree_root_bad_min_key, 60) \
x(btree_root_bad_max_key, 61) \ x(btree_root_bad_max_key, 61) \
x(btree_node_read_error, 62) \ x(btree_node_read_error, 62) \
x(btree_node_topology_bad_min_key, 63) \ x(btree_node_topology_bad_min_key, 63) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment