Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: Remove custom crc32c init code

The custom crc32 init code was introduced in
14a958e678cd ("Btrfs: fix btrfs boot when compiled as built-in") to
enable using btrfs as a built-in. However, later as pointed out by
60efa5eb2e88 ("Btrfs: use late_initcall instead of module_init") this
wasn't enough and finally btrfs was switched to late_initcall which
comes after the generic crc32c implementation is initiliased. The
latter commit superseeded the former. Now that we don't have to
maintain our own code let's just remove it and switch to using the
generic implementation.

Despite touching a lot of files the patch is really simple. Here is the gist of
the changes:

1. Select LIBCRC32C rather than the low-level modules.
2. s/btrfs_crc32c/crc32c/g
3. replace hash.h with linux/crc32c.h
4. Move the btrfs namehash funcs to ctree.h and change the tree accordingly.

I've tested this with btrfs being both a module and a built-in and xfstest
doesn't complain.

Does seem to fix the longstanding problem of not automatically selectiong
the crc32c module when btrfs is used. Possibly there is a workaround in
dracut.

The modinfo confirms that now all the module dependencies are there:

before:
depends: zstd_compress,zstd_decompress,raid6_pq,xor,zlib_deflate

after:
depends: libcrc32c,zstd_compress,zstd_decompress,raid6_pq,xor,zlib_deflate

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ add more info to changelog from mails ]
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Nikolay Borisov and committed by
David Sterba
9678c543 df91f56a

