Commit 08bc9590 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: unify inode trigger

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 282e7c37
...@@ -561,61 +561,46 @@ static inline bool bkey_is_deleted_inode(struct bkey_s_c k) ...@@ -561,61 +561,46 @@ static inline bool bkey_is_deleted_inode(struct bkey_s_c k)
return bkey_inode_flags(k) & BCH_INODE_unlinked; return bkey_inode_flags(k) & BCH_INODE_unlinked;
} }
int bch2_trans_mark_inode(struct btree_trans *trans, int bch2_trigger_inode(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c old,
struct bkey_s new, struct bkey_s new,
unsigned flags) unsigned flags)
{ {
s64 nr = bkey_is_inode(new.k) - bkey_is_inode(old.k); s64 nr = bkey_is_inode(new.k) - bkey_is_inode(old.k);
bool old_deleted = bkey_is_deleted_inode(old);
bool new_deleted = bkey_is_deleted_inode(new.s_c);
if (flags & BTREE_TRIGGER_TRANSACTIONAL) {
if (nr) { if (nr) {
int ret = bch2_replicas_deltas_realloc(trans, 0); int ret = bch2_replicas_deltas_realloc(trans, 0);
struct replicas_delta_list *d = trans->fs_usage_deltas;
if (ret) if (ret)
return ret; return ret;
d->nr_inodes += nr; trans->fs_usage_deltas->nr_inodes += nr;
} }
bool old_deleted = bkey_is_deleted_inode(old);
bool new_deleted = bkey_is_deleted_inode(new.s_c);
if (old_deleted != new_deleted) { if (old_deleted != new_deleted) {
int ret = bch2_btree_bit_mod(trans, BTREE_ID_deleted_inodes, new.k->p, new_deleted); int ret = bch2_btree_bit_mod(trans, BTREE_ID_deleted_inodes, new.k->p, new_deleted);
if (ret) if (ret)
return ret; return ret;
} }
}
return 0; if (!(flags & BTREE_TRIGGER_TRANSACTIONAL) && (flags & BTREE_TRIGGER_INSERT)) {
} BUG_ON(!trans->journal_res.seq);
int bch2_mark_inode(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
struct bch_fs *c = trans->c;
struct bch_fs_usage *fs_usage;
u64 journal_seq = trans->journal_res.seq;
if (flags & BTREE_TRIGGER_INSERT) {
BUG_ON(!journal_seq);
bkey_s_to_inode_v3(new).v->bi_journal_seq = cpu_to_le64(journal_seq); bkey_s_to_inode_v3(new).v->bi_journal_seq = cpu_to_le64(trans->journal_res.seq);
} }
if (flags & BTREE_TRIGGER_GC) { if (flags & BTREE_TRIGGER_GC) {
percpu_down_read(&c->mark_lock); struct bch_fs *c = trans->c;
preempt_disable();
fs_usage = fs_usage_ptr(c, journal_seq, flags & BTREE_TRIGGER_GC);
fs_usage->nr_inodes += bkey_is_inode(new.k);
fs_usage->nr_inodes -= bkey_is_inode(old.k);
preempt_enable(); percpu_down_read(&c->mark_lock);
this_cpu_add(c->usage_gc->nr_inodes, nr);
percpu_up_read(&c->mark_lock); percpu_up_read(&c->mark_lock);
} }
return 0; return 0;
} }
......
...@@ -17,32 +17,30 @@ int bch2_inode_v3_invalid(struct bch_fs *, struct bkey_s_c, ...@@ -17,32 +17,30 @@ int bch2_inode_v3_invalid(struct bch_fs *, struct bkey_s_c,
enum bkey_invalid_flags, struct printbuf *); enum bkey_invalid_flags, struct printbuf *);
void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c); void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
int bch2_trans_mark_inode(struct btree_trans *, enum btree_id, unsigned, int bch2_trigger_inode(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s, unsigned);
int bch2_mark_inode(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s, unsigned); struct bkey_s_c, struct bkey_s, unsigned);
#define bch2_bkey_ops_inode ((struct bkey_ops) { \ #define bch2_bkey_ops_inode ((struct bkey_ops) { \
.key_invalid = bch2_inode_invalid, \ .key_invalid = bch2_inode_invalid, \
.val_to_text = bch2_inode_to_text, \ .val_to_text = bch2_inode_to_text, \
.trans_trigger = bch2_trans_mark_inode, \ .trans_trigger = bch2_trigger_inode, \
.atomic_trigger = bch2_mark_inode, \ .atomic_trigger = bch2_trigger_inode, \
.min_val_size = 16, \ .min_val_size = 16, \
}) })
#define bch2_bkey_ops_inode_v2 ((struct bkey_ops) { \ #define bch2_bkey_ops_inode_v2 ((struct bkey_ops) { \
.key_invalid = bch2_inode_v2_invalid, \ .key_invalid = bch2_inode_v2_invalid, \
.val_to_text = bch2_inode_to_text, \ .val_to_text = bch2_inode_to_text, \
.trans_trigger = bch2_trans_mark_inode, \ .trans_trigger = bch2_trigger_inode, \
.atomic_trigger = bch2_mark_inode, \ .atomic_trigger = bch2_trigger_inode, \
.min_val_size = 32, \ .min_val_size = 32, \
}) })
#define bch2_bkey_ops_inode_v3 ((struct bkey_ops) { \ #define bch2_bkey_ops_inode_v3 ((struct bkey_ops) { \
.key_invalid = bch2_inode_v3_invalid, \ .key_invalid = bch2_inode_v3_invalid, \
.val_to_text = bch2_inode_to_text, \ .val_to_text = bch2_inode_to_text, \
.trans_trigger = bch2_trans_mark_inode, \ .trans_trigger = bch2_trigger_inode, \
.atomic_trigger = bch2_mark_inode, \ .atomic_trigger = bch2_trigger_inode, \
.min_val_size = 48, \ .min_val_size = 48, \
}) })
......
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