Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2222322imm; Mon, 28 May 2018 04:14:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZputXQfKrH9B45VgIrHL4iicCK7tJE1qveqbqnyhzu566jIfuH11mAUILvQmrjRCQqPxSd7 X-Received: by 2002:a63:788e:: with SMTP id t136-v6mr10396720pgc.424.1527506061852; Mon, 28 May 2018 04:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527506061; cv=none; d=google.com; s=arc-20160816; b=wGAJOw7b29m1hDy2/Esv9wZOJhQbwtcEG/V0rUAeyS3PhEuz/jmiWi4mLLK8rmytEw Ac6SgRhrL1vvYNwGiQgUQw5uLyJdAafhV9ZC/MKRzgZwh/cpS4DiXk7UCoH+LcGC42Vo w0YSl+7J1tz07c7tlp/DtO/4gJZp24vDwKY9zZrJUk23zYDS2Imk6Ld9/mo9V3XvKigy hmZQjexSIr8lCp2G1sBTvc1PHeX9ujZ97JjK6Q9i/seTRw0YNay6d5POhe8/lpjNzhki a8gw6g8V94lsFmSo6x2x48gARYACkvr+XbNuniAIjzcIcy5ij7TwVMQBC5K85qLkffgY TPbw== 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:dkim-signature :arc-authentication-results; bh=Qkzrhd3Jywk9n4vIlnYYzig0XNlW7qbdK19G+Lgkp6A=; b=jPswRFu9Ny3zTAmqGvAjAwd/b3XxvZVPCXMnMn6uKvo+Gjq9Tkhb/CexkcaniXPWau gTelJqwEMyFgB7R/tdFDsP8ImBvhAViXdqv52TPnTGYW54XXnXoWAaH/CoTklcUJgquv B6c/shG7m+Q93VdZSprGeVgYPbBf+X8n//ywtzPEvgESoJyU0nUjrEQAjKBLkOWK3Pld oj7KLcxnWnViYX9mwCULKrHo3vZvcrrplKs1Ze/wYNDWrCy5YXx7qgB7PwVL+pTdRwFA ehhYvFshyF3r37DQXNJUTRRRa3p1xvgEtO0MTZOPe8Sg+oOnVQRnib+Dx9Z5HRVbHrTq IDxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2SJ32XLe; 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 x23-v6si6913964pfe.318.2018.05.28.04.14.07; Mon, 28 May 2018 04:14:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=2SJ32XLe; 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 S938029AbeE1LNB (ORCPT + 99 others); Mon, 28 May 2018 07:13:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:60604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423949AbeE1LMz (ORCPT ); Mon, 28 May 2018 07:12:55 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 49F4D206B7; Mon, 28 May 2018 11:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505974; bh=m6NNMUTMFa83cJHPg/6pr4lNaDj/Eb8CtG/jzNlwdwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2SJ32XLeGXGP4js5I0HhvimQp4YgsgstfHNnduVHS6a6HYWi5Kfi3ftkA34YEWsVG usuyJWUbdcKtg1B3Q9d5u7N2+ohGndqlc4P4Zh8S7zxVRa34aO+KGZTNpe98X2QGwm zmUWN2TZ2ZT6t2YCZVryqS33fXXIRu63nx51fRhI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Gruenbacher , Bob Peterson , Sasha Levin Subject: [PATCH 4.16 196/272] gfs2: Fix fallocate chunk size Date: Mon, 28 May 2018 12:03:49 +0200 Message-Id: <20180528100257.076003397@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andreas Gruenbacher [ Upstream commit 174d1232ebc84fcde8f5889d1171c9c7e74a10a7 ] The chunk size of allocations in __gfs2_fallocate is calculated incorrectly. The size can collapse, causing __gfs2_fallocate to allocate one block at a time, which is very inefficient. This needs fixing in two places: In gfs2_quota_lock_check, always set ap->allowed to UINT_MAX to indicate that there is no quota limit. This fixes callers that rely on ap->allowed to be set even when quotas are off. In __gfs2_fallocate, reset max_blks to UINT_MAX in each iteration of the loop to make sure that allocation limits from one resource group won't spill over into another resource group. Signed-off-by: Andreas Gruenbacher Signed-off-by: Bob Peterson Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/gfs2/file.c | 5 +++-- fs/gfs2/quota.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -809,7 +809,7 @@ static long __gfs2_fallocate(struct file struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_alloc_parms ap = { .aflags = 0, }; unsigned int data_blocks = 0, ind_blocks = 0, rblocks; - loff_t bytes, max_bytes, max_blks = UINT_MAX; + loff_t bytes, max_bytes, max_blks; int error; const loff_t pos = offset; const loff_t count = len; @@ -861,7 +861,8 @@ static long __gfs2_fallocate(struct file return error; /* ap.allowed tells us how many blocks quota will allow * us to write. Check if this reduces max_blks */ - if (ap.allowed && ap.allowed < max_blks) + max_blks = UINT_MAX; + if (ap.allowed) max_blks = ap.allowed; error = gfs2_inplace_reserve(ip, &ap); --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -45,6 +45,8 @@ static inline int gfs2_quota_lock_check( { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); int ret; + + ap->allowed = UINT_MAX; /* Assume we are permitted a whole lot */ if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) return 0; ret = gfs2_quota_lock(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);