[PATCH v3 05/33] fs: add a generic emergency read-only state

Jan Kara jack at suse.cz
Fri Nov 13 06:53:49 PST 2026


On Fri 13-11-26 12:59:01, Christian Brauner wrote:
> ext4 and f2fs don't set SB_RDONLY after errors anymore and refuse
> modifications themselves. Doing that in all the other filesystems means
> the same checks in ->open, ->setattr, ->fsync, the directory and quota
> operations and ->reconfigure everywhere. Jan suggested a flag in the
> superblock instead so the VFS can do it once (cf. [1]).
> 
> So add sb->s_state with SB_STATE_EMERGENCY_RO. It's only ever set and
> never cleared and SB_RDONLY stays untouched. A filesystem calls
> sb_set_emergency_ro() where it used to set SB_RDONLY and the VFS refuses
> modifications wherever sb_rdonly() would:
> 
> - __mnt_is_readonly() and sb_permission(), so everything that takes
>   write access through mnt_want_write(), mnt_want_write_file() or
>   mnt_get_write_access()
> - notify_change(), rw_verify_area(), remap_verify_area(),
>   vfs_fallocate(), vfs_fsync_range() and do_page_mkwrite() for files
>   opened before the error
> - reconfigure_super() going read-write
> - the dquot code and quotactl(2)
> - sync_filesystem() and the per-superblock passes of sync(2)
> 
> sb_rdonly_any() is true for a read-only mount and for the emergency
> state so nobody has to open-code the pair.
> 
> So umount and the ->reconfigure() implementations that sync first don't
> write such a superblock anymore either. syncfs(2) and Q_SYNC fail with
> EROFS so userspace learns that nothing was written. Jan suggested that
> (cf. [2]).
> 
> freeze_super() refuses a new freeze with EROFS. Nothing is synced
> anymore so the flusher would keep writing to the frozen filesystem.
> Joining a freeze that's already in effect still works and thaw_super()
> is unchanged so an error while frozen is undone cleanly. FIFREEZE and dm
> suspend with lockfs fail on an errored filesystem now, like they already
> did for ext4.
> 
> /proc/mounts, statmount() and statfs() report the superblock as
> read-only. "emergency_ro" isn't shown as a mount option because remount
> helpers pass the shown options back.
> 
> The filesystem still has to refuse what doesn't go through the VFS: its
> allocators, its journal and deleting unlinked inodes. Writeback isn't
> stopped. The flusher, sync_bdevs() in sync(2) and sync_blockdev() in
> kill_block_super() keep writing, so the filesystem decides what its
> writeback still writes. Without a journal refusing only part of it
> leaves the disk inconsistent. ext4 refuses data writeback in that state,
> jfs commits the allocations writeback hasn't committed yet. The VFS
> can't decide that.
> 
> [1]: https://lore.kernel.org/r/my2k7257m265fp5ad77n5hfndl23i56gsog3jwnsyocp3yxbnj@aphfqdiej2hs
> [2]: https://lore.kernel.org/r/5qefa4mracb3x2z4vsdejmkyyfrhdcrixmmnooz4rzwcdfoejm@mqkvixj6afwp
> 
> Suggested-by: Jan Kara <jack at suse.cz>
> Signed-off-by: Christian Brauner (Amutable) <brauner at kernel.org>

Just one nit below. Otherwise feel free to add:

Reviewed-by: Jan Kara <jack at suse.cz>

> diff --git a/fs/quota/quota.c b/fs/quota/quota.c
> index 33bacd7075800..b488fb1f9cc44 100644
> --- a/fs/quota/quota.c
> +++ b/fs/quota/quota.c
> @@ -783,6 +783,19 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
>  	if (ret < 0)
>  		return ret;
>  
> +	/* An error made the filesystem read-only. */
> +	if (sb_emergency_ro(sb)) {
> +		switch (cmd) {
> +		case Q_QUOTAON:
> +		case Q_SETINFO:
> +		case Q_SETQUOTA:
> +		case Q_XQUOTAON:
> +		case Q_XQUOTARM:
> +		case Q_XSETQLIM:
> +			return -EROFS;
> +		}

I'd use existing quotactl_cmd_write() helper for this.

								Honza
-- 
Jan Kara <jack at suse.com>
SUSE Labs, CR



More information about the linux-mtd mailing list