All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] btrfs: fix qgroup rsv leak in subvol create
@ 2023-04-28 23:08 Boris Burkov
  2023-04-29  7:18 ` Qu Wenruo
  0 siblings, 1 reply; 9+ messages in thread
From: Boris Burkov @ 2023-04-28 23:08 UTC (permalink / raw)
  To: linux-btrfs, kernel-team, 'Qu Wenruo '

While working on testing my quota work, I tried running all fstests
while passing mkfs -R quota. That shook out a failure in btrfs/042.

The failure is a reservation leak detected at umount, and the cause is a
subtle difficulty with the qgroup rsv release accounting for inode
creation.

The issue stems from a recent change to subvol creation:
btrfs: don't commit transaction for every subvol create

Specifically, that test creates 10 subvols, and in the mode where we
commit each time, the logic for dir index item reservation never decides
that it can undo the reservation. However, if we keep joining the
previous transaction, this logic kicks in and calls
btrfs_block_rsv_release without specifying any of the qgroup release
return counter stuff. As a result, adding the new subvol inode blows
away the state needed for the later explicit call to
btrfs_subvolume_release_metadata.

I suspect this fix is incorrect and will break something to do with
normal inode creation, but it's an interesting starting point and I
would appreciate any suggestions or help with how to really fix it,
without reverting the subvol commit patch. Worst case, I suppose we can
commit every time if quotas are enabled.

The issue should reproduce on misc-next on btrfs/042 with
MKFS_OPTIONS="-K -R quota"
in the config file.

Signed-off-by: Boris Burkov <boris@bur.io>
---
 fs/btrfs/delayed-inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 6b457b010cbc..82b2e86f9bd9 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1480,6 +1480,7 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
 		delayed_node->index_item_leaves++;
 	} else if (!test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) {
 		const u64 bytes = btrfs_calc_insert_metadata_size(fs_info, 1);
+		u64 qgroup_to_release;
 
 		/*
 		 * Adding the new dir index item does not require touching another
@@ -1490,7 +1491,8 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
 		 */
 		trace_btrfs_space_reservation(fs_info, "transaction",
 					      trans->transid, bytes, 0);
-		btrfs_block_rsv_release(fs_info, trans->block_rsv, bytes, NULL);
+		btrfs_block_rsv_release(fs_info, trans->block_rsv, bytes, &qgroup_to_release);
+		btrfs_qgroup_convert_reserved_meta(delayed_node->root, qgroup_to_release);
 		ASSERT(trans->bytes_reserved >= bytes);
 		trans->bytes_reserved -= bytes;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-09 23:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-28 23:08 [PATCH RFC] btrfs: fix qgroup rsv leak in subvol create Boris Burkov
2023-04-29  7:18 ` Qu Wenruo
2023-05-01 16:50   ` Boris Burkov
2023-05-01 22:58     ` Qu Wenruo
2023-05-02  3:34       ` Boris Burkov
2023-05-01 17:09   ` Boris Burkov
2023-05-09 22:29     ` David Sterba
2023-05-09 23:05       ` Qu Wenruo
2023-05-09 23:14         ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.