+35 -127
+1 -2
fs/btrfs/Kconfig
··· 1 1 config BTRFS_FS 2 2 tristate "Btrfs filesystem support" 3 - select CRYPTO 4 - select CRYPTO_CRC32C 3 + select LIBCRC32C 5 4 select ZLIB_INFLATE 6 5 select ZLIB_DEFLATE 7 6 select LZO_COMPRESS
+1 -1
fs/btrfs/Makefile
··· 10 10 export.o tree-log.o free-space-cache.o zlib.o lzo.o zstd.o \ 11 11 compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \ 12 12 reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ 13 - uuid-tree.o props.o hash.o free-space-tree.o tree-checker.o 13 + uuid-tree.o props.o free-space-tree.o tree-checker.o 14 14 15 15 btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o 16 16 btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
+2 -2
fs/btrfs/check-integrity.c
··· 96 96 #include <linux/blkdev.h> 97 97 #include <linux/mm.h> 98 98 #include <linux/string.h> 99 + #include <linux/crc32c.h> 99 100 #include "ctree.h" 100 101 #include "disk-io.h" 101 - #include "hash.h" 102 102 #include "transaction.h" 103 103 #include "extent_io.h" 104 104 #include "volumes.h" ··· 1736 1736 size_t sublen = i ? PAGE_SIZE : 1737 1737 (PAGE_SIZE - BTRFS_CSUM_SIZE); 1738 1738 1739 - crc = btrfs_crc32c(crc, data, sublen); 1739 + crc = crc32c(crc, data, sublen); 1740 1740 } 1741 1741 btrfs_csum_final(crc, csum); 1742 1742 if (memcmp(csum, h->csum, state->csum_size))
+16
fs/btrfs/ctree.h
··· 40 40 #include <linux/sizes.h> 41 41 #include <linux/dynamic_debug.h> 42 42 #include <linux/refcount.h> 43 + #include <linux/crc32c.h> 43 44 #include "extent_io.h" 44 45 #include "extent_map.h" 45 46 #include "async-thread.h" ··· 98 97 #define BTRFS_DIRTY_METADATA_THRESH SZ_32M 99 98 100 99 #define BTRFS_MAX_EXTENT_SIZE SZ_128M 100 + 101 101 102 102 /* 103 103 * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size ··· 2554 2552 #define btrfs_item_ptr_offset(leaf, slot) \ 2555 2553 ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \ 2556 2554 btrfs_item_offset_nr(leaf, slot))) 2555 + 2556 + static inline u64 btrfs_name_hash(const char *name, int len) 2557 + { 2558 + return crc32c((u32)~1, name, len); 2559 + } 2560 + 2561 + /* 2562 + * Figure the key offset of an extended inode ref 2563 + */ 2564 + static inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name, 2565 + int len) 2566 + { 2567 + return (u64) crc32c(parent_objectid, name, len); 2568 + } 2557 2569 2558 2570 static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info) 2559 2571 {
-1
fs/btrfs/dir-item.c
··· 18 18 19 19 #include "ctree.h" 20 20 #include "disk-io.h" 21 - #include "hash.h" 22 21 #include "transaction.h" 23 22 24 23 /*
+2 -2
fs/btrfs/disk-io.c
··· 31 31 #include <linux/uuid.h> 32 32 #include <linux/semaphore.h> 33 33 #include <linux/error-injection.h> 34 + #include <linux/crc32c.h> 34 35 #include <asm/unaligned.h> 35 36 #include "ctree.h" 36 37 #include "disk-io.h" 37 - #include "hash.h" 38 38 #include "transaction.h" 39 39 #include "btrfs_inode.h" 40 40 #include "volumes.h" ··· 270 270 271 271 u32 btrfs_csum_data(const char *data, u32 seed, size_t len) 272 272 { 273 - return btrfs_crc32c(seed, data, len); 273 + return crc32c(seed, data, len); 274 274 } 275 275 276 276 void btrfs_csum_final(u32 crc, u8 *result)
+5 -5
fs/btrfs/extent-tree.c
··· 27 27 #include <linux/ratelimit.h> 28 28 #include <linux/percpu_counter.h> 29 29 #include <linux/lockdep.h> 30 - #include "hash.h" 30 + #include <linux/crc32c.h> 31 31 #include "tree-log.h" 32 32 #include "disk-io.h" 33 33 #include "print-tree.h" ··· 1203 1203 __le64 lenum; 1204 1204 1205 1205 lenum = cpu_to_le64(root_objectid); 1206 - high_crc = btrfs_crc32c(high_crc, &lenum, sizeof(lenum)); 1206 + high_crc = crc32c(high_crc, &lenum, sizeof(lenum)); 1207 1207 lenum = cpu_to_le64(owner); 1208 - low_crc = btrfs_crc32c(low_crc, &lenum, sizeof(lenum)); 1208 + low_crc = crc32c(low_crc, &lenum, sizeof(lenum)); 1209 1209 lenum = cpu_to_le64(offset); 1210 - low_crc = btrfs_crc32c(low_crc, &lenum, sizeof(lenum)); 1210 + low_crc = crc32c(low_crc, &lenum, sizeof(lenum)); 1211 1211 1212 1212 return ((u64)high_crc << 31) ^ (u64)low_crc; 1213 1213 } ··· 5944 5944 */ 5945 5945 u64 num_bytes = btrfs_calc_trans_metadata_size(fs_info, 1); 5946 5946 5947 - trace_btrfs_space_reservation(fs_info, "orphan", btrfs_ino(inode), 5947 + trace_btrfs_space_reservation(fs_info, "orphan", btrfs_ino(inode), 5948 5948 num_bytes, 1); 5949 5949 return btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes, 1); 5950 5950 }
-54
fs/btrfs/hash.c
··· 1 - /* 2 - * Copyright (C) 2014 Filipe David Borba Manana <fdmanana@gmail.com> 3 - * 4 - * This program is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU General Public 6 - * License v2 as published by the Free Software Foundation. 7 - * 8 - * This program is distributed in the hope that it will be useful, 9 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 - * General Public License for more details. 12 - */ 13 - 14 - #include <crypto/hash.h> 15 - #include <linux/err.h> 16 - #include "hash.h" 17 - 18 - static struct crypto_shash *tfm; 19 - 20 - int __init btrfs_hash_init(void) 21 - { 22 - tfm = crypto_alloc_shash("crc32c", 0, 0); 23 - 24 - return PTR_ERR_OR_ZERO(tfm); 25 - } 26 - 27 - const char* btrfs_crc32c_impl(void) 28 - { 29 - return crypto_tfm_alg_driver_name(crypto_shash_tfm(tfm)); 30 - } 31 - 32 - void btrfs_hash_exit(void) 33 - { 34 - crypto_free_shash(tfm); 35 - } 36 - 37 - u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length) 38 - { 39 - SHASH_DESC_ON_STACK(shash, tfm); 40 - u32 *ctx = (u32 *)shash_desc_ctx(shash); 41 - u32 retval; 42 - int err; 43 - 44 - shash->tfm = tfm; 45 - shash->flags = 0; 46 - *ctx = crc; 47 - 48 - err = crypto_shash_update(shash, address, length); 49 - BUG_ON(err); 50 - 51 - retval = *ctx; 52 - barrier_data(ctx); 53 - return retval; 54 - }
-43
fs/btrfs/hash.h
··· 1 - /* 2 - * Copyright (C) 2007 Oracle. All rights reserved. 3 - * 4 - * This program is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU General Public 6 - * License v2 as published by the Free Software Foundation. 7 - * 8 - * This program is distributed in the hope that it will be useful, 9 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 - * General Public License for more details. 12 - * 13 - * You should have received a copy of the GNU General Public 14 - * License along with this program; if not, write to the 15 - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 - * Boston, MA 021110-1307, USA. 17 - */ 18 - 19 - #ifndef __HASH__ 20 - #define __HASH__ 21 - 22 - int __init btrfs_hash_init(void); 23 - 24 - void btrfs_hash_exit(void); 25 - const char* btrfs_crc32c_impl(void); 26 - 27 - u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length); 28 - 29 - static inline u64 btrfs_name_hash(const char *name, int len) 30 - { 31 - return btrfs_crc32c((u32)~1, name, len); 32 - } 33 - 34 - /* 35 - * Figure the key offset of an extended inode ref 36 - */ 37 - static inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name, 38 - int len) 39 - { 40 - return (u64) btrfs_crc32c(parent_objectid, name, len); 41 - } 42 - 43 - #endif
-1
fs/btrfs/inode-item.c
··· 18 18 19 19 #include "ctree.h" 20 20 #include "disk-io.h" 21 - #include "hash.h" 22 21 #include "transaction.h" 23 22 #include "print-tree.h" 24 23
-1
fs/btrfs/inode.c
··· 58 58 #include "free-space-cache.h" 59 59 #include "inode-map.h" 60 60 #include "backref.h" 61 - #include "hash.h" 62 61 #include "props.h" 63 62 #include "qgroup.h" 64 63 #include "dedupe.h"
+1 -1
fs/btrfs/props.c
··· 19 19 #include <linux/hashtable.h> 20 20 #include "props.h" 21 21 #include "btrfs_inode.h" 22 - #include "hash.h" 23 22 #include "transaction.h" 23 + #include "ctree.h" 24 24 #include "xattr.h" 25 25 #include "compression.h" 26 26
+2 -2
fs/btrfs/send.c
··· 27 27 #include <linux/vmalloc.h> 28 28 #include <linux/string.h> 29 29 #include <linux/compat.h> 30 + #include <linux/crc32c.h> 30 31 31 32 #include "send.h" 32 33 #include "backref.h" 33 - #include "hash.h" 34 34 #include "locking.h" 35 35 #include "disk-io.h" 36 36 #include "btrfs_inode.h" ··· 695 695 hdr->len = cpu_to_le32(sctx->send_size - sizeof(*hdr)); 696 696 hdr->crc = 0; 697 697 698 - crc = btrfs_crc32c(0, (unsigned char *)sctx->send_buf, sctx->send_size); 698 + crc = crc32c(0, (unsigned char *)sctx->send_buf, sctx->send_size); 699 699 hdr->crc = cpu_to_le32(crc); 700 700 701 701 ret = write_buf(sctx->send_filp, sctx->send_buf, sctx->send_size,
+4 -10
fs/btrfs/super.c
··· 41 41 #include <linux/slab.h> 42 42 #include <linux/cleancache.h> 43 43 #include <linux/ratelimit.h> 44 + #include <linux/crc32c.h> 44 45 #include <linux/btrfs.h> 45 46 #include "delayed-inode.h" 46 47 #include "ctree.h" ··· 49 48 #include "transaction.h" 50 49 #include "btrfs_inode.h" 51 50 #include "print-tree.h" 52 - #include "hash.h" 53 51 #include "props.h" 54 52 #include "xattr.h" 55 53 #include "volumes.h" ··· 2357 2357 ", ref-verify=on" 2358 2358 #endif 2359 2359 "\n", 2360 - btrfs_crc32c_impl()); 2360 + crc32c_impl()); 2361 2361 } 2362 2362 2363 2363 static int __init init_btrfs_fs(void) 2364 2364 { 2365 2365 int err; 2366 2366 2367 - err = btrfs_hash_init(); 2368 - if (err) 2369 - return err; 2370 - 2371 2367 btrfs_props_init(); 2372 2368 2373 2369 err = btrfs_init_sysfs(); 2374 2370 if (err) 2375 - goto free_hash; 2371 + return err; 2376 2372 2377 2373 btrfs_init_compress(); 2378 2374 ··· 2449 2453 free_compress: 2450 2454 btrfs_exit_compress(); 2451 2455 btrfs_exit_sysfs(); 2452 - free_hash: 2453 - btrfs_hash_exit(); 2456 + 2454 2457 return err; 2455 2458 } 2456 2459 ··· 2469 2474 btrfs_exit_sysfs(); 2470 2475 btrfs_cleanup_fs_uuids(); 2471 2476 btrfs_exit_compress(); 2472 - btrfs_hash_exit(); 2473 2477 } 2474 2478 2475 2479 late_initcall(init_btrfs_fs);
-1
fs/btrfs/tree-checker.c
··· 30 30 #include "tree-checker.h" 31 31 #include "disk-io.h" 32 32 #include "compression.h" 33 - #include "hash.h" 34 33 35 34 /* 36 35 * Error message should follow the following format:
+1 -1
fs/btrfs/tree-log.c
··· 21 21 #include <linux/blkdev.h> 22 22 #include <linux/list_sort.h> 23 23 #include <linux/iversion.h> 24 + #include "ctree.h" 24 25 #include "tree-log.h" 25 26 #include "disk-io.h" 26 27 #include "locking.h" 27 28 #include "print-tree.h" 28 29 #include "backref.h" 29 - #include "hash.h" 30 30 #include "compression.h" 31 31 #include "qgroup.h" 32 32 #include "inode-map.h"