From patchwork Tue Dec 8 02:15:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11957431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7CB6C4361B for ; Tue, 8 Dec 2020 02:16:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3A70323A33 for ; Tue, 8 Dec 2020 02:16:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A70323A33 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BAF688D0006; Mon, 7 Dec 2020 21:16:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B62028D0001; Mon, 7 Dec 2020 21:16:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A771C8D0006; Mon, 7 Dec 2020 21:16:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id 9267A8D0001 for ; Mon, 7 Dec 2020 21:16:32 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6AFA3824999B for ; Tue, 8 Dec 2020 02:16:32 +0000 (UTC) X-FDA: 77568501024.16.walk45_5e14bba273e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 41FCA100E6903 for ; Tue, 8 Dec 2020 02:16:32 +0000 (UTC) X-HE-Tag: walk45_5e14bba273e3 X-Filterd-Recvd-Size: 6048 Received: from mail-ua1-f67.google.com (mail-ua1-f67.google.com [209.85.222.67]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 02:16:31 +0000 (UTC) Received: by mail-ua1-f67.google.com with SMTP id s42so1276719uad.11 for ; Mon, 07 Dec 2020 18:16:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=17HkpCiChNHQ4avz8nKjAF3KcVK7dbos9sXYlvZmUH8=; b=n/6QvM94DVIaoeHBWFUPjpkUZ4j/O5mJ+jA51Lh73p9x0+uvtbpC0HoWRQmED0QNOq kbgfzNCduM870rEJF1Zc1TwG+7LcNlDmZGRxchpk/beFs1Gh54SOlns9uzuykTCO/BYk f5Afyptne44QeiapkKKJask7G5pp4eTafU585QQUqM+QZJ/0vUBVklkT6GGWJabA2Fco wguxfefiuacN/SobE+skErGhpSQKQp1gL34VJVhqYhtKNHprE8sEQZc66vfDv6bgXOwU RgMchxarJfGlW5KL/ScQydw2XNnuK9kB8NZkbiMHWUXJ1P7IOcyc3+TW/bYg/2tVpNMu yfTw== 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:mime-version:content-transfer-encoding; bh=17HkpCiChNHQ4avz8nKjAF3KcVK7dbos9sXYlvZmUH8=; b=A50rY5msjh7RlM1iPxSG/xo4lUSTSzkSIyVIc3mv46IfcaJLS2FABEP4TX1PMYEJpt j2HqsT5OYlrCyGby0Febjaa5Hqb+F/qoYUBjw7so2RHi7kk5AbK96Exo/GxWa5rhXgHj 4LVjCaXqz2vhGnfrlEPKH7YhXyELJSu+76rqWRTxCrcdrFtWFL7CiiVJ9ppflm7qDNTB 9fWZSlJMj4mMEKLQQNXrcNC6nD/jXfHgXByO+Zu3W9AY06klLspj1tMWfm2Sckix9ygH FA9/9h5MoUvW1839xjmc0go00YQqBG+XpBvj4Ipy9A6HCOGcJ/KHiAKp5I4/xgaunBq1 xxxQ== X-Gm-Message-State: AOAM533N25271sgrdaRmjz0khucwZ8HyHl+9ErZIcG5/7li3tsUzNRG1 siCdmU2joIFehrCkWQFLo3A= X-Google-Smtp-Source: ABdhPJxAuBY/UnZNHubFCUfZmsEIfpluIuaN3ITsWJDSJ7t1vF3FgkWeihIAtqpg2YGnqcv789xk4w== X-Received: by 2002:ab0:558a:: with SMTP id v10mr6786221uaa.63.1607393791205; Mon, 07 Dec 2020 18:16:31 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id o192sm1936000vko.19.2020.12.07.18.16.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Dec 2020 18:16:30 -0800 (PST) From: Yafang Shao To: darrick.wong@oracle.com, willy@infradead.org, david@fromorbit.com, hch@infradead.org, mhocko@kernel.org, akpm@linux-foundation.org, dhowells@redhat.com, jlayton@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yafang Shao , Christoph Hellwig Subject: [PATCH v10 3/4] xfs: refactor the usage around xfs_trans_context_{set,clear} Date: Tue, 8 Dec 2020 10:15:42 +0800 Message-Id: <20201208021543.76501-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20201208021543.76501-1-laoar.shao@gmail.com> References: <20201208021543.76501-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The xfs_trans context should be active after it is allocated, and deactive when it is freed. So these two helpers are refactored as, - xfs_trans_context_set() Used in xfs_trans_alloc() - xfs_trans_context_clear() Used in xfs_trans_free() This patch is based on Darrick's work to fix the issue in xfs/141 in the earlier version. [1] 1. https://lore.kernel.org/linux-xfs/20201104001649.GN7123@magnolia Cc: Darrick J. Wong Cc: Matthew Wilcox (Oracle) Cc: Christoph Hellwig Cc: Dave Chinner Signed-off-by: Yafang Shao --- fs/xfs/xfs_trans.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 11d390f0d3f2..fe20398a214e 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -67,6 +67,9 @@ xfs_trans_free( xfs_extent_busy_sort(&tp->t_busy); xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false); + /* Detach the transaction from this thread. */ + xfs_trans_context_clear(tp); + trace_xfs_trans_free(tp, _RET_IP_); if (!(tp->t_flags & XFS_TRANS_NO_WRITECOUNT)) sb_end_intwrite(tp->t_mountp->m_super); @@ -153,9 +156,6 @@ xfs_trans_reserve( int error = 0; bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; - /* Mark this thread as being in a transaction */ - xfs_trans_context_set(tp); - /* * Attempt to reserve the needed disk blocks by decrementing * the number needed from the number available. This will @@ -163,10 +163,9 @@ xfs_trans_reserve( */ if (blocks > 0) { error = xfs_mod_fdblocks(mp, -((int64_t)blocks), rsvd); - if (error != 0) { - xfs_trans_context_clear(tp); + if (error != 0) return -ENOSPC; - } + tp->t_blk_res += blocks; } @@ -241,8 +240,6 @@ xfs_trans_reserve( tp->t_blk_res = 0; } - xfs_trans_context_clear(tp); - return error; } @@ -284,6 +281,8 @@ xfs_trans_alloc( INIT_LIST_HEAD(&tp->t_dfops); tp->t_firstblock = NULLFSBLOCK; + /* Mark this thread as being in a transaction */ + xfs_trans_context_set(tp); error = xfs_trans_reserve(tp, resp, blocks, rtextents); if (error) { xfs_trans_cancel(tp); @@ -878,7 +877,6 @@ __xfs_trans_commit( xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); - xfs_trans_context_clear(tp); xfs_trans_free(tp); /* @@ -911,7 +909,6 @@ __xfs_trans_commit( tp->t_ticket = NULL; } - xfs_trans_context_clear(tp); xfs_trans_free_items(tp, !!error); xfs_trans_free(tp); @@ -971,9 +968,6 @@ xfs_trans_cancel( tp->t_ticket = NULL; } - /* mark this thread as no longer being in a transaction */ - xfs_trans_context_clear(tp); - xfs_trans_free_items(tp, dirty); xfs_trans_free(tp); }