From: Kent Overstreet <kent.overstreet@linux.dev>
To: linux-bcachefs@vger.kernel.org
Cc: Kent Overstreet <kent.overstreet@linux.dev>,
bfoster@redhat.com, sandeen@redhat.com
Subject: [PATCH 07/10] bcachefs: Kill bch2_bucket_gens_read()
Date: Sun, 9 Jul 2023 13:15:48 -0400 [thread overview]
Message-ID: <20230709171551.2349961-8-kent.overstreet@linux.dev> (raw)
In-Reply-To: <20230709171551.2349961-1-kent.overstreet@linux.dev>
This folds bch2_bucket_gens_read() into bch2_alloc_read(), doing the
version check there.
This is prep work for enumarating all recovery passes: we need some
cleanup first to make calling all the recovery passes consistent.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
fs/bcachefs/alloc_background.c | 100 +++++++++++++++------------------
fs/bcachefs/alloc_background.h | 1 -
fs/bcachefs/recovery.c | 6 +-
3 files changed, 45 insertions(+), 62 deletions(-)
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c
index b1dfe300d9..291d97f837 100644
--- a/fs/bcachefs/alloc_background.c
+++ b/fs/bcachefs/alloc_background.c
@@ -551,40 +551,6 @@ bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree_iter *iter
return ERR_PTR(ret);
}
-int bch2_alloc_read(struct bch_fs *c)
-{
- struct btree_trans trans;
- struct btree_iter iter;
- struct bkey_s_c k;
- struct bch_alloc_v4 a;
- struct bch_dev *ca;
- int ret;
-
- bch2_trans_init(&trans, c, 0, 0);
-
- for_each_btree_key(&trans, iter, BTREE_ID_alloc, POS_MIN,
- BTREE_ITER_PREFETCH, k, ret) {
- /*
- * Not a fsck error because this is checked/repaired by
- * bch2_check_alloc_key() which runs later:
- */
- if (!bch2_dev_bucket_exists(c, k.k->p))
- continue;
-
- ca = bch_dev_bkey_exists(c, k.k->p.inode);
-
- *bucket_gen(ca, k.k->p.offset) = bch2_alloc_to_v4(k, &a)->gen;
- }
- bch2_trans_iter_exit(&trans, &iter);
-
- bch2_trans_exit(&trans);
-
- if (ret)
- bch_err_fn(c, ret);
-
- return ret;
-}
-
static struct bpos alloc_gens_pos(struct bpos pos, unsigned *offset)
{
*offset = pos.offset & KEY_TYPE_BUCKET_GENS_MASK;
@@ -692,45 +658,67 @@ int bch2_bucket_gens_init(struct bch_fs *c)
return ret;
}
-int bch2_bucket_gens_read(struct bch_fs *c)
+int bch2_alloc_read(struct bch_fs *c)
{
struct btree_trans trans;
struct btree_iter iter;
struct bkey_s_c k;
- const struct bch_bucket_gens *g;
struct bch_dev *ca;
- u64 b;
int ret;
+ down_read(&c->gc_lock);
bch2_trans_init(&trans, c, 0, 0);
- for_each_btree_key(&trans, iter, BTREE_ID_bucket_gens, POS_MIN,
- BTREE_ITER_PREFETCH, k, ret) {
- u64 start = bucket_gens_pos_to_alloc(k.k->p, 0).offset;
- u64 end = bucket_gens_pos_to_alloc(bpos_nosnap_successor(k.k->p), 0).offset;
+ if (c->sb.version_upgrade_complete >= bcachefs_metadata_version_bucket_gens) {
+ const struct bch_bucket_gens *g;
+ u64 b;
- if (k.k->type != KEY_TYPE_bucket_gens)
- continue;
+ for_each_btree_key(&trans, iter, BTREE_ID_bucket_gens, POS_MIN,
+ BTREE_ITER_PREFETCH, k, ret) {
+ u64 start = bucket_gens_pos_to_alloc(k.k->p, 0).offset;
+ u64 end = bucket_gens_pos_to_alloc(bpos_nosnap_successor(k.k->p), 0).offset;
- g = bkey_s_c_to_bucket_gens(k).v;
+ if (k.k->type != KEY_TYPE_bucket_gens)
+ continue;
- /*
- * Not a fsck error because this is checked/repaired by
- * bch2_check_alloc_key() which runs later:
- */
- if (!bch2_dev_exists2(c, k.k->p.inode))
- continue;
+ g = bkey_s_c_to_bucket_gens(k).v;
+
+ /*
+ * Not a fsck error because this is checked/repaired by
+ * bch2_check_alloc_key() which runs later:
+ */
+ if (!bch2_dev_exists2(c, k.k->p.inode))
+ continue;
- ca = bch_dev_bkey_exists(c, k.k->p.inode);
+ ca = bch_dev_bkey_exists(c, k.k->p.inode);
+
+ for (b = max_t(u64, ca->mi.first_bucket, start);
+ b < min_t(u64, ca->mi.nbuckets, end);
+ b++)
+ *bucket_gen(ca, b) = g->gens[b & KEY_TYPE_BUCKET_GENS_MASK];
+ }
+ bch2_trans_iter_exit(&trans, &iter);
+ } else {
+ struct bch_alloc_v4 a;
- for (b = max_t(u64, ca->mi.first_bucket, start);
- b < min_t(u64, ca->mi.nbuckets, end);
- b++)
- *bucket_gen(ca, b) = g->gens[b & KEY_TYPE_BUCKET_GENS_MASK];
+ for_each_btree_key(&trans, iter, BTREE_ID_alloc, POS_MIN,
+ BTREE_ITER_PREFETCH, k, ret) {
+ /*
+ * Not a fsck error because this is checked/repaired by
+ * bch2_check_alloc_key() which runs later:
+ */
+ if (!bch2_dev_bucket_exists(c, k.k->p))
+ continue;
+
+ ca = bch_dev_bkey_exists(c, k.k->p.inode);
+
+ *bucket_gen(ca, k.k->p.offset) = bch2_alloc_to_v4(k, &a)->gen;
+ }
+ bch2_trans_iter_exit(&trans, &iter);
}
- bch2_trans_iter_exit(&trans, &iter);
bch2_trans_exit(&trans);
+ up_read(&c->gc_lock);
if (ret)
bch_err_fn(c, ret);
diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
index d1bf45a4b4..c0914feb54 100644
--- a/fs/bcachefs/alloc_background.h
+++ b/fs/bcachefs/alloc_background.h
@@ -212,7 +212,6 @@ static inline bool bkey_is_alloc(const struct bkey *k)
}
int bch2_alloc_read(struct bch_fs *);
-int bch2_bucket_gens_read(struct bch_fs *);
int bch2_trans_mark_alloc(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_i *, unsigned);
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index c90205aa22..4c61a28e49 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -1309,11 +1309,7 @@ int bch2_fs_recovery(struct bch_fs *c)
goto err;
bch_verbose(c, "starting alloc read");
- down_read(&c->gc_lock);
- ret = c->sb.version < bcachefs_metadata_version_bucket_gens
- ? bch2_alloc_read(c)
- : bch2_bucket_gens_read(c);
- up_read(&c->gc_lock);
+ ret = bch2_alloc_read(c);
if (ret)
goto err;
bch_verbose(c, "alloc read done");
--
2.40.1
next prev parent reply other threads:[~2023-07-09 17:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-09 17:15 [PATCH 00/10] bcachefs - semvar, forward compatibility Kent Overstreet
2023-07-09 17:15 ` [PATCH 01/10] bcachefs: Allow for unknown btree IDs Kent Overstreet
2023-07-09 17:15 ` [PATCH 02/10] bcachefs: Allow for unknown key types Kent Overstreet
2023-07-09 17:15 ` [PATCH 03/10] bcachefs: Refactor bch_sb_field_ops handling Kent Overstreet
2023-07-09 17:15 ` [PATCH 04/10] bcachefs: Change check for invalid key types Kent Overstreet
2023-07-09 17:15 ` [PATCH 05/10] bcachefs: BCH_SB_VERSION_UPGRADE_COMPLETE() Kent Overstreet
2023-07-13 13:42 ` Brian Foster
2023-07-13 15:31 ` Kent Overstreet
2023-07-09 17:15 ` [PATCH 06/10] bcachefs: version_upgrade is now an enum Kent Overstreet
2023-07-09 17:15 ` Kent Overstreet [this message]
2023-07-09 17:15 ` [PATCH 08/10] bcachefs: Stash journal replay params in bch_fs Kent Overstreet
2023-07-09 17:15 ` [PATCH 09/10] bcachefs: Enumerate recovery passes Kent Overstreet
2023-07-09 17:15 ` [PATCH 10/10] bcachefs: bcachefs_metadata_version_major_minor Kent Overstreet
2023-07-09 17:49 ` Thomas Weißschuh
2023-07-09 18:31 ` Kent Overstreet
2023-07-09 19:29 ` Thomas Weißschuh
2023-07-09 20:08 ` Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230709171551.2349961-8-kent.overstreet@linux.dev \
--to=kent.overstreet@linux.dev \
--cc=bfoster@redhat.com \
--cc=linux-bcachefs@vger.kernel.org \
--cc=sandeen@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).