Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
5d69d09
bcachefs: retry allocator after global wakeups
Komzpa Jul 10, 2026
58d4374
bcachefs: fix NULL disk_reservation deref deleting compressed snapsho…
Jul 14, 2026
3bf445d
bcachefs: fix build on CONFIG_SCHED_ALT (BMQ/PDS) kernels
Jul 14, 2026
b45d4ff
bcachefs: don't fail the module build on large stack frames
Jul 14, 2026
1549881
bcachefs: run explicitly-requested recovery passes even if they faile…
Jul 14, 2026
4af37e5
fsck: explain the -p (preen) no-op instead of exiting silently
Jul 14, 2026
6a757ae
bcachefs: ratelimit failing recovery passes instead of masking them
Jul 14, 2026
96ebcfc
upgrade: add repair for new snapshot/subvol state enums
Jul 14, 2026
1c6ec23
bcachefs: add btrees_clean superblock bitmask
Jul 15, 2026
86e2443
bcachefs: clear btrees_clean on btree mutation
Jul 15, 2026
c3f98e4
bcachefs: set btrees_clean on check pass completion
Jul 15, 2026
f1dfb49
bcachefs: check_key_has_snapshot: gate destruction on btrees_clean
Jul 14, 2026
0d5b503
bcachefs: bch2_snapshot_live_descendent(): don't conflate damage with…
Jul 14, 2026
50fb701
bcachefs: snapshot damage on the runtime paths should defer, not BUG
Jul 15, 2026
b5d8b88
bcachefs: check_snapshots: revive a deleted node with a live child
Jul 15, 2026
1312d48
fetch-module: match the published bcachefs-v<ver>.ko module name
Jul 15, 2026
27c814d
bcachefs: data_update_init: pass a disk reservation to the key-delete…
Jul 15, 2026
a8f4385
bcachefs: journal: initialize the whole pin fifo buffer, not just the…
Jul 15, 2026
eba9fcd
bcachefs: journal: warn on pinning a journal entry outside the live r…
Jul 15, 2026
a7a764c
bcachefs: check_snapshots: autofix a garbage/zero snapshot state field
Jul 15, 2026
053b6eb
bcachefs: journal: limit the journal pin dump by pin count, not seq c…
Jul 15, 2026
c7c838f
bcachefs: journal: don't report flush_seq stuck before an IO could co…
Jul 15, 2026
4b1393a
bcachefs: list_replace{,_init}: match kernel semantics for empty lists
Jul 15, 2026
649d646
snapshots: recover a zeroed state field from the legacy flags
Jul 16, 2026
81d650b
build: rebuild libbcachefs.a from scratch to drop stale members
Jul 16, 2026
a229264
bcachefs: add BkeyS, a mutable bkey handle
Jul 16, 2026
6771c82
bcachefs: extent iterators: take a BkeyS handle
Jul 16, 2026
8c1e1e2
bcachefs: expose bset_encrypt and the nonce helpers to Rust
Jul 16, 2026
5449bb4
bcachefs: dump: --single-replica de-replicated metadata dumps
Jul 16, 2026
236af9c
bcachefs: count reservation sectors in per-snapshot accounting
Jul 16, 2026
76f7fb8
bcachefs: per-snapshot key-count accounting
Jul 16, 2026
fd227ec
bcachefs: snapshot deletion checks the per-snapshot key count
Jul 16, 2026
ce81e2b
bcachefs: per-(snapshot, btree) key accounting, with key_bytes
Jul 16, 2026
d756397
bcachefs: show per-snapshot key counts in subvolume list-snapshots
Jul 16, 2026
b227200
bcachefs: reconcile: count btree-node sectors in scan and pending cou…
Jul 17, 2026
ad90a0e
bcachefs: validate_member(): fix device not enough buckets message
jullanggit Feb 17, 2026
308dd23
bcachefs: validate_member(): extract variables
jullanggit Feb 17, 2026
ba3d039
bcachefs: validate_member(): not enough buckets: print actual amount …
jullanggit Feb 17, 2026
96fa0b1
bcachefs: validate_members(): fix bad search-and-replace
jullanggit Feb 18, 2026
301aaf2
bcachefs: add target_nbuckets to bch_member(_cpu)
jullanggit Feb 16, 2026
683f49c
bcachefs: print target_nbuckets = 0 as inactive instead of 0
jullanggit Feb 16, 2026
358f963
bcachefs: consider pointers after target_nbuckets as evacuating
jullanggit Feb 16, 2026
a2f3a9b
bcachefs: use dev-based evacuating check for may_reuse_stripe
jullanggit Feb 17, 2026
786e5d7
bcachefs: sharpen target_nbuckets semantics to only include (triviall…
jullanggit Feb 17, 2026
e8711b2
bcachefs: split bch2_dev_resze into grow & shrink paths
jullanggit Feb 17, 2026
0ce89dc
bcachefs: implement shrink superblock & alloc nouse interactions
jullanggit Feb 17, 2026
5ec65b8
bcachefs: refactor out per-device buckets_nouse alloc/free
jullanggit Feb 17, 2026
5ee5728
bcachefs: implement filesystem shrinking mvp
jullanggit Feb 17, 2026
db1c748
bcachefs: shrink: avoid holding two transactions at once
jullanggit Feb 17, 2026
b29e977
bcachefs: alloc: directly check against target_nbuckets for skipping …
jullanggit Feb 18, 2026
a39fa65
bcachefs: remove unused buckets_nouse code
jullanggit Feb 18, 2026
59912ec
bcachefs: shrink: print error message if reconcile scan fails
jullanggit Feb 18, 2026
8985b0a
bcachefs: shrink: close open buckets before evacuating data
jullanggit Feb 18, 2026
ba4611b
bcachefs: shrink: explicitly pass tail_cutoff instead of implicitly r…
jullanggit Feb 18, 2026
b43e04a
bcachefs: dev_resize_alloc: cast new - old buckets calculation to sig…
jullanggit Feb 18, 2026
86649b8
bcachefs: shrink: truncate alloc info
jullanggit Feb 21, 2026
2677d3e
bcachefs: shrink: run disk accounting
jullanggit Feb 21, 2026
8eaf4ac
bcachefs: shrink: disk accounting: properly handle negative changes
jullanggit Feb 21, 2026
9f7910a
bcachefs: shrink: truncate alloc: remove spurious dev_usage_remove call
jullanggit Feb 21, 2026
d9d9081
bcachefs: shrink: drop references to cutoff superblock copies
jullanggit Feb 21, 2026
b64009e
bcachefs: shrink: mark superblock buckets as metadata
jullanggit Feb 21, 2026
c6b29b0
bcachefs: shrink: use the same usage_remove path as dev_remove
jullanggit Feb 21, 2026
2f0c7ed
bcachefs: shrink: convert new nbuckets to little-endian before writin…
jullanggit Feb 21, 2026
8d82ca3
bcachefs: shrink: use alloc info to update accounting
jullanggit Feb 21, 2026
3093184
bcachefs: shrink: add comment about data being left as cached
jullanggit Feb 25, 2026
92b16cd
bcachefs: shrink: drop cached data after shrink cutoff
jullanggit Feb 25, 2026
5644a25
bcachefs: shrink: remove unnecessary sb metadata marking
jullanggit Mar 3, 2026
4267933
bcachefs: shrink: flush journal
jullanggit Mar 3, 2026
8e496bb
bcachefs: shrink: properly remove bucket gens
jullanggit Mar 18, 2026
4c4db4a
bcachefs: fix online shrink tail metadata cleanup
jullanggit Apr 12, 2026
77351f3
fix three-device shrink reconcile races
jullanggit Apr 13, 2026
8834141
bcachefs: tolerate transient shrink rereplicate state
jullanggit Apr 13, 2026
79ed5a8
bcachefs: update reconcile-only backpointer flags in place
jullanggit Apr 13, 2026
92fda8f
bcachefs: delete truncated backpointers in backpointer key space
jullanggit Apr 13, 2026
aa00cd6
bcachefs: close write points before stopping copygc
jullanggit Apr 13, 2026
292d23d
bcachefs: start reconcile extent iterators with intent locks
jullanggit Apr 13, 2026
f48c224
bcachefs: let shrink metadata spill off shrinking targets
jullanggit Apr 13, 2026
3b82404
bcachefs: resume pending shrink during recovery
jullanggit Apr 14, 2026
8679816
bcachefs: make device resize converge to the latest target
jullanggit Apr 14, 2026
29c9b8d
bcachefs: discard: drop need_discard iter before commit
jullanggit Apr 15, 2026
a25a624
fs/bcachefs: drop cached reconcile paths before move work
jullanggit Apr 15, 2026
dfbe1a8
fs/bcachefs: keep shrink discards out of the evacuated tail
jullanggit Apr 18, 2026
ab98f94
bcachefs: shrink: bch2_dev_resize_wait_done: improve readability
jullanggit Apr 19, 2026
27ca970
bcachefs: shrink: small code cleanups
jullanggit Apr 19, 2026
f2abeb8
bcachefs: fail impossible shrink after reconcile drains
jullanggit Apr 19, 2026
ba103de
bcachefs: keep shrink reconcile focused on the truncating tail
jullanggit Apr 19, 2026
7a60088
bcachefs: stop shrink waiting once the tail is empty
jullanggit Apr 19, 2026
b108504
bcachefs: bound shrink's final journal pin flush
jullanggit Apr 19, 2026
a09027a
bcachefs: add comment
jullanggit Apr 20, 2026
eda61fa
bcachefs: shrink_finish: remove redundant journal moving and restart …
jullanggit Apr 20, 2026
1afce5d
bcachefs: rename bch2_dev_shrink_finish -> bch2_dev_shrink_finalize
jullanggit Apr 20, 2026
056dd66
bcachefs: shorten comment about waking pending reconcile on shrink ca…
jullanggit Apr 20, 2026
d5b829f
bcachefs: shrink: add TODO
jullanggit Apr 20, 2026
d741097
bcachefs: shrink: change not-enough-space error message
jullanggit Apr 20, 2026
76003fb
bcachefs: shrink: bound stalled tail detection on reconcile work
jullanggit Apr 20, 2026
a9f50ac
bcachefs: shrink: only fail after quiescent stalled rescans
jullanggit Apr 20, 2026
57f0d41
bcachefs: shrink: document journal as imperfect progress signal
jullanggit Apr 20, 2026
7ac497d
bcachefs: shrink: add shrinking docs
jullanggit Jun 15, 2026
0f8b117
bcachefs: shrink: docs: remove unnecessary detail
jullanggit Jun 24, 2026
504c786
bcachefs: shrink: make docs more concise
jullanggit Jun 24, 2026
4d979d0
bcachefs: shrink: address review cleanups
Komzpa Jun 28, 2026
565b458
bcachefs: shrink: remove redundant bch2_dev_clear_need_discard call
jullanggit Jun 29, 2026
84ff719
bcachefs: remove bch2_dev_clear_need_discard and merge cutoff awarene…
jullanggit Jun 29, 2026
a4c2926
bcachefs: move bch2_dev_usage_remove() from bch2_dev_remove_alloc() i…
jullanggit Jun 29, 2026
ed709d8
bcachefs: bch2_dev_remove_alloc(): remove unnecessary comment
jullanggit Jun 29, 2026
1399c30
bcachefs: simplify bch2_dev_remove_bucket_gens()
jullanggit Jun 29, 2026
dfbfff8
bcachefs: shrink: add comment
jullanggit Jun 29, 2026
cd309f8
bcachefs: shrink: add bch2_target_has_non_shrinking_dev() helper
jullanggit Jun 29, 2026
6caf82a
bcachefs: rename bch2_trigger_extent_same_backpointers to bch2_trigge…
jullanggit Jul 1, 2026
44ef590
bcachefs: clean up bch2_do_discards
jullanggit Jul 1, 2026
60c6c1e
bcachefs: shrink: move optimized tail cache invalidation before loop …
jullanggit Jul 14, 2026
09fe5c8
bcachefs: shrink: clean up error handling using try() macro
jullanggit Jul 14, 2026
4bc4041
bcachefs: shrink: rephrase shrink failed message
jullanggit Jul 15, 2026
b5a4bd1
fix: bch2_dev_remove_bucket_gens: scope zero-tail-gens transaction so…
jullanggit Jul 15, 2026
b8407c7
bcachefs: shrink: remove broken optimized tail cache invalidation
jullanggit Jul 15, 2026
b3ac794
bcachefs: shrink: simplify shrink loop
jullanggit Jul 14, 2026
43a3719
fix: narrow btree_trans scope to avoid nested trans in __bch2_dev_shrink
jullanggit Jul 15, 2026
f66b8fb
bcachefs: shrink: remove outdated TODO
jullanggit Jul 15, 2026
94bba49
merge
jullanggit Jul 15, 2026
58ff117
bcachefs: resize: fix resizing to 0 buckets being interpreted as no c…
jullanggit Jul 16, 2026
78f6fa2
merge
jullanggit Jul 17, 2026
e2ea756
add back buckets_nouse code
jullanggit Jul 17, 2026
71fc44f
remove accidentally-added ambient code
jullanggit Jul 17, 2026
b99c3a4
work.c: fix indentation and bracketing
jullanggit Jul 17, 2026
fd335be
fix(merge): use atomic read for reconcile kick
jullanggit Jul 17, 2026
d156ed6
fix(shrink): validate target_nbuckets before normalization
jullanggit Jul 17, 2026
e51aad3
fix(merge): fix include placement
jullanggit Jul 17, 2026
9a68751
fix(merge): use proper helper to determine ptr evacuating state
jullanggit Jul 19, 2026
44f1bfc
don't apply alloc_nowait to btree ptrs
jullanggit Jul 19, 2026
12cc68d
fix: bch2_move_extent(): actually apply hipri-upgraded commit flags
jullanggit Jul 19, 2026
e59929e
reconcile: fix: set pass_complete when all passes are compelte
jullanggit Jul 17, 2026
dbeb7eb
fix(merge): bch2_bkey_durability: use shrink-aware bad or evacuating …
jullanggit Jul 19, 2026
9007028
fully replace bch2_dev_bad_or_evacuating with bch2_ptr_bad_or_evacuating
jullanggit Jul 19, 2026
cc2d249
fix(merge): __bch2_dev_grow: remove double state lock acquisition
jullanggit Jul 19, 2026
75496ad
fix(merge): fix userspace compile errors
jullanggit Aug 4, 2026
57c3d4d
bcachefs: shrink: don't count free buckets in shrink tail as free
jullanggit Jul 16, 2026
4dcc51c
shrink: make copygc shrink-aware for wait and free buckets amount
jullanggit Aug 6, 2026
376f228
(I think) remove obvious reconicle-ec-shrink blockers
jullanggit Jul 19, 2026
0bd1c41
flush outstanding ec
jullanggit Aug 4, 2026
4477edd
add logging for the stalling tail head
jullanggit Aug 4, 2026
9f2d5a5
add more logging
jullanggit Aug 4, 2026
0a3a1f5
attempt ec fix
jullanggit Aug 4, 2026
812384a
more logging
jullanggit Aug 4, 2026
1bc7b6d
some kind of fix
jullanggit Aug 4, 2026
aaa6043
more logging
jullanggit Aug 4, 2026
fc42c25
attempt fix
jullanggit Aug 4, 2026
344dd2a
fix?
jullanggit Aug 4, 2026
8819bb9
fix + logging
jullanggit Aug 4, 2026
5c6102e
mostly fix
jullanggit Aug 4, 2026
a9ea26a
logging
jullanggit Aug 4, 2026
42d8bc0
fix + logging
jullanggit Aug 4, 2026
d832417
diagnostics
jullanggit Aug 4, 2026
05c69d9
inconsistency fixes
jullanggit Aug 4, 2026
2cea0c4
logging
jullanggit Aug 4, 2026
3fe44df
run alloc check pass on next mount after shrink; required as ec-accou…
jullanggit Aug 4, 2026
7cbc6b1
TODO(squash): remove logs
jullanggit Aug 4, 2026
7da1b0c
reformulate comment
jullanggit Aug 4, 2026
0ae9623
remove debugging
jullanggit Aug 4, 2026
69f3315
ec: fix memory leak through stack-allocated alloc_request
jullanggit Aug 5, 2026
69207c2
shrink: ec: revert extent-level move
jullanggit Aug 6, 2026
0b668a5
add and use stripe_dev_and_region_matches helper
jullanggit Aug 6, 2026
8c7bdfc
use PTR_BUCKET_NR helper where applicable
jullanggit Aug 6, 2026
f251ba4
stripe_update_extent(): simplify a condition and add newline to error…
jullanggit Aug 6, 2026
f8d713b
shrink: schedule accounting recovery pass before entering reconcile loop
jullanggit Aug 6, 2026
0b96f97
rework comments
jullanggit Aug 6, 2026
a665ab3
merge
jullanggit Aug 7, 2026
71853ae
fix(ec): commit needs-reconcile zeroing on empty stripe
jullanggit Aug 7, 2026
44d544c
bch2_trigger_extent: guard in-place reconcile_phys update optimizatio…
jullanggit Aug 7, 2026
e0003ca
add bcachefs device resize cancel
jullanggit Jun 24, 2026
5ba9f57
flake.lock: Update
github-actions[bot] Aug 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions fs/alloc/accounting.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// SPDX-License-Identifier: GPL-2.0

#include "alloc/background.h"
#include "alloc/format.h"
#include "bcachefs.h"
#include "bcachefs_format.h"
#include "bcachefs_ioctl.h"
#include "alloc/accounting_format.h"

#include "alloc/accounting.h"
#include "alloc/buckets.h"
#include "alloc/replicas.h"

#include "btree/bkey_types.h"
#include "btree/cache.h"
#include "btree/iter.h"
#include "btree/journal_overlay.h"
#include "btree/types.h"
#include "btree/update.h"
#include "btree/write_buffer.h"

Expand Down Expand Up @@ -1260,6 +1267,55 @@ int bch2_accounting_read(struct bch_fs *c)
return accounting_read_mem_fixups(trans);
}

