Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3059603imm; Sun, 1 Jul 2018 11:17:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ0CYetPKBDH+pXxN6gY9IasRiCarQUUOWm8D/uFdTBJCLA2IUKhP8nihixoVHOyIlbAlQP X-Received: by 2002:a17:902:a505:: with SMTP id s5-v6mr23256169plq.66.1530469048195; Sun, 01 Jul 2018 11:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530469048; cv=none; d=google.com; s=arc-20160816; b=WcQrokuilWvsFmJddVe5mn0ifOwJKoP3cRS+XzBaC5h4dW0IaQ+HUDyBqtdno4Yh8L rIxPOQ+HQ9RYSi/7Wj7RktvP57KQKLvsXhQsdZxyHBB9lZ4HADIsLUtD25VPadxrz26F CQI0rsVid8bE0//8mfTYx8yWmII0XNN/0eIY/ErdfgtZ/yPLaUszpa8B7dg1iEHoXqgw j9U65fpSMxtWfRP4vhgfSHkjOGE4WtYYZIeKc+UH5EjDBs1h4AkSfDKfJ7CpAHq22Yzv 3dX+LFVBQSmQHBJNrVabXPV8RgNs+Bs3RME7OFWSgnTT0bcS4hPoo8ivXZS6l67WY6iV /BHg== 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 :arc-authentication-results; bh=WLIoVtS0cf1JnMVAm8oKerHFcWtfnNFEoEpaFYuZQYQ=; b=MdbKO6M+Bk6DVsRc3ee8dOvXrvnVmqVN4MVFZLFVfsAtWIdastu7eQP3rSjh2ksBmA pclaDwXpandDH2R3OdFy/2XE2/CLkfyt+XWnA1R381WK6mStNYovbjQ1Etufs1jrpW7J cvAru1gcbshVdryEFDBP6h5hynWX+SyRW9gaP3Bi9EFqax9Piy6Ww7pJtu0NtgMHc6eW ouKNILYTPsFefWCxlNFmbBJHszeE7zaX52AYIqsWHWMRci3UMaeAgYgSMXiw6a0DPfQW eBLtvYM9h/PFWYZ0COSIuWxVD5V5EBEE5PWG2I3I+pjT9bM8kHZVIgU6mAA2YPIjWjdK 31/g== ARC-Authentication-Results: i=1; mx.google.com; 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 h8-v6si13777582pls.69.2018.07.01.11.17.14; Sun, 01 Jul 2018 11:17:28 -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; 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 S965363AbeGAQ0p (ORCPT + 99 others); Sun, 1 Jul 2018 12:26:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33920 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965127AbeGAQ0g (ORCPT ); Sun, 1 Jul 2018 12:26:36 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3E41EACD; Sun, 1 Jul 2018 16:26:35 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Bo , David Sterba , Sudip Mukherjee Subject: [PATCH 4.9 054/101] Btrfs: fix unexpected cow in run_delalloc_nocow Date: Sun, 1 Jul 2018 18:21:40 +0200 Message-Id: <20180701160759.300817208@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Bo commit 5811375325420052fcadd944792a416a43072b7f upstream. Fstests generic/475 provides a way to fail metadata reads while checking if checksum exists for the inode inside run_delalloc_nocow(), and csum_exist_in_range() interprets error (-EIO) as inode having checksum and makes its caller enter the cow path. In case of free space inode, this ends up with a warning in cow_file_range(). The same problem applies to btrfs_cross_ref_exist() since it may also read metadata in between. With this, run_delalloc_nocow() bails out when errors occur at the two places. cc: v2.6.28+ Fixes: 17d217fe970d ("Btrfs: fix nodatasum handling in balancing code") Signed-off-by: Liu Bo Signed-off-by: David Sterba Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1230,6 +1230,8 @@ static noinline int csum_exist_in_range( list_del(&sums->list); kfree(sums); } + if (ret < 0) + return ret; return 1; } @@ -1381,10 +1383,23 @@ next_slot: goto out_check; if (btrfs_extent_readonly(root, disk_bytenr)) goto out_check; - if (btrfs_cross_ref_exist(trans, root, ino, + ret = btrfs_cross_ref_exist(trans, root, ino, found_key.offset - - extent_offset, disk_bytenr)) + extent_offset, disk_bytenr); + if (ret) { + /* + * ret could be -EIO if the above fails to read + * metadata. + */ + if (ret < 0) { + if (cow_start != (u64)-1) + cur_offset = cow_start; + goto error; + } + + WARN_ON_ONCE(nolock); goto out_check; + } disk_bytenr += extent_offset; disk_bytenr += cur_offset - found_key.offset; num_bytes = min(end + 1, extent_end) - cur_offset; @@ -1402,8 +1417,20 @@ next_slot: * this ensure that csum for a given extent are * either valid or do not exist. */ - if (csum_exist_in_range(root, disk_bytenr, num_bytes)) + ret = csum_exist_in_range(root, disk_bytenr, num_bytes); + if (ret) { + /* + * ret could be -EIO if the above fails to read + * metadata. + */ + if (ret < 0) { + if (cow_start != (u64)-1) + cur_offset = cow_start; + goto error; + } + WARN_ON_ONCE(nolock); goto out_check; + } if (!btrfs_inc_nocow_writers(root->fs_info, disk_bytenr)) goto out_check;