summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2020-05-25 19:29:48 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2020-06-09 21:32:46 -0400
commit9efbfabfe8d244b348c2a19c2564b8fc68cb6937 (patch)
tree44f4335be29df8b3c1a14885365ca2ac4cdcd9a2
parent45effed2a7c2c4a149ff8a921d23eb68e3a81427 (diff)
bcachefs: Add a mechanism for passing extra journal entries to bch2_trans_commit()
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/btree_iter.c3
-rw-r--r--fs/bcachefs/btree_types.h3
-rw-r--r--fs/bcachefs/btree_update_leaf.c12
-rw-r--r--fs/bcachefs/journal.h11
4 files changed, 25 insertions, 4 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c
index 5528ba0f1d44..1cded0540af5 100644
--- a/fs/bcachefs/btree_iter.c
+++ b/fs/bcachefs/btree_iter.c
@@ -2153,6 +2153,9 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
trans->nr_updates2 = 0;
trans->mem_top = 0;
+ trans->extra_journal_entries = NULL;
+ trans->extra_journal_entry_u64s = 0;
+
if (trans->fs_usage_deltas) {
trans->fs_usage_deltas->used = 0;
memset(&trans->fs_usage_deltas->memset_start, 0,
diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h
index 732cdc35aa7c..f957dd2cbbef 100644
--- a/fs/bcachefs/btree_types.h
+++ b/fs/bcachefs/btree_types.h
@@ -305,6 +305,9 @@ struct btree_trans {
struct btree_insert_entry *updates2;
/* update path: */
+ struct jset_entry *extra_journal_entries;
+ unsigned extra_journal_entry_u64s;
+
struct journal_res journal_res;
struct journal_preres journal_preres;
u64 *journal_seq;
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c
index 7faf98fd2f64..6e402027c63f 100644
--- a/fs/bcachefs/btree_update_leaf.c
+++ b/fs/bcachefs/btree_update_leaf.c
@@ -413,6 +413,16 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
goto err;
}
+ if (unlikely(trans->extra_journal_entry_u64s)) {
+ memcpy_u64s_small(bch2_journal_reservation_entry(&c->journal,
+ &trans->journal_res),
+ trans->extra_journal_entries,
+ trans->extra_journal_entry_u64s);
+
+ trans->journal_res.offset += trans->extra_journal_entry_u64s;
+ trans->journal_res.u64s -= trans->extra_journal_entry_u64s;
+ }
+
/*
* Not allowed to fail after we've gotten our journal reservation - we
* have to use it:
@@ -800,7 +810,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
memset(&trans->journal_preres, 0, sizeof(trans->journal_preres));
- trans->journal_u64s = 0;
+ trans->journal_u64s = trans->extra_journal_entry_u64s;
trans->journal_preres_u64s = 0;
if (!(trans->flags & BTREE_INSERT_NOCHECK_RW) &&
diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h
index 78f5fac06bf5..e4b7fe8ffa82 100644
--- a/fs/bcachefs/journal.h
+++ b/fs/bcachefs/journal.h
@@ -199,13 +199,18 @@ bch2_journal_add_entry_noreservation(struct journal_buf *buf, size_t u64s)
return entry;
}
+static inline struct jset_entry *
+bch2_journal_reservation_entry(struct journal *j, struct journal_res *res)
+{
+ return vstruct_idx(j->buf[res->idx].data, res->offset);
+}
+
static inline void bch2_journal_add_entry(struct journal *j, struct journal_res *res,
unsigned type, enum btree_id id,
unsigned level,
const void *data, unsigned u64s)
{
- struct journal_buf *buf = &j->buf[res->idx];
- struct jset_entry *entry = vstruct_idx(buf->data, res->offset);
+ struct jset_entry *entry = bch2_journal_reservation_entry(j, res);
unsigned actual = jset_u64s(u64s);
EBUG_ON(!res->ref);
@@ -219,7 +224,7 @@ static inline void bch2_journal_add_entry(struct journal *j, struct journal_res
entry->type = type;
entry->btree_id = id;
entry->level = level;
- memcpy_u64s(entry->_data, data, u64s);
+ memcpy_u64s_small(entry->_data, data, u64s);
}
static inline void bch2_journal_add_keys(struct journal *j, struct journal_res *res,