Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3468701imu; Sun, 11 Nov 2018 15:48:45 -0800 (PST) X-Google-Smtp-Source: AJdET5exBmpC8lMJ4f2xaL0lX7ADoy2mTFGEYnAebOaoAc41khIf5bHDIQYo2uVuKou4cM2GqX16 X-Received: by 2002:a63:a51b:: with SMTP id n27mr15809220pgf.17.1541980125001; Sun, 11 Nov 2018 15:48:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980124; cv=none; d=google.com; s=arc-20160816; b=MFuBnmQA3UjRSKcrfBYLhSyl5dx9KOd9v2lada/6XAd9vnDIU1Cu0oksAtG2OvrHdp 8kjm6hKrq0rcbLPZ+6aWeVQzF0omTc26ge+iQdNsq5IhvMtviis1/SCvwjwVEO6WjpeX 5VL4Gz/OkLc/4LqZ9N5C6QfiZ4Znu8DON835gdSuQfMWb5VbVibmOaLq9H6TsfpxCRml J1HKH1xkHjcn3ZZzLBwZY48y8UvNgaTpLC+kD0CQRKNvBZLNip9HgmLsK3GSVrfpPGv4 iYFLWuaEEJMmdexOjtcNDEC1CPtvKgPwBhrWO0mNTVsODM5L88bQyciTZKjO/gV5l3Cn DT3g== 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=y54rr73xoZIVjhTnfuCNawU4HgjGzhpWskRjkd5SKNE=; b=gsLzNSLumQtHDm9/3GwmxoPv5srnp55Ie1GCZAWTB83hXn03Ccck3V9jaw24gGSjhq RIiuj/ynIPvCxnYleJG5g+3Aeiu1dVoZqma25CZZP5V93z3XYTwyAXDvp6mTjW2fga18 +xYabcIUpEB9Ww0BDNMJaXV8BKj+sUQoRkh7gVj7LAEi+kN0wY6tfsRB6Jwg1zW7GEIR N0m0FonBKlhdGs1XVIgtqVCCgMtPGwhv8inyL9XOOd6/A+j337259UM7R9m9GbxkxFTh 6nwv3WFh4Nwp9VrHLEeCC6kvDiuK7xPgZafDKJt7SpzTgj59Jg4MOVUnH1Fs7D2Mqsrp TOWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XPyZuymc; 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 q76-v6si8423954pfa.211.2018.11.11.15.48.30; Sun, 11 Nov 2018 15:48:44 -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=XPyZuymc; 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 S1733303AbeKLJhN (ORCPT + 99 others); Mon, 12 Nov 2018 04:37:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:39252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733152AbeKLISt (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 40CF721780; 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=1541975333; bh=S1bAJpaki20h3/eBcELrLZhQibXZZ2XNGshSeqkgn6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XPyZuymcmVxwbwa+l+awtgeqN+76Sm58reyuS32BGNdF2DOxJeYc+dCLCkYCYztPS FMvV9MbYmGzTddwtst7hAZ9XCWY8IKi1QabQtUo5Fb+TejaJTTOoloTnxkTYYlSyO9 D/RbfGMdW/Uj4ty00KjufLJVncdTbBBavNRE02aY= 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.19 349/361] btrfs: set max_extent_size properly Date: Sun, 11 Nov 2018 14:21:36 -0800 Message-Id: <20181111221701.383076771@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 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 @@ -1772,6 +1772,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, @@ -1793,8 +1800,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; } @@ -1812,8 +1819,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; } @@ -1825,8 +1832,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; } @@ -2686,8 +2695,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; } @@ -2724,8 +2733,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)) {