Commit f9e69aa9 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

btrfs: simplify ->flush_bio handling

Use and embedded bios that is initialized when used instead of
bio_kmalloc plus bio_reset.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20220406061228.410163-2-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent b53f3dcd
...@@ -4226,6 +4226,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors) ...@@ -4226,6 +4226,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors)
*/ */
static void btrfs_end_empty_barrier(struct bio *bio) static void btrfs_end_empty_barrier(struct bio *bio)
{ {
bio_uninit(bio);
complete(bio->bi_private); complete(bio->bi_private);
} }
...@@ -4235,7 +4236,7 @@ static void btrfs_end_empty_barrier(struct bio *bio) ...@@ -4235,7 +4236,7 @@ static void btrfs_end_empty_barrier(struct bio *bio)
*/ */
static void write_dev_flush(struct btrfs_device *device) static void write_dev_flush(struct btrfs_device *device)
{ {
struct bio *bio = device->flush_bio; struct bio *bio = &device->flush_bio;
#ifndef CONFIG_BTRFS_FS_CHECK_INTEGRITY #ifndef CONFIG_BTRFS_FS_CHECK_INTEGRITY
/* /*
...@@ -4253,7 +4254,8 @@ static void write_dev_flush(struct btrfs_device *device) ...@@ -4253,7 +4254,8 @@ static void write_dev_flush(struct btrfs_device *device)
return; return;
#endif #endif
bio_reset(bio, device->bdev, REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH); bio_init(bio, device->bdev, NULL, 0,
REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH);
bio->bi_end_io = btrfs_end_empty_barrier; bio->bi_end_io = btrfs_end_empty_barrier;
init_completion(&device->flush_wait); init_completion(&device->flush_wait);
bio->bi_private = &device->flush_wait; bio->bi_private = &device->flush_wait;
...@@ -4267,7 +4269,7 @@ static void write_dev_flush(struct btrfs_device *device) ...@@ -4267,7 +4269,7 @@ static void write_dev_flush(struct btrfs_device *device)
*/ */
static blk_status_t wait_dev_flush(struct btrfs_device *device) static blk_status_t wait_dev_flush(struct btrfs_device *device)
{ {
struct bio *bio = device->flush_bio; struct bio *bio = &device->flush_bio;
if (!test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state)) if (!test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state))
return BLK_STS_OK; return BLK_STS_OK;
......
...@@ -405,7 +405,6 @@ void btrfs_free_device(struct btrfs_device *device) ...@@ -405,7 +405,6 @@ void btrfs_free_device(struct btrfs_device *device)
WARN_ON(!list_empty(&device->post_commit_list)); WARN_ON(!list_empty(&device->post_commit_list));
rcu_string_free(device->name); rcu_string_free(device->name);
extent_io_tree_release(&device->alloc_state); extent_io_tree_release(&device->alloc_state);
bio_put(device->flush_bio);
btrfs_destroy_dev_zone_info(device); btrfs_destroy_dev_zone_info(device);
kfree(device); kfree(device);
} }
...@@ -6949,16 +6948,6 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, ...@@ -6949,16 +6948,6 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
if (!dev) if (!dev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
/*
* Preallocate a bio that's always going to be used for flushing device
* barriers and matches the device lifespan
*/
dev->flush_bio = bio_kmalloc(GFP_KERNEL, 0);
if (!dev->flush_bio) {
kfree(dev);
return ERR_PTR(-ENOMEM);
}
INIT_LIST_HEAD(&dev->dev_list); INIT_LIST_HEAD(&dev->dev_list);
INIT_LIST_HEAD(&dev->dev_alloc_list); INIT_LIST_HEAD(&dev->dev_alloc_list);
INIT_LIST_HEAD(&dev->post_commit_list); INIT_LIST_HEAD(&dev->post_commit_list);
......
...@@ -121,8 +121,8 @@ struct btrfs_device { ...@@ -121,8 +121,8 @@ struct btrfs_device {
/* bytes used on the current transaction */ /* bytes used on the current transaction */
u64 commit_bytes_used; u64 commit_bytes_used;
/* for sending down flush barriers */ /* Bio used for flushing device barriers */
struct bio *flush_bio; struct bio flush_bio;
struct completion flush_wait; struct completion flush_wait;
/* per-device scrub information */ /* per-device scrub information */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment