]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/checksum.h
Update bcachefs sources to 8e1519ccb6 bcachefs: Add tracepoint & counter for btree...
[bcachefs-tools-debian] / libbcachefs / checksum.h
index c86c3c05d62054a66faffa4c5c2cde81ab5de1e8..409ad534d9f40c23efd94817349ca1eeffb4ff44 100644 (file)
@@ -61,8 +61,16 @@ int bch2_rechecksum_bio(struct bch_fs *, struct bio *, struct bversion,
                        struct bch_extent_crc_unpacked *,
                        unsigned, unsigned, unsigned);
 
-int bch2_encrypt_bio(struct bch_fs *, unsigned,
-                    struct nonce, struct bio *);
+int __bch2_encrypt_bio(struct bch_fs *, unsigned,
+                      struct nonce, struct bio *);
+
+static inline int bch2_encrypt_bio(struct bch_fs *c, unsigned type,
+                                  struct nonce nonce, struct bio *bio)
+{
+       return bch2_csum_type_is_encryption(type)
+               ? __bch2_encrypt_bio(c, type, nonce, bio)
+               : 0;
+}
 
 int bch2_decrypt_sb_key(struct bch_fs *, struct bch_sb_field_crypt *,
                        struct bch_key *);
@@ -78,27 +86,30 @@ static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opts type,
 {
        switch (type) {
        case BCH_CSUM_OPT_none:
-            return BCH_CSUM_none;
+               return BCH_CSUM_none;
        case BCH_CSUM_OPT_crc32c:
-            return data ? BCH_CSUM_crc32c : BCH_CSUM_crc32c_nonzero;
+               return data ? BCH_CSUM_crc32c : BCH_CSUM_crc32c_nonzero;
        case BCH_CSUM_OPT_crc64:
-            return data ? BCH_CSUM_crc64 : BCH_CSUM_crc64_nonzero;
+               return data ? BCH_CSUM_crc64 : BCH_CSUM_crc64_nonzero;
        case BCH_CSUM_OPT_xxhash:
-            return BCH_CSUM_xxhash;
+               return BCH_CSUM_xxhash;
        default:
-            BUG();
+               BUG();
        }
 }
 
 static inline enum bch_csum_type bch2_data_checksum_type(struct bch_fs *c,
-                                                        unsigned opt)
+                                                        struct bch_io_opts opts)
 {
+       if (opts.nocow)
+               return 0;
+
        if (c->sb.encryption_type)
                return c->opts.wide_macs
                        ? BCH_CSUM_chacha20_poly1305_128
                        : BCH_CSUM_chacha20_poly1305_80;
 
-       return bch2_csum_opt_to_type(opt, true);
+       return bch2_csum_opt_to_type(opts.data_checksum, true);
 }
 
 static inline enum bch_csum_type bch2_meta_checksum_type(struct bch_fs *c)