On 12:10 23/09, Nikolay Borisov wrote: > > > On 21.09.20 г. 17:43 ч., Goldwyn Rodrigues wrote: > > From: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx> > > > > fs_info->fs_state is a filesystem bit check as opposed to inode > > and can be performed before we begin with write checks. This eliminates > > inode lock/unlock in case of error bit is set. > > > > Signed-off-by: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx> > > --- > > fs/btrfs/file.c | 21 +++++++++------------ > > 1 file changed, 9 insertions(+), 12 deletions(-) > > > > diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c > > index 4c40a2742aab..ca374cb5ffc9 100644 > > --- a/fs/btrfs/file.c > > +++ b/fs/btrfs/file.c > > @@ -1981,6 +1981,15 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb, > > size_t count; > > loff_t oldsize; > > > > + /* > > + * If BTRFS flips readonly due to some impossible error > > + * (fs_info->fs_state now has BTRFS_SUPER_FLAG_ERROR), > > + * although we have opened a file as writable, we have > > + * to stop this write operation to ensure FS consistency. > > + */ > > + if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) > > + return -EROFS; > > + > > nit: Actually can't this check be eliminated altogether or the comment > vastly simplified because BTRFS_SUPER_FLAG_ERROR check is performed only > during mount so the description in the parantheses is invalid i.e the fs > won't flip to RO because BTRFS_SUPER_FLAG_ERROR is now set in the super > block. As a matter of fact how is this flag set - because I don't see it > set in the kernel code nor in btrfs-progs ? You are right. This flag originated from acce952b0263 ("Btrfs: forced readonly mounts on errors") However, the following commit removed writing the super in case of the error: 68ce9682a4bb ("Btrfs: remove superblock writing after fatal error") So, it does not land in the super flags anyways. The flag does not make sense if we use BTRFS_FS_STATE_ERROR. I will remove BTRFS_SUPER_FLAG_ERROR comment for now. -- Goldwyn