Skip to contentSkip to conversation

ovl: sync dirty data when remounting to ro mode

PATCH In review Chengguang Xu 2 participants 4 messages Apr 22, 2020 Overlay filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovl: sync dirty data when remounting to ro mode

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.

---
 fs/overlayfs/super.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
fs/overlayfs/super.c +10 -1
index f57aa348dcd6..1bab326342bc 100644
@@ -364,11 +364,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 = {
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 4 lines · Chengguang Xu

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.

Isn't the same true for ->put_super()?

Thanks,
Miklos

#2 lore raw

---- 在 星期三, 2020-04-22 15:29:33 Miklos Szeredi <[email protected]> 撰写 ----

Quoted 8 lines · Chengguang Xu
Quoted 4 lines

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.

Isn't the same true for ->put_super()?

Before getting into ->put_super(), dirty data have been synced through below functions, so I think we don't have to worry about ->put_super().

kill_anon_super()
generic_shutdown_super()
sync_filesystem()

Thanks,
cgxu

maintainer
#3 lore raw
Quoted 11 lines · Chengguang Xu

---- 在 星期三, 2020-04-22 15:29:33 Miklos Szeredi <[email protected]> 撰写 ----

Quoted 8 lines · Chengguang Xu
Quoted 4 lines

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.

Isn't the same true for ->put_super()?

Quoted 6 lines

Before getting into ->put_super(), dirty data have been synced through below functions, so I think we don't have to worry about ->put_super().

kill_anon_super()
generic_shutdown_super()
sync_filesystem()

Okay, makes sense.

Thanks,
Miklos