int bch2_dev_truncate_accounting(struct bch_fs *c, struct bch_dev *ca, u64 old_nbuckets, u64 cutoff) {
struct bpos start = POS(ca->dev_idx, cutoff);
struct bpos end = POS(ca->dev_idx, old_nbuckets);

CLASS(btree_trans, trans)(c);

/* accumulate deltas per data type, then apply them */
return commit_do(trans, NULL, NULL, 0, ({
s64 delta[BCH_DATA_NR][3] = {};
s64 keys = 0;
struct bkey_s_c k;
int ret = 0;

for_each_btree_key_max_norestart(trans, iter, BTREE_ID_alloc, start, end, BTREE_ITER_prefetch, k, ret) {
if (!k.k->type)
continue;

struct bch_alloc_v4 _alloc;
const struct bch_alloc_v4 *alloc = bch2_alloc_to_v4(k, &_alloc);

enum bch_data_type data_type = alloc->data_type;

delta[data_type][0] -= 1;
delta[data_type][1] -= bch2_bucket_sectors(*alloc);
delta[data_type][2] -= bch2_bucket_sectors_fragmented(ca, *alloc);

s64 unstriped = bch2_bucket_sectors_unstriped(*alloc);
if (unstriped) {
delta[BCH_DATA_unstriped][0] -= 1;
delta[BCH_DATA_unstriped][1] -= unstriped;
}

keys++;
}
if (!ret) {
delta[BCH_DATA_free][0] -= (old_nbuckets - cutoff) - keys;

for (unsigned type = 0; type < BCH_DATA_NR; type++) {
ret = bch2_disk_accounting_mod2(trans, false, delta[type], dev_data_type, .dev = ca->dev_idx, .data_type = type);

if (ret)
break;
}
}

ret;
}));
}

