Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3468645imu; Sun, 11 Nov 2018 15:48:41 -0800 (PST) X-Google-Smtp-Source: AJdET5fSAQboKttgwrrvSo8U1w/Mqk7c2f/UqjF+CK9kbN+5UB6ra5nUUJsFXD2OTfsrv3mo3soi X-Received: by 2002:a63:66c1:: with SMTP id a184-v6mr15804770pgc.26.1541980121534; Sun, 11 Nov 2018 15:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980121; cv=none; d=google.com; s=arc-20160816; b=tYbsP0jfsDOeuywAtt813feC0MQayEucNX2md83IOHCZCDw6a+Mzy5uF8ddA9YK/2Q BHaMjk3SvG1A3/X/EKVPET2ll1ADEEiowIixQd6DsfCt6lGPYNHTvXB1XMfqcs0nJRHL B8Jr1zfEZV3xaIbwmlrw1tzgy+Qrvpaqf0r+pJq80tzE/jSh8nvrr0tK8h4brfJjXWEw 27sIxGa8aFW3YuUbwUVx2bT8xmYpXc2nA/FRJKWt9A58HMXFLYFB5BN6Gs1QRRRS3nb+ v7H5O7e9aY7l7BZyPS6LT7ItrVp8S/ZH0AYoorhpl6aPaSK70iz9aYnfcP/brHotcV2j 4qFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ykfa7nGUkvR3loQH7bvuSQo+Y8z3EixBTozugK5V/Hc=; b=EPcA08V0XgEjRR56taJYAPToyuRoFx0UyFooDSR8dSR5SrmvADQH4SNPv8VjLGjuNL IwrSZqW5S71eCmg8psUrmo5aoNgYpUK8e8ErAvJPgPdn6REmpLax5umIw0uu4j9cFdai EL97okxY8YFAac6BbCZSmOM6i53JfSQm7NikcyHTSxmA5YvXVygFgisJrMlqaZNQ1YO+ 0rb+kRCuv7m3NVJHifbDnHcaXorEqj9QvLKvgbKR1ntPmPhyP0d6xiSkpIbOp25w5r/j tVE/DJuji9MGDNVUZxnl7CesUBepobDW1fJwf4woNFLbdep79QEtcQ4bM6MEUcmYTTZf 7ERA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i6hTBlx4; 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 59-v6si4723685plb.75.2018.11.11.15.48.26; Sun, 11 Nov 2018 15:48:41 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=i6hTBlx4; 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 S2387473AbeKLJhN (ORCPT + 99 others); Mon, 12 Nov 2018 04:37:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:39224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733185AbeKLISt (ORCPT ); Mon, 12 Nov 2018 03:18:49 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF3C121508; Sun, 11 Nov 2018 22:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975334; bh=VMSLAbxNIKm52+gk1IeiZVYz5C0fT0/EZ4DU255KdvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i6hTBlx4Frv83ay1sIJA62nVKQJONObfIZkJEdUnRbSxClggjyTJllRZRBZYg2MoC 3A9pInlB+1KHOkfD1NZBRmzP7Es6THGwiflz+XBZtJ3Tz2R4hkZJ8orlz34Insn3ix pUM6VMJb8seGDTqldFP3r7LBfzLFfR/zO7bhBnro= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Omar Sandoval , Filipe Manana , Josef Bacik , David Sterba Subject: [PATCH 4.19 351/361] btrfs: only free reserved extent if we didnt insert it Date: Sun, 11 Nov 2018 14:21:38 -0800 Message-Id: <20181111221701.563870763@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit 49940bdd57779c78462da7aa5a8650b2fea8c2ff upstream. When we insert the file extent once the ordered extent completes we free the reserved extent reservation as it'll have been migrated to the bytes_used counter. However if we error out after this step we'll still clear the reserved extent reservation, resulting in a negative accounting of the reserved bytes for the block group and space info. Fix this by only doing the free if we didn't successfully insert a file extent for this extent. CC: stable@vger.kernel.org # 4.14+ Reviewed-by: Omar Sandoval Reviewed-by: Filipe Manana Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2945,6 +2945,7 @@ static int btrfs_finish_ordered_io(struc bool truncated = false; bool range_locked = false; bool clear_new_delalloc_bytes = false; + bool clear_reserved_extent = true; if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) && @@ -3048,10 +3049,12 @@ static int btrfs_finish_ordered_io(struc logical_len, logical_len, compress_type, 0, 0, BTRFS_FILE_EXTENT_REG); - if (!ret) + if (!ret) { + clear_reserved_extent = false; btrfs_release_delalloc_bytes(fs_info, ordered_extent->start, ordered_extent->disk_len); + } } unpin_extent_cache(&BTRFS_I(inode)->extent_tree, ordered_extent->file_offset, ordered_extent->len, @@ -3112,8 +3115,13 @@ out: * wrong we need to return the space for this ordered extent * back to the allocator. We only free the extent in the * truncated case if we didn't write out the extent at all. + * + * If we made it past insert_reserved_file_extent before we + * errored out then we don't need to do this as the accounting + * has already been done. */ if ((ret || !logical_len) && + clear_reserved_extent && !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) btrfs_free_reserved_extent(fs_info,