ovl: Sync upper dirty data when sync overlayfs
Subsystems (2)
PATCH v3 1/1 ovl: Sync upper dirty data when sync overlayfs
Executes filesystem sync or umount on overlayfs,
dirty data does not be synced as expected on upper filesystem. This patch fixes sync filesystem method to keep data consistency for overlayfs.
---
Changes since v2:
- Fix checkpatch warning.
Changes since v1:
- Call __sync_filesystem() instead of directly calling low level syncing functions.
fs/overlayfs/super.c | 6 ++---- fs/sync.c | 3 ++- include/linux/fs.h | 1 + 3 files changed, 5 insertions(+), 5 deletions(-)
fs/overlayfs/super.c +2 -4
@@ -231,6 +231,7 @@ static void ovl_put_super(struct super_block *sb)kfree (ufs); } +/* Sync real dirty inodes in upper filesystem (if it exists) */ static int ovl_sync_fs (struct super_block *sb,int wait) {struct ovl_fs *ufs = sb->s_fs_info;
@@ -240,12 +241,9 @@ static int ovl_sync_fs(struct super_block *sb, int wait)if (!ufs->upper_mnt)return 0 ; upper_sb = ufs->upper_mnt->mnt_sb; -if (!upper_sb->s_op->sync_fs) -return 0 ; -/* real inodes have already been synced by sync_filesystem(ovl_sb) */ down_read (&upper_sb->s_umount); - ret = upper_sb->s_op->sync_fs (upper_sb, wait); + ret =__sync_filesystem (upper_sb, wait);up_read (&upper_sb->s_umount);return ret; }
fs/sync.c +2 -1
@@ -28,7 +28,7 @@* wait == 1 case since in that case write_inode() functions do * sync_dirty_buffer() and thus effectively write one block at a time. */ -static int __sync_filesystem (struct super_block *sb,int wait) +int __sync_filesystem (struct super_block *sb,int wait) {if (wait)sync_inodes_sb (sb);
@@ -39,6 +39,7 @@ static int __sync_filesystem(struct super_block *sb, int wait) sb->s_op->sync_fs (sb, wait);return __sync_blockdev (sb->s_bdev, wait); } +EXPORT_SYMBOL (__sync_filesystem);/* * Write out and wait upon all dirty data associated with this
include/linux/fs.h +1 -0
@@ -2463,6 +2463,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb) return false; }#endif +extern int __sync_filesystem (struct super_block *sb,int wait);extern int sync_filesystem (struct super_block *);extern const struct file_operations def_blk_fops;extern const struct file_operations def_chr_fops;
Signature · 1 line
1.8.3.1
Amir Goldstein
maintainerQuoted 1 line · Chengguang Xu
Executes filesystem sync or umount on overlayfs,
When executing...
Quoted 1 line
dirty data does not be synced as expected on upper filesystem.
...does not get synced...
Quoted 7 lines
This patch fixes sync filesystem method to keep data consistency for overlayfs.
Signed-off-by Chengguang Xu <[email protected]>---
Chengguang,
This patch looks fine, but it is not based on overlayfs-next nor on master. I guess by "mainline" you meant latest release or something. Please rebase V4 on overlayfs-next from Miklos' tree.
I enhanced my origin syncfs test to check for syncing of upper files:
https://github.com/amir73il/overlayfs/blob/master/tests/xfs_syncfs.sh
Without your fix, the upper file delalloc blocks are not flushed after syncfs, but only after fsync. With your fix delalloc blacks are flushed by syncfs.
Can you take the task to make this simple test into an xfstest? If you need help finding your way around xfstests, I can help you with that. You do not need the xfs specific parts of the test, only the generic delalloc part.
I think it is best to make a generic/* test (i.e. not fs specific), which tests flushing of delalloc blocks on sync/syncfs/fsync for fs that support delalloc, but it may also make sense to have an overlay/* specific regression test for syncfs. We can discuss those details after you post a test.
Thanks,
Amir.
Quoted 37 lines · 在 2017年11月28日,下午10:58,Amir Goldstein <[email protected]> 写道:
Quoted 1 line · Chengguang Xu
Executes filesystem sync or umount on overlayfs,
When executing...
Quoted 1 line
dirty data does not be synced as expected on upper filesystem.
...does not get synced...
Quoted 7 lines
This patch fixes sync filesystem method to keep data consistency for overlayfs.
Signed-off-by Chengguang Xu <[email protected]>---
Chengguang,
This patch looks fine, but it is not based on overlayfs-next nor on master. I guess by "mainline" you meant latest release or something. Please rebase V4 on overlayfs-next from Miklos' tree.
I enhanced my origin syncfs test to check for syncing of upper files:
https://github.com/amir73il/overlayfs/blob/master/tests/xfs_syncfs.shWithout your fix, the upper file delalloc blocks are not flushed after syncfs, but only after fsync. With your fix delalloc blacks are flushed by syncfs.
Can you take the task to make this simple test into an xfstest? If you need help finding your way around xfstests, I can help you with that. You do not need the xfs specific parts of the test, only the generic delalloc part.
Quoted 5 lines
I think it is best to make a generic/* test (i.e. not fs specific), which tests flushing of delalloc blocks on sync/syncfs/fsync for fs that support delalloc, but it may also make sense to have an overlay/* specific regression test for syncfs. We can discuss those details after you post a test.
OK, I’ll make test case for different sync scenarios.
Quoted 3 lines
Thanks,
Amir.