btrfs: use test_and_clear_bit() in wait_dev_flush()
authorAnand Jain <anand.jain@oracle.com>
Mon, 27 Mar 2023 09:53:10 +0000 (17:53 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Apr 2023 16:01:20 +0000 (18:01 +0200)
The function wait_dev_flush() tests for the BTRFS_DEV_STATE_FLUSH_SENT
bit and then clears it separately. Instead, use test_and_clear_bit().
Though we don't need to do the atomic test and clear, it's following a
common pattern.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c

index fb4f88faeacec3a69ec32c90eb94f0a623af980b..59ea049fe7ee0de22a15c6c9795fdf077b8369eb 100644 (file)
@@ -4122,10 +4122,9 @@ static bool wait_dev_flush(struct btrfs_device *device)
 {
        struct bio *bio = &device->flush_bio;
 
-       if (!test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state))
+       if (!test_and_clear_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state))
                return false;
 
-       clear_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state);
        wait_for_completion_io(&device->flush_wait);
 
        if (bio->bi_status) {