From patchwork Tue Sep 11 17:57:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10596061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4E3014F9 for ; Tue, 11 Sep 2018 17:58:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E763297BD for ; Tue, 11 Sep 2018 17:58:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92A55297EF; Tue, 11 Sep 2018 17:58:23 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 7D152297BD for ; Tue, 11 Sep 2018 17:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728136AbeIKW6m (ORCPT ); Tue, 11 Sep 2018 18:58:42 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:45560 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbeIKW6m (ORCPT ); Tue, 11 Sep 2018 18:58:42 -0400 Received: by mail-qt0-f193.google.com with SMTP id g44-v6so29155393qtb.12 for ; Tue, 11 Sep 2018 10:58:16 -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=rHTVMCxRLsTEVUkODyGqkPIz399o/p3gyRkwe0nkz4U=; b=Drin9XPGiMsI5ixGcyjocXECe7c5QuL5oEeKoDs9pb18DF0isWcoDep6FoE6HrTQqa MnCnyokMHU5NwWF3Be6eJd6sm9sk/rEFeILHFgqoLfLATEYv1dt+nc2lC5JtaigIEG2u kJ4edlsSlAlKM4BpzAT6jH/PR8cdCMwRCTsgyDDPi9GWz5kjgx0J2m2Vdc32r7MhAZ8W 87JLXlLCgaDfYcvWqu5pStFoaGhDbVETChIA+/uL8KjvUGColCdHwU+StJ/WDL9Z+vIY kwmOXeR8iP53jpvCW8Ll1m5ZkyNJA0X8+eJ0clLz1mmsqVijfScXgz3JJ/+1oSx1fcxx I3XA== 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=rHTVMCxRLsTEVUkODyGqkPIz399o/p3gyRkwe0nkz4U=; b=PQVjZDZm0G6VlJ4/s8vhK/0gHYmG1+wnfiRlJJMoblTD+/p0EO91PT4/XYeJNvp8Q9 Y47AN/LHkSRLkefNr9RfkdHPS9O8QSbov37Crn1vQ++5hJxV1RUAlc6gS+sL8/AcAGLG /t2/vO0Nc5yoD1uT8aU48QK5PARXU/95rSr7SMWrw5yExdkP/RN18HKiyM5NFv4Viva2 WeU3cRytu+WmTs8PhaDCrxfmCIE42tXP/2goot8QYw342W3P4RMJhxyWor7aJYuWpHmI 6pmL7uC34Fq9fAtdzEqxLZl+bbkN2BVA1/KqTKhb2ngfdGz+YqHR+DbvX3X4URT+S7nA Gqpw== X-Gm-Message-State: APzg51BNQCq7CHbFkdaXseLMO7RnWUeJj8WzYuohBg1av7u2dTGuXXDC HgxUt4cH902ovIl057Au3bRcbw== X-Google-Smtp-Source: ANB0VdYANNrZc4UKMf4rqCrF34j4fqeNvHzXI7jYozQoX25KIST08fcyl0S5PD4k2HayWlygFQ7GuA== X-Received: by 2002:ad4:414b:: with SMTP id z11-v6mr19637930qvp.77.1536688696489; Tue, 11 Sep 2018 10:58:16 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id l132-v6sm11244010qke.33.2018.09.11.10.58.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 10:58:15 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 03/36] btrfs: cleanup extent_op handling Date: Tue, 11 Sep 2018 13:57:34 -0400 Message-Id: <20180911175807.26181-4-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180911175807.26181-1-josef@toxicpanda.com> References: <20180911175807.26181-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 The cleanup_extent_op function actually would run the extent_op if it needed running, which made the name sort of a misnomer. Change it to run_and_cleanup_extent_op, and move the actual cleanup work to cleanup_extent_op so it can be used by check_ref_cleanup() in order to unify the extent op handling. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a44d55e36e11..98f36dfeccb0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2442,19 +2442,33 @@ static void unselect_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_ref btrfs_delayed_ref_unlock(head); } -static int cleanup_extent_op(struct btrfs_trans_handle *trans, - struct btrfs_delayed_ref_head *head) +static struct btrfs_delayed_extent_op * +cleanup_extent_op(struct btrfs_trans_handle *trans, + struct btrfs_delayed_ref_head *head) { struct btrfs_delayed_extent_op *extent_op = head->extent_op; - int ret; if (!extent_op) - return 0; - head->extent_op = NULL; + return NULL; + if (head->must_insert_reserved) { + head->extent_op = NULL; btrfs_free_delayed_extent_op(extent_op); - return 0; + return NULL; } + return extent_op; +} + +static int run_and_cleanup_extent_op(struct btrfs_trans_handle *trans, + struct btrfs_delayed_ref_head *head) +{ + struct btrfs_delayed_extent_op *extent_op = + cleanup_extent_op(trans, head); + int ret; + + if (!extent_op) + return 0; + head->extent_op = NULL; spin_unlock(&head->lock); ret = run_delayed_extent_op(trans, head, extent_op); btrfs_free_delayed_extent_op(extent_op); @@ -2506,7 +2520,7 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, delayed_refs = &trans->transaction->delayed_refs; - ret = cleanup_extent_op(trans, head); + ret = run_and_cleanup_extent_op(trans, head); if (ret < 0) { unselect_delayed_ref_head(delayed_refs, head); btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret); @@ -6977,12 +6991,8 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, if (!RB_EMPTY_ROOT(&head->ref_tree)) goto out; - if (head->extent_op) { - if (!head->must_insert_reserved) - goto out; - btrfs_free_delayed_extent_op(head->extent_op); - head->extent_op = NULL; - } + if (cleanup_extent_op(trans, head) != NULL) + goto out; /* * waiting for the lock here would deadlock. If someone else has it