Skip to content

Commit eeec259

Browse files
committed
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
2 parents f583772 + 7b474c7 commit eeec259

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

fs/bcachefs/btree_update.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,21 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
186186
enum btree_id btree_id = iter->btree_id;
187187
struct bkey_i *update;
188188
struct bpos new_start = bkey_start_pos(new.k);
189-
bool front_split = bkey_lt(bkey_start_pos(old.k), new_start);
190-
bool back_split = bkey_gt(old.k->p, new.k->p);
189+
unsigned front_split = bkey_lt(bkey_start_pos(old.k), new_start);
190+
unsigned back_split = bkey_gt(old.k->p, new.k->p);
191+
unsigned middle_split = (front_split || back_split) &&
192+
old.k->p.snapshot != new.k->p.snapshot;
193+
unsigned nr_splits = front_split + back_split + middle_split;
191194
int ret = 0, compressed_sectors;
192195

193196
/*
194197
* If we're going to be splitting a compressed extent, note it
195198
* so that __bch2_trans_commit() can increase our disk
196199
* reservation:
197200
*/
198-
if (((front_split && back_split) ||
199-
((front_split || back_split) && old.k->p.snapshot != new.k->p.snapshot)) &&
201+
if (nr_splits > 1 &&
200202
(compressed_sectors = bch2_bkey_sectors_compressed(old)))
201-
trans->extra_journal_res += compressed_sectors;
203+
trans->extra_journal_res += compressed_sectors * (nr_splits - 1);
202204

203205
if (front_split) {
204206
update = bch2_bkey_make_mut_noupdate(trans, old);
@@ -216,8 +218,7 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
216218
}
217219

218220
/* If we're overwriting in a different snapshot - middle split: */
219-
if (old.k->p.snapshot != new.k->p.snapshot &&
220-
(front_split || back_split)) {
221+
if (middle_split) {
221222
update = bch2_bkey_make_mut_noupdate(trans, old);
222223
if ((ret = PTR_ERR_OR_ZERO(update)))
223224
return ret;

fs/bcachefs/data_update.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ int bch2_data_update_init(struct btree_trans *trans,
587587
* Increasing replication is an explicit operation triggered by
588588
* rereplicate, currently, so that users don't get an unexpected -ENOSPC
589589
*/
590-
if (durability_have >= io_opts.data_replicas) {
590+
if (!(m->data_opts.write_flags & BCH_WRITE_CACHED) &&
591+
durability_have >= io_opts.data_replicas) {
591592
m->data_opts.kill_ptrs |= m->data_opts.rewrite_ptrs;
592593
m->data_opts.rewrite_ptrs = 0;
593594
/* if iter == NULL, it's just a promote */

fs/bcachefs/error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ void bch2_flush_fsck_errs(struct bch_fs *);
157157
#define fsck_err_on(cond, c, _err_type, ...) \
158158
__fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
159159

160+
__printf(4, 0)
160161
static inline void bch2_bkey_fsck_err(struct bch_fs *c,
161162
struct printbuf *err_msg,
162163
enum bch_sb_error_id err_type,
@@ -167,7 +168,6 @@ static inline void bch2_bkey_fsck_err(struct bch_fs *c,
167168
va_start(args, fmt);
168169
prt_vprintf(err_msg, fmt, args);
169170
va_end(args);
170-
171171
}
172172

173173
#define bkey_fsck_err(c, _err_msg, _err_type, ...) \

fs/bcachefs/journal_io.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ static int journal_entry_btree_root_validate(struct bch_fs *c,
408408
return 0;
409409
}
410410

411-
return journal_validate_key(c, jset, entry, 1, entry->btree_id, k,
412-
version, big_endian, flags);
411+
ret = journal_validate_key(c, jset, entry, 1, entry->btree_id, k,
412+
version, big_endian, flags);
413+
if (ret == FSCK_DELETED_KEY)
414+
ret = 0;
413415
fsck_err:
414416
return ret;
415417
}

fs/bcachefs/sb-errors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
x(btree_node_bkey_out_of_order, 57) \
6666
x(btree_root_bkey_invalid, 58) \
6767
x(btree_root_read_error, 59) \
68-
x(btree_root_bad_min_key, 50) \
68+
x(btree_root_bad_min_key, 60) \
6969
x(btree_root_bad_max_key, 61) \
7070
x(btree_node_read_error, 62) \
7171
x(btree_node_topology_bad_min_key, 63) \

0 commit comments

Comments
 (0)