Device-mapper and the filesystem shutdown ioctls freeze the filesystems on a device through bdev_freeze() and fs_bdev_freeze() freezes each superblock with FREEZE_HOLDER_USERSPACE | FREEZE_MAY_NEST. That's the same holder FIFREEZE uses. So FITHAW can drop that freeze while the device is still suspended. qemu-guest-agent's guest-fsfreeze-thaw does just that as it issues FITHAW on every mount until it fails. An emergency thaw does the same. do_thaw_all_callback() only thaws the device freezes of sb->s_bdev and then drops the remaining userspace freeze of the superblock which may belong to any other device of the filesystem, an external log or journal device or another btrfs member. The device's bdev_thaw() then calls fs_bdev_thaw() which gets -EINVAL from thaw_super() since there's nothing left to thaw. bdev_thaw() takes that to mean that the device is still frozen and keeps bd_fsfreeze_count elevated and device-mapper ignores the error. So the device stays frozen for good and every later mount of it fails: dm-0: Can't mount, blockdev is frozen fe967191e585 ("fs: don't return -EINVAL for successful nested thaw") fixed the same outcome for a freeze that nested with FIFREEZE. A freeze that lost its hold behind the device's back still ends up there. Treat -EINVAL from thaw_super() in fs_bdev_thaw() as the freeze being gone already. There's nothing left to thaw for the device then. Before fs_bdev_thaw() existed thaw_bdev() kept the count on the same error. Fixes: 49ef8832fb1a ("bdev: implement freeze and thaw holder operations") Cc: stable@vger.kernel.org Signed-off-by: Christian Brauner (Amutable) --- fs/super.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fs/super.c b/fs/super.c index 82290d094c03..ac4c4d067509 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1494,10 +1494,29 @@ static int fs_super_freeze(struct super_block *sb) static int fs_super_thaw(struct super_block *sb) { - if (sb->s_op->thaw_super) - return sb->s_op->thaw_super(sb, + int error; + + if (sb->s_op->thaw_super) { + error = sb->s_op->thaw_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL); - return thaw_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL); + /* -EINVAL means the freeze is gone already. */ + if (error == -EINVAL) + return 0; + return error; + } + + /* The caller holds an active reference. */ + if (WARN_ON_ONCE(!super_lock_excl(sb))) + return 0; + + /* FITHAW or an emergency thaw may have dropped the freeze already. */ + if (sb->s_writers.frozen != SB_FREEZE_COMPLETE || + !sb->s_writers.freeze_ucount) { + super_unlock_excl(sb); + return 0; + } + return thaw_super_locked(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, + NULL); } static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise) @@ -1610,7 +1629,8 @@ static int fs_bdev_freeze(struct block_device *bdev) * frozen more than once (by the kernel or via another device). * * Return: 0, or the first error on a single-fs device; a shared device swallows - * per-superblock errors, as fs_bdev_freeze() does. + * per-superblock errors, as fs_bdev_freeze() does. A superblock that + * lost the freeze already, e.g., to FITHAW, counts as thawed. */ static int fs_bdev_thaw(struct block_device *bdev) { -- 2.53.0