if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
                                ret = btrfs_lookup_bio_sums(inode, comp_bio,
-                                                           sums);
+                                                           false, 0, sums);
                                BUG_ON(ret); /* -ENOMEM */
                        }
 
        BUG_ON(ret); /* -ENOMEM */
 
        if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
-               ret = btrfs_lookup_bio_sums(inode, comp_bio, sums);
+               ret = btrfs_lookup_bio_sums(inode, comp_bio, false, 0, sums);
                BUG_ON(ret); /* -ENOMEM */
        }
 
 
 int btrfs_del_csums(struct btrfs_trans_handle *trans,
                    struct btrfs_root *root, u64 bytenr, u64 len);
 blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
-                                  u8 *dst);
-blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio,
-                             u64 logical_offset);
+                                  bool at_offset, u64 offset, u8 *dst);
 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
                             struct btrfs_root *root,
                             u64 objectid, u64 pos,
 
        return ret;
 }
 
-static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
-                                  u64 logical_offset, u8 *dst, int dio)
+/**
+ * btrfs_lookup_bio_sums - Look up checksums for a bio.
+ * @inode: inode that the bio is for.
+ * @bio: bio embedded in btrfs_io_bio.
+ * @at_offset: If true, look up checksums for the extent at @offset.
+ *             If false, use the page offsets from the bio.
+ * @offset: If @at_offset is true, offset in file to look up checksums for.
+ *          Ignored otherwise.
+ * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If
+ *       NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead.
+ *
+ * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise.
+ */
+blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
+                                  bool at_offset, u64 offset, u8 *dst)
 {
        struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
        struct bio_vec bvec;
        struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
        struct btrfs_path *path;
        u8 *csum;
-       u64 offset = 0;
        u64 item_start_offset = 0;
        u64 item_last_offset = 0;
        u64 disk_bytenr;
        }
 
        disk_bytenr = (u64)bio->bi_iter.bi_sector << 9;
-       if (dio)
-               offset = logical_offset;
 
        bio_for_each_segment(bvec, bio, iter) {
                page_bytes_left = bvec.bv_len;
                if (count)
                        goto next;
 
-               if (!dio)
+               if (!at_offset)
                        offset = page_offset(bvec.bv_page) + bvec.bv_offset;
                count = btrfs_find_ordered_sum(inode, offset, disk_bytenr,
                                               csum, nblocks);
 
        WARN_ON_ONCE(count);
        btrfs_free_path(path);
-       return 0;
-}
-
-blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
-                                  u8 *dst)
-{
-       return __btrfs_lookup_bio_sums(inode, bio, 0, dst, 0);
-}
-
-blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio, u64 offset)
-{
-       return __btrfs_lookup_bio_sums(inode, bio, offset, NULL, 1);
+       return BLK_STS_OK;
 }
 
 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
 
                                                           bio_flags);
                        goto out;
                } else if (!skip_sum) {
-                       ret = btrfs_lookup_bio_sums(inode, bio, NULL);
+                       ret = btrfs_lookup_bio_sums(inode, bio, false, 0, NULL);
                        if (ret)
                                goto out;
                }
         * contention.
         */
        if (dip->logical_offset == file_offset) {
-               ret = btrfs_lookup_bio_sums_dio(inode, dip->orig_bio,
-                                               file_offset);
+               ret = btrfs_lookup_bio_sums(inode, dip->orig_bio, true,
+                                           file_offset, NULL);
                if (ret)
                        return ret;
        }