Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3425495imu; Sun, 11 Nov 2018 14:48:57 -0800 (PST) X-Google-Smtp-Source: AJdET5ekPZqCmoBQ2EozSQmVnHA/V0zIVW+C/HVlCZwUvQLJn0RMeGjSRqjrjbpJWvV45G3QHJBD X-Received: by 2002:a17:902:4583:: with SMTP id n3-v6mr17588312pld.53.1541976537616; Sun, 11 Nov 2018 14:48:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976537; cv=none; d=google.com; s=arc-20160816; b=ejtIzz9g4C3D8MpzdMTOhw/bpTGX9+812m6GiwruHfXmVWDrk76uMKurjLL2sEcDZx jHThUzhfbOmRyRMnbw5a3ijZ/qbHznw/sY85yD56je2cMmb7kaGhCnGomNfBfKRTNdDu e7EsbtZf9Oor2Px37JMA6wKGiolQBBYENxkv4GSoAOiBqRAWIxOBWuRj3AHNL8oEUBGo 5iH8jS/gYLHJhuadNWRYpLeTNDLk6JcXN30sI3V66PeaGDAg84V3m8BCXcDGpvfLHHa7 2k4UtwV1i7UCaahO0bQmLyGLptXTsOHFU1pKk7PDYTtO1bTRfo3Jq5q59B+wqdkTjfv8 bbuw== 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=MBo2cIyYy2BNMPhaUzHxTIhr6M8xQpR7c4ruMvQtbiw=; b=DsoJOv4k9MtsRq7aZ4Zd+br/Kxvkjz7TUvMnUC2XL/vYJkwZkthfZEN0vBcQwLnoLL 4CRg3+2fn8ZEIiDRsHVho+T2YApjfXwl6mz4q0zmx4hit5kOlBkClQN22XAVWb/+lNt2 eiaBEq1ZNCvz6vcjmhleXnS+VMGdT4ACT94PnCmDWl2eWLTHraVIoNc5/CszXivj/Ouo 1xJEX4emydeVg+SM5Kfv72cfj6J9ZfMnc69qLZAonbl8C/719w2NrOgf1dQyJiN9e1oC RakTnwYF3XFFfYa0EXMkNTGgU6tURMSN2dRK35bMXWHfA9QGveOJznbhKn53P47pG3CM pIOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0s2QYiqr; 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 v64-v6si18221170pfj.167.2018.11.11.14.48.42; Sun, 11 Nov 2018 14:48:57 -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=0s2QYiqr; 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 S2390968AbeKLIi0 (ORCPT + 99 others); Mon, 12 Nov 2018 03:38:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:56794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404392AbeKLIXW (ORCPT ); Mon, 12 Nov 2018 03:23:22 -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 28832223C8; Sun, 11 Nov 2018 22:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975604; bh=IRUyuaGPN2S7E2Dop3xOXS+uMkv/bjwIPWe4vXD5MO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0s2QYiqr/xZUf11QaTAb4bMaA9r3N6/owfgARWmhtf0QpUwt0hr/FF28RfrAdgFKN /aF0iacJyPW/LTRFADiFX64CKWy2K/x6/FUZ6W8AuspPgnQRXPW+eEKXKVS1bUxPJ+ IpQsxplvyG2A/ki4BcgpcqEHlDtboZ3vBKr7mD/c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 4.14 213/222] btrfs: set max_extent_size properly Date: Sun, 11 Nov 2018 14:25:10 -0800 Message-Id: <20181111221705.523218209@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 ad22cf6ea47fa20fbe11ac324a0a15c0a9a4a2a9 upstream. We can't use entry->bytes if our entry is a bitmap entry, we need to use entry->max_extent_size in that case. Fix up all the logic to make this consistent. 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/free-space-cache.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1795,6 +1795,13 @@ static int search_bitmap(struct btrfs_fr return -1; } +static inline u64 get_max_extent_size(struct btrfs_free_space *entry) +{ + if (entry->bitmap) + return entry->max_extent_size; + return entry->bytes; +} + /* Cache the size of the max extent in bytes */ static struct btrfs_free_space * find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, @@ -1816,8 +1823,8 @@ find_free_space(struct btrfs_free_space_ for (node = &entry->offset_index; node; node = rb_next(node)) { entry = rb_entry(node, struct btrfs_free_space, offset_index); if (entry->bytes < *bytes) { - if (entry->bytes > *max_extent_size) - *max_extent_size = entry->bytes; + *max_extent_size = max(get_max_extent_size(entry), + *max_extent_size); continue; } @@ -1835,8 +1842,8 @@ find_free_space(struct btrfs_free_space_ } if (entry->bytes < *bytes + align_off) { - if (entry->bytes > *max_extent_size) - *max_extent_size = entry->bytes; + *max_extent_size = max(get_max_extent_size(entry), + *max_extent_size); continue; } @@ -1848,8 +1855,10 @@ find_free_space(struct btrfs_free_space_ *offset = tmp; *bytes = size; return entry; - } else if (size > *max_extent_size) { - *max_extent_size = size; + } else { + *max_extent_size = + max(get_max_extent_size(entry), + *max_extent_size); } continue; } @@ -2709,8 +2718,8 @@ static u64 btrfs_alloc_from_bitmap(struc err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); if (err) { - if (search_bytes > *max_extent_size) - *max_extent_size = search_bytes; + *max_extent_size = max(get_max_extent_size(entry), + *max_extent_size); return 0; } @@ -2747,8 +2756,9 @@ u64 btrfs_alloc_from_cluster(struct btrf entry = rb_entry(node, struct btrfs_free_space, offset_index); while (1) { - if (entry->bytes < bytes && entry->bytes > *max_extent_size) - *max_extent_size = entry->bytes; + if (entry->bytes < bytes) + *max_extent_size = max(get_max_extent_size(entry), + *max_extent_size); if (entry->bytes < bytes || (!entry->bitmap && entry->offset < min_start)) {