summaryrefslogtreecommitdiff
path: root/fs/bcachefs/move.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-06-20 19:43:35 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:35 -0400
commit4081ace307c15fb0c15bcc65fce2e3792c1979d9 (patch)
tree76a5708c59ee703b773dc485c30540c8e9638f6d /fs/bcachefs/move.c
parent0337cc7eeed19e81e50414b5199bb65029ca0ed5 (diff)
downloadlwn-4081ace307c15fb0c15bcc65fce2e3792c1979d9.tar.gz
lwn-4081ace307c15fb0c15bcc65fce2e3792c1979d9.zip
bcachefs: Get ref on c->writes in move.c
There's no point reading an extent in order to move it if the write is going to fail because we're shutting down. This patch changes the move path so that moving_io now owns a ref on c->writes - as a bonus, rebalance and copygc will now notice that we're shutting down and exit quicker. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/move.c')
-rw-r--r--fs/bcachefs/move.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c
index a19c3117f9fe..eae93c65e1c7 100644
--- a/fs/bcachefs/move.c
+++ b/fs/bcachefs/move.c
@@ -52,9 +52,11 @@ struct moving_io {
static void move_free(struct moving_io *io)
{
struct moving_context *ctxt = io->write.ctxt;
+ struct bch_fs *c = ctxt->c;
bch2_data_update_exit(&io->write);
wake_up(&ctxt->wait);
+ percpu_ref_put(&c->writes);
kfree(io);
}
@@ -192,6 +194,9 @@ static int bch2_move_extent(struct btree_trans *trans,
unsigned sectors = k.k->size, pages;
int ret = -ENOMEM;
+ if (!percpu_ref_tryget_live(&c->writes))
+ return -EROFS;
+
/* write path might have to decompress data: */
bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
sectors = max_t(unsigned, sectors, p.crc.uncompressed_size);
@@ -258,6 +263,7 @@ err_free_pages:
err_free:
kfree(io);
err:
+ percpu_ref_put(&c->writes);
trace_move_alloc_mem_fail(k.k);
return ret;
}