Currently all the checksum algorithms generate a fixed size digest size and we use it. The on-disk format can hold up to BTRFS_CSUM_SIZE bytes and BLAKE2b produces digest of 512 bits by default. We can't do that and will use the blake2b-256, this needs to be passed to the crypto API. Separate that from the base algorithm name and add a member to request specific driver, in this case with the digest size. The only place that uses the driver name is the crypto API setup.
Unified · Split
| @@ -32,6 +32,7 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, · 31 unmodified lines | |||
| 32 | static const struct btrfs_csums { | 32 | static const struct btrfs_csums { |
| 33 | u16 size; | 33 | u16 size; |
| 34 | const char *name; | 34 | const char *name; |
| 35 | const char *driver; | ||
| 35 | } btrfs_csums[] = { | 36 | } btrfs_csums[] = { |
| 36 | [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" }, | 37 | [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" }, |
| 37 | [BTRFS_CSUM_TYPE_XXHASH] = { .size = 8, .name = "xxhash64" }, | 38 | [BTRFS_CSUM_TYPE_XXHASH] = { .size = 8, .name = "xxhash64" }, |
| @@ -53,6 +54,17 @@ const char *btrfs_super_csum_name(u16 csum_type) · 15 unmodified lines | |||
| 53 | return btrfs_csums[csum_type].name; | 54 | return btrfs_csums[csum_type].name; |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 57 | /* | ||
| 58 | * Return driver name if defined, otherwise the name that's also a valid driver | ||
| 59 | * name | ||
| 60 | */ | ||
| 61 | const char *btrfs_super_csum_driver(u16 csum_type) | ||
| 62 | { | ||
| 63 | /* csum type is validated at mount time */ | ||
| 64 | return btrfs_csums[csum_type].driver ?: | ||
| 65 | btrfs_csums[csum_type].name; | ||
| 66 | } | ||
| 67 | |||
| 56 | size_t __const btrfs_get_num_csums(void) | 68 | size_t __const btrfs_get_num_csums(void) |
| 57 | { | 69 | { |
| 58 | return ARRAY_SIZE(btrfs_csums); | 70 | return ARRAY_SIZE(btrfs_csums); |
| @@ -2163,6 +2163,7 @@ BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, · 2162 unmodified lines | |||
| 2163 | 2163 | ||
| 2164 | int btrfs_super_csum_size(const struct btrfs_super_block *s); | 2164 | int btrfs_super_csum_size(const struct btrfs_super_block *s); |
| 2165 | const char *btrfs_super_csum_name(u16 csum_type); | 2165 | const char *btrfs_super_csum_name(u16 csum_type); |
| 2166 | const char *btrfs_super_csum_driver(u16 csum_type); | ||
| 2166 | size_t __const btrfs_get_num_csums(void); | 2167 | size_t __const btrfs_get_num_csums(void); |
| 2167 | 2168 | ||
| 2168 | 2169 | ||
| @@ -2219,13 +2219,13 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, · 2218 unmodified lines | |||
| 2219 | static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type) | 2219 | static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type) |
| 2220 | { | 2220 | { |
| 2221 | struct crypto_shash *csum_shash; | 2221 | struct crypto_shash *csum_shash; |
| 2222 | const char *csum_name = btrfs_super_csum_name(csum_type); | 2222 | const char *csum_driver = btrfs_super_csum_driver(csum_type); |
| 2223 | 2223 | ||
| 2224 | csum_shash = crypto_alloc_shash(csum_name, 0, 0); | 2224 | csum_shash = crypto_alloc_shash(csum_driver, 0, 0); |
| 2225 | 2225 | ||
| 2226 | if (IS_ERR(csum_shash)) { | 2226 | if (IS_ERR(csum_shash)) { |
| 2227 | btrfs_err(fs_info, "error allocating %s hash for checksum", | 2227 | btrfs_err(fs_info, "error allocating %s hash for checksum", |
| 2228 | csum_name); | 2228 | csum_driver); |
| 2229 | return PTR_ERR(csum_shash); | 2229 | return PTR_ERR(csum_shash); |
| 2230 | } | 2230 | } |
| 2231 | 2231 | ||