]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/rebalance.c
Update bcachefs sources to c887148ebf99 thread_with_file: add f_ops.flush
[bcachefs-tools-debian] / libbcachefs / rebalance.c
index 79bd4ad0126521d3719cc16e2a1a96a5420095a8..56336f3dd1d0771b94c30aaa78d2c6b0d00617e7 100644 (file)
@@ -177,7 +177,7 @@ static struct bkey_s_c next_rebalance_extent(struct btree_trans *trans,
                prt_str(&buf, "target=");
                bch2_target_to_text(&buf, c, r->target);
                prt_str(&buf, " compression=");
-               prt_str(&buf, bch2_compression_opts[r->compression]);
+               bch2_compression_opt_to_text(&buf, r->compression);
                prt_str(&buf, " ");
                bch2_bkey_val_to_text(&buf, c, k);
 
@@ -253,13 +253,12 @@ static bool rebalance_pred(struct bch_fs *c, void *arg,
 
        if (k.k->p.inode) {
                target          = io_opts->background_target;
-               compression     = io_opts->background_compression ?: io_opts->compression;
+               compression     = background_compression(*io_opts);
        } else {
                const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k);
 
                target          = r ? r->target : io_opts->background_target;
-               compression     = r ? r->compression :
-                       (io_opts->background_compression ?: io_opts->compression);
+               compression     = r ? r->compression : background_compression(*io_opts);
        }
 
        data_opts->rewrite_ptrs         = bch2_bkey_ptrs_need_rebalance(c, k, target, compression);
@@ -334,7 +333,7 @@ static int do_rebalance(struct moving_context *ctxt)
        while (!bch2_move_ratelimit(ctxt)) {
                if (!r->enabled) {
                        bch2_moving_ctxt_flush_all(ctxt);
-                       kthread_wait_freezable(c->copy_gc_enabled ||
+                       kthread_wait_freezable(r->enabled ||
                                               kthread_should_stop());
                }
 
@@ -370,6 +369,7 @@ static int do_rebalance(struct moving_context *ctxt)
            !kthread_should_stop() &&
            !atomic64_read(&r->work_stats.sectors_seen) &&
            !atomic64_read(&r->scan_stats.sectors_seen)) {
+               bch2_moving_ctxt_flush_all(ctxt);
                bch2_trans_unlock_long(trans);
                rebalance_wait(c);
        }
@@ -384,7 +384,6 @@ static int bch2_rebalance_thread(void *arg)
        struct bch_fs *c = arg;
        struct bch_fs_rebalance *r = &c->rebalance;
        struct moving_context ctxt;
-       int ret;
 
        set_freezable();
 
@@ -392,8 +391,7 @@ static int bch2_rebalance_thread(void *arg)
                              writepoint_ptr(&c->rebalance_write_point),
                              true);
 
-       while (!kthread_should_stop() &&
-              !(ret = do_rebalance(&ctxt)))
+       while (!kthread_should_stop() && !do_rebalance(&ctxt))
                ;
 
        bch2_moving_ctxt_exit(&ctxt);
@@ -414,11 +412,11 @@ void bch2_rebalance_status_to_text(struct printbuf *out, struct bch_fs *c)
                u64 now = atomic64_read(&c->io_clock[WRITE].now);
 
                prt_str(out, "io wait duration:  ");
-               bch2_prt_human_readable_s64(out, r->wait_iotime_end - r->wait_iotime_start);
+               bch2_prt_human_readable_s64(out, (r->wait_iotime_end - r->wait_iotime_start) << 9);
                prt_newline(out);
 
                prt_str(out, "io wait remaining: ");
-               bch2_prt_human_readable_s64(out, r->wait_iotime_end - now);
+               bch2_prt_human_readable_s64(out, (r->wait_iotime_end - now) << 9);
                prt_newline(out);
 
                prt_str(out, "duration waited:   ");
@@ -469,10 +467,9 @@ int bch2_rebalance_start(struct bch_fs *c)
 
        p = kthread_create(bch2_rebalance_thread, c, "bch-rebalance/%s", c->name);
        ret = PTR_ERR_OR_ZERO(p);
-       if (ret) {
-               bch_err_msg(c, ret, "creating rebalance thread");
+       bch_err_msg(c, ret, "creating rebalance thread");
+       if (ret)
                return ret;
-       }
 
        get_task_struct(p);
        rcu_assign_pointer(c->rebalance.thread, p);