Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3018150pxb; Mon, 18 Oct 2021 06:42:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwddpIPNYxwxktOyED1+hDuAeUkTRvlkiAbBl5IiV7qP6/6gfoiRgQCiaYQhI+ZLbbt5B/M X-Received: by 2002:a17:90b:3695:: with SMTP id mj21mr23830108pjb.194.1634564544670; Mon, 18 Oct 2021 06:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564544; cv=none; d=google.com; s=arc-20160816; b=jiFSo8LHs/AfhCn2OkD2PlmW6uHXpwWp0YgGkOwpZ0829/M8oPFUzabtPVlDG8lHbx 3rMdSKQ6sE7gF6vEcnc8avbx1Gwv+O3zR6bGJT3v+op9yW/n9pv93w/HHW9n7HSbgBWf k3ooi//NPjyvrh+PrvPf//1bdtZ+Zmbt9pQCwOwYQw2rX4V6O1x89QHsKzlOoxbQ06AA 1a2xfWRBXtDLCRFnmir4JlqmCSQJ/xQbUvo1lPquTvxyo8xPtcARyPQnJm6FijQ2W1fR letH1YbDFA2WdeHGc740L7zJHK9EbhoYywVq3He6evak0sC5smc9yJDVpRazrqdLpPqi FjTQ== 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=Wwy9iUjEaCxENlf4mcBUWMpSGMvTZJtxSt9gccQZj/A=; b=lCZQzWlo30Z6EZfqaWKVvaC0cyBL0NCKwrP514Uu59cbAhvDhlpn9DDdIc8lJdsrKD P9OS06XdCn6rdt39L0YDUcOUNgRlg+f90klf742vtpVlcz/Y2uItTT5hhw9j6bFdCKUU ozmkDsPHCk/DJ+SLK4OsiVz7YQSSP2HolZugphvPM0zu9eJr3shkz/A3f23xB6jPrQzX +pR0E5jWfKYfb1vATkIpPB81/fOc3HFSOr0TH3YwI7Yva7MA1yhWetDAxQ4rOEbeYTR8 vMz169jUujA00+afHnJkDHOT37wNFf756kYUiDGB99UadQrRU4nd37Zxbg/4NwqWP8Dw hElw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qLbeVmje; 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=pass (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 r18si4461123pgm.166.2021.10.18.06.42.11; Mon, 18 Oct 2021 06:42:24 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=qLbeVmje; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233084AbhJRNmR (ORCPT + 99 others); Mon, 18 Oct 2021 09:42:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:56376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233214AbhJRNkM (ORCPT ); Mon, 18 Oct 2021 09:40:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8178C6138D; Mon, 18 Oct 2021 13:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563988; bh=cE7s2eEP8NM2AQY52vlyesHhmKq32ZWnINA5dikkOFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qLbeVmje1tl6qADeY4li2ApZypRT/33aP5bMVMkanpRzPFjrFYFKAMAoaD5sv0MrR bJJFCZAHOuv9TY2gblp3mTmPtg94THe/qff7l+l7+NMVKWKS/S+uEXjTFAUusj199N yFhrjLUThY/EucEhbUWVa9YLrJeJWQ+akm2e3FaM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Josef Bacik , David Sterba Subject: [PATCH 5.10 023/103] btrfs: update refs for any root except tree log roots Date: Mon, 18 Oct 2021 15:23:59 +0200 Message-Id: <20211018132335.488532110@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132334.702559133@linuxfoundation.org> References: <20211018132334.702559133@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: Josef Bacik commit d175209be04d7d263fa1a54cde7608c706c9d0d7 upstream. I hit a stuck relocation on btrfs/061 during my overnight testing. This turned out to be because we had left over extent entries in our extent root for a data reloc inode that no longer existed. This happened because in btrfs_drop_extents() we only update refs if we have SHAREABLE set or we are the tree_root. This regression was introduced by aeb935a45581 ("btrfs: don't set SHAREABLE flag for data reloc tree") where we stopped setting SHAREABLE for the data reloc tree. The problem here is we actually do want to update extent references for data extents in the data reloc tree, in fact we only don't want to update extent references if the file extents are in the log tree. Update this check to only skip updating references in the case of the log tree. This is relatively rare, because you have to be running scrub at the same time, which is what btrfs/061 does. The data reloc inode has its extents pre-allocated, and then we copy the extent into the pre-allocated chunks. We theoretically should never be calling btrfs_drop_extents() on a data reloc inode. The exception of course is with scrub, if our pre-allocated extent falls inside of the block group we are scrubbing, then the block group will be marked read only and we will be forced to cow that extent. This means we will call btrfs_drop_extents() on that range when we COW that file extent. This isn't really problematic if we do this, the data reloc inode requires that our extent lengths match exactly with the extent we are copying, thankfully we validate the extent is correct with get_new_location(), so if we happen to COW only part of the extent we won't link it in when we do the relocation, so we are safe from any other shenanigans that arise because of this interaction with scrub. Fixes: aeb935a45581 ("btrfs: don't set SHAREABLE flag for data reloc tree") CC: stable@vger.kernel.org # 5.8+ Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -710,8 +710,7 @@ int __btrfs_drop_extents(struct btrfs_tr if (start >= inode->disk_i_size && !replace_extent) modify_tree = 0; - update_refs = (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) || - root == fs_info->tree_root); + update_refs = (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID); while (1) { recow = 0; ret = btrfs_lookup_file_extent(trans, root, path, ino,