Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp825322pxb; Tue, 3 Nov 2020 13:37:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2F3/5iImBkW3sNQzc8txD7y/AhhOEe5hVJhV4LVgTjP+tpryttYFfzJWhozvgV2LL8f8y X-Received: by 2002:a05:6402:1218:: with SMTP id c24mr4908761edw.259.1604439420348; Tue, 03 Nov 2020 13:37:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439420; cv=none; d=google.com; s=arc-20160816; b=tfVuDqTiyTIfEs8pbRUTsm3uC8Dgw8SPL5LGMNmf50yEAkIqj0gsHih62yB6d/l7Tp 1wSHvdV2v20UtdxJ53Kq3M5dOW2GsP7z7e7Spwv+7u97u8PNFsRwHjQ+90f2XIoP6B5m Ppv8oSTzFQrxlqDM4In2wh8T5Rhb/hsI6vcxXMxyC/djIM3xwfjWE738qqY865bLsQcH KsqRi344wCqwqayGMOKPrREbp63pqtsGYgx/0cODHGDmSiGqvpybDLKlPhndQu8f15uZ 8w7yv3WexxOjg4DD5iOhKkumJKQv+PrlV24r9m5imkauf/SocfnSYHY63YrpIg3Rs3Pw e+Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4dX8Wap9+yA0gulpYy31yX9Avn62SS4ofu327UgNBR8=; b=puwJ20Jvf8kF+4aV4oiHWXeY+0URvSlSjhWKFiIDb385U+1cPbYAvAwAHollQinJw9 nHY9M15+ZYG5wfe2zKg6d7H6kHBcJySTG+ROJx+LmFksvSFSZOniqi/M//mLD33xTKyu y6qxUmcIps2240x+3PYQsyAouYb9/1dkxYcOuvEoshxn6dRgvCi+9Sj4Fifyci6Vr2uN 9797bqXORO3I7yfsGOxLyMT7HnBF1rubFQ8T4MD03Rkfdaht104AHSVHk9mRpOXqHxtb w7DrMqkH/xEEcCjaVsvM0A2WpHvHcmSUMlbYPDVvEWs2HHRUaFgEFKb2M9tqjUm3eDj2 AIYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=maZcqnYj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si12007103edc.106.2020.11.03.13.36.37; Tue, 03 Nov 2020 13:37:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=maZcqnYj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732922AbgKCVcH (ORCPT + 99 others); Tue, 3 Nov 2020 16:32:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:59620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732023AbgKCU5W (ORCPT ); Tue, 3 Nov 2020 15:57:22 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 28C5222226; Tue, 3 Nov 2020 20:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437041; bh=V1ebKRZILqhuVkapQZVuUtsopgzgh0nAYU7+1qLih9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=maZcqnYjJP9ZxmY3cdUUXIqspi3fw9TQbKbsY1yoRl7swY4MufKEmPdBv4NgTAPdi uDFN1VUjVc4Ok862UQd3szg83cjiAV96W91opkdRhds12XQh1+KfRfb4sy17X5lzyu 61hjCHtj61OpvdPb/k0TUbLKMIvuamAsvnxNaLAw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Qu Wenruo , David Sterba Subject: [PATCH 5.4 122/214] btrfs: qgroup: fix wrong qgroup metadata reserve for delayed inode Date: Tue, 3 Nov 2020 21:36:10 +0100 Message-Id: <20201103203302.294976395@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit b4c5d8fdfff3e2b6c4fa4a5043e8946dff500f8c upstream. For delayed inode facility, qgroup metadata is reserved for it, and later freed. However we're freeing more bytes than we reserved. In btrfs_delayed_inode_reserve_metadata(): num_bytes = btrfs_calc_metadata_size(fs_info, 1); ... ret = btrfs_qgroup_reserve_meta_prealloc(root, fs_info->nodesize, true); ... if (!ret) { node->bytes_reserved = num_bytes; But in btrfs_delayed_inode_release_metadata(): if (qgroup_free) btrfs_qgroup_free_meta_prealloc(node->root, node->bytes_reserved); else btrfs_qgroup_convert_reserved_meta(node->root, node->bytes_reserved); This means, we're always releasing more qgroup metadata rsv than we have reserved. This won't trigger selftest warning, as btrfs qgroup metadata rsv has extra protection against cases like quota enabled half-way. But we still need to fix this problem any way. This patch will use the same num_bytes for qgroup metadata rsv so we could handle it correctly. Fixes: f218ea6c4792 ("btrfs: delayed-inode: Remove wrong qgroup meta reservation calls") CC: stable@vger.kernel.org # 4.19+ Reviewed-by: Josef Bacik Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/delayed-inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -627,8 +627,7 @@ static int btrfs_delayed_inode_reserve_m */ if (!src_rsv || (!trans->bytes_reserved && src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) { - ret = btrfs_qgroup_reserve_meta_prealloc(root, - fs_info->nodesize, true); + ret = btrfs_qgroup_reserve_meta_prealloc(root, num_bytes, true); if (ret < 0) return ret; ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes,