]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/move.c
Update bcachefs sources to a180af9dd349 bcachefs: Refactor memcpy into direct assignment
[bcachefs-tools-debian] / libbcachefs / move.c
index 05272673901d2ba93cccd69c0b1e9febf4042803..39a14e3216807d222fc11856fa285448f4a24ca3 100644 (file)
@@ -14,7 +14,8 @@
 #include "errcode.h"
 #include "error.h"
 #include "inode.h"
-#include "io.h"
+#include "io_read.h"
+#include "io_write.h"
 #include "journal_reclaim.h"
 #include "keylist.h"
 #include "move.h"
@@ -524,7 +525,7 @@ static int __bch2_move_data(struct moving_context *ctxt,
        struct bch_fs *c = ctxt->c;
        struct bch_io_opts io_opts = bch2_opts_to_inode_opts(c->opts);
        struct bkey_buf sk;
-       struct btree_trans trans;
+       struct btree_trans *trans = bch2_trans_get(c);
        struct btree_iter iter;
        struct bkey_s_c k;
        struct data_update_opts data_opts;
@@ -532,7 +533,6 @@ static int __bch2_move_data(struct moving_context *ctxt,
        int ret = 0, ret2;
 
        bch2_bkey_buf_init(&sk);
-       bch2_trans_init(&trans, c, 0, 0);
 
        if (ctxt->stats) {
                ctxt->stats->data_type  = BCH_DATA_user;
@@ -540,15 +540,15 @@ static int __bch2_move_data(struct moving_context *ctxt,
                ctxt->stats->pos        = start;
        }
 
-       bch2_trans_iter_init(&trans, &iter, btree_id, start,
+       bch2_trans_iter_init(trans, &iter, btree_id, start,
                             BTREE_ITER_PREFETCH|
                             BTREE_ITER_ALL_SNAPSHOTS);
 
        if (ctxt->rate)
                bch2_ratelimit_reset(ctxt->rate);
 
-       while (!move_ratelimit(&trans, ctxt)) {
-               bch2_trans_begin(&trans);
+       while (!move_ratelimit(trans, ctxt)) {
+               bch2_trans_begin(trans);
 
                k = bch2_btree_iter_peek(&iter);
                if (!k.k)
@@ -569,7 +569,7 @@ static int __bch2_move_data(struct moving_context *ctxt,
                if (!bkey_extent_is_direct_data(k.k))
                        goto next_nondata;
 
-               ret = move_get_io_opts(&trans, &io_opts, k, &cur_inum);
+               ret = move_get_io_opts(trans, &io_opts, k, &cur_inum);
                if (ret)
                        continue;
 
@@ -584,7 +584,7 @@ static int __bch2_move_data(struct moving_context *ctxt,
                bch2_bkey_buf_reassemble(&sk, c, k);
                k = bkey_i_to_s_c(sk.k);
 
-               ret2 = bch2_move_extent(&trans, &iter, ctxt, NULL,
+               ret2 = bch2_move_extent(trans, &iter, ctxt, NULL,
                                        io_opts, btree_id, k, data_opts);
                if (ret2) {
                        if (bch2_err_matches(ret2, BCH_ERR_transaction_restart))
@@ -592,7 +592,7 @@ static int __bch2_move_data(struct moving_context *ctxt,
 
                        if (ret2 == -ENOMEM) {
                                /* memory allocation failure, wait for some IO to finish */
-                               bch2_move_ctxt_wait_for_io(ctxt, &trans);
+                               bch2_move_ctxt_wait_for_io(ctxt, trans);
                                continue;
                        }
 
@@ -609,8 +609,8 @@ next_nondata:
                bch2_btree_iter_advance(&iter);
        }
 
-       bch2_trans_iter_exit(&trans, &iter);
-       bch2_trans_exit(&trans);
+       bch2_trans_iter_exit(trans, &iter);
+       bch2_trans_put(trans);
        bch2_bkey_buf_exit(&sk, c);
 
        return ret;
@@ -627,7 +627,7 @@ int bch2_move_data(struct bch_fs *c,
 {
        struct moving_context ctxt;
        enum btree_id id;
-       int ret;
+       int ret = 0;
 
        bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc);
 
@@ -723,7 +723,6 @@ int __bch2_evacuate_bucket(struct btree_trans *trans,
 
                if (!bp.level) {
                        const struct bch_extent_ptr *ptr;
-                       struct bkey_s_c k;
                        unsigned i = 0;
 
                        k = bch2_backpointer_get_key(trans, &iter, bp_pos, bp, 0);
@@ -826,15 +825,14 @@ int bch2_evacuate_bucket(struct bch_fs *c,
                         struct write_point_specifier wp,
                         bool wait_on_copygc)
 {
-       struct btree_trans trans;
+       struct btree_trans *trans = bch2_trans_get(c);
        struct moving_context ctxt;
        int ret;
 
-       bch2_trans_init(&trans, c, 0, 0);
        bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc);
-       ret = __bch2_evacuate_bucket(&trans, &ctxt, NULL, bucket, gen, data_opts);
+       ret = __bch2_evacuate_bucket(trans, &ctxt, NULL, bucket, gen, data_opts);
        bch2_moving_ctxt_exit(&ctxt);
-       bch2_trans_exit(&trans);
+       bch2_trans_put(trans);
 
        return ret;
 }
@@ -851,14 +849,13 @@ static int bch2_move_btree(struct bch_fs *c,
 {
        bool kthread = (current->flags & PF_KTHREAD) != 0;
        struct bch_io_opts io_opts = bch2_opts_to_inode_opts(c->opts);
-       struct btree_trans trans;
+       struct btree_trans *trans = bch2_trans_get(c);
        struct btree_iter iter;
        struct btree *b;
        enum btree_id id;
        struct data_update_opts data_opts;
        int ret = 0;
 
-       bch2_trans_init(&trans, c, 0, 0);
        progress_list_add(c, stats);
 
        stats->data_type = BCH_DATA_btree;
@@ -871,11 +868,11 @@ static int bch2_move_btree(struct bch_fs *c,
                if (!bch2_btree_id_root(c, id)->b)
                        continue;
 
-               bch2_trans_node_iter_init(&trans, &iter, id, POS_MIN, 0, 0,
+               bch2_trans_node_iter_init(trans, &iter, id, POS_MIN, 0, 0,
                                          BTREE_ITER_PREFETCH);
 retry:
                ret = 0;
-               while (bch2_trans_begin(&trans),
+               while (bch2_trans_begin(trans),
                       (b = bch2_btree_iter_peek_node(&iter)) &&
                       !(ret = PTR_ERR_OR_ZERO(b))) {
                        if (kthread && kthread_should_stop())
@@ -890,7 +887,7 @@ retry:
                        if (!pred(c, arg, b, &io_opts, &data_opts))
                                goto next;
 
-                       ret = bch2_btree_node_rewrite(&trans, &iter, b, 0) ?: ret;
+                       ret = bch2_btree_node_rewrite(trans, &iter, b, 0) ?: ret;
                        if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
                                continue;
                        if (ret)
@@ -901,13 +898,13 @@ next:
                if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
                        goto retry;
 
-               bch2_trans_iter_exit(&trans, &iter);
+               bch2_trans_iter_exit(trans, &iter);
 
                if (kthread && kthread_should_stop())
                        break;
        }
 
-       bch2_trans_exit(&trans);
+       bch2_trans_put(trans);
 
        if (ret)
                bch_err_fn(c, ret);
@@ -1103,46 +1100,40 @@ int bch2_data_job(struct bch_fs *c,
        return ret;
 }
 
-void bch2_data_jobs_to_text(struct printbuf *out, struct bch_fs *c)
-{
-       struct bch_move_stats *stats;
-
-       mutex_lock(&c->data_progress_lock);
-       list_for_each_entry(stats, &c->data_progress_list, list) {
-               prt_printf(out, "%s: data type %s btree_id %s position: ",
-                      stats->name,
-                      bch2_data_types[stats->data_type],
-                      bch2_btree_ids[stats->btree_id]);
-               bch2_bpos_to_text(out, stats->pos);
-               prt_printf(out, "%s", "\n");
-       }
-       mutex_unlock(&c->data_progress_lock);
-}
-
-static void bch2_moving_ctxt_to_text(struct printbuf *out, struct moving_context *ctxt)
+static void bch2_moving_ctxt_to_text(struct printbuf *out, struct bch_fs *c, struct moving_context *ctxt)
 {
+       struct bch_move_stats *stats = ctxt->stats;
        struct moving_io *io;
 
-       prt_printf(out, "%ps:", ctxt->fn);
+       prt_printf(out, "%s (%ps):", stats->name, ctxt->fn);
+       prt_newline(out);
+
+       prt_printf(out, " data type %s btree_id %s position: ",
+                  bch2_data_types[stats->data_type],
+                  bch2_btree_ids[stats->btree_id]);
+       bch2_bpos_to_text(out, stats->pos);
        prt_newline(out);
        printbuf_indent_add(out, 2);
 
-       prt_printf(out, "reads: %u sectors %u",
+       prt_printf(out, "reads: ios %u/%u sectors %u/%u",
                   atomic_read(&ctxt->read_ios),
-                  atomic_read(&ctxt->read_sectors));
+                  c->opts.move_ios_in_flight,
+                  atomic_read(&ctxt->read_sectors),
+                  c->opts.move_bytes_in_flight >> 9);
        prt_newline(out);
 
-       prt_printf(out, "writes: %u sectors %u",
+       prt_printf(out, "writes: ios %u/%u sectors %u/%u",
                   atomic_read(&ctxt->write_ios),
-                  atomic_read(&ctxt->write_sectors));
+                  c->opts.move_ios_in_flight,
+                  atomic_read(&ctxt->write_sectors),
+                  c->opts.move_bytes_in_flight >> 9);
        prt_newline(out);
 
        printbuf_indent_add(out, 2);
 
        mutex_lock(&ctxt->lock);
-       list_for_each_entry(io, &ctxt->ios, io_list) {
+       list_for_each_entry(io, &ctxt->ios, io_list)
                bch2_write_op_to_text(out, &io->write.op);
-       }
        mutex_unlock(&ctxt->lock);
 
        printbuf_indent_sub(out, 4);
@@ -1154,7 +1145,7 @@ void bch2_fs_moving_ctxts_to_text(struct printbuf *out, struct bch_fs *c)
 
        mutex_lock(&c->moving_context_lock);
        list_for_each_entry(ctxt, &c->moving_context_list, list)
-               bch2_moving_ctxt_to_text(out, ctxt);
+               bch2_moving_ctxt_to_text(out, c, ctxt);
        mutex_unlock(&c->moving_context_lock);
 }