Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3425938imu; Sun, 11 Nov 2018 14:49:36 -0800 (PST) X-Google-Smtp-Source: AJdET5ejZYmpcz47ovi2wcy5khj/DO/Z8sleUnZlmXRb39hDhZCN42bRbo0+kR1Zsas3xV+ORt1r X-Received: by 2002:a63:2f86:: with SMTP id v128mr14851518pgv.407.1541976576742; Sun, 11 Nov 2018 14:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976576; cv=none; d=google.com; s=arc-20160816; b=WH4Ww8/t0H4uly6we0zwXsS7/z4qZI1UGhdeacxajqk+P/tjTcQrQbsDLY2o4k5AeI W1FE2r8P7xp1ZcHgxA47YOH4X5l7usgQ5KcXtoEkaEGxGL48McQQPkPlyhC9MxNzoXkC jh4lTTFVDWyYipDFtFaz1gZamGey5mnSss5NDZC3fyvdLz9D9054EqtE7Lk7ySI+MhJS OVZaWAm5DVaVocvtPWaAtm+IE3r55v/7prl9LBJJEa2kxx808wYBK6+dlmjJDgRRjUHq AJfOIdR6/QD8fmxgCUH5BdPQ7AJaJsA1CX6hRvuMcLA6JOJGhkTG5AWPXlDvTGuVbetw g2FA== 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=aa+H++grrqpIzV8nxRAGjKdo55iYNV69KvdAOU1B0/Y=; b=LdSrbuRrXw5zJxpLKcDDTjuEYsZdMXyZu8FGwstoT+Qk0y68WDi0Zok3pw98Tf7Unx gzFSpaF0IbdSB5wFMAvTTTgE65pk5N1aAaiqqj96eGwl/NAqYq2YkVtfhKRd7BvI/Me1 MxAnygSRuJIMEzY84O3o2SZ3tbdvt6hIXbUD/vFea9qrP/t8tRfCIdIQKBoFnsLebjxw xOVVo5RElq1hQxZb1B/1Ogs2ygIbICLSBlZVj3taSvlMHefVvOYZvHznF5n41jeQwva4 hdDzEPmP9ZajKlodOmVBbAfZrfoNDysLuI/reYyWLmq6USM/hRrdq072S1zaLESVJjr4 dbVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="0DOLbq/5"; 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 p188-v6si17472396pfp.119.2018.11.11.14.49.21; Sun, 11 Nov 2018 14:49:36 -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="0DOLbq/5"; 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 S2404360AbeKLIXT (ORCPT + 99 others); Mon, 12 Nov 2018 03:23:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:56460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731178AbeKLIXS (ORCPT ); Mon, 12 Nov 2018 03:23:18 -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 83F65208A3; Sun, 11 Nov 2018 22:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975600; bh=6NYavegaDhYpR12VTyCvOnuppdRrdnC6cAQLS3RKbq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0DOLbq/5oNems0OhyrT/DeKAVIEXjY0lROd3BRpuKB5UaIME+OpB22brY47mmxtL1 8pWZ3sl7m/CzfghpqcZuoaZKdUmifL1kNdfmJNJsazf/jIcRdVj5bAaTESj3CaPmdQ pjX/BFy5L131JObs0cBuTDqmmKOIMEf1mhgv2rzw= 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.14 215/222] btrfs: only free reserved extent if we didnt insert it Date: Sun, 11 Nov 2018 14:25:12 -0800 Message-Id: <20181111221705.648298106@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -2966,6 +2966,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) && @@ -3069,10 +3070,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, @@ -3132,8 +3135,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,