FAILED: patch "[PATCH] btrfs: fix qgroup reservation leak on failure to allocate" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 1f2889f5594a2bc4c6a52634c4a51b93e785def5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025062054-stopping-boil-ca87@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 1f2889f5594a2bc4c6a52634c4a51b93e785def5 Mon Sep 17 00:00:00 2001
From: Filipe Manana <[email protected]>
Date: Wed, 7 May 2025 13:05:36 +0100
Subject: [PATCH] btrfs: fix qgroup reservation leak on failure to allocate
ordered extent
If we fail to allocate an ordered extent for a COW write we end up leaking a qgroup data reservation since we called btrfs_qgroup_release_data() but we didn't call btrfs_qgroup_free_refroot() (which would happen when running the respective data delayed ref created by ordered extent completion or when finishing the ordered extent in case an error happened).
So make sure we call btrfs_qgroup_free_refroot() if we fail to allocate an ordered extent for a COW write.
fs/btrfs/ordered-data.c +9 -3
@@ -153,9 +153,10 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(struct btrfs_ordered_extent *entry;int ret;u64 qgroup_rsv =0 ; +const bool is_nocow = (flags & + ((1U <<BTRFS_ORDERED_NOCOW ) | (1U <<BTRFS_ORDERED_PREALLOC ))); -if (flags & - ((1U <<BTRFS_ORDERED_NOCOW ) | (1U <<BTRFS_ORDERED_PREALLOC ))) { +if (is_nocow) {/* For nocow write, we can release the qgroup rsv right now */ ret =btrfs_qgroup_free_data (inode,NULL , file_offset, num_bytes, &qgroup_rsv);if (ret <0 )
@@ -170,8 +171,13 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(return ERR_PTR (ret); } entry =kmem_cache_zalloc (btrfs_ordered_extent_cache,GFP_NOFS ); -if (!entry) +if (!entry) { +if (!is_nocow) +btrfs_qgroup_free_refroot (inode->root->fs_info, +btrfs_root_id (inode->root), + qgroup_rsv,BTRFS_QGROUP_RSV_DATA );return ERR_PTR (-ENOMEM ); + } entry->file_offset = file_offset; entry->num_bytes = num_bytes;