bcachefs: Get ref on c->writes in move.c
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 20 Jun 2022 23:43:35 +0000 (19:43 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:35 +0000 (17:09 -0400)
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>
fs/bcachefs/io.c
fs/bcachefs/move.c

index c22ce1eb6b8b5d57d19fd602652e158fdb625cb6..f137a8e90f072983df98348ce00daaa03d08ae54 100644 (file)
@@ -1227,12 +1227,6 @@ again:
                                        BKEY_EXTENT_U64s_MAX))
                        break;
 
-               if ((op->flags & BCH_WRITE_FROM_INTERNAL) &&
-                   percpu_ref_is_dying(&c->writes)) {
-                       ret = -EROFS;
-                       goto err;
-               }
-
                /*
                 * The copygc thread is now global, which means it's no longer
                 * freeing up space on specific disks, which means that
index a19c3117f9febc33c656d3132b89f42e8a647c17..eae93c65e1c712e5c51dbd0d23ec0c65ea83eb03 100644 (file)
@@ -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;
 }