With errors=remount-ro, the hpfs default, hpfs_error() sets SB_RDONLY on the first error without holding s_umount. If that happens while the filesystem is frozen through bdev_freeze() thaw_super() sees a read-only superblock and leaves the s_writers rwsems locked so every writer hangs. hpfs_error() is also called from hpfs_fill_super() where nothing can freeze the superblock yet, so keep setting SB_RDONLY there. After that call sb_set_emergency_ro() instead and let the VFS refuse modifications. FITRIM is refused and unmark_dirty() does nothing in that state so the next mount reports the volume as improperly stopped. hpfs_map_dnode() and hpfs_lookup() treat the state like read-only so lookups behave as before. After a remount to read-only a remount to read-write fails until umount. A plain remount to read-write right after the error succeeds but the filesystem stays read-only. A remount to read-only doesn't write the spare block. Writes through file descriptors opened before the error fail with EROFS. Signed-off-by: Christian Brauner (Amutable) --- fs/hpfs/alloc.c | 4 ++-- fs/hpfs/dir.c | 2 +- fs/hpfs/map.c | 3 ++- fs/hpfs/super.c | 11 +++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fs/hpfs/alloc.c b/fs/hpfs/alloc.c index f5150372618ed..15b12afa856a4 100644 --- a/fs/hpfs/alloc.c +++ b/fs/hpfs/alloc.c @@ -539,7 +539,7 @@ int hpfs_trim_fs(struct super_block *s, u64 start, u64 end, u64 minlen, unsigned return 0; if (start < sbi->sb_dirband_start + sbi->sb_dirband_size && end > sbi->sb_dirband_start) { hpfs_lock(s); - if (sb_rdonly(s)) { + if (sb_rdonly_any(s)) { err = -EROFS; goto unlock_1; } @@ -560,7 +560,7 @@ int hpfs_trim_fs(struct super_block *s, u64 start, u64 end, u64 minlen, unsigned end_bmp = (end + 0x3fff) >> 14; while (start_bmp < end_bmp && !err) { hpfs_lock(s); - if (sb_rdonly(s)) { + if (sb_rdonly_any(s)) { err = -EROFS; goto unlock_2; } diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c index 3bf11202e2d3c..a82c06635b891 100644 --- a/fs/hpfs/dir.c +++ b/fs/hpfs/dir.c @@ -265,7 +265,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, unsigned in hpfs_result = hpfs_i(result); if (!de->directory) hpfs_result->i_parent_dir = dir->i_ino; - if (de->has_acl || de->has_xtd_perm) if (!sb_rdonly(dir->i_sb)) { + if ((de->has_acl || de->has_xtd_perm) && !sb_rdonly_any(dir->i_sb)) { hpfs_error(result->i_sb, "ACLs or XPERM found. This is probably HPFS386. This driver doesn't support it now. Send me some info on these structures"); iput(result); result = ERR_PTR(-EINVAL); diff --git a/fs/hpfs/map.c b/fs/hpfs/map.c index be73233502f81..9cfda43215cc9 100644 --- a/fs/hpfs/map.c +++ b/fs/hpfs/map.c @@ -288,7 +288,8 @@ struct dnode *hpfs_map_dnode(struct super_block *s, unsigned secno, goto bail; } if (((31 + de->namelen + de->down*4 + 3) & ~3) != le16_to_cpu(de->length)) { - if (((31 + de->namelen + de->down*4 + 3) & ~3) < le16_to_cpu(de->length) && s->s_flags & SB_RDONLY) goto ok; + if (((31 + de->namelen + de->down*4 + 3) & ~3) < le16_to_cpu(de->length) && + sb_rdonly_any(s)) goto ok; hpfs_error(s, "namelen does not match dirent size in dnode %08x, dirent %03x, last %03x", secno, p, pp); goto bail; } diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c index 8fbdbf0806276..a9e26ae2e3752 100644 --- a/fs/hpfs/super.c +++ b/fs/hpfs/super.c @@ -44,7 +44,7 @@ static void unmark_dirty(struct super_block *s) { struct buffer_head *bh; struct hpfs_spare_block *sb; - if (sb_rdonly(s)) return; + if (sb_rdonly_any(s)) return; sync_blockdev(s->s_bdev); if ((sb = hpfs_map_sector(s, 17, &bh, 0))) { sb->dirty = hpfs_sb(s)->sb_chkdsk > 1 - hpfs_sb(s)->sb_was_error; @@ -81,7 +81,14 @@ void hpfs_error(struct super_block *s, const char *fmt, ...) else { pr_cont("; remounting read-only\n"); mark_dirty(s, 0); - s->s_flags |= SB_RDONLY; + /* + * Before SB_BORN the mounter holds s_umount, + * later see sb_set_emergency_ro(). + */ + if (s->s_flags & SB_BORN) + sb_set_emergency_ro(s); + else + s->s_flags |= SB_RDONLY; } } else if (sb_rdonly(s)) pr_cont("; going on - but anything won't be destroyed because it's read-only\n"); -- 2.53.0