Skip to content

Commit 2a6c013

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_journal_write_checksum()
We need to delay checksumming the journal write; we don't know the blocksize until after we allocate the write. Signed-off-by: Kent Overstreet <[email protected]>
1 parent d385ca5 commit 2a6c013

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

fs/bcachefs/journal_io.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,9 +1864,8 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
18641864
struct jset_entry *start, *end;
18651865
struct jset *jset = w->data;
18661866
struct journal_keys_to_wb wb = { NULL };
1867-
unsigned sectors, bytes, u64s;
1867+
unsigned u64s;
18681868
unsigned long btree_roots_have = 0;
1869-
bool validate_before_checksum = false;
18701869
u64 seq = le64_to_cpu(jset->seq);
18711870
int ret;
18721871

@@ -1949,8 +1948,7 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
19491948

19501949
le32_add_cpu(&jset->u64s, u64s);
19511950

1952-
sectors = vstruct_sectors(jset, c->block_bits);
1953-
bytes = vstruct_bytes(jset);
1951+
unsigned sectors = vstruct_sectors(jset, c->block_bits);
19541952

19551953
if (sectors > w->sectors) {
19561954
bch2_fs_fatal_error(c, ": journal write overran available space, %zu > %u (extra %u reserved %u/%u)",
@@ -1959,6 +1957,17 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
19591957
return -EINVAL;
19601958
}
19611959

1960+
return 0;
1961+
}
1962+
1963+
static int bch2_journal_write_checksum(struct journal *j, struct journal_buf *w)
1964+
{
1965+
struct bch_fs *c = container_of(j, struct bch_fs, journal);
1966+
struct jset *jset = w->data;
1967+
u64 seq = le64_to_cpu(jset->seq);
1968+
bool validate_before_checksum = false;
1969+
int ret = 0;
1970+
19621971
jset->magic = cpu_to_le64(jset_magic(c));
19631972
jset->version = cpu_to_le32(c->sb.version);
19641973

@@ -1981,7 +1990,7 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
19811990
ret = bch2_encrypt(c, JSET_CSUM_TYPE(jset), journal_nonce(jset),
19821991
jset->encrypted_start,
19831992
vstruct_end(jset) - (void *) jset->encrypted_start);
1984-
if (bch2_fs_fatal_err_on(ret, c, "decrypting journal entry: %s", bch2_err_str(ret)))
1993+
if (bch2_fs_fatal_err_on(ret, c, "encrypting journal entry: %s", bch2_err_str(ret)))
19851994
return ret;
19861995

19871996
jset->csum = csum_vstruct(c, JSET_CSUM_TYPE(jset),
@@ -1991,6 +2000,8 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
19912000
(ret = jset_validate(c, NULL, jset, 0, WRITE)))
19922001
return ret;
19932002

2003+
unsigned sectors = vstruct_sectors(jset, c->block_bits);
2004+
unsigned bytes = vstruct_bytes(jset);
19942005
memset((void *) jset + bytes, 0, (sectors << 9) - bytes);
19952006
return 0;
19962007
}
@@ -2088,6 +2099,10 @@ CLOSURE_CALLBACK(bch2_journal_write)
20882099
if (unlikely(ret))
20892100
goto err_allocate_write;
20902101

2102+
ret = bch2_journal_write_checksum(j, w);
2103+
if (unlikely(ret))
2104+
goto err;
2105+
20912106
spin_lock(&j->lock);
20922107
/*
20932108
* write is allocated, no longer need to account for it in

0 commit comments

Comments
 (0)