We can use bio::remaining counter to sync the offloaded checksumming.
As a result we can slim down the btrfs_bio structure by 24 bytes
and simplify the code a bit.
Difference in pahole output:
- /* size: 328, cachelines: 6, members: 15 */
+ /* size: 304, cachelines: 5, members: 14 */
Moreover this will allow us enabling async checksumming with encryption
where we need to checksum the bounce bio instead of our regular one
embedded in btrfs_bio. And so we need to extend it's lifetime. This is
the preferred way to do so.
This also fixes a bug in experimental build where the async checksumming
was using the system workqueue instead of fs_info::endio_workers.
Fixes: dd57c78aec39 ("btrfs: introduce btrfs_bio::async_csum")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
bbio->can_use_append = orig_bbio->can_use_append;
bbio->is_scrub = orig_bbio->is_scrub;
bbio->is_remap = orig_bbio->is_remap;
- bbio->async_csum = orig_bbio->async_csum;
atomic_inc(&orig_bbio->pending_ios);
return bbio;
/* Make sure we're already in task context. */
ASSERT(in_task());
- if (bbio->async_csum)
- wait_for_completion(&bbio->csum_done);
-
bbio->bio.bi_status = status;
if (bbio->bio.bi_pool == &btrfs_clone_bioset) {
struct btrfs_bio *orig_bbio = bbio->private;
struct btrfs_ordered_extent *ordered;
struct btrfs_ordered_sum *sums;
struct work_struct csum_work;
- struct completion csum_done;
struct bvec_iter csum_saved_iter;
u64 orig_physical;
u64 orig_logical;
/* Whether the bio is coming from copy_remapped_data_io(). */
bool is_remap:1;
- /* Whether the csum generation for data write is async. */
- bool async_csum:1;
-
/* Whether the bio is written using zone append. */
bool can_use_append:1;
struct btrfs_bio *bbio = container_of(work, struct btrfs_bio, csum_work);
ASSERT(btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE);
- ASSERT(bbio->async_csum == true);
csum_one_bio(bbio);
- complete(&bbio->csum_done);
+ bio_endio(&bbio->bio);
}
/*
csum_one_bio(bbio);
return 0;
}
- init_completion(&bbio->csum_done);
- bbio->async_csum = true;
+ bio_inc_remaining(bio);
INIT_WORK(&bbio->csum_work, csum_one_bio_work);
- schedule_work(&bbio->csum_work);
+ queue_work(fs_info->endio_workers, &bbio->csum_work);
return 0;
}