From patchwork Thu Jul 19 14:49:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10534667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E93BB600D0 for ; Thu, 19 Jul 2018 14:50:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE8032936B for ; Thu, 19 Jul 2018 14:50:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2C7929CBB; Thu, 19 Jul 2018 14:50:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B1CA2936B for ; Thu, 19 Jul 2018 14:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731126AbeGSPdm (ORCPT ); Thu, 19 Jul 2018 11:33:42 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:38581 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727584AbeGSPdm (ORCPT ); Thu, 19 Jul 2018 11:33:42 -0400 Received: by mail-qt0-f193.google.com with SMTP id y19-v6so7407237qto.5 for ; Thu, 19 Jul 2018 07:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L8/Ll3ktT+S+fYvBCceIzEuCQQQL7g0PJjIovnUWQrQ=; b=eXtOQNBmLDadQ7nyGZuaUzteR5Ok6D5yaHkBnuMfGocqcsUaCGBswoZLz3QFdcMq2B spsWMH3B8zYI3vOoEpkCfjnoHsu5mio7le08oqKoQhfMn5LoBlbBnhcBzompm8WPMtgP reGCxoicPPMeUz5PuTIKz9h2Q0LQ1e5gbsyLCBeph0mFPZhNnTzUz0JjlFSOCaTDPtfD KbWPz91J+WizhnpI/3GiuUuDDRz3fP/0/Y0B7QhxSgVmPqVFGmGoICF2g9KuwBUuqfMJ dZfLAk+nXi4T7WvyZqodzQ1xjwC0Itm46wK+oAr2x34Z57EDRA8SKTJNJvuwcGNBnGdx Iv+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L8/Ll3ktT+S+fYvBCceIzEuCQQQL7g0PJjIovnUWQrQ=; b=R4u+joVmKSUsQdo39hhvvRka2oHubhTV8e7zOP6wGqlWq2gyEA1544s75qF5YbpqCx gXbjiDVy+LnRV5Monq8gleMpUrPIPbsmO1rpx++Dn5PBKn5V9vIDRZQKexu9t6yxiIAf 84VsWm5f4nLB29yPdYMLrGAfQZJu/uFcYA3bvW0xwuKzxdoEfUs3eIQOOkMGExGOBP3d eTJYfEmXozdbqCxg/XkPMp/9iTCa44xVEmz5MLEojlOwQlw+DaCkVVLL2iYqXQuqgeke 9KedkI5fxofj1f1WMETB12eeTVykYGPCSJjZ5JyHO01ro7UlaXmqd2ug3lw1/CpJZFr1 LA1w== X-Gm-Message-State: AOUpUlEylbwa5VCdy6ObyB3zDlvvdlxYUQ/D6bq8SURQCcuh6tHWGqDi YIkMvuL7Y0AbSTDqI4tF9C36a9M1laA= X-Google-Smtp-Source: AAOMgpc3wf0vhRhWYeZvWxiulJdCAh9RoKot/4CV4sfDyPPo2p8VD3RIt8E6w9zSesvTnXbBfDN1zg== X-Received: by 2002:ac8:367:: with SMTP id w39-v6mr10215045qtg.334.1532011810314; Thu, 19 Jul 2018 07:50:10 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id s1-v6sm5422127qte.89.2018.07.19.07.50.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 07:50:09 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH 02/22] btrfs: add cleanup_ref_head_accounting helper Date: Thu, 19 Jul 2018 10:49:46 -0400 Message-Id: <20180719145006.17532-2-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180719145006.17532-1-josef@toxicpanda.com> References: <20180719145006.17532-1-josef@toxicpanda.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik We were missing some quota cleanups in check_ref_cleanup, so break the ref head accounting cleanup into a helper and call that from both check_ref_cleanup and cleanup_ref_head. This will hopefully ensure that we don't screw up accounting in the future for other things that we add. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 65 +++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index ccaccd78534e..cf1152d01309 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2547,6 +2547,40 @@ static int cleanup_extent_op(struct btrfs_trans_handle *trans, return ret ? ret : 1; } +static void cleanup_ref_head_accounting(struct btrfs_trans_handle *trans, + struct btrfs_delayed_ref_head *head) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_delayed_ref_root *delayed_refs = + &trans->transaction->delayed_refs; + + if (head->total_ref_mod < 0) { + struct btrfs_space_info *space_info; + u64 flags; + + if (head->is_data) + flags = BTRFS_BLOCK_GROUP_DATA; + else if (head->is_system) + flags = BTRFS_BLOCK_GROUP_SYSTEM; + else + flags = BTRFS_BLOCK_GROUP_METADATA; + space_info = __find_space_info(fs_info, flags); + ASSERT(space_info); + percpu_counter_add(&space_info->total_bytes_pinned, + -head->num_bytes); + + if (head->is_data) { + spin_lock(&delayed_refs->lock); + delayed_refs->pending_csums -= head->num_bytes; + spin_unlock(&delayed_refs->lock); + } + } + + /* Also free its reserved qgroup space */ + btrfs_qgroup_free_delayed_ref(fs_info, head->qgroup_ref_root, + head->qgroup_reserved); +} + static int cleanup_ref_head(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_head *head) @@ -2581,30 +2615,6 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, spin_unlock(&delayed_refs->lock); spin_unlock(&head->lock); - trace_run_delayed_ref_head(fs_info, head, 0); - - if (head->total_ref_mod < 0) { - struct btrfs_space_info *space_info; - u64 flags; - - if (head->is_data) - flags = BTRFS_BLOCK_GROUP_DATA; - else if (head->is_system) - flags = BTRFS_BLOCK_GROUP_SYSTEM; - else - flags = BTRFS_BLOCK_GROUP_METADATA; - space_info = __find_space_info(fs_info, flags); - ASSERT(space_info); - percpu_counter_add(&space_info->total_bytes_pinned, - -head->num_bytes); - - if (head->is_data) { - spin_lock(&delayed_refs->lock); - delayed_refs->pending_csums -= head->num_bytes; - spin_unlock(&delayed_refs->lock); - } - } - if (head->must_insert_reserved) { btrfs_pin_extent(fs_info, head->bytenr, head->num_bytes, 1); @@ -2614,9 +2624,9 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, } } - /* Also free its reserved qgroup space */ - btrfs_qgroup_free_delayed_ref(fs_info, head->qgroup_ref_root, - head->qgroup_reserved); + cleanup_ref_head_accounting(trans, head); + + trace_run_delayed_ref_head(fs_info, head, 0); btrfs_delayed_ref_unlock(head); btrfs_put_delayed_ref_head(head); return 0; @@ -7129,6 +7139,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, if (head->must_insert_reserved) ret = 1; + cleanup_ref_head_accounting(trans, head); mutex_unlock(&head->mutex); btrfs_put_delayed_ref_head(head); return ret;