Skip to content

Commit 38c23fb

Browse files
author
Kent Overstreet
committed
bcachefs: BTREE_TRIGGER_ATOMIC
Add a new flag to be explicit about when we're running atomic triggers. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 9d5dba2 commit 38c23fb

8 files changed

Lines changed: 27 additions & 30 deletions

File tree

fs/bcachefs/alloc_background.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
821821
}
822822
}
823823

824-
if (!(flags & BTREE_TRIGGER_TRANSACTIONAL) && (flags & BTREE_TRIGGER_INSERT)) {
824+
if ((flags & BTREE_TRIGGER_ATOMIC) && (flags & BTREE_TRIGGER_INSERT)) {
825825
struct bch_alloc_v4 *new_a = bkey_s_to_alloc_v4(new).v;
826826
u64 journal_seq = trans->journal_res.seq;
827827
u64 bucket_journal_seq = new_a->journal_seq;

fs/bcachefs/bkey_methods.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ enum btree_update_flags {
8383

8484
__BTREE_TRIGGER_NORUN,
8585
__BTREE_TRIGGER_TRANSACTIONAL,
86+
__BTREE_TRIGGER_ATOMIC,
87+
__BTREE_TRIGGER_GC,
8688
__BTREE_TRIGGER_INSERT,
8789
__BTREE_TRIGGER_OVERWRITE,
88-
__BTREE_TRIGGER_GC,
8990
__BTREE_TRIGGER_BUCKET_INVALIDATE,
9091
};
9192

@@ -107,16 +108,17 @@ enum btree_update_flags {
107108
* causing us to go emergency read-only)
108109
*/
109110
#define BTREE_TRIGGER_TRANSACTIONAL (1U << __BTREE_TRIGGER_TRANSACTIONAL)
111+
#define BTREE_TRIGGER_ATOMIC (1U << __BTREE_TRIGGER_ATOMIC)
112+
113+
/* We're in gc/fsck: running triggers to recalculate e.g. disk usage */
114+
#define BTREE_TRIGGER_GC (1U << __BTREE_TRIGGER_GC)
110115

111116
/* @new is entering the btree */
112117
#define BTREE_TRIGGER_INSERT (1U << __BTREE_TRIGGER_INSERT)
113118

114119
/* @old is leaving the btree */
115120
#define BTREE_TRIGGER_OVERWRITE (1U << __BTREE_TRIGGER_OVERWRITE)
116121

117-
/* We're in gc/fsck: running triggers to recalculate e.g. disk usage */
118-
#define BTREE_TRIGGER_GC (1U << __BTREE_TRIGGER_GC)
119-
120122
/* signal from bucket invalidate path to alloc trigger */
121123
#define BTREE_TRIGGER_BUCKET_INVALIDATE (1U << __BTREE_TRIGGER_BUCKET_INVALIDATE)
122124

fs/bcachefs/btree_trans_commit.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,6 @@ static int run_one_mem_trigger(struct btree_trans *trans,
448448
if (unlikely(flags & BTREE_TRIGGER_NORUN))
449449
return 0;
450450

451-
if (!btree_node_type_needs_gc(__btree_node_type(i->level, i->btree_id)))
452-
return 0;
453-
454451
if (old_ops->trigger == new_ops->trigger) {
455452
ret = bch2_key_trigger(trans, i->btree_id, i->level,
456453
old, bkey_i_to_s(new),
@@ -586,24 +583,22 @@ static int bch2_trans_commit_run_triggers(struct btree_trans *trans)
586583

587584
static noinline int bch2_trans_commit_run_gc_triggers(struct btree_trans *trans)
588585
{
589-
struct bch_fs *c = trans->c;
590-
int ret = 0;
591-
592586
trans_for_each_update(trans, i) {
593587
/*
594588
* XXX: synchronization of cached update triggers with gc
595589
* XXX: synchronization of interior node updates with gc
596590
*/
597591
BUG_ON(i->cached || i->level);
598592

599-
if (gc_visited(c, gc_pos_btree_node(insert_l(trans, i)->b))) {
600-
ret = run_one_mem_trigger(trans, i, i->flags|BTREE_TRIGGER_GC);
593+
if (btree_node_type_needs_gc(__btree_node_type(i->level, i->btree_id)) &&
594+
gc_visited(trans->c, gc_pos_btree_node(insert_l(trans, i)->b))) {
595+
int ret = run_one_mem_trigger(trans, i, i->flags|BTREE_TRIGGER_GC);
601596
if (ret)
602-
break;
597+
return ret;
603598
}
604599
}
605600

606-
return ret;
601+
return 0;
607602
}
608603

609604
static inline int
@@ -689,8 +684,8 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
689684
}
690685

691686
trans_for_each_update(trans, i)
692-
if (BTREE_NODE_TYPE_HAS_MEM_TRIGGERS & (1U << i->bkey_type)) {
693-
ret = run_one_mem_trigger(trans, i, i->flags);
687+
if (BTREE_NODE_TYPE_HAS_ATOMIC_TRIGGERS & (1U << i->bkey_type)) {
688+
ret = run_one_mem_trigger(trans, i, BTREE_TRIGGER_ATOMIC|i->flags);
694689
if (ret)
695690
goto fatal_err;
696691
}

fs/bcachefs/btree_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,15 @@ const char *bch2_btree_node_type_str(enum btree_node_type);
653653
BIT_ULL(BKEY_TYPE_reflink)| \
654654
BIT_ULL(BKEY_TYPE_btree))
655655

656-
#define BTREE_NODE_TYPE_HAS_MEM_TRIGGERS \
656+
#define BTREE_NODE_TYPE_HAS_ATOMIC_TRIGGERS \
657657
(BIT_ULL(BKEY_TYPE_alloc)| \
658658
BIT_ULL(BKEY_TYPE_inodes)| \
659659
BIT_ULL(BKEY_TYPE_stripes)| \
660660
BIT_ULL(BKEY_TYPE_snapshots))
661661

662662
#define BTREE_NODE_TYPE_HAS_TRIGGERS \
663663
(BTREE_NODE_TYPE_HAS_TRANS_TRIGGERS| \
664-
BTREE_NODE_TYPE_HAS_MEM_TRIGGERS)
664+
BTREE_NODE_TYPE_HAS_ATOMIC_TRIGGERS)
665665

666666
static inline bool btree_node_type_needs_gc(enum btree_node_type type)
667667
{

fs/bcachefs/ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ int bch2_trigger_stripe(struct btree_trans *trans,
367367
}
368368
}
369369

370-
if (!(flags & (BTREE_TRIGGER_TRANSACTIONAL|BTREE_TRIGGER_GC))) {
370+
if (flags & BTREE_TRIGGER_ATOMIC) {
371371
struct stripe *m = genradix_ptr(&c->stripes, idx);
372372

373373
if (!m) {

fs/bcachefs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ int bch2_trigger_inode(struct btree_trans *trans,
587587
}
588588
}
589589

590-
if (!(flags & BTREE_TRIGGER_TRANSACTIONAL) && (flags & BTREE_TRIGGER_INSERT)) {
590+
if ((flags & BTREE_TRIGGER_ATOMIC) && (flags & BTREE_TRIGGER_INSERT)) {
591591
BUG_ON(!trans->journal_res.seq);
592592

593593
bkey_s_to_inode_v3(new).v->bi_journal_seq = cpu_to_le64(trans->journal_res.seq);

fs/bcachefs/reflink.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ static inline void check_indirect_extent_deleting(struct bkey_s new, unsigned *f
292292
}
293293
}
294294

295-
int bch2_trans_mark_reflink_v(struct btree_trans *trans,
296-
enum btree_id btree_id, unsigned level,
297-
struct bkey_s_c old, struct bkey_s new,
298-
unsigned flags)
295+
int bch2_trigger_reflink_v(struct btree_trans *trans,
296+
enum btree_id btree_id, unsigned level,
297+
struct bkey_s_c old, struct bkey_s new,
298+
unsigned flags)
299299
{
300300
if ((flags & BTREE_TRIGGER_TRANSACTIONAL) &&
301301
(flags & BTREE_TRIGGER_INSERT))
@@ -324,7 +324,7 @@ void bch2_indirect_inline_data_to_text(struct printbuf *out,
324324
min(datalen, 32U), d.v->data);
325325
}
326326

327-
int bch2_trans_mark_indirect_inline_data(struct btree_trans *trans,
327+
int bch2_trigger_indirect_inline_data(struct btree_trans *trans,
328328
enum btree_id btree_id, unsigned level,
329329
struct bkey_s_c old, struct bkey_s new,
330330
unsigned flags)

fs/bcachefs/reflink.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ int bch2_reflink_v_invalid(struct bch_fs *, struct bkey_s_c,
2424
enum bkey_invalid_flags, struct printbuf *);
2525
void bch2_reflink_v_to_text(struct printbuf *, struct bch_fs *,
2626
struct bkey_s_c);
27-
int bch2_trans_mark_reflink_v(struct btree_trans *, enum btree_id, unsigned,
27+
int bch2_trigger_reflink_v(struct btree_trans *, enum btree_id, unsigned,
2828
struct bkey_s_c, struct bkey_s, unsigned);
2929

3030
#define bch2_bkey_ops_reflink_v ((struct bkey_ops) { \
3131
.key_invalid = bch2_reflink_v_invalid, \
3232
.val_to_text = bch2_reflink_v_to_text, \
3333
.swab = bch2_ptr_swab, \
34-
.trigger = bch2_trans_mark_reflink_v, \
34+
.trigger = bch2_trigger_reflink_v, \
3535
.min_val_size = 8, \
3636
})
3737

3838
int bch2_indirect_inline_data_invalid(struct bch_fs *, struct bkey_s_c,
3939
enum bkey_invalid_flags, struct printbuf *);
4040
void bch2_indirect_inline_data_to_text(struct printbuf *,
4141
struct bch_fs *, struct bkey_s_c);
42-
int bch2_trans_mark_indirect_inline_data(struct btree_trans *,
42+
int bch2_trigger_indirect_inline_data(struct btree_trans *,
4343
enum btree_id, unsigned,
4444
struct bkey_s_c, struct bkey_s,
4545
unsigned);
4646

4747
#define bch2_bkey_ops_indirect_inline_data ((struct bkey_ops) { \
4848
.key_invalid = bch2_indirect_inline_data_invalid, \
4949
.val_to_text = bch2_indirect_inline_data_to_text, \
50-
.trigger = bch2_trans_mark_indirect_inline_data, \
50+
.trigger = bch2_trigger_indirect_inline_data, \
5151
.min_val_size = 8, \
5252
})
5353

0 commit comments

Comments
 (0)