Merge tag 'objtool-core-2020-06-01' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / fs / block_dev.c
index 52b6f646cdbd0af27d827d9e4d983ec1455c87f0..93672c3f1c78c886eaeffaff6746bf2ee2937d99 100644 (file)
@@ -19,7 +19,6 @@
 #include <linux/module.h>
 #include <linux/blkpg.h>
 #include <linux/magic.h>
-#include <linux/dax.h>
 #include <linux/buffer_head.h>
 #include <linux/swap.h>
 #include <linux/pagevec.h>
@@ -1893,6 +1892,16 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
        struct gendisk *disk = bdev->bd_disk;
        struct block_device *victim = NULL;
 
+       /*
+        * Sync early if it looks like we're the last one.  If someone else
+        * opens the block device between now and the decrement of bd_openers
+        * then we did a sync that we didn't need to, but that's not the end
+        * of the world and we want to avoid long (could be several minute)
+        * syncs while holding the mutex.
+        */
+       if (bdev->bd_openers == 1)
+               sync_blockdev(bdev);
+
        mutex_lock_nested(&bdev->bd_mutex, for_part);
        if (for_part)
                bdev->bd_part_count--;