Commit d3083cf2 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_btree_write_buffer_flush_locked()

Minor refactoring - improved naming, and move the responsibility for
flush_lock to the caller instead of having it be shared.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 183bcc89
...@@ -961,7 +961,8 @@ int bch2_trans_commit_error(struct btree_trans *trans, unsigned flags, ...@@ -961,7 +961,8 @@ int bch2_trans_commit_error(struct btree_trans *trans, unsigned flags,
if (wb->state.nr > wb->size * 3 / 4) { if (wb->state.nr > wb->size * 3 / 4) {
bch2_trans_begin(trans); bch2_trans_begin(trans);
ret = __bch2_btree_write_buffer_flush(trans, true); ret = bch2_btree_write_buffer_flush_locked(trans);
mutex_unlock(&wb->flush_lock);
if (!ret) { if (!ret) {
trace_and_count(c, trans_restart_write_buffer_flush, trans, _THIS_IP_); trace_and_count(c, trans_restart_write_buffer_flush, trans, _THIS_IP_);
ret = btree_trans_restart(trans, BCH_ERR_transaction_restart_write_buffer_flush); ret = btree_trans_restart(trans, BCH_ERR_transaction_restart_write_buffer_flush);
...@@ -1076,7 +1077,8 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags) ...@@ -1076,7 +1077,8 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
bch2_trans_begin(trans); bch2_trans_begin(trans);
bch2_trans_unlock(trans); bch2_trans_unlock(trans);
ret = __bch2_btree_write_buffer_flush(trans, true); ret = bch2_btree_write_buffer_flush_locked(trans);
mutex_unlock(&c->btree_write_buffer.flush_lock);
if (!ret) { if (!ret) {
trace_and_count(c, trans_restart_write_buffer_flush, trans, _THIS_IP_); trace_and_count(c, trans_restart_write_buffer_flush, trans, _THIS_IP_);
ret = btree_trans_restart(trans, BCH_ERR_transaction_restart_write_buffer_flush); ret = btree_trans_restart(trans, BCH_ERR_transaction_restart_write_buffer_flush);
......
...@@ -137,7 +137,7 @@ btree_write_buffered_insert(struct btree_trans *trans, ...@@ -137,7 +137,7 @@ btree_write_buffered_insert(struct btree_trans *trans,
return ret; return ret;
} }
int __bch2_btree_write_buffer_flush(struct btree_trans *trans, bool locked) int bch2_btree_write_buffer_flush_locked(struct btree_trans *trans)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct journal *j = &c->journal; struct journal *j = &c->journal;
...@@ -152,9 +152,6 @@ int __bch2_btree_write_buffer_flush(struct btree_trans *trans, bool locked) ...@@ -152,9 +152,6 @@ int __bch2_btree_write_buffer_flush(struct btree_trans *trans, bool locked)
memset(&pin, 0, sizeof(pin)); memset(&pin, 0, sizeof(pin));
if (!locked && !mutex_trylock(&wb->flush_lock))
return 0;
bch2_journal_pin_copy(j, &pin, &wb->journal_pin, bch2_journal_pin_copy(j, &pin, &wb->journal_pin,
bch2_btree_write_buffer_journal_flush); bch2_btree_write_buffer_journal_flush);
bch2_journal_pin_drop(j, &wb->journal_pin); bch2_journal_pin_drop(j, &wb->journal_pin);
...@@ -237,7 +234,6 @@ int __bch2_btree_write_buffer_flush(struct btree_trans *trans, bool locked) ...@@ -237,7 +234,6 @@ int __bch2_btree_write_buffer_flush(struct btree_trans *trans, bool locked)
bch2_fs_fatal_err_on(ret, c, "%s: insert error %s", __func__, bch2_err_str(ret)); bch2_fs_fatal_err_on(ret, c, "%s: insert error %s", __func__, bch2_err_str(ret));
out: out:
bch2_journal_pin_drop(j, &pin); bch2_journal_pin_drop(j, &pin);
mutex_unlock(&wb->flush_lock);
return ret; return ret;
slowpath: slowpath:
trace_and_count(c, write_buffer_flush_slowpath, trans, slowpath, nr); trace_and_count(c, write_buffer_flush_slowpath, trans, slowpath, nr);
...@@ -282,15 +278,25 @@ int bch2_btree_write_buffer_flush_sync(struct btree_trans *trans) ...@@ -282,15 +278,25 @@ int bch2_btree_write_buffer_flush_sync(struct btree_trans *trans)
trace_and_count(c, write_buffer_flush_sync, trans, _RET_IP_); trace_and_count(c, write_buffer_flush_sync, trans, _RET_IP_);
bch2_trans_unlock(trans); bch2_trans_unlock(trans);
mutex_lock(&trans->c->btree_write_buffer.flush_lock); mutex_lock(&c->btree_write_buffer.flush_lock);
int ret = __bch2_btree_write_buffer_flush(trans, true); int ret = bch2_btree_write_buffer_flush_locked(trans);
mutex_unlock(&c->btree_write_buffer.flush_lock);
bch2_write_ref_put(c, BCH_WRITE_REF_btree_write_buffer); bch2_write_ref_put(c, BCH_WRITE_REF_btree_write_buffer);
return ret; return ret;
} }
int bch2_btree_write_buffer_flush_nocheck_rw(struct btree_trans *trans) int bch2_btree_write_buffer_flush_nocheck_rw(struct btree_trans *trans)
{ {
return __bch2_btree_write_buffer_flush(trans, false); struct bch_fs *c = trans->c;
struct btree_write_buffer *wb = &c->btree_write_buffer;
int ret = 0;
if (mutex_trylock(&wb->flush_lock)) {
ret = bch2_btree_write_buffer_flush_locked(trans);
mutex_unlock(&wb->flush_lock);
}
return ret;
} }
int bch2_btree_write_buffer_flush(struct btree_trans *trans) int bch2_btree_write_buffer_flush(struct btree_trans *trans)
...@@ -312,9 +318,10 @@ static int bch2_btree_write_buffer_journal_flush(struct journal *j, ...@@ -312,9 +318,10 @@ static int bch2_btree_write_buffer_journal_flush(struct journal *j,
struct btree_write_buffer *wb = &c->btree_write_buffer; struct btree_write_buffer *wb = &c->btree_write_buffer;
mutex_lock(&wb->flush_lock); mutex_lock(&wb->flush_lock);
int ret = bch2_trans_run(c, bch2_btree_write_buffer_flush_locked(trans));
mutex_unlock(&wb->flush_lock);
return bch2_trans_run(c, return ret;
__bch2_btree_write_buffer_flush(trans, true));
} }
static inline u64 btree_write_buffer_ref(int idx) static inline u64 btree_write_buffer_ref(int idx)
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#ifndef _BCACHEFS_BTREE_WRITE_BUFFER_H #ifndef _BCACHEFS_BTREE_WRITE_BUFFER_H
#define _BCACHEFS_BTREE_WRITE_BUFFER_H #define _BCACHEFS_BTREE_WRITE_BUFFER_H
int bch2_btree_write_buffer_flush_locked(struct btree_trans *);
int bch2_btree_write_buffer_flush_nocheck_rw(struct btree_trans *); int bch2_btree_write_buffer_flush_nocheck_rw(struct btree_trans *);
int __bch2_btree_write_buffer_flush(struct btree_trans *, bool);
int bch2_btree_write_buffer_flush_sync(struct btree_trans *); int bch2_btree_write_buffer_flush_sync(struct btree_trans *);
int bch2_btree_write_buffer_flush(struct btree_trans *); int bch2_btree_write_buffer_flush(struct btree_trans *);
......
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