Skip to content

Commit 00839ad

Browse files
author
Kent Overstreet
committed
bcachefs: Convert bch2_replicas_gc2() to new accounting
bch2_replicas_gc2() is used for garbage collection superblock replicas entries that are empty - this converts it to the new accounting scheme. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent fb23d57 commit 00839ad

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

fs/bcachefs/replicas.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "bcachefs.h"
44
#include "buckets.h"
5+
#include "disk_accounting.h"
56
#include "journal.h"
67
#include "replicas.h"
78
#include "super-io.h"
@@ -418,8 +419,6 @@ int bch2_replicas_gc_start(struct bch_fs *c, unsigned typemask)
418419
*/
419420
int bch2_replicas_gc2(struct bch_fs *c)
420421
{
421-
return 0;
422-
#if 0
423422
struct bch_replicas_cpu new = { 0 };
424423
unsigned i, nr;
425424
int ret = 0;
@@ -449,20 +448,26 @@ int bch2_replicas_gc2(struct bch_fs *c)
449448
struct bch_replicas_entry_v1 *e =
450449
cpu_replicas_entry(&c->replicas, i);
451450

452-
if (e->data_type == BCH_DATA_journal ||
453-
c->usage_base->replicas[i] ||
454-
percpu_u64_get(&c->usage[0]->replicas[i]) ||
455-
percpu_u64_get(&c->usage[1]->replicas[i]) ||
456-
percpu_u64_get(&c->usage[2]->replicas[i]) ||
457-
percpu_u64_get(&c->usage[3]->replicas[i]))
451+
struct disk_accounting_pos k = {
452+
.type = BCH_DISK_ACCOUNTING_replicas,
453+
};
454+
455+
memcpy(&k.replicas, e, replicas_entry_bytes(e));
456+
457+
u64 v = 0;
458+
bch2_accounting_mem_read(c, disk_accounting_pos_to_bpos(&k), &v, 1);
459+
460+
if (e->data_type == BCH_DATA_journal || v)
458461
memcpy(cpu_replicas_entry(&new, new.nr++),
459462
e, new.entry_size);
460463
}
461464

462465
bch2_cpu_replicas_sort(&new);
463466

464-
ret = bch2_cpu_replicas_to_sb_replicas(c, &new) ?:
465-
replicas_table_update(c, &new);
467+
ret = bch2_cpu_replicas_to_sb_replicas(c, &new);
468+
469+
if (!ret)
470+
swap(c->replicas, new);
466471

467472
kfree(new.entries);
468473

@@ -474,7 +479,6 @@ int bch2_replicas_gc2(struct bch_fs *c)
474479
mutex_unlock(&c->sb_lock);
475480

476481
return ret;
477-
#endif
478482
}
479483

480484
/* Replicas tracking - superblock: */

0 commit comments

Comments
 (0)