Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3133644pxj; Mon, 17 May 2021 18:40:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnAIYe0pKhhIDpyn080CBTScD90GDMgXItcA92j3Oy4SXT4IQHNRl2GlnQB8XRwaeyBHVj X-Received: by 2002:a05:6638:37a6:: with SMTP id w38mr2874034jal.106.1621302017326; Mon, 17 May 2021 18:40:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621302017; cv=none; d=google.com; s=arc-20160816; b=cez/99U9MdDizPHml8kSRk60dXdWx9FpvrMAUa5SDoiZOju20JX5znP+fO87FhTByH dCzFWnhowO1lwPYIz4hr1KPNJQegZSgHN4LsHU0XWhC/CJH9d5BjkmK1WWDjbMsbuC94 J9xTzDHMQ6STF9Locw4ikOrEY2Fko/arhLbtW1mI7jzl9fVlDtadjAK1dq3yNq7WOfjO uPPVaYP6U2J6riMMOHb1B4/AtKTBRSEmprB1buCTdDnneTCh+na1PTQoQ7VXukoaNRzO crDNoFlUza9QbHgO9ecqJuuMOdoHIUQeQDzLF27laOOhn8Zxty2rD/5XHrfaRt8T/UGl Vtxw== 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=4z3K7DrE2xim9m/cEnl4mAsGLCtayGhUeZAP8+DdAys=; b=qC/4P50QfTCAEnKPup+DrSwDpMRom/ngyoVW/QJSC059n5kN6TK2GDCo+8UflmBTJN iKsXg06CInrT8YQWaNkACITaGFmYVw+9fGmW8bgi7Eu2BRqanM0WxXztCDdmLiuyxfMG JdeOlhpp1Ky6kEfxal3c1HW+ps5q/140hLHJxufMnDTXG7N0L/CFGxto5WVQtlTQWaGX yb62ENJsOlprTfdiUzTQt4TiNx/+GJSCIejRUqmJhVbuLFrShQOukk1G0y/fgaldE45b yNzLFkzR7RPuhk0z2OeeT1z0mk8sjWPH8I9WNkXmhEuAoDEMw+g4ymEMZzXlFvmHzA+0 15zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Shch4o56; 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 w11si27509306ilu.8.2021.05.17.18.39.57; Mon, 17 May 2021 18:40:17 -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=Shch4o56; 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 S240849AbhEQOfT (ORCPT + 99 others); Mon, 17 May 2021 10:35:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:40368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240128AbhEQOaF (ORCPT ); Mon, 17 May 2021 10:30:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D18A76191B; Mon, 17 May 2021 14:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260911; bh=Lw7QXz+KOCEH0MBTLcmFIcb8RtJ28j6AMY2VWljdY/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Shch4o56KtmuvWc6CAtRZpvLrl5HD9QEapQi22gHA2T1RZnnqIgTJQUQp5YKRnJgq LVh15j0QPV1bk7P9a37uBSnMzrEAqjsWTfAd4jyfnQt/l8hafrq9zIUsYyKasxrA5P XZlmk5rkzZhooiuC4a7AiuyxPvch9sFgUzbd7X4g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba Subject: [PATCH 5.12 265/363] btrfs: zoned: fix silent data loss after failure splitting ordered extent Date: Mon, 17 May 2021 16:02:11 +0200 Message-Id: <20210517140311.573621862@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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: Filipe Manana commit adbd914dcde0b03bfc08ffe40b81f31b0457833f upstream. On a zoned filesystem, sometimes we need to split an ordered extent into 3 different ordered extents. The original ordered extent is shortened, at the front and at the rear, and we create two other new ordered extents to represent the trimmed parts of the original ordered extent. After adjusting the original ordered extent, we create an ordered extent to represent the pre-range, and that may fail with ENOMEM for example. After that we always try to create the ordered extent for the post-range, and if that happens to succeed we end up returning success to the caller as we overwrite the 'ret' variable which contained the previous error. This means we end up with a file range for which there is no ordered extent, which results in the range never getting a new file extent item pointing to the new data location. And since the split operation did not return an error, writeback does not fail and the inode's mapping is not flagged with an error, resulting in a subsequent fsync not reporting an error either. It's possibly very unlikely to have the creation of the post-range ordered extent succeed after the creation of the pre-range ordered extent failed, but it's not impossible. So fix this by making sure we only create the post-range ordered extent if there was no error creating the ordered extent for the pre-range. Fixes: d22002fd37bd97 ("btrfs: zoned: split ordered extent when bio is sent") CC: stable@vger.kernel.org # 5.12+ Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ordered-data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -995,7 +995,7 @@ int btrfs_split_ordered_extent(struct bt if (pre) ret = clone_ordered_extent(ordered, 0, pre); - if (post) + if (ret == 0 && post) ret = clone_ordered_extent(ordered, pre + ordered->disk_num_bytes, post);