Skip to content

Commit e593b2b

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: properly implement sync_filesystem()
overlayfs syncs all inode pages on sync_filesystem(), but it also needs to call s_op->sync_fs() of upper fs for metadata sync. This fixes correctness of syncfs(2) as demonstrated by following xfs specific test: xfs_sync_stats() { echo $1 echo -n "xfs_log_force = " grep log /proc/fs/xfs/stat | awk '{ print $5 }' } xfs_sync_stats "before touch" touch x xfs_sync_stats "after touch" xfs_io -c syncfs . xfs_sync_stats "after syncfs" xfs_io -c fsync x xfs_sync_stats "after fsync" xfs_io -c fsync x xfs_sync_stats "after fsync #2" When this test is run in overlay mount over xfs, log force count does not increase with syncfs command. Signed-off-by: Amir Goldstein <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 01ad3eb commit e593b2b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

fs/overlayfs/super.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ static void ovl_put_super(struct super_block *sb)
160160
kfree(ufs);
161161
}
162162

163+
static int ovl_sync_fs(struct super_block *sb, int wait)
164+
{
165+
struct ovl_fs *ufs = sb->s_fs_info;
166+
struct super_block *upper_sb;
167+
int ret;
168+
169+
if (!ufs->upper_mnt)
170+
return 0;
171+
upper_sb = ufs->upper_mnt->mnt_sb;
172+
if (!upper_sb->s_op->sync_fs)
173+
return 0;
174+
175+
/* real inodes have already been synced by sync_filesystem(ovl_sb) */
176+
down_read(&upper_sb->s_umount);
177+
ret = upper_sb->s_op->sync_fs(upper_sb, wait);
178+
up_read(&upper_sb->s_umount);
179+
return ret;
180+
}
181+
163182
/**
164183
* ovl_statfs
165184
* @sb: The overlayfs super block
@@ -222,6 +241,7 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)
222241

223242
static const struct super_operations ovl_super_operations = {
224243
.put_super = ovl_put_super,
244+
.sync_fs = ovl_sync_fs,
225245
.statfs = ovl_statfs,
226246
.show_options = ovl_show_options,
227247
.remount_fs = ovl_remount,

0 commit comments

Comments
 (0)