diff mbox series

btrfs: fix missing snapshot drew unlock when root is dead during swap activation

Message ID 76ef43063706a4ef1a4313ba03ca6225e7d7dbac.1732887615.git.fdmanana@suse.com (mailing list archive)
State New
Headers show
Series btrfs: fix missing snapshot drew unlock when root is dead during swap activation | expand

Commit Message

Filipe Manana Nov. 29, 2024, 1:41 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

When activating a swap file we acquire the root's snapshot drew lock and
then check if the root is dead, failing and returning with -EPERM if it's
dead but without unlocking the root's snapshot lock. Fix this by adding
the missing unlock.

Fixes: 60021bd754c6 ("btrfs: prevent subvol with swapfile from being deleted")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/inode.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Johannes Thumshirn Nov. 29, 2024, 1:54 p.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
David Sterba Nov. 29, 2024, 4:45 p.m. UTC | #2
On Fri, Nov 29, 2024 at 01:41:37PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> When activating a swap file we acquire the root's snapshot drew lock and
> then check if the root is dead, failing and returning with -EPERM if it's
> dead but without unlocking the root's snapshot lock. Fix this by adding
> the missing unlock.
> 
> Fixes: 60021bd754c6 ("btrfs: prevent subvol with swapfile from being deleted")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: David Sterba <dsterba@suse.com>
Qu Wenruo Nov. 29, 2024, 8:39 p.m. UTC | #3
在 2024/11/30 00:11, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> When activating a swap file we acquire the root's snapshot drew lock and
> then check if the root is dead, failing and returning with -EPERM if it's
> dead but without unlocking the root's snapshot lock. Fix this by adding
> the missing unlock.
>
> Fixes: 60021bd754c6 ("btrfs: prevent subvol with swapfile from being deleted")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/inode.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 9267861f8ab0..6baa0269a85b 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -9876,6 +9876,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
>   	if (btrfs_root_dead(root)) {
>   		spin_unlock(&root->root_item_lock);
>
> +		btrfs_drew_write_unlock(&root->snapshot_lock);
>   		btrfs_exclop_finish(fs_info);
>   		btrfs_warn(fs_info,
>   		"cannot activate swapfile because subvolume %llu is being deleted",
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9267861f8ab0..6baa0269a85b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -9876,6 +9876,7 @@  static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
 	if (btrfs_root_dead(root)) {
 		spin_unlock(&root->root_item_lock);
 
+		btrfs_drew_write_unlock(&root->snapshot_lock);
 		btrfs_exclop_finish(fs_info);
 		btrfs_warn(fs_info,
 		"cannot activate swapfile because subvolume %llu is being deleted",