From: Josef Bacik <[email protected]>

We only ever needed the bbio in btrfs_csum_one_bio, since that has the
bio embedded in it.  However with encryption we'll have a different bio
with the encrypted data in it, and the original bbio.  Update
btrfs_csum_one_bio to take the bio we're going to csum as an argument,
which will allow us to csum the encrypted bio and stuff the csums into
the corresponding bbio to be used later when the IO completes.

Signed-off-by: Josef Bacik <[email protected]>
Signed-off-by: Daniel Vacek <[email protected]>
---

v5: 
https://lore.kernel.org/linux-btrfs/595a2e46dae3d18bceb5dfa60ac3ae23760fc800.1706116485.git.jo...@toxicpanda.com/
 * Adapted for async csums.  For writes we have to stick with sync
   csums.  Otherwise fscrypt would have to hand us the bounced bio
   instead of releasing it.  Though that is not implemented yet.
---
 fs/btrfs/bio.c       |  4 ++--
 fs/btrfs/bio.h       |  1 +
 fs/btrfs/file-item.c | 13 ++++++-------
 fs/btrfs/file-item.h |  2 +-
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index 0a69e09bfe28..487dd9267fd7 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -592,9 +592,9 @@ static int btrfs_bio_csum(struct btrfs_bio *bbio)
        if (bbio->bio.bi_opf & REQ_META)
                return btree_csum_one_bio(bbio);
 #ifdef CONFIG_BTRFS_EXPERIMENTAL
-       return btrfs_csum_one_bio(bbio, true);
+       return btrfs_csum_one_bio(bbio, &bbio->bio, true);
 #else
-       return btrfs_csum_one_bio(bbio, false);
+       return btrfs_csum_one_bio(bbio, &bbio->bio, false);
 #endif
 }
 
diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h
index 303ed6c7103d..43f7544029ac 100644
--- a/fs/btrfs/bio.h
+++ b/fs/btrfs/bio.h
@@ -59,6 +59,7 @@ struct btrfs_bio {
                        struct btrfs_ordered_sum *sums;
                        struct work_struct csum_work;
                        struct completion csum_done;
+                       struct bio *csum_bio;
                        struct bvec_iter csum_saved_iter;
                        u64 orig_physical;
                        u64 orig_logical;
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 08dc78295707..ef0b6faf3de0 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -764,11 +764,10 @@ int btrfs_lookup_csums_bitmap(struct btrfs_root *root, 
struct btrfs_path *path,
        return ret;
 }
 
-static void csum_one_bio(struct btrfs_bio *bbio, struct bvec_iter *src)
+static void csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, struct 
bvec_iter *src)
 {
        struct btrfs_inode *inode = bbio->inode;
        struct btrfs_fs_info *fs_info = inode->root->fs_info;
-       struct bio *bio = &bbio->bio;
        struct btrfs_ordered_sum *sums = bbio->sums;
        struct bvec_iter iter = *src;
        phys_addr_t paddr;
@@ -796,19 +795,18 @@ static void csum_one_bio_work(struct work_struct *work)
 
        ASSERT(btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE);
        ASSERT(bbio->async_csum == true);
-       csum_one_bio(bbio, &bbio->csum_saved_iter);
+       csum_one_bio(bbio, bbio->csum_bio, &bbio->csum_saved_iter);
        complete(&bbio->csum_done);
 }
 
 /*
  * Calculate checksums of the data contained inside a bio.
  */
-int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool async)
+int btrfs_csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, bool async)
 {
        struct btrfs_ordered_extent *ordered = bbio->ordered;
        struct btrfs_inode *inode = bbio->inode;
        struct btrfs_fs_info *fs_info = inode->root->fs_info;
-       struct bio *bio = &bbio->bio;
        struct btrfs_ordered_sum *sums;
        unsigned nofs_flag;
 
@@ -827,12 +825,13 @@ int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool async)
        btrfs_add_ordered_sum(ordered, sums);
 
        if (!async) {
-               csum_one_bio(bbio, &bbio->bio.bi_iter);
+               csum_one_bio(bbio, bio, &bio->bi_iter);
                return 0;
        }
        init_completion(&bbio->csum_done);
        bbio->async_csum = true;
-       bbio->csum_saved_iter = bbio->bio.bi_iter;
+       bbio->csum_bio = bio;
+       bbio->csum_saved_iter = bio->bi_iter;
        INIT_WORK(&bbio->csum_work, csum_one_bio_work);
        schedule_work(&bbio->csum_work);
        return 0;
diff --git a/fs/btrfs/file-item.h b/fs/btrfs/file-item.h
index 5645c5e3abdb..d16fd2144552 100644
--- a/fs/btrfs/file-item.h
+++ b/fs/btrfs/file-item.h
@@ -64,7 +64,7 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
 int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
                           struct btrfs_root *root,
                           struct btrfs_ordered_sum *sums);
-int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool async);
+int btrfs_csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, bool async);
 int btrfs_alloc_dummy_sum(struct btrfs_bio *bbio);
 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
                             struct list_head *list, int search_commit,
-- 
2.51.0


Reply via email to