Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp844201pxb; Tue, 3 Nov 2020 14:11:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/SgHQBkO9alfUdsYaIS+EEdj5UzCpb1NMiNqCu0mCFoxzMQvk1GROYEZ+YOyoSG4UUDXu X-Received: by 2002:a17:906:c094:: with SMTP id f20mr22938407ejz.550.1604441501660; Tue, 03 Nov 2020 14:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604441501; cv=none; d=google.com; s=arc-20160816; b=n9XfQx1tJwQXbWmJLIWkKE9kcXrgThNLKLVQI7XsiqBJUayRsGTrb7Hde225SihKgp exfGXg74OszLoUUgCsR5M8493BfYONsSkeukW2dUrU5P/u2QqqgtAsqHhmXbUidCsFf+ TnjzxYkA6B8oycVl7BQ67muGvtdUn3+Q8UugoSfcPXfTJXhsglT0ECUcQ2P4uDMhmZ0X xcgwfxNGAKVH+OQaHM5b5zDNur2KkTP9bU8E3DTK6v1Elx4swVAbo3421KNzFKO+wk+u zIHQ1HoS+cd8GcZ8zPdKQWQGGluQGblUgOeUovHgDCGpEUVkj/YmpkCYPaHJF0E38Smx bDSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h7zKA6M5Ra7lVFZMc4sjqWZ/AF/xZmUDRe+zgUTWrYY=; b=QKWSRoRObRAt7v8HBEZ1PBzZnXkJW5aBY60fPCBJmC1uC8lOXwKZTTwz+uvfE/Nirp FB9uGt716TlJu6edhjFA99I1eQ5TI//4JIux/Pni6JI2q1zWtFnNcU8mt/Vla6S745S8 8WGuIJFqXu1zOc9NIu+Uh384CfmH00bD3cSv36hMpWs8KhmGI6gLWTpHeVsT6yXnhzDz 4tFM7xQn04xe7YeiWU/t1sK3qD4RT0OTinvAd3K2PTaUrV3sFN565dLOFcsiNA+KvHcN 2NebDhbxv0KhWMtWou89f/qR2gEygRvwm2MlQB608sI0iNjiLGWTbDZDwKdoIiv2TT5j afXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v+mIiiDy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z26si119664eje.469.2020.11.03.14.11.18; Tue, 03 Nov 2020 14:11:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v+mIiiDy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730166AbgKCUkS (ORCPT + 99 others); Tue, 3 Nov 2020 15:40:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:51468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730169AbgKCUkO (ORCPT ); Tue, 3 Nov 2020 15:40:14 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 888932236F; Tue, 3 Nov 2020 20:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436013; bh=YfCK3/s3YRC/xrO+Mqfu3S76C6okP1k+p6y0U08jYpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v+mIiiDyXpc4w0leV3fBuaNVU8TEySKAb68V1CL7Ar5NxJn2tYSmjkoUaC8+MrXv1 Ci5xWwPgjATG0a0qn2ltGuGDxVHYBG6JQjrJR9tmlNbvMuV8IWJODwX08TmljJDOkd FerETuA3GSlVlDMJ3CVQXrbPJKIhWv5m2BI+WQWQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Christoph Hellwig , Dave Chinner , Sasha Levin Subject: [PATCH 5.9 066/391] xfs: log new intent items created as part of finishing recovered intent items Date: Tue, 3 Nov 2020 21:31:57 +0100 Message-Id: <20201103203351.758438818@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Darrick J. Wong [ Upstream commit 93293bcbde93567efaf4e6bcd58cad270e1fcbf5 ] During a code inspection, I found a serious bug in the log intent item recovery code when an intent item cannot complete all the work and decides to requeue itself to get that done. When this happens, the item recovery creates a new incore deferred op representing the remaining work and attaches it to the transaction that it allocated. At the end of _item_recover, it moves the entire chain of deferred ops to the dummy parent_tp that xlog_recover_process_intents passed to it, but fail to log a new intent item for the remaining work before committing the transaction for the single unit of work. xlog_finish_defer_ops logs those new intent items once recovery has finished dealing with the intent items that it recovered, but this isn't sufficient. If the log is forced to disk after a recovered log item decides to requeue itself and the system goes down before we call xlog_finish_defer_ops, the second log recovery will never see the new intent item and therefore has no idea that there was more work to do. It will finish recovery leaving the filesystem in a corrupted state. The same logic applies to /any/ deferred ops added during intent item recovery, not just the one handling the remaining work. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Dave Chinner Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_defer.c | 26 ++++++++++++++++++++++++-- fs/xfs/libxfs/xfs_defer.h | 6 ++++++ fs/xfs/xfs_bmap_item.c | 2 +- fs/xfs/xfs_refcount_item.c | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_defer.c b/fs/xfs/libxfs/xfs_defer.c index d8f586256add7..29e9762f3b77c 100644 --- a/fs/xfs/libxfs/xfs_defer.c +++ b/fs/xfs/libxfs/xfs_defer.c @@ -186,8 +186,9 @@ xfs_defer_create_intent( { const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; - dfp->dfp_intent = ops->create_intent(tp, &dfp->dfp_work, - dfp->dfp_count, sort); + if (!dfp->dfp_intent) + dfp->dfp_intent = ops->create_intent(tp, &dfp->dfp_work, + dfp->dfp_count, sort); } /* @@ -390,6 +391,7 @@ xfs_defer_finish_one( list_add(li, &dfp->dfp_work); dfp->dfp_count++; dfp->dfp_done = NULL; + dfp->dfp_intent = NULL; xfs_defer_create_intent(tp, dfp, false); } @@ -552,3 +554,23 @@ xfs_defer_move( xfs_defer_reset(stp); } + +/* + * Prepare a chain of fresh deferred ops work items to be completed later. Log + * recovery requires the ability to put off until later the actual finishing + * work so that it can process unfinished items recovered from the log in + * correct order. + * + * Create and log intent items for all the work that we're capturing so that we + * can be assured that the items will get replayed if the system goes down + * before log recovery gets a chance to finish the work it put off. Then we + * move the chain from stp to dtp. + */ +void +xfs_defer_capture( + struct xfs_trans *dtp, + struct xfs_trans *stp) +{ + xfs_defer_create_intents(stp); + xfs_defer_move(dtp, stp); +} diff --git a/fs/xfs/libxfs/xfs_defer.h b/fs/xfs/libxfs/xfs_defer.h index 6b2ca580f2b06..3164199162b61 100644 --- a/fs/xfs/libxfs/xfs_defer.h +++ b/fs/xfs/libxfs/xfs_defer.h @@ -63,4 +63,10 @@ extern const struct xfs_defer_op_type xfs_rmap_update_defer_type; extern const struct xfs_defer_op_type xfs_extent_free_defer_type; extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; +/* + * Functions to capture a chain of deferred operations and continue them later. + * This doesn't normally happen except log recovery. + */ +void xfs_defer_capture(struct xfs_trans *dtp, struct xfs_trans *stp); + #endif /* __XFS_DEFER_H__ */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index ec3691372e7c0..815a0563288f4 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -534,7 +534,7 @@ xfs_bui_item_recover( xfs_bmap_unmap_extent(tp, ip, &irec); } - xfs_defer_move(parent_tp, tp); + xfs_defer_capture(parent_tp, tp); error = xfs_trans_commit(tp); xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_irele(ip); diff --git a/fs/xfs/xfs_refcount_item.c b/fs/xfs/xfs_refcount_item.c index ca93b64883774..492d80a0b4060 100644 --- a/fs/xfs/xfs_refcount_item.c +++ b/fs/xfs/xfs_refcount_item.c @@ -555,7 +555,7 @@ xfs_cui_item_recover( } xfs_refcount_finish_one_cleanup(tp, rcur, error); - xfs_defer_move(parent_tp, tp); + xfs_defer_capture(parent_tp, tp); error = xfs_trans_commit(tp); return error; -- 2.27.0