]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
block: simplify the block device syncing code
authorChristoph Hellwig <hch@lst.de>
Tue, 19 Oct 2021 06:25:30 +0000 (08:25 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 22 Jun 2022 12:22:03 +0000 (14:22 +0200)
BugLink: https://bugs.launchpad.net/bugs/1972905
[ Upstream commit 1e03a36bdff4709c1bbf0f57f60ae3f776d51adf ]

Get rid of the indirections and just provide a sync_bdevs
helper for the generic sync code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20211019062530.2174626-8-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
block/bdev.c
fs/internal.h
fs/sync.c
include/linux/blkdev.h

index 485a258b0ab37ee7cab7b9e28411dd0032f19830..a364f8166f02175e628b288bce61347a3be468ac 100644 (file)
@@ -1016,7 +1016,7 @@ int __invalidate_device(struct block_device *bdev, bool kill_dirty)
 }
 EXPORT_SYMBOL(__invalidate_device);
 
-void iterate_bdevs(void (*func)(struct block_device *, void *), void *arg)
+void sync_bdevs(bool wait)
 {
        struct inode *inode, *old_inode = NULL;
 
@@ -1047,8 +1047,19 @@ void iterate_bdevs(void (*func)(struct block_device *, void *), void *arg)
                bdev = I_BDEV(inode);
 
                mutex_lock(&bdev->bd_disk->open_mutex);
-               if (bdev->bd_openers)
-                       func(bdev, arg);
+               if (!bdev->bd_openers) {
+                       ; /* skip */
+               } else if (wait) {
+                       /*
+                        * We keep the error status of individual mapping so
+                        * that applications can catch the writeback error using
+                        * fsync(2). See filemap_fdatawait_keep_errors() for
+                        * details.
+                        */
+                       filemap_fdatawait_keep_errors(inode->i_mapping);
+               } else {
+                       filemap_fdatawrite(inode->i_mapping);
+               }
                mutex_unlock(&bdev->bd_disk->open_mutex);
 
                spin_lock(&blockdev_superblock->s_inode_list_lock);
index 3cd065c8a66b4ceb99d255f4c0fa82314fa218d9..ad0eb48c35663887aa0b4f05c620d1f743ecc531 100644 (file)
@@ -24,7 +24,6 @@ struct pipe_inode_info;
 extern void __init bdev_cache_init(void);
 
 extern int __sync_blockdev(struct block_device *bdev, int wait);
-void iterate_bdevs(void (*)(struct block_device *, void *), void *);
 void emergency_thaw_bdev(struct super_block *sb);
 #else
 static inline void bdev_cache_init(void)
@@ -35,10 +34,6 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)
 {
        return 0;
 }
-static inline void iterate_bdevs(void (*f)(struct block_device *, void *),
-               void *arg)
-{
-}
 static inline int emergency_thaw_bdev(struct super_block *sb)
 {
        return 0;
index fa5c7fba7f1ba466ef2f85743298aa5f3deb58db..c7d6607c9d9545e479219243c4bd7fa07335e4d6 100644 (file)
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -82,21 +82,6 @@ static void sync_fs_one_sb(struct super_block *sb, void *arg)
                sb->s_op->sync_fs(sb, *(int *)arg);
 }
 
-static void fdatawrite_one_bdev(struct block_device *bdev, void *arg)
-{
-       filemap_fdatawrite(bdev->bd_inode->i_mapping);
-}
-
-static void fdatawait_one_bdev(struct block_device *bdev, void *arg)
-{
-       /*
-        * We keep the error status of individual mapping so that
-        * applications can catch the writeback error using fsync(2).
-        * See filemap_fdatawait_keep_errors() for details.
-        */
-       filemap_fdatawait_keep_errors(bdev->bd_inode->i_mapping);
-}
-
 /*
  * Sync everything. We start by waking flusher threads so that most of
  * writeback runs on all devices in parallel. Then we sync all inodes reliably
@@ -115,8 +100,8 @@ void ksys_sync(void)
        iterate_supers(sync_inodes_one_sb, NULL);
        iterate_supers(sync_fs_one_sb, &nowait);
        iterate_supers(sync_fs_one_sb, &wait);
-       iterate_bdevs(fdatawrite_one_bdev, NULL);
-       iterate_bdevs(fdatawait_one_bdev, NULL);
+       sync_bdevs(false);
+       sync_bdevs(true);
        if (unlikely(laptop_mode))
                laptop_sync_completion();
 }
@@ -137,10 +122,10 @@ static void do_sync_work(struct work_struct *work)
         */
        iterate_supers(sync_inodes_one_sb, &nowait);
        iterate_supers(sync_fs_one_sb, &nowait);
-       iterate_bdevs(fdatawrite_one_bdev, NULL);
+       sync_bdevs(false);
        iterate_supers(sync_inodes_one_sb, &nowait);
        iterate_supers(sync_fs_one_sb, &nowait);
-       iterate_bdevs(fdatawrite_one_bdev, NULL);
+       sync_bdevs(false);
        printk("Emergency Sync complete\n");
        kfree(work);
 }
index 413c0148c0ce565fbfbf0902a6001c3cb7916c65..a388591173f8c5e144307ababea4619adc974004 100644 (file)
@@ -1999,6 +1999,7 @@ int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart,
 #ifdef CONFIG_BLOCK
 void invalidate_bdev(struct block_device *bdev);
 int sync_blockdev(struct block_device *bdev);
+void sync_bdevs(bool wait);
 #else
 static inline void invalidate_bdev(struct block_device *bdev)
 {
@@ -2007,6 +2008,9 @@ static inline int sync_blockdev(struct block_device *bdev)
 {
        return 0;
 }
+static inline void sync_bdevs(bool wait)
+{
+}
 #endif
 int fsync_bdev(struct block_device *bdev);