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

btrfs: get rid of trivial __btrfs_lookup_bio_sums() wrappers

Currently, we have two wrappers for __btrfs_lookup_bio_sums():
btrfs_lookup_bio_sums_dio(), which is used for direct I/O, and
btrfs_lookup_bio_sums(), which is used everywhere else. The only
difference is that the _dio variant looks up csums starting at the given
offset instead of using the page index, which isn't actually direct
I/O-specific. Let's clean up the signature and return value of
__btrfs_lookup_bio_sums(), rename it to btrfs_lookup_bio_sums(), and get
rid of the trivial helpers.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Omar Sandoval and committed by
David Sterba
e62958fc 321f69f8

+23 -26
+2 -2
fs/btrfs/compression.c
··· 763 763 764 764 if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { 765 765 ret = btrfs_lookup_bio_sums(inode, comp_bio, 766 - sums); 766 + false, 0, sums); 767 767 BUG_ON(ret); /* -ENOMEM */ 768 768 } 769 769 ··· 791 791 BUG_ON(ret); /* -ENOMEM */ 792 792 793 793 if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { 794 - ret = btrfs_lookup_bio_sums(inode, comp_bio, sums); 794 + ret = btrfs_lookup_bio_sums(inode, comp_bio, false, 0, sums); 795 795 BUG_ON(ret); /* -ENOMEM */ 796 796 } 797 797
+1 -3
fs/btrfs/ctree.h
··· 2789 2789 int btrfs_del_csums(struct btrfs_trans_handle *trans, 2790 2790 struct btrfs_root *root, u64 bytenr, u64 len); 2791 2791 blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, 2792 - u8 *dst); 2793 - blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio, 2794 - u64 logical_offset); 2792 + bool at_offset, u64 offset, u8 *dst); 2795 2793 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, 2796 2794 struct btrfs_root *root, 2797 2795 u64 objectid, u64 pos,
+17 -18
fs/btrfs/file-item.c
··· 148 148 return ret; 149 149 } 150 150 151 - static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, 152 - u64 logical_offset, u8 *dst, int dio) 151 + /** 152 + * btrfs_lookup_bio_sums - Look up checksums for a bio. 153 + * @inode: inode that the bio is for. 154 + * @bio: bio embedded in btrfs_io_bio. 155 + * @at_offset: If true, look up checksums for the extent at @offset. 156 + * If false, use the page offsets from the bio. 157 + * @offset: If @at_offset is true, offset in file to look up checksums for. 158 + * Ignored otherwise. 159 + * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If 160 + * NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead. 161 + * 162 + * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise. 163 + */ 164 + blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, 165 + bool at_offset, u64 offset, u8 *dst) 153 166 { 154 167 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 155 168 struct bio_vec bvec; ··· 172 159 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 173 160 struct btrfs_path *path; 174 161 u8 *csum; 175 - u64 offset = 0; 176 162 u64 item_start_offset = 0; 177 163 u64 item_last_offset = 0; 178 164 u64 disk_bytenr; ··· 217 205 } 218 206 219 207 disk_bytenr = (u64)bio->bi_iter.bi_sector << 9; 220 - if (dio) 221 - offset = logical_offset; 222 208 223 209 bio_for_each_segment(bvec, bio, iter) { 224 210 page_bytes_left = bvec.bv_len; 225 211 if (count) 226 212 goto next; 227 213 228 - if (!dio) 214 + if (!at_offset) 229 215 offset = page_offset(bvec.bv_page) + bvec.bv_offset; 230 216 count = btrfs_find_ordered_sum(inode, offset, disk_bytenr, 231 217 csum, nblocks); ··· 295 285 296 286 WARN_ON_ONCE(count); 297 287 btrfs_free_path(path); 298 - return 0; 299 - } 300 - 301 - blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, 302 - u8 *dst) 303 - { 304 - return __btrfs_lookup_bio_sums(inode, bio, 0, dst, 0); 305 - } 306 - 307 - blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio, u64 offset) 308 - { 309 - return __btrfs_lookup_bio_sums(inode, bio, offset, NULL, 1); 288 + return BLK_STS_OK; 310 289 } 311 290 312 291 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
+3 -3
fs/btrfs/inode.c
··· 2127 2127 bio_flags); 2128 2128 goto out; 2129 2129 } else if (!skip_sum) { 2130 - ret = btrfs_lookup_bio_sums(inode, bio, NULL); 2130 + ret = btrfs_lookup_bio_sums(inode, bio, false, 0, NULL); 2131 2131 if (ret) 2132 2132 goto out; 2133 2133 } ··· 8387 8387 * contention. 8388 8388 */ 8389 8389 if (dip->logical_offset == file_offset) { 8390 - ret = btrfs_lookup_bio_sums_dio(inode, dip->orig_bio, 8391 - file_offset); 8390 + ret = btrfs_lookup_bio_sums(inode, dip->orig_bio, true, 8391 + file_offset, NULL); 8392 8392 if (ret) 8393 8393 return ret; 8394 8394 }