When not compressed, these must be equal - this fixes an assertion pop
in bch2_rechecksum_bio().

Reported-by: [email protected]
Signed-off-by: Kent Overstreet <[email protected]>
---
 fs/bcachefs/extents.c          | 22 +++++++++++++---------
 fs/bcachefs/sb-errors_format.h |  5 +++--
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index aa3b88291814..2fc9ace5533c 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -1323,9 +1323,6 @@ int bch2_bkey_ptrs_validate(struct bch_fs *c, struct 
bkey_s_c k,
                case BCH_EXTENT_ENTRY_crc128:
                        crc = bch2_extent_crc_unpack(k.k, entry_to_crc(entry));
 
-                       bkey_fsck_err_on(crc.offset + crc.live_size > 
crc.uncompressed_size,
-                                        c, ptr_crc_uncompressed_size_too_small,
-                                        "checksum offset + key size > 
uncompressed size");
                        bkey_fsck_err_on(!bch2_checksum_type_valid(c, 
crc.csum_type),
                                         c, ptr_crc_csum_type_unknown,
                                         "invalid checksum type");
@@ -1333,6 +1330,19 @@ int bch2_bkey_ptrs_validate(struct bch_fs *c, struct 
bkey_s_c k,
                                         c, ptr_crc_compression_type_unknown,
                                         "invalid compression type");
 
+                       bkey_fsck_err_on(crc.offset + crc.live_size > 
crc.uncompressed_size,
+                                        c, ptr_crc_uncompressed_size_too_small,
+                                        "checksum offset + key size > 
uncompressed size");
+                       bkey_fsck_err_on(crc_is_encoded(crc) &&
+                                        (crc.uncompressed_size > 
c->opts.encoded_extent_max >> 9) &&
+                                        (from.flags & 
(BCH_VALIDATE_write|BCH_VALIDATE_commit)),
+                                        c, ptr_crc_uncompressed_size_too_big,
+                                        "too large encoded extent");
+                       bkey_fsck_err_on(!crc_is_compressed(crc) &&
+                                        crc.compressed_size != 
crc.uncompressed_size,
+                                        c, ptr_crc_uncompressed_size_mismatch,
+                                        "not compressed but compressed != 
uncompressed size");
+
                        if (bch2_csum_type_is_encryption(crc.csum_type)) {
                                if (nonce == UINT_MAX)
                                        nonce = crc.offset + crc.nonce;
@@ -1346,12 +1356,6 @@ int bch2_bkey_ptrs_validate(struct bch_fs *c, struct 
bkey_s_c k,
                                         "redundant crc entry");
                        crc_since_last_ptr = true;
 
-                       bkey_fsck_err_on(crc_is_encoded(crc) &&
-                                        (crc.uncompressed_size > 
c->opts.encoded_extent_max >> 9) &&
-                                        (from.flags & 
(BCH_VALIDATE_write|BCH_VALIDATE_commit)),
-                                        c, ptr_crc_uncompressed_size_too_big,
-                                        "too large encoded extent");
-
                        size_ondisk = crc.compressed_size;
                        break;
                case BCH_EXTENT_ENTRY_stripe_ptr:
diff --git a/fs/bcachefs/sb-errors_format.h b/fs/bcachefs/sb-errors_format.h
index 342eda8ab69f..3bbda181f314 100644
--- a/fs/bcachefs/sb-errors_format.h
+++ b/fs/bcachefs/sb-errors_format.h
@@ -172,10 +172,11 @@ enum bch_fsck_flags {
        x(ptr_bucket_data_type_mismatch,                        155,    0)      
        \
        x(ptr_cached_and_erasure_coded,                         156,    0)      
        \
        x(ptr_crc_uncompressed_size_too_small,                  157,    0)      
        \
+       x(ptr_crc_uncompressed_size_too_big,                    161,    0)      
        \
+       x(ptr_crc_uncompressed_size_mismatch,                   300,    0)      
        \
        x(ptr_crc_csum_type_unknown,                            158,    0)      
        \
        x(ptr_crc_compression_type_unknown,                     159,    0)      
        \
        x(ptr_crc_redundant,                                    160,    0)      
        \
-       x(ptr_crc_uncompressed_size_too_big,                    161,    0)      
        \
        x(ptr_crc_nonce_mismatch,                               162,    0)      
        \
        x(ptr_stripe_redundant,                                 163,    0)      
        \
        x(reservation_key_nr_replicas_invalid,                  164,    0)      
        \
@@ -310,7 +311,7 @@ enum bch_fsck_flags {
        x(logged_op_but_clean,                                  283,    
FSCK_AUTOFIX)   \
        x(compression_opt_not_marked_in_sb,                     295,    
FSCK_AUTOFIX)   \
        x(compression_type_not_marked_in_sb,                    296,    
FSCK_AUTOFIX)   \
-       x(MAX,                                                  300,    0)
+       x(MAX,                                                  301,    0)
 
 enum bch_sb_error_id {
 #define x(t, n, ...) BCH_FSCK_ERR_##t = n,
-- 
2.45.2


Reply via email to