[RFC PATCH v5 09/10] fs: introduce new helper sync_fs_and_blockdev()
From: Chengguang Xu
Date: Thu Sep 23 2021 - 09:24:54 EST
Overlayfs needs to call upper layer's ->sync_fs
and __sync_blockdev() to sync metadata during syncfs(2).
Currently, __sync_blockdev() does not export to module
so introduce new helper sync_fs_and_blockdev() to wrap
those operations.
Signed-off-by: Chengguang Xu <cgxu519@xxxxxxxxxxxx>
---
fs/sync.c | 14 ++++++++++----
include/linux/fs.h | 1 +
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/sync.c b/fs/sync.c
index 1373a610dc78..36c755e6568a 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -21,6 +21,15 @@
#define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \
SYNC_FILE_RANGE_WAIT_AFTER)
+
+int sync_fs_and_blockdev(struct super_block *sb, int wait)
+{
+ if (sb->s_op->sync_fs)
+ sb->s_op->sync_fs(sb, wait);
+ return __sync_blockdev(sb->s_bdev, wait);
+}
+EXPORT_SYMBOL(sync_fs_and_blockdev);
+
/*
* Do the filesystem syncing work. For simple filesystems
* writeback_inodes_sb(sb) just dirties buffers with inodes so we have to
@@ -34,10 +43,7 @@ static int __sync_filesystem(struct super_block *sb, int wait)
sync_inodes_sb(sb);
else
writeback_inodes_sb(sb, WB_REASON_SYNC);
-
- if (sb->s_op->sync_fs)
- sb->s_op->sync_fs(sb, wait);
- return __sync_blockdev(sb->s_bdev, wait);
+ return sync_fs_and_blockdev(sb, wait);
}
/*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e7a633353fd2..e5ebf126281c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2777,6 +2777,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
void emergency_thaw_all(void);
extern int sync_filesystem(struct super_block *);
+extern int sync_fs_and_blockdev(struct super_block *sb, int wait);
extern const struct file_operations def_blk_fops;
extern const struct file_operations def_chr_fops;
--
2.27.0