Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4837269pxj; Wed, 9 Jun 2021 03:09:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJY98C/kD7/R8xODrK4QY+KBiaVLUYsyRFM+TjHGssWRelV4f9mXWWwBma5cXBHQeZ+GXb X-Received: by 2002:a05:6402:3586:: with SMTP id y6mr1044855edc.154.1623233341477; Wed, 09 Jun 2021 03:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623233341; cv=none; d=google.com; s=arc-20160816; b=COJNS4XgdaIrMtQJMbb2SAY+k33SfGCT8Zful/2NKXPiZi8cwDJ7kzTdfxS0SkB32e pnchDuQ6OKumNXV64S1Wpdi+4EcXQiP51Yoi0+T/PJ4lMiGCQDeHsScESl2nnbzdgUfk J9gUuoRuThyFB+10rkrwQIOR7jDHUVpVJZFFfochaVRJCv/+InE7DPcmlJ4NkNawySLG riZ4GF7Qe7uaFRf0+GWWkM85d6TgcoYw/bwkkmTQmguL8QSQNL8iVrGhgD8xYj6KRexA OvLtye9I8TKQ75s4INs5+svLu9aIWsOC0M+esHLMnBhnojsUwepJolx/GT6YbAWCAFQn lnqw== 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=bCsb2opuqCylGEr4m9uGqXV8urOTzBlyL84xQZwvars=; b=wdWeSqNdMgOOixiegxhf9R17IJzbmHJJ2ALUp6+ttNZi1bbgX762lkIwo5x0lAC+R+ DDZCk9FsjDbWlS6BdD4PE775fMTbFEa8/1ZFUO+pGhlVUfs01JbBmQ4TLUHBoPV5Vv3m fsAKCReoDg5FbueGKQGxsh+BGwbO+XCBP+oaE8+nNrSPQvF8wWDS7roYQ9n2ZvI4cw1J M9T/CDZ6BJlM1zO2WSUcmm4IJORYc1SNiJv44+3e9KFfXGsMPilHxJYXsp5iPx6mWwSn KjSAzu1xGz83b2FaVEMh+MAMjW3BCR8Ht6f/P8iNkCvqHOm4A6d9+9qT6HWhB/cLWhM9 FaNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=deLvTEdK; 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 jz5si2264058ejb.22.2021.06.09.03.08.38; Wed, 09 Jun 2021 03:09:01 -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=deLvTEdK; 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 S235506AbhFHSwO (ORCPT + 99 others); Tue, 8 Jun 2021 14:52:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:44020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235163AbhFHSqt (ORCPT ); Tue, 8 Jun 2021 14:46:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7FD2461457; Tue, 8 Jun 2021 18:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177462; bh=MkMB8LnhR/wQ2FgkNkkfsqVwkK5F68zjorlKDzb9t8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=deLvTEdKsDxFZXRgEIvl4WwKe7y1MgM4Ar46A2YvjFGzZ4t8y6fGeN0g9qJet4KFN nhL5ddS3okZjSX+hFgtOmpNwXIQWwwQ2IeybTQ04oIEJBCsctKjRxWjcgwZsFIKaiP z8NXVzr+G0tgIz5+ye29QP8fx2EoaqPAW6xCqalg= 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.4 60/78] btrfs: fix error handling in btrfs_del_csums Date: Tue, 8 Jun 2021 20:27:29 +0200 Message-Id: <20210608175937.302704632@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@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 b86652be7c83f70bf406bed18ecf55adb9bfb91b upstream. Error injection stress would sometimes fail with checksums on disk that did not have a corresponding extent. This occurred because the pattern in btrfs_del_csums was while (1) { ret = btrfs_search_slot(); if (ret < 0) break; } ret = 0; out: btrfs_free_path(path); return ret; If we got an error from btrfs_search_slot we'd clear the error because we were breaking instead of goto out. Instead of using goto out, simply handle the cases where we may leave a random value in ret, and get rid of the ret = 0; out: pattern and simply allow break to have the proper error reporting. With this fix we properly abort the transaction and do not commit thinking we successfully deleted the csum. Reviewed-by: Qu Wenruo CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/file-item.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -599,7 +599,7 @@ int btrfs_del_csums(struct btrfs_trans_h u64 end_byte = bytenr + len; u64 csum_end; struct extent_buffer *leaf; - int ret; + int ret = 0; u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); int blocksize_bits = fs_info->sb->s_blocksize_bits; @@ -618,6 +618,7 @@ int btrfs_del_csums(struct btrfs_trans_h path->leave_spinning = 1; ret = btrfs_search_slot(trans, root, &key, path, -1, 1); if (ret > 0) { + ret = 0; if (path->slots[0] == 0) break; path->slots[0]--; @@ -674,7 +675,7 @@ int btrfs_del_csums(struct btrfs_trans_h ret = btrfs_del_items(trans, root, path, path->slots[0], del_nr); if (ret) - goto out; + break; if (key.offset == bytenr) break; } else if (key.offset < bytenr && csum_end > end_byte) { @@ -718,8 +719,9 @@ int btrfs_del_csums(struct btrfs_trans_h ret = btrfs_split_item(trans, root, path, &key, offset); if (ret && ret != -EAGAIN) { btrfs_abort_transaction(trans, ret); - goto out; + break; } + ret = 0; key.offset = end_byte - 1; } else { @@ -729,8 +731,6 @@ int btrfs_del_csums(struct btrfs_trans_h } btrfs_release_path(path); } - ret = 0; -out: btrfs_free_path(path); return ret; }