@@ -1864,9 +1864,8 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
1864
1864
struct jset_entry * start , * end ;
1865
1865
struct jset * jset = w -> data ;
1866
1866
struct journal_keys_to_wb wb = { NULL };
1867
- unsigned sectors , bytes , u64s ;
1867
+ unsigned u64s ;
1868
1868
unsigned long btree_roots_have = 0 ;
1869
- bool validate_before_checksum = false;
1870
1869
u64 seq = le64_to_cpu (jset -> seq );
1871
1870
int ret ;
1872
1871
@@ -1949,8 +1948,7 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
1949
1948
1950
1949
le32_add_cpu (& jset -> u64s , u64s );
1951
1950
1952
- sectors = vstruct_sectors (jset , c -> block_bits );
1953
- bytes = vstruct_bytes (jset );
1951
+ unsigned sectors = vstruct_sectors (jset , c -> block_bits );
1954
1952
1955
1953
if (sectors > w -> sectors ) {
1956
1954
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)
1959
1957
return - EINVAL ;
1960
1958
}
1961
1959
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
+
1962
1971
jset -> magic = cpu_to_le64 (jset_magic (c ));
1963
1972
jset -> version = cpu_to_le32 (c -> sb .version );
1964
1973
@@ -1981,7 +1990,7 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
1981
1990
ret = bch2_encrypt (c , JSET_CSUM_TYPE (jset ), journal_nonce (jset ),
1982
1991
jset -> encrypted_start ,
1983
1992
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 )))
1985
1994
return ret ;
1986
1995
1987
1996
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)
1991
2000
(ret = jset_validate (c , NULL , jset , 0 , WRITE )))
1992
2001
return ret ;
1993
2002
2003
+ unsigned sectors = vstruct_sectors (jset , c -> block_bits );
2004
+ unsigned bytes = vstruct_bytes (jset );
1994
2005
memset ((void * ) jset + bytes , 0 , (sectors << 9 ) - bytes );
1995
2006
return 0 ;
1996
2007
}
@@ -2088,6 +2099,10 @@ CLOSURE_CALLBACK(bch2_journal_write)
2088
2099
if (unlikely (ret ))
2089
2100
goto err_allocate_write ;
2090
2101
2102
+ ret = bch2_journal_write_checksum (j , w );
2103
+ if (unlikely (ret ))
2104
+ goto err ;
2105
+
2091
2106
spin_lock (& j -> lock );
2092
2107
/*
2093
2108
* write is allocated, no longer need to account for it in
0 commit comments