Commit 4fc6441a authored by Anand Jain's avatar Anand Jain Committed by David Sterba

btrfs: wait part of the write_dev_flush() can be separated out

Submit and wait parts of write_dev_flush() can be split into two
separate functions for better readability.
Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent cea7c8bf
...@@ -3488,37 +3488,16 @@ static void btrfs_end_empty_barrier(struct bio *bio) ...@@ -3488,37 +3488,16 @@ static void btrfs_end_empty_barrier(struct bio *bio)
} }
/* /*
* trigger flushes for one the devices. If you pass wait == 0, the flushes are * Submit a flush request to the device if it supports it. Error handling is
* sent down. With wait == 1, it waits for the previous flush. * done in the waiting counterpart.
*
* any device where the flush fails with eopnotsupp are flagged as not-barrier
* capable
*/ */
static int write_dev_flush(struct btrfs_device *device, int wait) static void write_dev_flush(struct btrfs_device *device)
{ {
struct request_queue *q = bdev_get_queue(device->bdev); struct request_queue *q = bdev_get_queue(device->bdev);
struct bio *bio; struct bio *bio;
int ret = 0;
if (!test_bit(QUEUE_FLAG_WC, &q->queue_flags)) if (!test_bit(QUEUE_FLAG_WC, &q->queue_flags))
return 0; return;
if (wait) {
bio = device->flush_bio;
wait_for_completion(&device->flush_wait);
if (bio->bi_error) {
ret = bio->bi_error;
btrfs_dev_stat_inc_and_print(device,
BTRFS_DEV_STAT_FLUSH_ERRS);
}
/* drop the reference from the wait == 0 run */
bio_put(bio);
device->flush_bio = NULL;
return ret;
}
/* /*
* one reference for us, and we leave it for the * one reference for us, and we leave it for the
...@@ -3535,8 +3514,32 @@ static int write_dev_flush(struct btrfs_device *device, int wait) ...@@ -3535,8 +3514,32 @@ static int write_dev_flush(struct btrfs_device *device, int wait)
bio_get(bio); bio_get(bio);
btrfsic_submit_bio(bio); btrfsic_submit_bio(bio);
}
/*
* If the flush bio has been submitted by write_dev_flush, wait for it.
*/
static int wait_dev_flush(struct btrfs_device *device)
{
int ret = 0;
struct bio *bio = device->flush_bio;
if (!bio)
return 0; return 0;
wait_for_completion(&device->flush_wait);
if (bio->bi_error) {
ret = bio->bi_error;
btrfs_dev_stat_inc_and_print(device,
BTRFS_DEV_STAT_FLUSH_ERRS);
}
/* drop the reference from the wait == 0 run */
bio_put(bio);
device->flush_bio = NULL;
return ret;
} }
static int check_barrier_error(struct btrfs_fs_devices *fsdevs) static int check_barrier_error(struct btrfs_fs_devices *fsdevs)
...@@ -3577,7 +3580,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info) ...@@ -3577,7 +3580,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info)
if (!dev->in_fs_metadata || !dev->writeable) if (!dev->in_fs_metadata || !dev->writeable)
continue; continue;
write_dev_flush(dev, 0); write_dev_flush(dev);
dev->last_flush_error = 0; dev->last_flush_error = 0;
} }
...@@ -3592,7 +3595,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info) ...@@ -3592,7 +3595,7 @@ static int barrier_all_devices(struct btrfs_fs_info *info)
if (!dev->in_fs_metadata || !dev->writeable) if (!dev->in_fs_metadata || !dev->writeable)
continue; continue;
ret = write_dev_flush(dev, 1); ret = wait_dev_flush(dev);
if (ret) { if (ret) {
dev->last_flush_error = ret; dev->last_flush_error = ret;
errors_wait++; errors_wait++;
......
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