Received: by 10.213.65.68 with SMTP id h4csp656123imn; Fri, 6 Apr 2018 06:52:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/3S9dJgtMJJXusMD7oxp6m396y60ArnxBvl/MTDOFPJvNa+ZO1sdnddQaMH7y21Rw372Wn X-Received: by 10.167.128.140 with SMTP id v12mr20697356pff.177.1523022750432; Fri, 06 Apr 2018 06:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523022750; cv=none; d=google.com; s=arc-20160816; b=G6VVvHC0Y1aCuK5R7MBn02Bn3bq3GE8MxSHiUUNmlhqsfIj/HGET8tWgUVG5Y3eFIi biF+pZ4H9ydc6af4tDFPxEvE1B4mLfKRbA2HuxxtuwbgQ7G1eD12CQptk5umJ3TGOcKr wVROLZcKzR0h0vP48yBdUP/WDds4/Vr0eiTPIcbXDcGkwT0wi4jZfXKNHHNuTl3dTz+S oPXmipQBtEnKLYPhbga1uphXQeDWBDaBM5MPn49qHCamy+g192sV6nDU7jYZAvHN2Zwz fgXx9KEjtzKbFdM1AvKnHdO5meT5vGuL0P5uzBY4Gy1fMA1LcVYp5oyPgK8YaMxr/VHv NKZA== 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=DA7ONM31sqcCfXCKrLjrCC8VgZZX7zXejxj9SPtth2Y=; b=Z8Vcw66PzC0IgDqXfNHCnBMwG2AXGOXXszvCGxTegj5YurzftSRDT+YL1UL/4QWUcC u21QmkuDJb7HrhowDVJNxSPaGT6cc8TXlIEMix8PF+u3YRDoFMHUTsKQSxN//7fEc5kH mpaJ/mUAp3n6gPSIPoAUGLyBfynLJyC+qd517GLu8bUWIxnAT0kmIoiiCmzUqCgoxoEC niKH3bQ+X0/OQgaS86MH7mpCXpOsgl2NubNNAmJcH7TyrZq2hQpp5t9Jz7pRiXQ0J0Xr mV8Q4rC4RbCk1wyPoEC4D3/D9m0iyZM8+FLho+w3v4CsTzsxhJzoDWY97zlQoYmKYd6S aKWA== 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 z22-v6si8523501plo.270.2018.04.06.06.52.16; Fri, 06 Apr 2018 06:52:30 -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 S1757011AbeDFNuZ (ORCPT + 99 others); Fri, 6 Apr 2018 09:50:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37924 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932978AbeDFNox (ORCPT ); Fri, 6 Apr 2018 09:44:53 -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 5EE96E08; Fri, 6 Apr 2018 13:44:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Bo , David Sterba Subject: [PATCH 4.16 22/31] Btrfs: fix unexpected cow in run_delalloc_nocow Date: Fri, 6 Apr 2018 15:24:47 +0200 Message-Id: <20180406084344.022961066@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084340.999820380@linuxfoundation.org> References: <20180406084340.999820380@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: 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: Greg Kroah-Hartman --- fs/btrfs/inode.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1262,6 +1262,8 @@ static noinline int csum_exist_in_range( list_del(&sums->list); kfree(sums); } + if (ret < 0) + return ret; return 1; } @@ -1394,10 +1396,23 @@ next_slot: goto out_check; if (btrfs_extent_readonly(fs_info, disk_bytenr)) goto out_check; - if (btrfs_cross_ref_exist(root, ino, - found_key.offset - - extent_offset, disk_bytenr)) + ret = btrfs_cross_ref_exist(root, ino, + found_key.offset - + 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; @@ -1415,10 +1430,22 @@ next_slot: * this ensure that csum for a given extent are * either valid or do not exist. */ - if (csum_exist_in_range(fs_info, disk_bytenr, - num_bytes)) { + ret = csum_exist_in_range(fs_info, disk_bytenr, + num_bytes); + if (ret) { if (!nolock) btrfs_end_write_no_snapshotting(root); + + /* + * 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(fs_info, disk_bytenr)) {