Received: by 10.213.65.68 with SMTP id h4csp1728203imn; Mon, 19 Mar 2018 11:35:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELuI4MIYjVwgeU6sSYRgKpOT3sHAQarixTglN+wLaM8VIFHbdhIXG/LE42X+xrUlL9HsjcJW X-Received: by 2002:a17:902:bcc6:: with SMTP id o6-v6mr13207653pls.16.1521484558216; Mon, 19 Mar 2018 11:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484558; cv=none; d=google.com; s=arc-20160816; b=diLNyeF8Tg4+aQqXzrxUVIDJ1ge+w+5nPX7tzULSIrXc5YuGMv3N/ma8rhepAABmBS MjYwaD9iKOY4DA3NzMGCtHvDDACcNdS55l6wekVcK43RKTsnGDgIrRdYQWPzOyWoV599 4h+q00jtBv1/uP5Z99qLYVva0AvN2RpUQPVyJSz1kxLlo7Mcrl1oPQeMDZQlN7ZIPPhR CF50egxvKr9fXctWccqsabdSghHx/5RABFKQIpHfzX+nhR0xbN2E/cOg40ahVw/8rGbB QtM0CZeXjeKWXRcYzvlKQjaeJiNSv7XjOnaFyCYBeg4B+YX8LklvC2CfPECaCOEmXD8s yd9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=UZ5tNPX/atpUOcDdRITGmxqc7Qenm75CK9KNhTh4DOc=; b=lX+nWwBnWiFq9XRFOD2L0dCA5WPldQgsT4JMLm0K7V2UiaaYtkCzz7KQu37asrWLA7 Q9xVtAcxqCdO5etf+rhk1TyVP8xM2Sa0ar4//nJ+BS+yMKHutKnq3I4n+HAGjO1oxXTV acllpIhQvStqbWFMJWNuLJs9HN4Kuch3HrLPOdxEZYHFcjuqNrdOllV/y8abnrgBa4oL XvbMZZnXQlS1KbSUStEP0/z1IsqcqMA1qG9s5KdXmL4iB9QOqToPpYlWZbB9xoiI2Z9i 75QFisInQwX+0inmMN6of9WLaBX/73yKlLU/5UWSKjP4ZCpnWqbWvuF5pndF3ZLDvEla Mduw== ARC-Authentication-Results: i=1; mx.google.com; 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 h12si286288pgn.317.2018.03.19.11.35.43; Mon, 19 Mar 2018 11:35:58 -0700 (PDT) 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; 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 S970226AbeCSSeI (ORCPT + 99 others); Mon, 19 Mar 2018 14:34:08 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54736 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032214AbeCSSd0 (ORCPT ); Mon, 19 Mar 2018 14:33:26 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D6964DD0; Mon, 19 Mar 2018 18:33:25 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Naohiro Aota , Hans van Kranenburg , David Sterba Subject: [PATCH 4.15 34/52] btrfs: alloc_chunk: fix DUP stripe size handling Date: Mon, 19 Mar 2018 19:08:32 +0100 Message-Id: <20180319180736.927690482@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180734.976730813@linuxfoundation.org> References: <20180319180734.976730813@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hans van Kranenburg commit 92e222df7b8f05c565009c7383321b593eca488b upstream. In case of using DUP, we search for enough unallocated disk space on a device to hold two stripes. The devices_info[ndevs-1].max_avail that holds the amount of unallocated space found is directly assigned to stripe_size, while it's actually twice the stripe size. Later on in the code, an unconditional division of stripe_size by dev_stripes corrects the value, but in the meantime there's a check to see if the stripe_size does not exceed max_chunk_size. Since during this check stripe_size is twice the amount as intended, the check will reduce the stripe_size to max_chunk_size if the actual correct to be used stripe_size is more than half the amount of max_chunk_size. The unconditional division later tries to correct stripe_size, but will actually make sure we can't allocate more than half the max_chunk_size. Fix this by moving the division by dev_stripes before the max chunk size check, so it always contains the right value, instead of putting a duct tape division in further on to get it fixed again. Since in all other cases than DUP, dev_stripes is 1, this change only affects DUP. Other attempts in the past were made to fix this: * 37db63a400 "Btrfs: fix max chunk size check in chunk allocator" tried to fix the same problem, but still resulted in part of the code acting on a wrongly doubled stripe_size value. * 86db25785a "Btrfs: fix max chunk size on raid5/6" unintentionally broke this fix again. The real problem was already introduced with the rest of the code in 73c5de0051. The user visible result however will be that the max chunk size for DUP will suddenly double, while it's actually acting according to the limits in the code again like it was 5 years ago. Reported-by: Naohiro Aota Link: https://www.spinics.net/lists/linux-btrfs/msg69752.html Fixes: 73c5de0051 ("btrfs: quasi-round-robin for chunk allocation") Fixes: 86db25785a ("Btrfs: fix max chunk size on raid5/6") Signed-off-by: Hans van Kranenburg Reviewed-by: David Sterba [ update comment ] Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/volumes.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4737,10 +4737,13 @@ static int __btrfs_alloc_chunk(struct bt ndevs = min(ndevs, devs_max); /* - * the primary goal is to maximize the number of stripes, so use as many - * devices as possible, even if the stripes are not maximum sized. + * The primary goal is to maximize the number of stripes, so use as + * many devices as possible, even if the stripes are not maximum sized. + * + * The DUP profile stores more than one stripe per device, the + * max_avail is the total size so we have to adjust. */ - stripe_size = devices_info[ndevs-1].max_avail; + stripe_size = div_u64(devices_info[ndevs - 1].max_avail, dev_stripes); num_stripes = ndevs * dev_stripes; /* @@ -4775,8 +4778,6 @@ static int __btrfs_alloc_chunk(struct bt stripe_size = devices_info[ndevs-1].max_avail; } - stripe_size = div_u64(stripe_size, dev_stripes); - /* align to BTRFS_STRIPE_LEN */ stripe_size = round_down(stripe_size, BTRFS_STRIPE_LEN);