bcachefs: Store logical location of journal entries

When viewing what's in the journal, it's more useful to have the logical
location - journal bucket and offset within that bucket - than just the
offset on that device.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-02-19 01:18:18 -05:00 committed by Kent Overstreet
parent a9de137bf6
commit 72b7d6332b
2 changed files with 24 additions and 11 deletions

View File

@ -46,12 +46,12 @@ struct journal_list {
* be replayed:
*/
static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
struct bch_extent_ptr entry_ptr,
struct journal_ptr entry_ptr,
struct journal_list *jlist, struct jset *j,
bool bad)
{
struct journal_replay *i, *pos, *dup = NULL;
struct bch_extent_ptr *ptr;
struct journal_ptr *ptr;
struct list_head *where;
size_t bytes = vstruct_bytes(j);
u64 last_seq = 0;
@ -871,9 +871,12 @@ static int journal_read_bucket(struct bch_dev *ca,
ja->bucket_seq[bucket] = le64_to_cpu(j->seq);
mutex_lock(&jlist->lock);
ret = journal_entry_add(c, ca, (struct bch_extent_ptr) {
.dev = ca->dev_idx,
.offset = offset,
ret = journal_entry_add(c, ca, (struct journal_ptr) {
.dev = ca->dev_idx,
.bucket = bucket,
.bucket_offset = offset -
bucket_to_sector(ca, ja->buckets[bucket]),
.sector = offset,
}, jlist, j, ret != 0);
mutex_unlock(&jlist->lock);
@ -964,8 +967,8 @@ static void bch2_journal_read_device(struct closure *cl)
goto out;
}
static void bch2_journal_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
struct journal_replay *j)
void bch2_journal_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
struct journal_replay *j)
{
unsigned i;
@ -973,13 +976,15 @@ static void bch2_journal_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
struct bch_dev *ca = bch_dev_bkey_exists(c, j->ptrs[i].dev);
u64 offset;
div64_u64_rem(j->ptrs[i].offset, ca->mi.bucket_size, &offset);
div64_u64_rem(j->ptrs[i].sector, ca->mi.bucket_size, &offset);
if (i)
pr_buf(out, " ");
pr_buf(out, "%u:%llu (offset %llu)",
pr_buf(out, "%u:%u:%u (sector %llu)",
j->ptrs[i].dev,
(u64) j->ptrs[i].offset, offset);
j->ptrs[i].bucket,
j->ptrs[i].bucket_offset,
j->ptrs[i].sector);
}
}

View File

@ -8,7 +8,12 @@
*/
struct journal_replay {
struct list_head list;
struct bch_extent_ptr ptrs[BCH_REPLICAS_MAX];
struct journal_ptr {
u8 dev;
u32 bucket;
u32 bucket_offset;
u64 sector;
} ptrs[BCH_REPLICAS_MAX];
unsigned nr_ptrs;
/* checksum error, but we may want to try using it anyways: */
@ -45,6 +50,9 @@ int bch2_journal_entry_validate(struct bch_fs *, const char *,
void bch2_journal_entry_to_text(struct printbuf *, struct bch_fs *,
struct jset_entry *);
void bch2_journal_ptrs_to_text(struct printbuf *, struct bch_fs *,
struct journal_replay *);
int bch2_journal_read(struct bch_fs *, struct list_head *, u64 *, u64 *);
void bch2_journal_write(struct closure *);