History

btrfs: add member for a specific checksum driver

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.

David Sterba committed 7 years ago

Commit b4e967b1 parent 41e6d2a3 files · +16 −3Browse files

Unified · Split

3 files
  1. fs/btrfs/ctree.c +12 −0
  2. fs/btrfs/ctree.h +1 −0
  3. fs/btrfs/disk-io.c +3 −3
fs/btrfs/ctree.c+12−0
@@ -32,6 +32,7 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, · 31 unmodified lines
3232 static const struct btrfs_csums {
3333 u16 size;
3434 const char *name;
35+ const char *driver;
3536 } btrfs_csums[] = {
3637 [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" },
3738 [BTRFS_CSUM_TYPE_XXHASH] = { .size = 8, .name = "xxhash64" },
@@ -53,6 +54,17 @@ const char *btrfs_super_csum_name(u16 csum_type) · 15 unmodified lines
5354 return btrfs_csums[csum_type].name;
5455 }
5556
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+
5668 size_t __const btrfs_get_num_csums(void)
5769 {
5870 return ARRAY_SIZE(btrfs_csums);
fs/btrfs/ctree.h+1−0
@@ -2163,6 +2163,7 @@ BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, · 2162 unmodified lines
21632163
21642164 int btrfs_super_csum_size(const struct btrfs_super_block *s);
21652165 const char *btrfs_super_csum_name(u16 csum_type);
2166+const char *btrfs_super_csum_driver(u16 csum_type);
21662167 size_t __const btrfs_get_num_csums(void);
21672168
21682169
fs/btrfs/disk-io.c+3−3
@@ -2219,13 +2219,13 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, · 2218 unmodified lines
22192219 static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type)
22202220 {
22212221 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);
22232223
2224− csum_shash = crypto_alloc_shash(csum_name, 0, 0);
2224+ csum_shash = crypto_alloc_shash(csum_driver, 0, 0);
22252225
22262226 if (IS_ERR(csum_shash)) {
22272227 btrfs_err(fs_info, "error allocating %s hash for checksum",
2228− csum_name);
2228+ csum_driver);
22292229 return PTR_ERR(csum_shash);
22302230 }
22312231

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t