int bch2_dev_usage_remove(struct bch_fs *c, struct bch_dev *ca)
{
CLASS(btree_trans, trans)(c);
Expand Down
3 changes: 3 additions & 0 deletions fs/alloc/accounting.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ int bch2_gc_accounting_done(struct bch_fs *);

int bch2_accounting_read(struct bch_fs *);


int bch2_dev_truncate_accounting(struct bch_fs *, struct bch_dev *, u64, u64);

int bch2_dev_usage_remove(struct bch_fs *, struct bch_dev *);
int bch2_dev_usage_init(struct bch_dev *, bool);

Expand Down
2 changes: 1 addition & 1 deletion fs/alloc/accounting_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Here, the key has considerably more structure than a typical key (bpos); an
* accounting key is 'struct disk_accounting_pos', which is a union of bpos.
*
* More specifically: a key is just a muliword integer (where word endianness
* More specifically: a key is just a multiword integer (where word endianness
* matches native byte order), so we're treating bpos as an opaque 20 byte
* integer and mapping bch_accounting_key to that.
*
Expand Down
80 changes: 64 additions & 16 deletions fs/alloc/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,52 @@ int bch2_alloc_read(struct bch_fs *c)
return ret;
}

int bch2_dev_remove_bucket_gens(struct bch_fs *c, struct bch_dev *ca, u64 cutoff)
{
unsigned offset;
struct bpos pos = alloc_gens_pos(POS(ca->dev_idx, cutoff), &offset);

/* cutoff on key boundary */
if (!offset)
return bch2_btree_delete_range(c, BTREE_ID_bucket_gens,
pos,
POS(ca->dev_idx, U64_MAX),
BTREE_TRIGGER_norun);

/* Cutoff mid-key
*
* Scope the zero-tail-gens transaction so it is cleared
* before bch2_btree_delete_range creates its own transaction.
*/
{
CLASS(btree_trans, trans)(c);

/* zero tail gens */
try(commit_do(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({
CLASS(btree_iter, iter)(trans, BTREE_ID_bucket_gens, pos, BTREE_ITER_intent);
struct bkey_s_c k = bkey_try(bch2_btree_iter_peek_slot(&iter));

try(bkey_err(k));

if (k.k->type == KEY_TYPE_bucket_gens) {
struct bkey_i_bucket_gens *g =
errptr_try(bch2_trans_kmalloc(trans, sizeof(*g)));

bkey_reassemble(&g->k_i, k);
memset(&g->v.gens[offset], 0, sizeof(g->v.gens) - offset);
try(bch2_trans_update(trans, &iter, &g->k_i, 0));
}
0;
})));
}

/* delete remaining keys */
return bch2_btree_delete_range(c, BTREE_ID_bucket_gens,
bpos_nosnap_successor(pos),
POS(ca->dev_idx, U64_MAX),
BTREE_TRIGGER_norun);
}

/* Free space/discard btree: */

int bch2_bucket_do_freespace_index(struct btree_trans *trans,
Expand Down Expand Up @@ -1489,47 +1535,49 @@ int bch2_trigger_alloc(struct btree_trans *trans, struct btree_trigger_op op)
return ret;
}

/* device removal */
/* device removal / shrinking */

static int bch2_dev_remove_need_discard(struct bch_fs *c, struct bch_dev *ca)
static int bch2_dev_remove_need_discard(struct bch_fs *c, struct bch_dev *ca, u64 cutoff)
{
CLASS(btree_trans, trans)(c);
unsigned dev_idx = ca->dev_idx;

return for_each_btree_key_commit(trans, iter,
BTREE_ID_need_discard, POS_MIN,
BTREE_ITER_intent|BTREE_ITER_prefetch, k,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({
NULL, NULL, BCH_WATERMARK_reclaim|
BCH_TRANS_COMMIT_no_enospc, ({
struct bpos bucket = u64_to_bucket(k.k->p.offset);
(bucket.inode == dev_idx)
(bucket.inode == dev_idx && bucket.offset >= cutoff)
? bch2_btree_delete_at(trans, &iter,
BTREE_TRIGGER_norun)
: 0;
}));
}

int bch2_dev_remove_alloc(struct bch_fs *c, struct bch_dev *ca)
int bch2_dev_remove_alloc(struct bch_fs *c, struct bch_dev *ca, u64 cutoff)
{
struct bpos start = POS(ca->dev_idx, 0);
struct bpos start = POS(ca->dev_idx, cutoff);
struct bpos end = POS(ca->dev_idx, U64_MAX);
struct bpos bp_start = bucket_pos_to_bp_start(ca, start);
struct bpos bp_end = POS(ca->dev_idx + 1, 0);
int ret;

/*
* We clear the LRU and need_discard btrees first so that we don't race
* with bch2_do_invalidates() and bch2_do_discards_async()
* with bch2_do_invalidates() and bch2_do_discards()
*/
ret = bch2_dev_remove_lrus(c, ca) ?:
bch2_dev_remove_need_discard(c, ca) ?:
ret = bch2_dev_remove_lrus(c, ca, cutoff) ?:
bch2_dev_remove_need_discard(c, ca, cutoff) ?:
bch2_btree_delete_range(c, BTREE_ID_freespace, start, end,
BTREE_TRIGGER_norun) ?:
bch2_btree_delete_range(c, BTREE_ID_backpointers, start, end,
BTREE_TRIGGER_norun) ?:
bch2_btree_delete_range(c, BTREE_ID_bucket_gens, start, end,
bch2_btree_delete_range(c, BTREE_ID_backpointers, bp_start, bp_end,
BTREE_TRIGGER_norun) ?:
bch2_dev_remove_bucket_gens(c, ca, cutoff) ?:
bch2_btree_delete_range(c, BTREE_ID_alloc, start, end,
BTREE_TRIGGER_norun) ?:
bch2_dev_usage_remove(c, ca);
bch_err_msg_dev(ca, ret, "removing dev alloc info");
BTREE_TRIGGER_norun);
bch_err_msg_dev(ca, ret, "%s dev alloc info",
cutoff ? "truncating" : "removing");
return ret;
}

Expand Down Expand Up @@ -1712,7 +1760,7 @@ void bch2_dev_allocator_remove(struct bch_fs *c, struct bch_dev *ca)
*/
bch2_recalc_capacity(c);

bch2_open_buckets_stop(c, ca, false);
bch2_open_buckets_stop(c, ca, false, 0);

/*
* Wake up threads that were blocked on allocation, so they can notice
Expand Down
3 changes: 2 additions & 1 deletion fs/alloc/background.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ void bch2_bucket_gens_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_
})

int bch2_bucket_gens_init(struct bch_fs *);
int bch2_dev_remove_bucket_gens(struct bch_fs *, struct bch_dev *, u64);

int bch2_alloc_read(struct bch_fs *);

Expand All @@ -308,7 +309,7 @@ int bch2_alloc_key_to_dev_counters(struct btree_trans *, struct bch_dev *,
const struct bch_alloc_v4 *, unsigned);
int bch2_trigger_alloc(struct btree_trans *, struct btree_trigger_op);

int bch2_dev_remove_alloc(struct bch_fs *, struct bch_dev *);
int bch2_dev_remove_alloc(struct bch_fs *, struct bch_dev *, u64);

void bch2_recalc_capacity(struct bch_fs *);
unsigned long bch2_fs_ra_pages(struct bch_fs *);
Expand Down
Loading