Re: [PATCH 03/11] fs: add frozen sb state helpers

From: Jan Kara
Date: Sat Apr 21 2018 - 19:53:37 EST


On Fri 20-04-18 11:49:32, Luis R. Rodriguez wrote:
> On Tue, Apr 17, 2018 at 05:59:36PM -0700, Luis R. Rodriguez wrote:
> > On Thu, Dec 21, 2017 at 12:03:29PM +0100, Jan Kara wrote:
> > > Hello,
> > >
> > > I think I owe you a reply here... Sorry that it took so long.
> >
> > Took me just as long :)
> >
> > > On Fri 01-12-17 22:13:27, Luis R. Rodriguez wrote:
> > > >
> > > > I'll note that its still not perfectly clear if really the semantics behind
> > > > freeze_bdev() match what I described above fully. That still needs to be
> > > > vetted for. For instance, does thaw_bdev() keep a superblock frozen if we
> > > > an ioctl initiated freeze had occurred before? If so then great. Otherwise
> > > > I think we'll need to distinguish the ioctl interface. Worst possible case
> > > > is that bdev semantics and in-kernel semantics differ somehow, then that
> > > > will really create a holy fucking mess.
> > >
> > > I believe nobody really thought about mixing those two interfaces to fs
> > > freezing and so the behavior is basically defined by the implementation.
> > > That is:
> > >
> > > freeze_bdev() on sb frozen by ioctl_fsfreeze() -> EBUSY
> > > freeze_bdev() on sb frozen by freeze_bdev() -> success
> > > ioctl_fsfreeze() on sb frozen by freeze_bdev() -> EBUSY
> > > ioctl_fsfreeze() on sb frozen by ioctl_fsfreeze() -> EBUSY
> > >
> > > thaw_bdev() on sb frozen by ioctl_fsfreeze() -> EINVAL
> >
> > Phew, so this is what we want for the in-kernel freezing so we're good
> > and *can* combine these then.
>
> I double checked, and I don't see where you get EINVAL for this case.
> We *do* keep the sb frozen though, which is good, and the worst fear
> I had was that we did not. However we return 0 if there was already
> a prior freeze_bdev() or ioctl_fsfreeze() other than the context that
> started the prior freeze (--bdev->bd_fsfreeze_count > 0).
>
> The -EINVAL is only returned currently if there were no freezers.
>
> int thaw_bdev(struct block_device *bdev, struct super_block *sb)
> {
> int error = -EINVAL;
>
> mutex_lock(&bdev->bd_fsfreeze_mutex);
> if (!bdev->bd_fsfreeze_count)
> goto out;

But this is precisely where we'd bail if we freeze sb by ioctl_fsfreeze()
but try to thaw by thaw_bdev(). ioctl_fsfreeze() does not touch
bd_fsfreeze_count...

Honza

--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR