From cf79ac47932b377d0cfe6b61f4472cdc17eac042 Mon Sep 17 00:00:00 2001 From: Boris Burkov Date: Wed, 28 Jun 2023 14:03:35 -0700 Subject: btrfs: track original extent owner in head_ref Simple quotas requires tracking the original creating root of any given extent. This gets complicated when multiple subvolumes create overlapping/contradictory refs in the same transaction. For example, due to modifying or deleting an extent while also snapshotting it. To resolve this in a general way, take advantage of the fact that we are essentially already tracking this for handling releasing reservations. The head ref coalesces the various refs and uses must_insert_reserved to check if it needs to create an extent/free reservation. Store the ref that set must_insert_reserved as the owning ref on the head ref. Note that this can result in writing an extent for the very first time with an owner different from its only ref, but it will look the same as if you first created it with the original owning ref, then added the other ref, then removed the owning ref. Signed-off-by: Boris Burkov Signed-off-by: David Sterba --- fs/btrfs/delayed-ref.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'fs/btrfs/delayed-ref.h') diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 84b37888bff3..47e4bdf4fb30 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -110,6 +110,12 @@ struct btrfs_delayed_ref_head { */ int ref_mod; + /* + * The root that triggered the allocation when must_insert_reserved is + * set to true. + */ + u64 owning_root; + /* * when a new extent is allocated, it is just reserved in memory * The actual extent isn't inserted into the extent allocation tree @@ -123,6 +129,7 @@ struct btrfs_delayed_ref_head { * the free has happened. */ bool must_insert_reserved; + bool is_data; bool is_system; bool processing; -- cgit v1.2.3