]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: control extent reference updates with a control flag for truncate
authorJosef Bacik <josef@toxicpanda.com>
Fri, 3 Dec 2021 22:18:12 +0000 (17:18 -0500)
committerDavid Sterba <dsterba@suse.com>
Fri, 7 Jan 2022 13:18:24 +0000 (14:18 +0100)
We've had weird bugs in the past where we forgot to adjust the truncate
path to deal with the fact that we can be called by the tree log path.
Instead of checking if our root is a LOG_ROOT use a flag on the
btrfs_truncate_control to indicate that we don't want to do extent
reference updates during this truncate.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode-item.c
fs/btrfs/inode-item.h
fs/btrfs/tree-log.c

index 278d579f50bdffc788c02a6053f51b6f1c25b107..4c753415ab06eb6ff9598aab0a8d7b488c646609 100644 (file)
@@ -659,8 +659,7 @@ delete:
                }
                should_throttle = false;
 
-               if (del_item && extent_start != 0 &&
-                   root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
+               if (del_item && extent_start != 0 && !control->skip_ref_updates) {
                        struct btrfs_ref ref = { 0 };
 
                        bytes_deleted += extent_num_bytes;
index 7b5b455262cbf28ef894c6158f609a8352bc847a..1f31bb407f4a601e222e5cc8cae4fe12e4f36580 100644 (file)
@@ -37,6 +37,12 @@ struct btrfs_truncate_control {
         * removed only if their offset >= new_size.
         */
        u32 min_type;
+
+       /*
+        * IN: true if we don't want to do extent reference updates for any file
+        * extents we drop.
+        */
+       bool skip_ref_updates;
 };
 
 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
index c732a429a1c667c863774c6082d79f4c21421cd6..2b5e24c24a6b32daa8febeef69677f8eb113be5a 100644 (file)
@@ -4101,6 +4101,7 @@ static int truncate_inode_items(struct btrfs_trans_handle *trans,
        struct btrfs_truncate_control control = {
                .new_size = new_size,
                .min_type = min_type,
+               .skip_ref_updates = true,
        };
        int ret;