From mboxrd@z Thu Jan 1 00:00:00 1970 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 EBFFEC433FE for ; Tue, 8 Dec 2020 12:29:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9EA4923A5B for ; Tue, 8 Dec 2020 12:29:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9EA4923A5B 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 445C66B006C; Tue, 8 Dec 2020 07:29:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F6CE6B006E; Tue, 8 Dec 2020 07:29:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30CF16B0070; Tue, 8 Dec 2020 07:29:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 1C9276B006C for ; Tue, 8 Dec 2020 07:29:09 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CF706180AD815 for ; Tue, 8 Dec 2020 12:29:08 +0000 (UTC) X-FDA: 77570044776.05.chain51_3a04117273e7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id B69FF18010BEE for ; Tue, 8 Dec 2020 12:29:08 +0000 (UTC) X-HE-Tag: chain51_3a04117273e7 X-Filterd-Recvd-Size: 6047 Received: from mail-vs1-f65.google.com (mail-vs1-f65.google.com [209.85.217.65]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 12:29:08 +0000 (UTC) Received: by mail-vs1-f65.google.com with SMTP id v8so9428406vso.2 for ; Tue, 08 Dec 2020 04:29:08 -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=VeGWhsY1ue+SdOpldgrBQjuMDFPzbeLB+nGnFuBPWQVn7U663xva9hNTEgeNdDn7UX KwpN2bNKxAKXXQpY9BtZol09EntEehekiNiJf98pTeZ1zLn8RCrKXkGImE4vahbzP1ts X4WYV7qMvbzVatTDq+SI+R4AMhj7Q3vPxnPfsc+H4nPBV7QCgyDf1syrik+wSXzj6+oF vXkxQCZlik43K56ximqrGGLKrxa3RBR+7I+wTKg+6LP8lkhMcqifMQH3jLlNi7C6mVo8 hWsLzqKIrpHMH6uXkp1EJ86OPY8KYzK86g42wThpvvukUzVbdLw+3kx1tjdaF3vL7hit jOOA== 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=TpeS5bhKqCIhtS865W4uCFLTt2v/HrlCpomECTf/xZhcQxLk2HJfhvSytLNC7nHGF8 YTVW9U9fj6gyVCiMYR7IFeNwYq4sdwQovlI5lJUgjZc6epqJy04dQHZQ3Ka1svQ7O0Ox yjM9Xp8B1csPlkyccedARXcuSWDIP4befOj9uzmUPYXs448euq+ei/qARd1FJX6EoKLy GRvfCqMLbjtN7k94Nga4TMv1tQlUb4qcuY0M3MMjJvp65puQlAXtiSX64jttOZ63ASh8 ZDEk9AOmlSn8cg5KcxRHYI7RkWVdKo8wBhTnFxG+HcSeKqtnpAAGVHSAJSiQ1O35QqM8 GtvQ== X-Gm-Message-State: AOAM533PcD/RW4Nj31lzwaw91uAplc5OOpchn/HsbuG7veRuKCP5Jvui JcBz03THOA31GxKPkLKv9QA= X-Google-Smtp-Source: ABdhPJzB7us8JzVAWeOHv8/fHrg99szKANSxsykkf7kNaONPTq8lgv76MK10x5L5LcEp8esxH8xd7g== X-Received: by 2002:a67:bd0a:: with SMTP id y10mr15127725vsq.28.1607430547745; Tue, 08 Dec 2020 04:29:07 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id w202sm2001106vkd.25.2020.12.08.04.29.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Dec 2020 04:29:07 -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 v11 3/4] xfs: refactor the usage around xfs_trans_context_{set,clear} Date: Tue, 8 Dec 2020 20:28:23 +0800 Message-Id: <20201208122824.16118-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20201208122824.16118-1-laoar.shao@gmail.com> References: <20201208122824.16118-1-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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); =20 + /* 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 =3D 0; bool rsvd =3D (tp->t_flags & XFS_TRANS_RESERVE) !=3D 0; =20 - /* 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 =3D xfs_mod_fdblocks(mp, -((int64_t)blocks), rsvd); - if (error !=3D 0) { - xfs_trans_context_clear(tp); + if (error !=3D 0) return -ENOSPC; - } + tp->t_blk_res +=3D blocks; } =20 @@ -241,8 +240,6 @@ xfs_trans_reserve( tp->t_blk_res =3D 0; } =20 - xfs_trans_context_clear(tp); - return error; } =20 @@ -284,6 +281,8 @@ xfs_trans_alloc( INIT_LIST_HEAD(&tp->t_dfops); tp->t_firstblock =3D NULLFSBLOCK; =20 + /* Mark this thread as being in a transaction */ + xfs_trans_context_set(tp); error =3D xfs_trans_reserve(tp, resp, blocks, rtextents); if (error) { xfs_trans_cancel(tp); @@ -878,7 +877,6 @@ __xfs_trans_commit( =20 xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); =20 - xfs_trans_context_clear(tp); xfs_trans_free(tp); =20 /* @@ -911,7 +909,6 @@ __xfs_trans_commit( tp->t_ticket =3D NULL; } =20 - xfs_trans_context_clear(tp); xfs_trans_free_items(tp, !!error); xfs_trans_free(tp); =20 @@ -971,9 +968,6 @@ xfs_trans_cancel( tp->t_ticket =3D NULL; } =20 - /* 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); } --=20 2.18.4