Re: [RFC PATCH] btrfs: don't call btrfs_sync_file from iomap context

Goldwyn Rodrigues
2020-09-01T18:40:47Z

On 14:44 01/09, Johannes Thumshirn wrote:
> On 01/09/2020 16:37, Filipe Manana wrote:
> >> + iocb->ki_flags |= IOCB_DSYNC;
> >
> > This should be set before calling generic_write_sync() above,
> > otherwise we don't do the persistence required by dsync.
> >
> > I have to be honest, I don't like this approach that much, it's a bit
> > fragile - what if some other code, invoked in between clearing and
> > setting back the flag, needs that flag to operate correctly?
>
> Yes I don't like it either.
>
> I've compared btrfs to ext4 and xfs and both don't hold on the inode
> lock for (nearly) the whole xxx_file_write_iter() time, so I think
> the correct fix would be to relax this time. But I haven't found any
> documentation yet on which functions need to be under the inode_lock
> and which not.

I think you have got this reversed. ext4 and xfs hold the inode lock for
the entire xxx_file_write_iter(). OTOH, they don't take the inode lock
during fsync operations. The comments in btrfs_sync_file() mention that
it needs to make sure inode lock is acquired to make sure no other
process dirty the pages while sync is running.

>
> Any input is appreciated here.
>

--
Goldwyn