Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4489514ivc; Tue, 3 Nov 2020 13:24:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8irkO+/fuzi4ZccDyxlPlgdkzUQw7Db0lbj0MfdZ2Bd/1g6fytxdr22PvGr1OlvgcrfWI X-Received: by 2002:a17:907:c14:: with SMTP id ga20mr15135926ejc.526.1604438656822; Tue, 03 Nov 2020 13:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438656; cv=none; d=google.com; s=arc-20160816; b=pCz9a0zk1vA+qTqZxAP7du/SDJXIDBFbFYofxqQ5tNtv+uWP7/XYXJsU7eD0rPeRee XqcHHiUXYBjiImjbn8z3dx0PW3gvBNKH4S0k3OW0dbPN3O+yXbqYHEHnkpgRqgjwgXR8 Y87D+ftly8rMeB5PmkncE0KToZy34Ft1pCJRecx47YUVyQstAhxx4aWpxY4DrwaGlb48 bmrwfMxuNKucorOT6Pam15dZkRzPY7q3ChdKaM6auhyt7LQ9eZfFEPqpwD8cZOFBLqX7 pkHXWu1EaDQJXDMItSH9LuPe4Ny9sxJtlS2pO12p4++qboHKLboNqOiTcr/7EKSd84Kw WrCQ== 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=93vZNoQXdT4JZQEeuPJX/KsLskDxwTAQZyT312bVfCA=; b=BFt9gaLu0arqZZ9pFMqyp7tTxNY0VOZ0I4SFhtZzKSykoYdiGPVIH8xKybSNk+qlpt xhcV/1qYAJH1UZMbQ2nT8fdEDEpHBsS+jGsNGOOx2kCcKa1zPdGkhSdhS5Bc5XUTSpaG ekRha1B/scui6lN+p7OyiBeJMpFg0L2yttZqKfVviTVCpPMSxqArOA5RH7h0gW64yjJG IFL7dqE2W3jTVkzWXwXDx3ChaaeSrCq0Sd6ONFo85lSGWv2wOlNM+QElssQ9S/6xGTYv U/gyDN8ASKLQH3j7wCjjQSSUL1iBHZfZL1x6spHe2qC+3onBnlrrqWm7zdD8HSsO1+Vk h68Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HEgAbmYm; 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 o60si14175318eda.61.2020.11.03.13.23.53; Tue, 03 Nov 2020 13:24:16 -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=HEgAbmYm; 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 S2388202AbgKCVGl (ORCPT + 99 others); Tue, 3 Nov 2020 16:06:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:45660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388197AbgKCVGj (ORCPT ); Tue, 3 Nov 2020 16:06:39 -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 5DE31205ED; Tue, 3 Nov 2020 21:06:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437598; bh=Dfdhbeiqel2PPFbuFVOTIlPxH709A4ndOr6BQIcowRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEgAbmYmhxMQaxoj1vLrub8M51xJ1TX+17hwjgH1qyq9Tsi8mhcZzcn6WobKIX/1U bR0rGazL0/b4MVCZCN43RIggKIGonCHVy8WV+Dj7G4kS+LTn1Ox20OFMVggTaBNeBc x0N0rXQhHXqNcp0m69izuYqO73glRzUHEdWsJ5b0= 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 4.19 128/191] btrfs: qgroup: fix wrong qgroup metadata reserve for delayed inode Date: Tue, 3 Nov 2020 21:37:00 +0100 Message-Id: <20201103203245.136301717@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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 @@ -620,8 +620,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,