]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/move.c
Update bcachefs sources to 04f2d2ae5b bcachefs: Fix build error on weird gcc
[bcachefs-tools-debian] / libbcachefs / move.c
index 200aa5dc0cf9d3959812586533ad95e53e5915c4..05272673901d2ba93cccd69c0b1e9febf4042803 100644 (file)
 #include "inode.h"
 #include "io.h"
 #include "journal_reclaim.h"
+#include "keylist.h"
 #include "move.h"
 #include "replicas.h"
 #include "super-io.h"
-#include "keylist.h"
+#include "trace.h"
 
 #include <linux/ioprio.h>
 #include <linux/kthread.h>
 
-#include <trace/events/bcachefs.h>
-
 static void trace_move_extent2(struct bch_fs *c, struct bkey_s_c k)
 {
        if (trace_move_extent_enabled()) {
@@ -252,7 +251,7 @@ static int bch2_extent_drop_ptrs(struct btree_trans *trans,
        struct bkey_i *n;
        int ret;
 
-       n = bch2_bkey_make_mut(trans, k);
+       n = bch2_bkey_make_mut_noupdate(trans, k);
        ret = PTR_ERR_OR_ZERO(n);
        if (ret)
                return ret;
@@ -428,7 +427,7 @@ static int lookup_inode(struct btree_trans *trans, struct bpos pos,
                goto err;
 
        if (!k.k || !bkey_eq(k.k->p, pos)) {
-               ret = -ENOENT;
+               ret = -BCH_ERR_ENOENT_inode;
                goto err;
        }
 
@@ -584,7 +583,6 @@ static int __bch2_move_data(struct moving_context *ctxt,
                 */
                bch2_bkey_buf_reassemble(&sk, c, k);
                k = bkey_i_to_s_c(sk.k);
-               bch2_trans_unlock(&trans);
 
                ret2 = bch2_move_extent(&trans, &iter, ctxt, NULL,
                                        io_opts, btree_id, k, data_opts);
@@ -634,7 +632,7 @@ int bch2_move_data(struct bch_fs *c,
        bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc);
 
        for (id = start_btree_id;
-            id <= min_t(unsigned, end_btree_id, BTREE_ID_NR - 1);
+            id <= min_t(unsigned, end_btree_id, btree_id_nr_alive(c) - 1);
             id++) {
                stats->btree_id = id;
 
@@ -642,6 +640,9 @@ int bch2_move_data(struct bch_fs *c,
                    id != BTREE_ID_reflink)
                        continue;
 
+               if (!bch2_btree_id_root(c, id)->b)
+                       continue;
+
                ret = __bch2_move_data(&ctxt,
                                       id == start_btree_id ? start_pos : POS_MIN,
                                       id == end_btree_id   ? end_pos   : POS_MAX,
@@ -676,7 +677,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans,
        struct bpos bp_pos = POS_MIN;
        int ret = 0;
 
-       trace_bucket_evacuate(c, bucket);
+       trace_bucket_evacuate(c, &bucket);
 
        bch2_bkey_buf_init(&sk);
 
@@ -692,7 +693,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans,
        bch2_trans_iter_exit(trans, &iter);
 
        if (ret) {
-               bch_err(c, "%s: error looking up alloc key: %s", __func__, bch2_err_str(ret));
+               bch_err_msg(c, ret, "looking up alloc key");
                goto err;
        }
 
@@ -703,7 +704,7 @@ int __bch2_evacuate_bucket(struct btree_trans *trans,
 
        ret = bch2_btree_write_buffer_flush(trans);
        if (ret) {
-               bch_err(c, "%s: error flushing btree write buffer: %s", __func__, bch2_err_str(ret));
+               bch_err_msg(c, ret, "flushing btree write buffer");
                goto err;
        }
 
@@ -863,10 +864,13 @@ static int bch2_move_btree(struct bch_fs *c,
        stats->data_type = BCH_DATA_btree;
 
        for (id = start_btree_id;
-            id <= min_t(unsigned, end_btree_id, BTREE_ID_NR - 1);
+            id <= min_t(unsigned, end_btree_id, btree_id_nr_alive(c) - 1);
             id++) {
                stats->btree_id = id;
 
+               if (!bch2_btree_id_root(c, id)->b)
+                       continue;
+
                bch2_trans_node_iter_init(&trans, &iter, id, POS_MIN, 0, 0,
                                          BTREE_ITER_PREFETCH);
 retry:
@@ -906,7 +910,7 @@ next:
        bch2_trans_exit(&trans);
 
        if (ret)
-               bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret));
+               bch_err_fn(c, ret);
 
        bch2_btree_interior_updates_flush(c);
 
@@ -1031,6 +1035,8 @@ int bch2_scan_old_btree_nodes(struct bch_fs *c, struct bch_move_stats *stats)
                mutex_unlock(&c->sb_lock);
        }
 
+       if (ret)
+               bch_err_fn(c, ret);
        return ret;
 }