]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Add a progress indicator to bch2_dev_data_drop()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 6 Feb 2025 21:25:29 +0000 (16:25 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 15 Mar 2025 01:02:12 +0000 (21:02 -0400)
This code needs quite a bit of work: we don't want to be walking all
metadata in the filesystem, we should just be walking backpointers, and
it should be switched to a data ioctl that can report progress via a
file descriptor, not the system console.

But that'll take more work - before we can safely walk only backpointers
we need to change device add to not reuse device indexes, since with
that change accounting being wrong introduces the possibility of
removing a device that still has pointers.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/migrate.c

index ddc187fb693d1441fec6ecb39b0b49cec848dc6f..57ad662871ba9b65d0de0d09f9e174d6282fb217 100644 (file)
@@ -15,6 +15,7 @@
 #include "keylist.h"
 #include "migrate.h"
 #include "move.h"
+#include "progress.h"
 #include "replicas.h"
 #include "super-io.h"
 
@@ -76,7 +77,9 @@ static int bch2_dev_usrdata_drop_key(struct btree_trans *trans,
        return 0;
 }
 
-static int bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
+static int bch2_dev_usrdata_drop(struct bch_fs *c,
+                                struct progress_indicator_state *progress,
+                                unsigned dev_idx, int flags)
 {
        struct btree_trans *trans = bch2_trans_get(c);
        enum btree_id id;
@@ -88,8 +91,10 @@ static int bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
 
                ret = for_each_btree_key_commit(trans, iter, id, POS_MIN,
                                BTREE_ITER_prefetch|BTREE_ITER_all_snapshots, k,
-                               NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
-                       bch2_dev_usrdata_drop_key(trans, &iter, k, dev_idx, flags));
+                               NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({
+                       bch2_progress_update_iter(trans, progress, &iter, "dropping user data");
+                       bch2_dev_usrdata_drop_key(trans, &iter, k, dev_idx, flags);
+               }));
                if (ret)
                        break;
        }
@@ -99,7 +104,9 @@ static int bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
        return ret;
 }
 
-static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
+static int bch2_dev_metadata_drop(struct bch_fs *c,
+                                 struct progress_indicator_state *progress,
+                                 unsigned dev_idx, int flags)
 {
        struct btree_trans *trans;
        struct btree_iter iter;
@@ -125,6 +132,8 @@ retry:
                while (bch2_trans_begin(trans),
                       (b = bch2_btree_iter_peek_node(&iter)) &&
                       !(ret = PTR_ERR_OR_ZERO(b))) {
+                       bch2_progress_update_iter(trans, progress, &iter, "dropping metadata");
+
                        if (!bch2_bkey_has_device_c(bkey_i_to_s_c(&b->key), dev_idx))
                                goto next;
 
@@ -169,6 +178,11 @@ err:
 
 int bch2_dev_data_drop(struct bch_fs *c, unsigned dev_idx, int flags)
 {
-       return bch2_dev_usrdata_drop(c, dev_idx, flags) ?:
-               bch2_dev_metadata_drop(c, dev_idx, flags);
+       struct progress_indicator_state progress;
+       bch2_progress_init(&progress, c,
+                          BIT_ULL(BTREE_ID_extents)|
+                          BIT_ULL(BTREE_ID_reflink));
+
+       return bch2_dev_usrdata_drop(c, &progress, dev_idx, flags) ?:
+               bch2_dev_metadata_drop(c, &progress, dev_idx, flags);
 }