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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 11D0CC43603 for ; Mon, 16 Dec 2019 18:09:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC2FC20CC7 for ; Mon, 16 Dec 2019 18:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519776; bh=lUCy/3tbuoM4EAAkmim6/84CwKN9aTb7ibGXNYj6/js=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EusMlvIxzv3HZnfiUmYQIovQVnwgoLMfJaZ2fIMqj6WyRQsSrH5Z2xYrPJsK6FeQx FVba91R1bnAArA9sG8OT9ILnte2quUXKEPtaH2VtDxBRmle0Fj2ms7JFWjVq3saj6c HeBvfrrssfzvPUgebnWClZYx63VVATGQ8JFgJMPU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730460AbfLPSJf (ORCPT ); Mon, 16 Dec 2019 13:09:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:52056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730458AbfLPSJe (ORCPT ); Mon, 16 Dec 2019 13:09:34 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 ED89C206B7; Mon, 16 Dec 2019 18:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519774; bh=lUCy/3tbuoM4EAAkmim6/84CwKN9aTb7ibGXNYj6/js=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRozrZBGbImzw1tCgp1UObcf8b8ceJbzE3r2kCDoeOOvIhJorjYRMymQ7lhXGs7X/ wD23woSJdIGs7mXzyTe0xDsFFH8MX4MsEvCHCaaTw48xNmlA87colnWuPNueab6hfe ozrjESaRLW/Vfa8wGgJA5ubXaOlJ12xDZavssIn8= 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 5.3 062/180] btrfs: record all roots for rename exchange on a subvol Date: Mon, 16 Dec 2019 18:48:22 +0100 Message-Id: <20191216174829.459011248@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174806.018988360@linuxfoundation.org> References: <20191216174806.018988360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Josef Bacik commit 3e1740993e43116b3bc71b0aad1e6872f6ccf341 upstream. Testing with the new fsstress support for subvolumes uncovered a pretty bad problem with rename exchange on subvolumes. We're modifying two different subvolumes, but we only start the transaction on one of them, so the other one is not added to the dirty root list. This is caught by btrfs_cow_block() with a warning because the root has not been updated, however if we do not modify this root again we'll end up pointing at an invalid root because the root item is never updated. Fix this by making sure we add the destination root to the trans list, the same as we do with normal renames. This fixes the corruption. Fixes: cdd1fedf8261 ("btrfs: add support for RENAME_EXCHANGE and RENAME_WHITEOUT") CC: stable@vger.kernel.org # 4.9+ Reviewed-by: Filipe Manana Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9533,6 +9533,9 @@ static int btrfs_rename_exchange(struct goto out_notrans; } + if (dest != root) + btrfs_record_root_in_trans(trans, dest); + /* * We need to find a free sequence number both in the source and * in the destination directory for the exchange.