From patchwork Wed Feb 23 19:06:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12757342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 911CBC433FE for ; Wed, 23 Feb 2022 19:06:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244140AbiBWTHW (ORCPT ); Wed, 23 Feb 2022 14:07:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239899AbiBWTHU (ORCPT ); Wed, 23 Feb 2022 14:07:20 -0500 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D758B31372 for ; Wed, 23 Feb 2022 11:06:51 -0800 (PST) Received: by mail-qv1-xf35.google.com with SMTP id fc19so10052370qvb.7 for ; Wed, 23 Feb 2022 11:06:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yhWbaIjm4R8j5f9SmxsYeqBAu+dHxU2EbmIDonB/X5c=; b=I892kQgzQQ/4HcZ8Bf3Y58UhbMrW1igRiNJaBBWQs2Bop6y88vok9TUApXxoWHMvtb ZrvmDod9azE2bub8yFY99cV9/fD0oGdpcbuQW/jStCyEDBDYvrD4vfgqKiZs0VnV7/LA +e0tNPqH5u+IJRbIU5B65j7tr8Z+p9ABbgYEEEyhrWu++0k/lE/gZ0IoDzUN2DTQFzRB PJ+hVtlBQtrZuKfUD53VVTZWcz0cz/u1RgWw7+4YnyAHTnruyoBuHROVhY9g7RgkawJK gfKQvGVJwSW2fkJ9KSSGGCwtcujxjd944cVZ8NKdSnLk96lrLPBbasQK1Ygyh33ifXvt QyiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yhWbaIjm4R8j5f9SmxsYeqBAu+dHxU2EbmIDonB/X5c=; b=tHB4nDi+7ejCa7cE2aSwY341kHmDHfjfPgi/Cxz+Sv5QDvyS8awvgdVbYj+ACnvQ6K R0mu6UUl5LxSlWJVq+lwoAdq6ZchoCvc9uQ8DASdcFCA106rvC6yCiE9bVEH3+EH5Z71 WRitxeZs7TlKDbKpPvxAJCtFnE3Vni4GojRN7QuDUd67Yny8UgioNkXoPuTsxnfM1I1h EOAErEsUxy6jzjE3ZQnq2PhjKdKmBq2c7fFXsDKM5bml5B5uFsa+RpiUJV2QtaIQnJwq vXHQ+j1WNsRNzz3cm9/ZCUNJWanTbPmJlDZXYYNJEZLD2K8pjXZ+lOzOxVC8eKNEpqP2 7puQ== X-Gm-Message-State: AOAM533hrYdMfcTFC9ltJbD62Dir29iddzr3jW+x63k7lfpTo99IO8gh proIj42rCFIlEf/zVtpZcwgsL2TdZFXm0D7J X-Google-Smtp-Source: ABdhPJyLRPRWthHIMX+01eaeCi4wM3h2bhBMXc8MwFwCmOZU4NOsEgFBvRyX099hJNId56E0fArzZA== X-Received: by 2002:a05:6214:2504:b0:42d:7b1a:8dd1 with SMTP id gf4-20020a056214250400b0042d7b1a8dd1mr1046937qvb.8.1645643210313; Wed, 23 Feb 2022 11:06:50 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id i22sm289873qtm.46.2022.02.23.11.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:06:49 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/4] btrfs: remove BUG_ON(ret) in alloc_reserved_tree_block Date: Wed, 23 Feb 2022 14:06:43 -0500 Message-Id: <74adf5fd8aa9d9a5e25d86f0e74614aa7295fb92.1645643109.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Switch this to an ASSERT() and return the error in the normal case. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 99e550b83794..7b8414fdae36 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4761,9 +4761,10 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, ret = btrfs_update_block_group(trans, extent_key.objectid, fs_info->nodesize, true); if (ret) { /* -ENOENT, logic error */ + ASSERT(!ret); btrfs_err(fs_info, "update block group failed for %llu %llu", extent_key.objectid, extent_key.offset); - BUG(); + return ret; } trace_btrfs_reserved_extent_alloc(fs_info, extent_key.objectid, From patchwork Wed Feb 23 19:06:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12757343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 673F1C433F5 for ; Wed, 23 Feb 2022 19:06:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244137AbiBWTHX (ORCPT ); Wed, 23 Feb 2022 14:07:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244131AbiBWTHW (ORCPT ); Wed, 23 Feb 2022 14:07:22 -0500 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B42A931537 for ; Wed, 23 Feb 2022 11:06:52 -0800 (PST) Received: by mail-qv1-xf29.google.com with SMTP id v18so2185567qvh.11 for ; Wed, 23 Feb 2022 11:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=A38L4ZoDZZiHJDtnHKnoadH1Hzas5142dhODHlwp/Pc=; b=tu/3M1HR0kf9l2zrFZ7DCywHHyjqfrRGvoupF9RO4zGm6+ATz5ejA4fiS/ohk3nAdU rJOsyCVquMWESREUfYKWDQU6UNYN5+gfIFvlG86n3+zwk7YaDCm+D8H7sL4qWxuNMgwf B5n8BhTv81qrF5xA05PQ0fylt7oM6D35IVeanIboLzgCcawN4L0nUnqp8EUC6+JDJx53 L6TvKtf1c0HnHu0lGRkOtGh1/65nm+bReqkpdBnVWf0VsGhonVgOZQSBY35GHTM/kuDK HYqw0bnGEF3Zg5FR5LtDAzS6APWIcOcGQwzhzQ7dQqWVMKy67H6HEcwIGgBnACbrSZzX WEGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A38L4ZoDZZiHJDtnHKnoadH1Hzas5142dhODHlwp/Pc=; b=xkuT2lCy8undJxwkHu9tDNtV3c+FaFMxonxIBRGf05VkKWr4YxUFkKPIXFVEq5XB/7 TTXKmKWncXuarwsnvyr0XU3JhjdaZZy4RzifhsvOJWxvLMRQxCGrpvtcqIhjDXXAA4NZ I6yiE9hvoRHw7A880fT+ManlnbAdRyshKQUYJS0M5ptuykFWfgRwzXTzhbcDT1vELq7p fWSd7hhXmzip6ufIylzz+CMjKw9O358I2xKeTEl8VuFV5JwECz6wXY4h8kAYuLMp/45V wyr8WfHdkGcPI/RAKI6BMd53cSd7dqnXgn69CBTArPUtf61jHjr4g+WBYnxkilZqBd1O 674Q== X-Gm-Message-State: AOAM531rVl8wcFB70cQAI4rWxqi/2IHeaajxfM9HhEdLBtwsk3zcnwc6 ZjgpcXowl3VTUgFbqAaXQFACS+Gdeqj47/NI X-Google-Smtp-Source: ABdhPJwnHs3RALSq74owkLxirFUj/4cy+9aFcskEucaj5kKPoOYyVwgEx1u952esEl02Aa6VZlubqg== X-Received: by 2002:a0c:8151:0:b0:42c:2329:91a0 with SMTP id 75-20020a0c8151000000b0042c232991a0mr676657qvc.107.1645643211622; Wed, 23 Feb 2022 11:06:51 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id o11sm287048qta.79.2022.02.23.11.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:06:51 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/4] btrfs: add a alloc_reserved_extent helper Date: Wed, 23 Feb 2022 14:06:44 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We duplicate this logic for both data and metadata, at this point we've already done our type specific extent root operations, this is just doing the accounting and removing the space from the free space tree. Extract this common logic out into a helper. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 56 ++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 7b8414fdae36..2738af449767 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4604,6 +4604,28 @@ int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start, return ret; } +static int alloc_reserved_extent(struct btrfs_trans_handle *trans, u64 bytenr, + u64 num_bytes) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + int ret; + + ret = remove_from_free_space_tree(trans, bytenr, num_bytes); + if (ret) + return ret; + + ret = btrfs_update_block_group(trans, bytenr, num_bytes, true); + if (ret) { + ASSERT(!ret); + btrfs_err(fs_info, "update block group failed for %llu %llu", + bytenr, num_bytes); + return ret; + } + + trace_btrfs_reserved_extent_alloc(fs_info, bytenr, num_bytes); + return 0; +} + static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans, u64 parent, u64 root_objectid, u64 flags, u64 owner, u64 offset, @@ -4664,18 +4686,7 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans, btrfs_mark_buffer_dirty(path->nodes[0]); btrfs_free_path(path); - ret = remove_from_free_space_tree(trans, ins->objectid, ins->offset); - if (ret) - return ret; - - ret = btrfs_update_block_group(trans, ins->objectid, ins->offset, true); - if (ret) { /* -ENOENT, logic error */ - btrfs_err(fs_info, "update block group failed for %llu %llu", - ins->objectid, ins->offset); - BUG(); - } - trace_btrfs_reserved_extent_alloc(fs_info, ins->objectid, ins->offset); - return ret; + return alloc_reserved_extent(trans, ins->objectid, ins->offset); } static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, @@ -4693,7 +4704,6 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, struct extent_buffer *leaf; struct btrfs_delayed_tree_ref *ref; u32 size = sizeof(*extent_item) + sizeof(*iref); - u64 num_bytes; u64 flags = extent_op->flags_to_set; bool skinny_metadata = btrfs_fs_incompat(fs_info, SKINNY_METADATA); @@ -4703,12 +4713,10 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, if (skinny_metadata) { extent_key.offset = ref->level; extent_key.type = BTRFS_METADATA_ITEM_KEY; - num_bytes = fs_info->nodesize; } else { extent_key.offset = node->num_bytes; extent_key.type = BTRFS_EXTENT_ITEM_KEY; size += sizeof(*block_info); - num_bytes = node->num_bytes; } path = btrfs_alloc_path(); @@ -4753,23 +4761,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, btrfs_mark_buffer_dirty(leaf); btrfs_free_path(path); - ret = remove_from_free_space_tree(trans, extent_key.objectid, - num_bytes); - if (ret) - return ret; - - ret = btrfs_update_block_group(trans, extent_key.objectid, - fs_info->nodesize, true); - if (ret) { /* -ENOENT, logic error */ - ASSERT(!ret); - btrfs_err(fs_info, "update block group failed for %llu %llu", - extent_key.objectid, extent_key.offset); - return ret; - } - - trace_btrfs_reserved_extent_alloc(fs_info, extent_key.objectid, - fs_info->nodesize); - return ret; + return alloc_reserved_extent(trans, node->bytenr, fs_info->nodesize); } int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, From patchwork Wed Feb 23 19:06:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12757344 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27A40C433EF for ; Wed, 23 Feb 2022 19:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244138AbiBWTHY (ORCPT ); Wed, 23 Feb 2022 14:07:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244139AbiBWTHW (ORCPT ); Wed, 23 Feb 2022 14:07:22 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 176D133A14 for ; Wed, 23 Feb 2022 11:06:54 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id d84so5202401qke.8 for ; Wed, 23 Feb 2022 11:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wcESVMOgK2q6rOIlehEcwryBQW0f2UHkj6B3CPhnAug=; b=q3xNmxZCd2sMCeVqccihmp/4apKfbO9MAdqIUkSX9WeT26B06Xgj10LN4iSQZfLVqK r7UwyzueqjUZ6cwB+UIqRXv+Ks1d8Z9CPrbz9uDd4RIQotAOCmv1FE6AnQqQSJB50Gnd 6TCgbOzAb6v+1bly8RixqHTUbTnxw0P3zJMtF4N3mGI0w5k8kLfoEsT7qd82budI2u3b DMfzrEHc/QVVlFzAR0QYS8DNq7z5HBfO1A0JxOVAg8Qzx15auo548HWP6JnVYYGnKZJQ QhUE4dkg7LQDbxZ8HkjMKV0pWSNopHrpnyE9/WBBdrdKqqAcE+czfQYuGUUy3hAeCejH 36lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wcESVMOgK2q6rOIlehEcwryBQW0f2UHkj6B3CPhnAug=; b=cdAjSiBRjkROhzPdX6enULir9yyLM8ii63nzIzQtMIsdzgt5wLqr7i76LMaRpqY7U8 NeHdQ0YTPMTWtU4tjf5uX+H8hArk15O+4ogrpGnOZxDuDzF7HzWjMpvdbDfrQDLdOUcv qnm8CTRwoEATjEyuQTfNTyXRmX9f3JQlTMC61q/bHd19byHF/GOwKntcW7/yCjr5cGej 80bto++daMah6qKREMzrGQDibtMuHOOcg9R5J8O0GjBXLcDKT9ZGV/M42HZvQoipAA9k NIgDPD2nbpy4Cnd0fUEYFBo9ZK4lr8Is0Xj0GGBasNElA/2V6yzalQS7VTwP+1vEWLcE JTOQ== X-Gm-Message-State: AOAM5307DWZdEJ+25gjBoBHpB9YR6RLAKMNaICwma5YgiIKwJygs/NdC ovJjFdKk4NUIPPlNj/TYFWTl+MW0SdJJL2+a X-Google-Smtp-Source: ABdhPJy5s6bQh9v1ySIJutt24xh253yFISqc9x6TxnwNiY2EBcaMjmgGYxVhw4KCdiJbcXMkFpGl3A== X-Received: by 2002:ae9:dd47:0:b0:507:a35:6cb8 with SMTP id r68-20020ae9dd47000000b005070a356cb8mr772972qkf.676.1645643212935; Wed, 23 Feb 2022 11:06:52 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id h23sm262363qto.36.2022.02.23.11.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:06:52 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 3/4] btrfs: remove `last_ref` from the extent freeing code Date: Wed, 23 Feb 2022 14:06:45 -0500 Message-Id: <58a2bf7403b10ba1d0da1647504b5ee10812c077.1645643109.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is a remnant of the work I did for qgroups a long time ago to only run for a block when we had dropped the last ref. We haven't done that for years, but the code remains. Drop this remnant. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 2738af449767..4ec03d004040 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -598,7 +598,7 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, - int refs_to_drop, int *last_ref) + int refs_to_drop) { struct btrfs_key key; struct btrfs_extent_data_ref *ref1 = NULL; @@ -631,7 +631,6 @@ static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans, if (num_refs == 0) { ret = btrfs_del_item(trans, root, path); - *last_ref = 1; } else { if (key.type == BTRFS_EXTENT_DATA_REF_KEY) btrfs_set_extent_data_ref_count(leaf, ref1, num_refs); @@ -1072,8 +1071,7 @@ static noinline_for_stack void update_inline_extent_backref(struct btrfs_path *path, struct btrfs_extent_inline_ref *iref, int refs_to_mod, - struct btrfs_delayed_extent_op *extent_op, - int *last_ref) + struct btrfs_delayed_extent_op *extent_op) { struct extent_buffer *leaf = path->nodes[0]; struct btrfs_extent_item *ei; @@ -1121,7 +1119,6 @@ void update_inline_extent_backref(struct btrfs_path *path, else btrfs_set_shared_data_ref_count(leaf, sref, refs); } else { - *last_ref = 1; size = btrfs_extent_inline_ref_size(type); item_size = btrfs_item_size(leaf, path->slots[0]); ptr = (unsigned long)iref; @@ -1167,7 +1164,7 @@ int insert_inline_extent_backref(struct btrfs_trans_handle *trans, return -EUCLEAN; } update_inline_extent_backref(path, iref, refs_to_add, - extent_op, NULL); + extent_op); } else if (ret == -ENOENT) { setup_inline_extent_backref(trans->fs_info, path, iref, parent, root_objectid, owner, offset, @@ -1181,21 +1178,17 @@ static int remove_extent_backref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, struct btrfs_extent_inline_ref *iref, - int refs_to_drop, int is_data, int *last_ref) + int refs_to_drop, int is_data) { int ret = 0; BUG_ON(!is_data && refs_to_drop != 1); - if (iref) { - update_inline_extent_backref(path, iref, -refs_to_drop, NULL, - last_ref); - } else if (is_data) { - ret = remove_extent_data_ref(trans, root, path, refs_to_drop, - last_ref); - } else { - *last_ref = 1; + if (iref) + update_inline_extent_backref(path, iref, -refs_to_drop, NULL); + else if (is_data) + ret = remove_extent_data_ref(trans, root, path, refs_to_drop); + else ret = btrfs_del_item(trans, root, path); - } return ret; } @@ -2942,7 +2935,6 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, u64 refs; u64 bytenr = node->bytenr; u64 num_bytes = node->num_bytes; - int last_ref = 0; bool skinny_metadata = btrfs_fs_incompat(info, SKINNY_METADATA); extent_root = btrfs_extent_root(info, bytenr); @@ -3009,8 +3001,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, } /* Must be SHARED_* item, remove the backref first */ ret = remove_extent_backref(trans, extent_root, path, - NULL, refs_to_drop, is_data, - &last_ref); + NULL, refs_to_drop, is_data); if (ret) { btrfs_abort_transaction(trans, ret); goto out; @@ -3135,8 +3126,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, } if (found_extent) { ret = remove_extent_backref(trans, extent_root, path, - iref, refs_to_drop, is_data, - &last_ref); + iref, refs_to_drop, is_data); if (ret) { btrfs_abort_transaction(trans, ret); goto out; @@ -3181,7 +3171,6 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, } } - last_ref = 1; ret = btrfs_del_items(trans, extent_root, path, path->slots[0], num_to_del); if (ret) { From patchwork Wed Feb 23 19:06:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12757345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31A03C433FE for ; Wed, 23 Feb 2022 19:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244144AbiBWTHZ (ORCPT ); Wed, 23 Feb 2022 14:07:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244135AbiBWTHY (ORCPT ); Wed, 23 Feb 2022 14:07:24 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F139132ECD for ; Wed, 23 Feb 2022 11:06:55 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id t21so5229164qkg.6 for ; Wed, 23 Feb 2022 11:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9gq+UaKOqGXi8IJZ4BiCXybhej9h4jUKvAC5mlr+miw=; b=SGcMGz7j+rhepYC/i6MLLjXq0tr65zgNqef4TCJ0xLtR17emDqpOSH8vg+scTGJjOF lXYdg5VFnvZUz6kV2Apa5yyjWm8Mmc6LlkQreBf+eCjBUM+ERou+V0qGpdni8oqLA2AL UKBa8az20XIPUBBP4GJJ9+9cNKgsdsyggIxb9O8GyP1OJHIPif9oeUbLf0nrQZBOju7/ 7g2m5dSgBx1UzVmamdit8YrpLufhRaRVFh3nhxNMR1iVhmbI6BqHLST+vrP0g21JIkTe xzpgBRlDzJReZzyD+BKpW0s+bdnRajyt6tTF7Ja4FOknUjAxY/bP8BEB0Rub5Lv8YJEs oGSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9gq+UaKOqGXi8IJZ4BiCXybhej9h4jUKvAC5mlr+miw=; b=aL7L3dD7cVIkLlFelf/ySfbsgjzo1GFmPEy7l8VZoboJqEFHMZYLJ9UAm8aN95zh8P gRSikE2Sm0FqGD4dcKWnEyT7lKg9YRH+Xh0Ig2gY7cjDf1L5fwjyIFoFKpZV6u+zB2Tm HwJZrC7uh/A9WHaxlFHZrhgNw9ebhyzRJvJuQCOw+x9vLy0PaIO2rC8Q7JsiFmDT3lz8 /tPrprMkYrWAYq1EhilFdxBGNb7GUBTHicRTCObXD1qbzNb598/YAMmwbQPS8GaDuVaq gorC24eRGG53I+BwkrFteJ6jCLNlWG/9kwoU1c79cW+zt6eDJEu18gCNfLTiEgcxSugW ZADw== X-Gm-Message-State: AOAM531KkQjxWrA/gyxvxlrR6hcbesmtd3LQfuLCIvtDaQxYG5BiQ0Ie jZg1YjZF4y/46gZbQMfOTQ2q7sbWeonMtvbM X-Google-Smtp-Source: ABdhPJx1p62WctTVIAtvyTKmG3xoHvpAq0S5t4lOoiyBm7M8hNjRElO0prc6KBdNcU4lI6kvRu/cqg== X-Received: by 2002:a37:909:0:b0:62c:e1df:905d with SMTP id 9-20020a370909000000b0062ce1df905dmr791769qkj.748.1645643214195; Wed, 23 Feb 2022 11:06:54 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id e7sm324999qtx.77.2022.02.23.11.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:06:53 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/4] btrfs: add a do_free_extent_accounting helper Date: Wed, 23 Feb 2022 14:06:46 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org __btrfs_free_extent() does all of the hard work of updating the extent ref items, and then at the end if we dropped the extent completely it does the cleanup accounting work. We're going to only want to do that work for metadata with extent tree v2, so extract this bit into its own helper. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 53 ++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 4ec03d004040..7e162d2dfd33 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2854,6 +2854,35 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans) return 0; } +static int do_free_extent_accounting(struct btrfs_trans_handle *trans, + u64 bytenr, u64 num_bytes, bool is_data) +{ + int ret; + + if (is_data) { + struct btrfs_root *csum_root; + csum_root = btrfs_csum_root(trans->fs_info, bytenr); + ret = btrfs_del_csums(trans, csum_root, bytenr, + num_bytes); + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } + } + + ret = add_to_free_space_tree(trans, bytenr, num_bytes); + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } + + ret = btrfs_update_block_group(trans, bytenr, num_bytes, false); + if (ret) + btrfs_abort_transaction(trans, ret); + + return ret; +} + /* * Drop one or more refs of @node. * @@ -3179,28 +3208,8 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, } btrfs_release_path(path); - if (is_data) { - struct btrfs_root *csum_root; - csum_root = btrfs_csum_root(info, bytenr); - ret = btrfs_del_csums(trans, csum_root, bytenr, - num_bytes); - if (ret) { - btrfs_abort_transaction(trans, ret); - goto out; - } - } - - ret = add_to_free_space_tree(trans, bytenr, num_bytes); - if (ret) { - btrfs_abort_transaction(trans, ret); - goto out; - } - - ret = btrfs_update_block_group(trans, bytenr, num_bytes, false); - if (ret) { - btrfs_abort_transaction(trans, ret); - goto out; - } + ret = do_free_extent_accounting(trans, bytenr, num_bytes, + is_data); } btrfs_release_path(path);