ovl: sync dirty data when remounting to ro mode
authorChengguang Xu <cgxu519@mykernel.net>
Wed, 22 Apr 2020 04:28:43 +0000 (12:28 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Wed, 13 May 2020 09:11:24 +0000 (11:11 +0200)
sync_filesystem() does not sync dirty data for readonly filesystem during
umount, so before changing to readonly filesystem we should sync dirty data
for data integrity.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/super.c

index a88a7ba..60dfb27 100644 (file)
@@ -365,11 +365,20 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
 static int ovl_remount(struct super_block *sb, int *flags, char *data)
 {
        struct ovl_fs *ofs = sb->s_fs_info;
+       struct super_block *upper_sb;
+       int ret = 0;
 
        if (!(*flags & SB_RDONLY) && ovl_force_readonly(ofs))
                return -EROFS;
 
-       return 0;
+       if (*flags & SB_RDONLY && !sb_rdonly(sb)) {
+               upper_sb = ofs->upper_mnt->mnt_sb;
+               down_read(&upper_sb->s_umount);
+               ret = sync_filesystem(upper_sb);
+               up_read(&upper_sb->s_umount);
+       }
+
+       return ret;
 }
 
 static const struct super_operations ovl_super_operations = {