Skip to content

Commit e8d4bfe

Browse files
Chengguang XuMiklos Szeredi
authored andcommitted
ovl: Sync upper dirty data when syncing overlayfs
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]>
1 parent b02a16e commit e8d4bfe

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
@@ -252,6 +252,7 @@ static void ovl_put_super(struct super_block *sb)
252252
ovl_free_fs(ofs);
253253
}
254254

255+
/* Sync real dirty inodes in upper filesystem (if it exists) */
255256
static int ovl_sync_fs(struct super_block *sb, int wait)
256257
{
257258
struct ovl_fs *ofs = sb->s_fs_info;
@@ -260,14 +261,24 @@ static int ovl_sync_fs(struct super_block *sb, int wait)
260261

261262
if (!ofs->upper_mnt)
262263
return 0;
263-
upper_sb = ofs->upper_mnt->mnt_sb;
264-
if (!upper_sb->s_op->sync_fs)
264+
265+
/*
266+
* If this is a sync(2) call or an emergency sync, all the super blocks
267+
* will be iterated, including upper_sb, so no need to do anything.
268+
*
269+
* If this is a syncfs(2) call, then we do need to call
270+
* sync_filesystem() on upper_sb, but enough if we do it when being
271+
* called with wait == 1.
272+
*/
273+
if (!wait)
265274
return 0;
266275

267-
/* real inodes have already been synced by sync_filesystem(ovl_sb) */
276+
upper_sb = ofs->upper_mnt->mnt_sb;
277+
268278
down_read(&upper_sb->s_umount);
269-
ret = upper_sb->s_op->sync_fs(upper_sb, wait);
279+
ret = sync_filesystem(upper_sb);
270280
up_read(&upper_sb->s_umount);
281+
271282
return ret;
272283
}
273284

0 commit comments

Comments
 (0)