diff --git a/6.4/misc/0001-bcachefs.patch b/6.4/misc/0001-bcachefs.patch index fdc2b559..d411014a 100644 --- a/6.4/misc/0001-bcachefs.patch +++ b/6.4/misc/0001-bcachefs.patch @@ -1,6 +1,6 @@ -From be070befba53c2f1c7c79d6a528c162c7ed943bb Mon Sep 17 00:00:00 2001 +From a14a7b200d823d9ba18f1dbae21705e8a3e88f22 Mon Sep 17 00:00:00 2001 From: Piotr Gorski -Date: Wed, 28 Jun 2023 08:17:01 +0200 +Date: Thu, 29 Jun 2023 08:18:38 +0200 Subject: [PATCH] bcachefs Signed-off-by: Piotr Gorski @@ -22,7 +22,7 @@ Signed-off-by: Piotr Gorski fs/bcachefs/Makefile | 74 + fs/bcachefs/acl.c | 414 ++ fs/bcachefs/acl.h | 58 + - fs/bcachefs/alloc_background.c | 2216 +++++++++ + fs/bcachefs/alloc_background.c | 2218 +++++++++ fs/bcachefs/alloc_background.h | 251 ++ fs/bcachefs/alloc_foreground.c | 1535 +++++++ fs/bcachefs/alloc_foreground.h | 224 + @@ -31,7 +31,7 @@ Signed-off-by: Piotr Gorski fs/bcachefs/backpointers.h | 131 + fs/bcachefs/bbpos.h | 48 + fs/bcachefs/bcachefs.h | 1139 +++++ - fs/bcachefs/bcachefs_format.h | 2245 ++++++++++ + fs/bcachefs/bcachefs_format.h | 2243 ++++++++++ fs/bcachefs/bcachefs_ioctl.h | 368 ++ fs/bcachefs/bkey.c | 1063 +++++ fs/bcachefs/bkey.h | 774 ++++ @@ -51,16 +51,16 @@ Signed-off-by: Piotr Gorski fs/bcachefs/btree_io.h | 228 + fs/bcachefs/btree_iter.c | 3214 ++++++++++++++ fs/bcachefs/btree_iter.h | 916 ++++ - fs/bcachefs/btree_key_cache.c | 1088 +++++ + fs/bcachefs/btree_key_cache.c | 1087 +++++ fs/bcachefs/btree_key_cache.h | 48 + fs/bcachefs/btree_locking.c | 804 ++++ fs/bcachefs/btree_locking.h | 424 ++ fs/bcachefs/btree_types.h | 737 +++ - fs/bcachefs/btree_update.h | 360 ++ - fs/bcachefs/btree_update_interior.c | 2476 +++++++++++ - fs/bcachefs/btree_update_interior.h | 327 ++ + fs/bcachefs/btree_update.h | 357 ++ + fs/bcachefs/btree_update_interior.c | 2477 +++++++++++ + fs/bcachefs/btree_update_interior.h | 328 ++ fs/bcachefs/btree_update_leaf.c | 2050 +++++++++ - fs/bcachefs/btree_write_buffer.c | 343 ++ + fs/bcachefs/btree_write_buffer.c | 345 ++ fs/bcachefs/btree_write_buffer.h | 14 + fs/bcachefs/btree_write_buffer_types.h | 44 + fs/bcachefs/buckets.c | 2200 +++++++++ @@ -81,7 +81,7 @@ Signed-off-by: Piotr Gorski fs/bcachefs/counters.c | 107 + fs/bcachefs/counters.h | 17 + fs/bcachefs/darray.h | 87 + - fs/bcachefs/data_update.c | 565 +++ + fs/bcachefs/data_update.c | 564 +++ fs/bcachefs/data_update.h | 43 + fs/bcachefs/debug.c | 957 ++++ fs/bcachefs/debug.h | 32 + @@ -120,7 +120,7 @@ Signed-off-by: Piotr Gorski fs/bcachefs/io_types.h | 165 + fs/bcachefs/journal.c | 1448 ++++++ fs/bcachefs/journal.h | 526 +++ - fs/bcachefs/journal_io.c | 1868 ++++++++ + fs/bcachefs/journal_io.c | 1858 ++++++++ fs/bcachefs/journal_io.h | 64 + fs/bcachefs/journal_reclaim.c | 863 ++++ fs/bcachefs/journal_reclaim.h | 86 + @@ -144,8 +144,8 @@ Signed-off-by: Piotr Gorski fs/bcachefs/nocow_locking.c | 123 + fs/bcachefs/nocow_locking.h | 49 + fs/bcachefs/nocow_locking_types.h | 20 + - fs/bcachefs/opts.c | 555 +++ - fs/bcachefs/opts.h | 543 +++ + fs/bcachefs/opts.c | 550 +++ + fs/bcachefs/opts.h | 542 +++ fs/bcachefs/printbuf.c | 415 ++ fs/bcachefs/printbuf.h | 284 ++ fs/bcachefs/quota.c | 980 ++++ @@ -154,7 +154,7 @@ Signed-off-by: Piotr Gorski fs/bcachefs/rebalance.c | 363 ++ fs/bcachefs/rebalance.h | 28 + fs/bcachefs/rebalance_types.h | 26 + - fs/bcachefs/recovery.c | 1648 +++++++ + fs/bcachefs/recovery.c | 1653 +++++++ fs/bcachefs/recovery.h | 58 + fs/bcachefs/reflink.c | 388 ++ fs/bcachefs/reflink.h | 79 + @@ -168,9 +168,9 @@ Signed-off-by: Piotr Gorski fs/bcachefs/subvolume.c | 1505 +++++++ fs/bcachefs/subvolume.h | 167 + fs/bcachefs/subvolume_types.h | 22 + - fs/bcachefs/super-io.c | 1597 +++++++ - fs/bcachefs/super-io.h | 126 + - fs/bcachefs/super.c | 1993 +++++++++ + fs/bcachefs/super-io.c | 1616 +++++++ + fs/bcachefs/super-io.h | 134 + + fs/bcachefs/super.c | 1995 +++++++++ fs/bcachefs/super.h | 266 ++ fs/bcachefs/super_types.h | 51 + fs/bcachefs/sysfs.c | 1064 +++++ @@ -242,7 +242,7 @@ Signed-off-by: Piotr Gorski mm/vmscan.c | 99 +- scripts/Kbuild.include | 10 + scripts/Makefile.lib | 2 +- - 237 files changed, 93032 insertions(+), 249 deletions(-) + 237 files changed, 93049 insertions(+), 249 deletions(-) create mode 100644 fs/bcachefs/Kconfig create mode 100644 fs/bcachefs/Makefile create mode 100644 fs/bcachefs/acl.c @@ -1491,10 +1491,10 @@ index 000000000..bb21d8d69 +#endif /* _BCACHEFS_ACL_H */ diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c new file mode 100644 -index 000000000..9f8311111 +index 000000000..7bd472ae5 --- /dev/null +++ b/fs/bcachefs/alloc_background.c -@@ -0,0 +1,2216 @@ +@@ -0,0 +1,2218 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "bcachefs.h" +#include "alloc_background.h" @@ -3216,7 +3216,8 @@ index 000000000..9f8311111 +write: + ret = bch2_trans_update(trans, &iter, &a->k_i, 0) ?: + bch2_trans_commit(trans, NULL, NULL, -+ BTREE_INSERT_USE_RESERVE|BTREE_INSERT_NOFAIL); ++ BCH_WATERMARK_btree| ++ BTREE_INSERT_NOFAIL); + if (ret) + goto out; + @@ -3324,7 +3325,8 @@ index 000000000..9f8311111 + ret = bch2_trans_update(trans, &alloc_iter, &a->k_i, + BTREE_TRIGGER_BUCKET_INVALIDATE) ?: + bch2_trans_commit(trans, NULL, NULL, -+ BTREE_INSERT_USE_RESERVE|BTREE_INSERT_NOFAIL); ++ BCH_WATERMARK_btree| ++ BTREE_INSERT_NOFAIL); + if (ret) + goto out; + @@ -8101,10 +8103,10 @@ index 000000000..b8d50fe64 +#endif /* _BCACHEFS_H */ diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h new file mode 100644 -index 000000000..158cefb87 +index 000000000..4401d2767 --- /dev/null +++ b/fs/bcachefs/bcachefs_format.h -@@ -0,0 +1,2245 @@ +@@ -0,0 +1,2243 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_FORMAT_H +#define _BCACHEFS_FORMAT_H @@ -9681,8 +9683,6 @@ index 000000000..158cefb87 + * One common version number for all on disk data structures - superblock, btree + * nodes, journal entries + */ -+#define BCH_JSET_VERSION_OLD 2 -+#define BCH_BSET_VERSION_OLD 3 + +#define BCH_METADATA_VERSIONS() \ + x(bkey_renumber, 10) \ @@ -19521,7 +19521,7 @@ index 000000000..95d803b57 +#endif /* _BCACHEFS_BTREE_GC_H */ diff --git a/fs/bcachefs/btree_io.c b/fs/bcachefs/btree_io.c new file mode 100644 -index 000000000..19aca1c0f +index 000000000..9985ecd72 --- /dev/null +++ b/fs/bcachefs/btree_io.c @@ -0,0 +1,2261 @@ @@ -20226,11 +20226,9 @@ index 000000000..19aca1c0f + struct printbuf buf2 = PRINTBUF; + int ret = 0; + -+ btree_err_on((version != BCH_BSET_VERSION_OLD && -+ version < bcachefs_metadata_version_min) || -+ version >= bcachefs_metadata_version_max, ++ btree_err_on(!bch2_version_compatible(version), + BTREE_ERR_INCOMPATIBLE, c, ca, b, i, -+ "unsupported bset version"); ++ "unsupported bset version %u", version); + + if (btree_err_on(version < c->sb.version_min, + BTREE_ERR_FIXABLE, c, NULL, b, i, @@ -21293,7 +21291,11 @@ index 000000000..19aca1c0f + } else { + ret = bch2_trans_do(c, NULL, NULL, 0, + bch2_btree_node_update_key_get_iter(&trans, b, &wbio->key, -+ !wbio->wbio.failed.nr)); ++ BCH_WATERMARK_reclaim| ++ BTREE_INSERT_JOURNAL_RECLAIM| ++ BTREE_INSERT_NOFAIL| ++ BTREE_INSERT_NOCHECK_RW, ++ !wbio->wbio.failed.nr)); + if (ret) + goto err; + } @@ -21542,9 +21544,7 @@ index 000000000..19aca1c0f + BUG_ON(BSET_BIG_ENDIAN(i) != CPU_BIG_ENDIAN); + BUG_ON(i->seq != b->data->keys.seq); + -+ i->version = c->sb.version < bcachefs_metadata_version_bkey_renumber -+ ? cpu_to_le16(BCH_BSET_VERSION_OLD) -+ : cpu_to_le16(c->sb.version); ++ i->version = cpu_to_le16(c->sb.version); + SET_BSET_OFFSET(i, b->written); + SET_BSET_CSUM_TYPE(i, bch2_meta_checksum_type(c)); + @@ -26164,10 +26164,10 @@ index 000000000..13d4e9aac +#endif /* _BCACHEFS_BTREE_ITER_H */ diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c new file mode 100644 -index 000000000..1629e3155 +index 000000000..a71db7ab7 --- /dev/null +++ b/fs/bcachefs/btree_key_cache.c -@@ -0,0 +1,1088 @@ +@@ -0,0 +1,1087 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "bcachefs.h" @@ -26821,7 +26821,6 @@ index 000000000..1629e3155 + bch2_trans_commit(trans, NULL, NULL, + BTREE_INSERT_NOCHECK_RW| + BTREE_INSERT_NOFAIL| -+ BTREE_INSERT_USE_RESERVE| + (ck->journal.seq == journal_last_seq(j) + ? BCH_WATERMARK_reclaim + : 0)| @@ -29295,10 +29294,10 @@ index 000000000..d4ff72128 +#endif /* _BCACHEFS_BTREE_TYPES_H */ diff --git a/fs/bcachefs/btree_update.h b/fs/bcachefs/btree_update.h new file mode 100644 -index 000000000..e1aa24946 +index 000000000..93d2e54aa --- /dev/null +++ b/fs/bcachefs/btree_update.h -@@ -0,0 +1,360 @@ +@@ -0,0 +1,357 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_BTREE_UPDATE_H +#define _BCACHEFS_BTREE_UPDATE_H @@ -29328,7 +29327,6 @@ index 000000000..e1aa24946 + __BTREE_INSERT_NOFAIL = BCH_WATERMARK_BITS, + __BTREE_INSERT_NOCHECK_RW, + __BTREE_INSERT_LAZY_RW, -+ __BTREE_INSERT_USE_RESERVE, + __BTREE_INSERT_JOURNAL_REPLAY, + __BTREE_INSERT_JOURNAL_RECLAIM, + __BTREE_INSERT_NOWAIT, @@ -29338,26 +29336,23 @@ index 000000000..e1aa24946 +}; + +/* Don't check for -ENOSPC: */ -+#define BTREE_INSERT_NOFAIL (1 << __BTREE_INSERT_NOFAIL) ++#define BTREE_INSERT_NOFAIL BIT(__BTREE_INSERT_NOFAIL) + -+#define BTREE_INSERT_NOCHECK_RW (1 << __BTREE_INSERT_NOCHECK_RW) -+#define BTREE_INSERT_LAZY_RW (1 << __BTREE_INSERT_LAZY_RW) -+ -+/* for copygc, or when merging btree nodes */ -+#define BTREE_INSERT_USE_RESERVE (1 << __BTREE_INSERT_USE_RESERVE) ++#define BTREE_INSERT_NOCHECK_RW BIT(__BTREE_INSERT_NOCHECK_RW) ++#define BTREE_INSERT_LAZY_RW BIT(__BTREE_INSERT_LAZY_RW) + +/* Insert is for journal replay - don't get journal reservations: */ -+#define BTREE_INSERT_JOURNAL_REPLAY (1 << __BTREE_INSERT_JOURNAL_REPLAY) ++#define BTREE_INSERT_JOURNAL_REPLAY BIT(__BTREE_INSERT_JOURNAL_REPLAY) + +/* Insert is being called from journal reclaim path: */ -+#define BTREE_INSERT_JOURNAL_RECLAIM (1 << __BTREE_INSERT_JOURNAL_RECLAIM) ++#define BTREE_INSERT_JOURNAL_RECLAIM BIT(__BTREE_INSERT_JOURNAL_RECLAIM) + +/* Don't block on allocation failure (for new btree nodes: */ -+#define BTREE_INSERT_NOWAIT (1 << __BTREE_INSERT_NOWAIT) -+#define BTREE_INSERT_GC_LOCK_HELD (1 << __BTREE_INSERT_GC_LOCK_HELD) ++#define BTREE_INSERT_NOWAIT BIT(__BTREE_INSERT_NOWAIT) ++#define BTREE_INSERT_GC_LOCK_HELD BIT(__BTREE_INSERT_GC_LOCK_HELD) + -+#define BCH_HASH_SET_MUST_CREATE (1 << __BCH_HASH_SET_MUST_CREATE) -+#define BCH_HASH_SET_MUST_REPLACE (1 << __BCH_HASH_SET_MUST_REPLACE) ++#define BCH_HASH_SET_MUST_CREATE BIT(__BCH_HASH_SET_MUST_CREATE) ++#define BCH_HASH_SET_MUST_REPLACE BIT(__BCH_HASH_SET_MUST_REPLACE) + +int bch2_btree_delete_extent_at(struct btree_trans *, struct btree_iter *, + unsigned, unsigned); @@ -29381,9 +29376,10 @@ index 000000000..e1aa24946 + struct btree *, unsigned); +void bch2_btree_node_rewrite_async(struct bch_fs *, struct btree *); +int bch2_btree_node_update_key(struct btree_trans *, struct btree_iter *, -+ struct btree *, struct bkey_i *, bool); -+int bch2_btree_node_update_key_get_iter(struct btree_trans *, -+ struct btree *, struct bkey_i *, bool); ++ struct btree *, struct bkey_i *, ++ unsigned, bool); ++int bch2_btree_node_update_key_get_iter(struct btree_trans *, struct btree *, ++ struct bkey_i *, unsigned, bool); + +int __bch2_insert_snapshot_whiteouts(struct btree_trans *, enum btree_id, + struct bpos, struct bpos); @@ -29661,10 +29657,10 @@ index 000000000..e1aa24946 +#endif /* _BCACHEFS_BTREE_UPDATE_H */ diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c new file mode 100644 -index 000000000..914cb80fc +index 000000000..4c8effa4b --- /dev/null +++ b/fs/bcachefs/btree_update_interior.c -@@ -0,0 +1,2476 @@ +@@ -0,0 +1,2477 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "bcachefs.h" @@ -29913,18 +29909,12 @@ index 000000000..914cb80fc + BKEY_PADDED_ONSTACK(k, BKEY_BTREE_PTR_VAL_U64s_MAX) tmp; + struct open_buckets ob = { .nr = 0 }; + struct bch_devs_list devs_have = (struct bch_devs_list) { 0 }; -+ unsigned nr_reserve; -+ enum bch_watermark alloc_reserve; ++ enum bch_watermark watermark = flags & BCH_WATERMARK_MASK; ++ unsigned nr_reserve = watermark > BCH_WATERMARK_reclaim ++ ? BTREE_NODE_RESERVE ++ : 0; + int ret; + -+ if (flags & BTREE_INSERT_USE_RESERVE) { -+ nr_reserve = 0; -+ alloc_reserve = BCH_WATERMARK_btree_copygc; -+ } else { -+ nr_reserve = BTREE_NODE_RESERVE; -+ alloc_reserve = BCH_WATERMARK_btree; -+ } -+ + mutex_lock(&c->btree_reserve_cache_lock); + if (c->btree_reserve_cache_nr > nr_reserve) { + struct btree_alloc *a = @@ -29946,7 +29936,7 @@ index 000000000..914cb80fc + &devs_have, + res->nr_replicas, + c->opts.metadata_replicas_required, -+ alloc_reserve, 0, cl, &wp); ++ watermark, 0, cl, &wp); + if (unlikely(ret)) + return ERR_PTR(ret); + @@ -30314,11 +30304,10 @@ index 000000000..914cb80fc + * which may require allocations as well. + */ + ret = commit_do(&trans, &as->disk_res, &journal_seq, ++ BCH_WATERMARK_reclaim| + BTREE_INSERT_NOFAIL| + BTREE_INSERT_NOCHECK_RW| -+ BTREE_INSERT_USE_RESERVE| -+ BTREE_INSERT_JOURNAL_RECLAIM| -+ BCH_WATERMARK_reclaim, ++ BTREE_INSERT_JOURNAL_RECLAIM, + btree_update_nodes_written_trans(&trans, as)); + bch2_trans_unlock(&trans); + @@ -30716,14 +30705,24 @@ index 000000000..914cb80fc + ? BCH_DISK_RESERVATION_NOFAIL : 0; + unsigned nr_nodes[2] = { 0, 0 }; + unsigned update_level = level; -+ int journal_flags = flags & BCH_WATERMARK_MASK; ++ enum bch_watermark watermark = flags & BCH_WATERMARK_MASK; ++ unsigned journal_flags = 0; + int ret = 0; + u32 restart_count = trans->restart_count; + + BUG_ON(!path->should_be_locked); + ++ if (watermark == BCH_WATERMARK_copygc) ++ watermark = BCH_WATERMARK_btree_copygc; ++ if (watermark < BCH_WATERMARK_btree) ++ watermark = BCH_WATERMARK_btree; ++ ++ flags &= ~BCH_WATERMARK_MASK; ++ flags |= watermark; ++ + if (flags & BTREE_INSERT_JOURNAL_RECLAIM) + journal_flags |= JOURNAL_RES_GET_NONBLOCK; ++ journal_flags |= watermark; + + while (1) { + nr_nodes[!!update_level] += 1 + split; @@ -31512,9 +31511,7 @@ index 000000000..914cb80fc + + parent = btree_node_parent(path, b); + as = bch2_btree_update_start(trans, path, level, false, -+ BTREE_INSERT_NOFAIL| -+ BTREE_INSERT_USE_RESERVE| -+ flags); ++ BTREE_INSERT_NOFAIL|flags); + ret = PTR_ERR_OR_ZERO(as); + if (ret) + goto err; @@ -31794,6 +31791,7 @@ index 000000000..914cb80fc + struct btree_iter *iter, + struct btree *b, struct btree *new_hash, + struct bkey_i *new_key, ++ unsigned commit_flags, + bool skip_triggers) +{ + struct bch_fs *c = trans->c; @@ -31854,12 +31852,7 @@ index 000000000..914cb80fc + trans->extra_journal_entries.nr += jset_u64s(new_key->k.u64s); + } + -+ ret = bch2_trans_commit(trans, NULL, NULL, -+ BTREE_INSERT_NOFAIL| -+ BTREE_INSERT_NOCHECK_RW| -+ BTREE_INSERT_USE_RESERVE| -+ BTREE_INSERT_JOURNAL_RECLAIM| -+ BCH_WATERMARK_reclaim); ++ ret = bch2_trans_commit(trans, NULL, NULL, commit_flags); + if (ret) + goto err; + @@ -31893,7 +31886,7 @@ index 000000000..914cb80fc + +int bch2_btree_node_update_key(struct btree_trans *trans, struct btree_iter *iter, + struct btree *b, struct bkey_i *new_key, -+ bool skip_triggers) ++ unsigned commit_flags, bool skip_triggers) +{ + struct bch_fs *c = trans->c; + struct btree *new_hash = NULL; @@ -31923,8 +31916,8 @@ index 000000000..914cb80fc + } + + path->intent_ref++; -+ ret = __bch2_btree_node_update_key(trans, iter, b, new_hash, -+ new_key, skip_triggers); ++ ret = __bch2_btree_node_update_key(trans, iter, b, new_hash, new_key, ++ commit_flags, skip_triggers); + --path->intent_ref; + + if (new_hash) { @@ -31942,7 +31935,7 @@ index 000000000..914cb80fc + +int bch2_btree_node_update_key_get_iter(struct btree_trans *trans, + struct btree *b, struct bkey_i *new_key, -+ bool skip_triggers) ++ unsigned commit_flags, bool skip_triggers) +{ + struct btree_iter iter; + int ret; @@ -31963,7 +31956,8 @@ index 000000000..914cb80fc + + BUG_ON(!btree_node_hashed(b)); + -+ ret = bch2_btree_node_update_key(trans, &iter, b, new_key, skip_triggers); ++ ret = bch2_btree_node_update_key(trans, &iter, b, new_key, ++ commit_flags, skip_triggers); +out: + bch2_trans_iter_exit(trans, &iter); + return ret; @@ -32119,7 +32113,7 @@ index 000000000..914cb80fc + mempool_exit(&c->btree_interior_update_pool); +} + -+int bch2_fs_btree_interior_update_init(struct bch_fs *c) ++void bch2_fs_btree_interior_update_init_early(struct bch_fs *c) +{ + mutex_init(&c->btree_reserve_cache_lock); + INIT_LIST_HEAD(&c->btree_interior_update_list); @@ -32129,7 +32123,10 @@ index 000000000..914cb80fc + + INIT_LIST_HEAD(&c->pending_node_rewrites); + mutex_init(&c->pending_node_rewrites_lock); ++} + ++int bch2_fs_btree_interior_update_init(struct bch_fs *c) ++{ + c->btree_interior_update_worker = + alloc_workqueue("btree_update", WQ_UNBOUND|WQ_MEM_RECLAIM, 1); + if (!c->btree_interior_update_worker) @@ -32143,10 +32140,10 @@ index 000000000..914cb80fc +} diff --git a/fs/bcachefs/btree_update_interior.h b/fs/bcachefs/btree_update_interior.h new file mode 100644 -index 000000000..dcfd7ceac +index 000000000..221b7ad5d --- /dev/null +++ b/fs/bcachefs/btree_update_interior.h -@@ -0,0 +1,327 @@ +@@ -0,0 +1,328 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_BTREE_UPDATE_INTERIOR_H +#define _BCACHEFS_BTREE_UPDATE_INTERIOR_H @@ -32471,6 +32468,7 @@ index 000000000..dcfd7ceac +void bch2_free_pending_node_rewrites(struct bch_fs *); + +void bch2_fs_btree_interior_update_exit(struct bch_fs *); ++void bch2_fs_btree_interior_update_init_early(struct bch_fs *); +int bch2_fs_btree_interior_update_init(struct bch_fs *); + +#endif /* _BCACHEFS_BTREE_UPDATE_INTERIOR_H */ @@ -34532,10 +34530,10 @@ index 000000000..b20b8c090 +} diff --git a/fs/bcachefs/btree_write_buffer.c b/fs/bcachefs/btree_write_buffer.c new file mode 100644 -index 000000000..fb0b28a1a +index 000000000..3a3e36c16 --- /dev/null +++ b/fs/bcachefs/btree_write_buffer.c -@@ -0,0 +1,343 @@ +@@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "bcachefs.h" @@ -34751,6 +34749,9 @@ index 000000000..fb0b28a1a + btree_write_buffered_journal_cmp, + NULL); + ++ commit_flags &= ~BCH_WATERMARK_MASK; ++ commit_flags |= BCH_WATERMARK_reclaim; ++ + for (i = keys; i < keys + nr; i++) { + if (!i->journal_seq) + continue; @@ -34769,8 +34770,7 @@ index 000000000..fb0b28a1a + ret = commit_do(trans, NULL, NULL, + commit_flags| + BTREE_INSERT_NOFAIL| -+ BTREE_INSERT_JOURNAL_RECLAIM| -+ BCH_WATERMARK_reclaim, ++ BTREE_INSERT_JOURNAL_RECLAIM, + __bch2_btree_insert(trans, i->btree, &i->k, 0)); + if (bch2_fs_fatal_err_on(ret, c, "%s: insert error %s", __func__, bch2_err_str(ret))) + break; @@ -40788,10 +40788,10 @@ index 000000000..d4485fa01 +#endif /* _BCACHEFS_DARRAY_H */ diff --git a/fs/bcachefs/data_update.c b/fs/bcachefs/data_update.c new file mode 100644 -index 000000000..cc79bcb67 +index 000000000..3c918368b --- /dev/null +++ b/fs/bcachefs/data_update.c -@@ -0,0 +1,565 @@ +@@ -0,0 +1,564 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "bcachefs.h" @@ -41252,8 +41252,7 @@ index 000000000..cc79bcb67 + m->op.compression_type = + bch2_compression_opt_to_type[io_opts.background_compression ?: + io_opts.compression]; -+ if (m->data_opts.btree_insert_flags & BTREE_INSERT_USE_RESERVE) -+ m->op.watermark = BCH_WATERMARK_copygc; ++ m->op.watermark = m->data_opts.btree_insert_flags & BCH_WATERMARK_MASK; + + bkey_for_each_ptr(ptrs, ptr) + percpu_ref_get(&bch_dev_bkey_exists(c, ptr->dev)->ref); @@ -57034,7 +57033,7 @@ index 000000000..2e63cb660 +#endif /* _BCACHEFS_FS_H */ diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c new file mode 100644 -index 000000000..7af65030f +index 000000000..674018a58 --- /dev/null +++ b/fs/bcachefs/fsck.c @@ -0,0 +1,2505 @@ @@ -58256,7 +58255,7 @@ index 000000000..7af65030f + if (ret) + break; + -+ if (fsck_err(c, buf.buf)) { ++ if (fsck_err(c, "%s", buf.buf)) { + struct bkey_i *update = bch2_trans_kmalloc(trans, bkey_bytes(k.k)); + if ((ret = PTR_ERR_OR_ZERO(update))) + goto err; @@ -66058,10 +66057,10 @@ index 000000000..008a2e25a +#endif /* _BCACHEFS_JOURNAL_H */ diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c new file mode 100644 -index 000000000..7d0dd1b1d +index 000000000..a084c6d0f --- /dev/null +++ b/fs/bcachefs/journal_io.c -@@ -0,0 +1,1868 @@ +@@ -0,0 +1,1858 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "bcachefs.h" +#include "alloc_background.h" @@ -66809,14 +66808,10 @@ index 000000000..7d0dd1b1d + return JOURNAL_ENTRY_NONE; + + version = le32_to_cpu(jset->version); -+ if (journal_entry_err_on((version != BCH_JSET_VERSION_OLD && -+ version < bcachefs_metadata_version_min) || -+ version >= bcachefs_metadata_version_max, -+ c, jset, NULL, -+ "%s sector %llu seq %llu: unknown journal entry version %u", ++ if (journal_entry_err_on(!bch2_version_compatible(version), c, jset, NULL, ++ "%s sector %llu seq %llu: incompatible journal entry version %u", + ca ? ca->name : c->name, -+ sector, le64_to_cpu(jset->seq), -+ version)) { ++ sector, le64_to_cpu(jset->seq), version)) { + /* don't try to continue: */ + return -EINVAL; + } @@ -66860,14 +66855,10 @@ index 000000000..7d0dd1b1d + return JOURNAL_ENTRY_NONE; + + version = le32_to_cpu(jset->version); -+ if (journal_entry_err_on((version != BCH_JSET_VERSION_OLD && -+ version < bcachefs_metadata_version_min) || -+ version >= bcachefs_metadata_version_max, -+ c, jset, NULL, ++ if (journal_entry_err_on(!bch2_version_compatible(version), c, jset, NULL, + "%s sector %llu seq %llu: unknown journal entry version %u", + ca ? ca->name : c->name, -+ sector, le64_to_cpu(jset->seq), -+ version)) { ++ sector, le64_to_cpu(jset->seq), version)) { + /* don't try to continue: */ + return -EINVAL; + } @@ -67819,9 +67810,7 @@ index 000000000..7d0dd1b1d + } + + jset->magic = cpu_to_le64(jset_magic(c)); -+ jset->version = c->sb.version < bcachefs_metadata_version_bkey_renumber -+ ? cpu_to_le32(BCH_JSET_VERSION_OLD) -+ : cpu_to_le32(c->sb.version); ++ jset->version = cpu_to_le32(c->sb.version); + + SET_JSET_BIG_ENDIAN(jset, CPU_BIG_ENDIAN); + SET_JSET_CSUM_TYPE(jset, bch2_meta_checksum_type(c)); @@ -70338,7 +70327,7 @@ index 000000000..adb984292 +#endif /* _BCACHEFS_LRU_H */ diff --git a/fs/bcachefs/migrate.c b/fs/bcachefs/migrate.c new file mode 100644 -index 000000000..783e9442b +index 000000000..81c8cdbac --- /dev/null +++ b/fs/bcachefs/migrate.c @@ -0,0 +1,182 @@ @@ -70485,7 +70474,7 @@ index 000000000..783e9442b + break; + } + -+ ret = bch2_btree_node_update_key(&trans, &iter, b, k.k, false); ++ ret = bch2_btree_node_update_key(&trans, &iter, b, k.k, 0, false); + if (bch2_err_matches(ret, BCH_ERR_transaction_restart)) { + ret = 0; + continue; @@ -71851,7 +71840,7 @@ index 000000000..baf1f8570 +#endif /* _BCACHEFS_MOVE_TYPES_H */ diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c new file mode 100644 -index 000000000..e1ca41404 +index 000000000..5242f20bb --- /dev/null +++ b/fs/bcachefs/movinggc.c @@ -0,0 +1,421 @@ @@ -72059,7 +72048,7 @@ index 000000000..e1ca41404 +{ + struct bch_fs *c = trans->c; + struct data_update_opts data_opts = { -+ .btree_insert_flags = BTREE_INSERT_USE_RESERVE|BCH_WATERMARK_copygc, ++ .btree_insert_flags = BCH_WATERMARK_copygc, + }; + move_buckets buckets = { 0 }; + struct move_bucket_in_flight *f; @@ -72506,10 +72495,10 @@ index 000000000..bd12bf677 + diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c new file mode 100644 -index 000000000..04e2989cd +index 000000000..a05c38983 --- /dev/null +++ b/fs/bcachefs/opts.c -@@ -0,0 +1,555 @@ +@@ -0,0 +1,550 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include @@ -72523,11 +72512,6 @@ index 000000000..04e2989cd + +#define x(t, n) [n] = #t, + -+const char * const bch2_metadata_versions[] = { -+ BCH_METADATA_VERSIONS() -+ NULL -+}; -+ +const char * const bch2_error_actions[] = { + BCH_ERROR_ACTIONS() + NULL @@ -73067,10 +73051,10 @@ index 000000000..04e2989cd +} diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h new file mode 100644 -index 000000000..719693b33 +index 000000000..e7cf7e92f --- /dev/null +++ b/fs/bcachefs/opts.h -@@ -0,0 +1,543 @@ +@@ -0,0 +1,542 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_OPTS_H +#define _BCACHEFS_OPTS_H @@ -73081,7 +73065,6 @@ index 000000000..719693b33 +#include +#include "bcachefs_format.h" + -+extern const char * const bch2_metadata_versions[]; +extern const char * const bch2_error_actions[]; +extern const char * const bch2_sb_features[]; +extern const char * const bch2_sb_compat[]; @@ -75875,10 +75858,10 @@ index 000000000..7462a92e9 +#endif /* _BCACHEFS_REBALANCE_TYPES_H */ diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c new file mode 100644 -index 000000000..16a99edb2 +index 000000000..b86442c7c --- /dev/null +++ b/fs/bcachefs/recovery.c -@@ -0,0 +1,1648 @@ +@@ -0,0 +1,1653 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "bcachefs.h" @@ -77027,17 +77010,22 @@ index 000000000..16a99edb2 + goto err; + } + -+ if (!c->opts.nochanges) { -+ if (c->sb.version < bcachefs_metadata_required_upgrade_below) { -+ bch_info(c, "version %s (%u) prior to %s (%u), upgrade and fsck required", -+ bch2_metadata_versions[c->sb.version], -+ c->sb.version, -+ bch2_metadata_versions[bcachefs_metadata_required_upgrade_below], -+ bcachefs_metadata_required_upgrade_below); -+ c->opts.version_upgrade = true; -+ c->opts.fsck = true; -+ c->opts.fix_errors = FSCK_OPT_YES; -+ } ++ if (!c->opts.nochanges && ++ c->sb.version < bcachefs_metadata_required_upgrade_below) { ++ struct printbuf buf = PRINTBUF; ++ ++ prt_str(&buf, "version "); ++ bch2_version_to_text(&buf, c->sb.version); ++ prt_str(&buf, " prior to "); ++ bch2_version_to_text(&buf, bcachefs_metadata_required_upgrade_below); ++ prt_str(&buf, ", upgrade and fsck required"); ++ ++ bch_info(c, "%s", buf.buf); ++ printbuf_exit(&buf); ++ ++ c->opts.version_upgrade = true; ++ c->opts.fsck = true; ++ c->opts.fix_errors = FSCK_OPT_YES; + } + + if (c->opts.fsck && c->opts.norecovery) { @@ -81678,10 +81666,10 @@ index 000000000..c6c1cbad9 +#endif /* _BCACHEFS_SUBVOLUME_TYPES_H */ diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c new file mode 100644 -index 000000000..e5636c32f +index 000000000..481f9de6e --- /dev/null +++ b/fs/bcachefs/super-io.c -@@ -0,0 +1,1597 @@ +@@ -0,0 +1,1616 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "bcachefs.h" @@ -81707,6 +81695,21 @@ index 000000000..e5636c32f +#include +#include + ++static const char * const bch2_metadata_versions[] = { ++#define x(t, n) [n] = #t, ++ BCH_METADATA_VERSIONS() ++#undef x ++}; ++ ++void bch2_version_to_text(struct printbuf *out, unsigned v) ++{ ++ const char *str = v < ARRAY_SIZE(bch2_metadata_versions) ++ ? bch2_metadata_versions[v] ++ : "(unknown version)"; ++ ++ prt_printf(out, "%u: %s", v, str); ++} ++ +const char * const bch2_sb_fields[] = { +#define x(name, nr) #name, + BCH_SB_FIELDS() @@ -81934,40 +81937,58 @@ index 000000000..e5636c32f + return 0; +} + -+static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out, -+ int rw) ++static int bch2_sb_compatible(struct bch_sb *sb, struct printbuf *out) +{ -+ struct bch_sb *sb = disk_sb->sb; -+ struct bch_sb_field *f; -+ struct bch_sb_field_members *mi; -+ enum bch_opt_id opt_id; -+ u32 version, version_min; -+ u16 block_size; -+ int ret; -+ -+ version = le16_to_cpu(sb->version); -+ version_min = version >= bcachefs_metadata_version_bkey_renumber -+ ? le16_to_cpu(sb->version_min) -+ : version; ++ u16 version = le16_to_cpu(sb->version); ++ u16 version_min = le16_to_cpu(sb->version_min); + -+ if (version >= bcachefs_metadata_version_max) { -+ prt_printf(out, "Unsupported superblock version %u (min %u, max %u)", -+ version, bcachefs_metadata_version_min, bcachefs_metadata_version_max); ++ if (!bch2_version_compatible(version)) { ++ prt_str(out, "Unsupported superblock version "); ++ bch2_version_to_text(out, version); ++ prt_str(out, " (min "); ++ bch2_version_to_text(out, bcachefs_metadata_version_min); ++ prt_str(out, ", max "); ++ bch2_version_to_text(out, bcachefs_metadata_version_current); ++ prt_str(out, ")"); + return -BCH_ERR_invalid_sb_version; + } + -+ if (version_min < bcachefs_metadata_version_min) { -+ prt_printf(out, "Unsupported superblock version %u (min %u, max %u)", -+ version_min, bcachefs_metadata_version_min, bcachefs_metadata_version_max); ++ if (!bch2_version_compatible(version_min)) { ++ prt_str(out, "Unsupported superblock version_min "); ++ bch2_version_to_text(out, version_min); ++ prt_str(out, " (min "); ++ bch2_version_to_text(out, bcachefs_metadata_version_min); ++ prt_str(out, ", max "); ++ bch2_version_to_text(out, bcachefs_metadata_version_current); ++ prt_str(out, ")"); + return -BCH_ERR_invalid_sb_version; + } + + if (version_min > version) { -+ prt_printf(out, "Bad minimum version %u, greater than version field %u", -+ version_min, version); ++ prt_str(out, "Bad minimum version "); ++ bch2_version_to_text(out, version_min); ++ prt_str(out, ", greater than version field "); ++ bch2_version_to_text(out, version); + return -BCH_ERR_invalid_sb_version; + } + ++ return 0; ++} ++ ++static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out, ++ int rw) ++{ ++ struct bch_sb *sb = disk_sb->sb; ++ struct bch_sb_field *f; ++ struct bch_sb_field_members *mi; ++ enum bch_opt_id opt_id; ++ u16 block_size; ++ int ret; ++ ++ ret = bch2_sb_compatible(sb, out); ++ if (ret) ++ return ret; ++ + if (sb->features[1] || + (le64_to_cpu(sb->features[0]) & (~0ULL << BCH_FEATURE_NR))) { + prt_printf(out, "Filesystem has incompatible features"); @@ -82015,7 +82036,7 @@ index 000000000..e5636c32f + if (rw == READ) { + /* + * Been seeing a bug where these are getting inexplicably -+ * zeroed, so we'r now validating them, but we have to be ++ * zeroed, so we're now validating them, but we have to be + * careful not to preven people's filesystems from mounting: + */ + if (!BCH_SB_JOURNAL_FLUSH_DELAY(sb)) @@ -82196,7 +82217,6 @@ index 000000000..e5636c32f +static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf *err) +{ + struct bch_csum csum; -+ u32 version, version_min; + size_t bytes; + int ret; +reread: @@ -82216,22 +82236,9 @@ index 000000000..e5636c32f + return -BCH_ERR_invalid_sb_magic; + } + -+ version = le16_to_cpu(sb->sb->version); -+ version_min = version >= bcachefs_metadata_version_bkey_renumber -+ ? le16_to_cpu(sb->sb->version_min) -+ : version; -+ -+ if (version >= bcachefs_metadata_version_max) { -+ prt_printf(err, "Unsupported superblock version %u (min %u, max %u)", -+ version, bcachefs_metadata_version_min, bcachefs_metadata_version_max); -+ return -BCH_ERR_invalid_sb_version; -+ } -+ -+ if (version_min < bcachefs_metadata_version_min) { -+ prt_printf(err, "Unsupported superblock version %u (min %u, max %u)", -+ version_min, bcachefs_metadata_version_min, bcachefs_metadata_version_max); -+ return -BCH_ERR_invalid_sb_version; -+ } ++ ret = bch2_sb_compatible(sb->sb, err); ++ if (ret) ++ return ret; + + bytes = vstruct_bytes(sb->sb); + @@ -83187,12 +83194,12 @@ index 000000000..e5636c32f + + prt_str(out, "Version:"); + prt_tab(out); -+ prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version)]); ++ bch2_version_to_text(out, le16_to_cpu(sb->version)); + prt_newline(out); + + prt_printf(out, "Oldest version on disk:"); + prt_tab(out); -+ prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version_min)]); ++ bch2_version_to_text(out, le16_to_cpu(sb->version_min)); + prt_newline(out); + + prt_printf(out, "Created:"); @@ -83281,10 +83288,10 @@ index 000000000..e5636c32f +} diff --git a/fs/bcachefs/super-io.h b/fs/bcachefs/super-io.h new file mode 100644 -index 000000000..ab0ad3248 +index 000000000..cda71ec84 --- /dev/null +++ b/fs/bcachefs/super-io.h -@@ -0,0 +1,126 @@ +@@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_SUPER_IO_H +#define _BCACHEFS_SUPER_IO_H @@ -83296,6 +83303,14 @@ index 000000000..ab0ad3248 + +#include + ++static inline bool bch2_version_compatible(u16 version) ++{ ++ return version <= bcachefs_metadata_version_current && ++ version >= bcachefs_metadata_version_min; ++} ++ ++void bch2_version_to_text(struct printbuf *, unsigned); ++ +struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type); +struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *, + enum bch_sb_field_type, unsigned); @@ -83413,10 +83428,10 @@ index 000000000..ab0ad3248 +#endif /* _BCACHEFS_SUPER_IO_H */ diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c new file mode 100644 -index 000000000..99b767051 +index 000000000..bcd28a2d3 --- /dev/null +++ b/fs/bcachefs/super.c -@@ -0,0 +1,1993 @@ +@@ -0,0 +1,1995 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * bcachefs setup/teardown code, and some metadata io - read a superblock and @@ -84104,6 +84119,7 @@ index 000000000..99b767051 + + bch2_fs_copygc_init(c); + bch2_fs_btree_key_cache_init_early(&c->btree_key_cache); ++ bch2_fs_btree_interior_update_init_early(c); + bch2_fs_allocator_background_init(c); + bch2_fs_allocator_foreground_init(c); + bch2_fs_rebalance_init(c); @@ -84294,7 +84310,8 @@ index 000000000..99b767051 + struct printbuf p = PRINTBUF; + bool first = true; + -+ prt_printf(&p, "mounted version=%s", bch2_metadata_versions[c->sb.version]); ++ prt_str(&p, "mounted version "); ++ bch2_version_to_text(&p, c->sb.version); + + if (c->opts.read_only) { + prt_str(&p, " opts="); diff --git a/Files b/Files index d8d6352e..02d7714f 100644 --- a/Files +++ b/Files @@ -515,6 +515,7 @@ │   │   ├── 0001-aufs-6.4-merge-v20230515.patch │   │   ├── 0001-bcachefs.patch │   │   ├── 0001-bore-tuning-sysctl.patch +│   │   ├── 0001-high-hz.patch │   │   ├── 0001-rt.patch │   │   └── 0001-sched-Implement-BPF-extensible-scheduler-class.patch │   ├── sched @@ -532,4 +533,4 @@ ├── Files └── README.md -51 directories, 482 files +51 directories, 483 files