btrfs: create qgroup earlier in snapshot creation
authorBoris Burkov <boris@bur.io>
Wed, 28 Jun 2023 18:00:05 +0000 (11:00 -0700)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:10 +0000 (16:44 +0200)
Pull creating the qgroup earlier in the snapshot. This allows simple
quotas qgroups to see all the metadata writes related to the snapshot
being created and to be born with the root node accounted.

Note this has an impact on transaction commit where the qgroup creation
can do a lot of work, allocate memory and take locks. The change is done
for correctness, potential performance issues will be fixed in the
future.

Signed-off-by: Boris Burkov <boris@bur.io>
[ add note ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/qgroup.c
fs/btrfs/transaction.c

index a95c11a163f2b8bbe882d40f5c387b4ac31877db..3a6fb57b99f03252c0ffb27162ca2afa7035f9b6 100644 (file)
@@ -1689,6 +1689,9 @@ int btrfs_create_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
        struct btrfs_qgroup *prealloc = NULL;
        int ret = 0;
 
+       if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_DISABLED)
+               return 0;
+
        mutex_lock(&fs_info->qgroup_ioctl_lock);
        if (!fs_info->quota_root) {
                ret = -ENOTCONN;
index f5c3ea01c3d6a95435d368126050a18ab5099b80..6c24d00c3612795699b18257212756863393f714 100644 (file)
@@ -1812,6 +1812,12 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
        }
        btrfs_release_path(path);
 
+       ret = btrfs_create_qgroup(trans, objectid);
+       if (ret) {
+               btrfs_abort_transaction(trans, ret);
+               goto fail;
+       }
+
        /*
         * pull in the delayed directory update
         * and the delayed inode item