Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3544740imu; Mon, 7 Jan 2019 05:24:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/Um22ZQMpedU7BZRNsW32GsAz9JwCi3W8IGv7MdVoEKw4uF9Ihlex5X6XX5Uzz2q7job1D9 X-Received: by 2002:a62:3888:: with SMTP id f130mr61784654pfa.132.1546867448092; Mon, 07 Jan 2019 05:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546867448; cv=none; d=google.com; s=arc-20160816; b=H8l0weZzKw4IFGR7Qsb23mUqTJAt8pAcPPN9cKgwC0ITVmyLW+YR4/QAQTTvcK3BvS DLIrbpb1D+v5M9dcV1vc5l5zGELfkLP++E6reNzEKT7YXeoFTc3zLNR9rnj84SdNPatv NxKtq7ct7tzwmY9hWJ03A0CknxTSv2qWWCgjJuno72qj7z9Uq7XpdGMe+pdZ0sntcD5S ZUSgu+X4NfsjlHBQk9XCoCHXGKYsZ+09qVqny7Lyo9ajOxoH4856a7Cks7nspdurUcnj rSNTLXahTrVO6IKals1qUq9szy1l9jJFniUsbuOg6K7ErqhV5eyY03Tn5R+dDLSSbVYM 7FUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3guMgsMryGbZ9KeUpPWLfTWSsgTbqtJCLSv/bO3AYAI=; b=Rcb1xAMH1hklqwgXe2ifh+vOkQk33YZ5YbUF8YTC0S2EpKwHWT4IgWwM713nYgE16q YaLNinC6kC5RVufkiyEsHDHPIxeVKRhtLKE0KPSXQgcxvcdfkyTMmdlaMa5FFeatxSgD /9ZXph/D2jLfWgjJg7SiGr1jHK85G4g3/8/UdRVRHDE3P6Z+hxMxMfk1QzPHrhvPecDt 8M6bAOMdkB4dvRLLS06tTJfBIHBerQsfEdggPFM9ohAuneRvUnJoIwnOkSAqqp+2gj37 u3PNe3lMBX9wO+CCl2PLPeKD8tI1gTFlcshJLw0aCZIN6ogAkdusepwfD34qtozx1ulV U68Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PEDhSYAe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si30933567plq.138.2019.01.07.05.23.52; Mon, 07 Jan 2019 05:24:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PEDhSYAe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728059AbfAGMo0 (ORCPT + 99 others); Mon, 7 Jan 2019 07:44:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:32854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728731AbfAGMoX (ORCPT ); Mon, 7 Jan 2019 07:44:23 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 C895620665; Mon, 7 Jan 2019 12:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546865062; bh=r7kdQw1nJIhqa+2rdmHkhCfGnx/efgG//Av8/fe16BM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PEDhSYAelB082uC9+dlMzODdUJRRQClLbgbgpJAcc8uH7KEop2sp2smdP3FlBQVfi FxFYlOC4ZeO1DiSWclfvkO0mfi+ILsEWWwkCVSCyk/ADwkD/PnbbwtBPgO2nExEzZM aAl3IHalGR1E+oHg7NH4Ib5Zb4oht5aZKtop7RP4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Josef Bacik , David Sterba Subject: [PATCH 4.20 097/145] btrfs: run delayed items before dropping the snapshot Date: Mon, 7 Jan 2019 13:32:14 +0100 Message-Id: <20190107104449.906025975@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104437.308206189@linuxfoundation.org> References: <20190107104437.308206189@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit 0568e82dbe2510fc1fa664f58e5c997d3f1e649e upstream. With my delayed refs patches in place we started seeing a large amount of aborts in __btrfs_free_extent: BTRFS error (device sdb1): unable to find ref byte nr 91947008 parent 0 root 35964 owner 1 offset 0 Call Trace: ? btrfs_merge_delayed_refs+0xaf/0x340 __btrfs_run_delayed_refs+0x6ea/0xfc0 ? btrfs_set_path_blocking+0x31/0x60 btrfs_run_delayed_refs+0xeb/0x180 btrfs_commit_transaction+0x179/0x7f0 ? btrfs_check_space_for_delayed_refs+0x30/0x50 ? should_end_transaction.isra.19+0xe/0x40 btrfs_drop_snapshot+0x41c/0x7c0 btrfs_clean_one_deleted_snapshot+0xb5/0xd0 cleaner_kthread+0xf6/0x120 kthread+0xf8/0x130 ? btree_invalidatepage+0x90/0x90 ? kthread_bind+0x10/0x10 ret_from_fork+0x35/0x40 This was because btrfs_drop_snapshot depends on the root not being modified while it's dropping the snapshot. It will unlock the root node (and really every node) as it walks down the tree, only to re-lock it when it needs to do something. This is a problem because if we modify the tree we could cow a block in our path, which frees our reference to that block. Then once we get back to that shared block we'll free our reference to it again, and get ENOENT when trying to lookup our extent reference to that block in __btrfs_free_extent. This is ultimately happening because we have delayed items left to be processed for our deleted snapshot _after_ all of the inodes are closed for the snapshot. We only run the delayed inode item if we're deleting the inode, and even then we do not run the delayed insertions or delayed removals. These can be run at any point after our final inode does its last iput, which is what triggers the snapshot deletion. We can end up with the snapshot deletion happening and then have the delayed items run on that file system, resulting in the above problem. This problem has existed forever, however my patches made it much easier to hit as I wake up the cleaner much more often to deal with delayed iputs, which made us more likely to start the snapshot dropping work before the transaction commits, which is when the delayed items would generally be run. Before, generally speaking, we would run the delayed items, commit the transaction, and wakeup the cleaner thread to start deleting snapshots, which means we were less likely to hit this problem. You could still hit it if you had multiple snapshots to be deleted and ended up with lots of delayed items, but it was definitely harder. Fix for now by simply running all the delayed items before starting to drop the snapshot. We could make this smarter in the future by making the delayed items per-root, and then simply drop any delayed items for roots that we are going to delete. But for now just a quick and easy solution is the safest. CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Filipe Manana Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent-tree.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -8944,6 +8944,10 @@ int btrfs_drop_snapshot(struct btrfs_roo goto out_free; } + err = btrfs_run_delayed_items(trans); + if (err) + goto out_end_trans; + if (block_rsv) trans->block_rsv = block_rsv;