Skip to content

Commit 6aaaca7

Browse files
Chengguang Xugregkh
authored andcommitted
ovl: Sync upper dirty data when syncing overlayfs
commit e8d4bfe upstream. When executing filesystem sync or umount on overlayfs, dirty data does not get synced as expected on upper filesystem. This patch fixes sync filesystem method to keep data consistency for overlayfs. Signed-off-by: Chengguang Xu <[email protected]> Fixes: e593b2b ("ovl: properly implement sync_filesystem()") Cc: <[email protected]> #4.11 Signed-off-by: Miklos Szeredi <[email protected]> Signed-off-by: Sudip Mukherjee <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 21b5b5e commit 6aaaca7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

fs/overlayfs/super.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static void ovl_put_super(struct super_block *sb)
232232
kfree(ufs);
233233
}
234234

235+
/* Sync real dirty inodes in upper filesystem (if it exists) */
235236
static int ovl_sync_fs(struct super_block *sb, int wait)
236237
{
237238
struct ovl_fs *ufs = sb->s_fs_info;
@@ -240,14 +241,24 @@ static int ovl_sync_fs(struct super_block *sb, int wait)
240241

241242
if (!ufs->upper_mnt)
242243
return 0;
243-
upper_sb = ufs->upper_mnt->mnt_sb;
244-
if (!upper_sb->s_op->sync_fs)
244+
245+
/*
246+
* If this is a sync(2) call or an emergency sync, all the super blocks
247+
* will be iterated, including upper_sb, so no need to do anything.
248+
*
249+
* If this is a syncfs(2) call, then we do need to call
250+
* sync_filesystem() on upper_sb, but enough if we do it when being
251+
* called with wait == 1.
252+
*/
253+
if (!wait)
245254
return 0;
246255

247-
/* real inodes have already been synced by sync_filesystem(ovl_sb) */
256+
upper_sb = ufs->upper_mnt->mnt_sb;
257+
248258
down_read(&upper_sb->s_umount);
249-
ret = upper_sb->s_op->sync_fs(upper_sb, wait);
259+
ret = sync_filesystem(upper_sb);
250260
up_read(&upper_sb->s_umount);
261+
251262
return ret;
252263
}
253264

0 commit comments

Comments
 (0)