Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2260404imm; Mon, 28 May 2018 05:00:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZryHBO5VrPf3L39YcbuK/VNJ7D4j7wreNcJ2zPFNE+Fwd6ktrzbCb8rhO6y5ChAo7btzajS X-Received: by 2002:a62:ed12:: with SMTP id u18-v6mr13285299pfh.127.1527508803974; Mon, 28 May 2018 05:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527508803; cv=none; d=google.com; s=arc-20160816; b=BV6FK1eH3ZkpMF2yXXhDclXiGXot8xBBwVjQp0aj+pDKcIZfuAkTKDho+nKMn9Id9c //wK5qRpApJ4L3+W6KMPI44ZujHgIAfOHxknqF7ZWhViaTunrbSSo2RgG0qBkZQ8q1dT UptKOpfXDYuv1kW5DtErLhYUoW4NENNMm8kq5W5bg6uIXe/0Oog12QpqZIkcG6zkIg65 sqr6x00hhO9OaDFm31JwjbKJx537PY2yeek04HnFA+0c8AUmSzYXdGmBS5AGINJ4vqU+ iaBLt4ZlK1t2gC3+Ar0/FdnzIsClbf1JtmDULH/mu5oM50S3JgXUuXLJOdnhkOI+Spsf RW4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=FBP7E1vXklq/zCuY58z2aXtDUxm5VoI/4Gb0xEH5P+Q=; b=Tjcedq4dHaxMSJTnccFM68tnibQzuq7HssFVGnqFZCQqVSw7AH6sWTb67fVaFthlSa Ci3hGg2RWuqferCEd/kQnnh+Fkx1HJjU4pDB0G1oOF20RupE/a4GJ/pRTb2KOIsnvHXl 5rwI8XcglwrwIJkcRDH2NT/sKKOF4BryyJOto8DSeqNZj8RsWnXo4maKP/hlqP+odHaw PUXRlPt+KKSgyy7NQimtx1KoCI2jjoind48iBHSAPg1PR+rtEu6JSs0VUehcfDk9+5wr yAkLKmvBaBGa+F1fqCBA4dFJPNaEPa2DS8sX07xhb346LLJd1QUs48ZeEsh30I4Gwhk3 dPVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WYkLahb4; 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 j6-v6si24215305pgc.509.2018.05.28.04.59.49; Mon, 28 May 2018 05:00:03 -0700 (PDT) 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=WYkLahb4; 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 S938426AbeE1L5g (ORCPT + 99 others); Mon, 28 May 2018 07:57:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:55430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423533AbeE1LII (ORCPT ); Mon, 28 May 2018 07:08:08 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 35B3E208A3; Mon, 28 May 2018 11:08:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505687; bh=Yl090xZXq5hGdEEZUiQC+ZjJDcP9FeHN0jCQytBwxeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WYkLahb4OJkLXRT4OYT945+MlA3kaIojFYBIIMDROjfg9vFP7u/Nf3qIR5QJ4Ax8G QH6ToPUg57US7u3TEQ++Qhdb3E4ARL3XkWYw93bcwxpZxmaCJ9sLFAMcoUqcx2aPah gkPegH8uXAq3dR1f+SCKTwnGP2+T28xqSQnOyfkk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Justin Maggard , Qu Wenruo , Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 4.16 093/272] btrfs: qgroup: Fix root item corruption when multiple same source snapshots are created with quota enabled Date: Mon, 28 May 2018 12:02:06 +0200 Message-Id: <20180528100248.964280991@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qu Wenruo [ Upstream commit 4d31778aa2fa342f5f92ca4025b293a1729161d1 ] When multiple pending snapshots referring to the same source subvolume are executed, enabled quota will cause root item corruption, where root items are using old bytenr (no backref in extent tree). This can be triggered by fstests btrfs/152. The cause is when source subvolume is still dirty, extra commit (simplied transaction commit) of qgroup_account_snapshot() can skip dirty roots not recorded in current transaction, making root item of source subvolume not updated. Fix it by forcing recording source subvolume in current transaction before qgroup sub-transaction commit. Reported-by: Justin Maggard Signed-off-by: Qu Wenruo Reviewed-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/transaction.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -319,7 +319,7 @@ static int record_root_in_trans(struct b if ((test_bit(BTRFS_ROOT_REF_COWS, &root->state) && root->last_trans < trans->transid) || force) { WARN_ON(root == fs_info->extent_root); - WARN_ON(root->commit_root != root->node); + WARN_ON(!force && root->commit_root != root->node); /* * see below for IN_TRANS_SETUP usage rules @@ -1366,6 +1366,14 @@ static int qgroup_account_snapshot(struc return 0; /* + * Ensure dirty @src will be commited. Or, after comming + * commit_fs_roots() and switch_commit_roots(), any dirty but not + * recorded root will never be updated again, causing an outdated root + * item. + */ + record_root_in_trans(trans, src, 1); + + /* * We are going to commit transaction, see btrfs_commit_transaction() * comment for reason locking tree_log_mutex */