Skip to contentSkip to conversation

Make statfs properly return read-only state after emergency remount

PATCH In review Carlos Maiolino 2 participants 2 messages Jun 29, 2017 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make statfs properly return read-only state after emergency remount

Emergency remount (sysrq-u) sets MS_RDONLY to the superblock but doesn't set MNT_READONLY to the mount point.

Once calculate_f_flags() only check for the mount point read only state, when setting kstatfs flags, after an emergency remount, statfs does not report the filesystem as read-only, even though it is.

Enable flags_by_sb() to also check for superblock read only state, so the kstatfs and consequently statfs can properly show the read-only state of the filesystem.

---
 fs/statfs.c | 2 ++
 1 file changed, 2 insertions(+)
fs/statfs.c +2 -0
index 4e4623c..c1dfc37 100644
@@ -38,6 +38,8 @@ static int flags_by_sb(int s_flags)
 		flags |= ST_SYNCHRONOUS;
 	if (s_flags & MS_MANDLOCK)
 		flags |= ST_MANDLOCK;
+	if (s_flags & MS_RDONLY)
+		flags |= ST_RDONLY;
 	return flags;
 }
 
Signature · 1 line
2.9.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Carlos Maiolino

Emergency remount (sysrq-u) sets MS_RDONLY to the superblock but doesn't set MNT_READONLY to the mount point.

Once calculate_f_flags() only check for the mount point read only state, when setting kstatfs flags, after an emergency remount, statfs does not report the filesystem as read-only, even though it is.

Enable flags_by_sb() to also check for superblock read only state, so the kstatfs and consequently statfs can properly show the read-only state of the filesystem.

---
 fs/statfs.c | 2 ++
 1 file changed, 2 insertions(+)
fs/statfs.c +0 -0
index 4e4623c..c1dfc37 100644

fs/statfs.c static int flags_by_sb(int s_flags) · line 45

Quoted 8 lines
fs/statfs.c +2 -0
@@ -38,6 +38,8 @@ static int flags_by_sb(int s_flags)
 		flags |= ST_SYNCHRONOUS;
 	if (s_flags & MS_MANDLOCK)
 		flags |= ST_MANDLOCK;
+	if (s_flags & MS_RDONLY)
+		flags |= ST_RDONLY;
 	return flags;
 }
 

IIUC, the superblock won't be writeable once MS_RDONLY is set, so every mount that uses it also becomes readonly regardless of how MNT_READONLY is set. LGTM: