Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658047pxa; Mon, 17 Aug 2020 15:44:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTx+37LQJD0HukymbVDgp96Ylx8MGucryS1PPmDmXTS8qYWiWCq8LbFszml5ssV53ZWToC X-Received: by 2002:a17:906:2a04:: with SMTP id j4mr18166102eje.440.1597704279886; Mon, 17 Aug 2020 15:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704279; cv=none; d=google.com; s=arc-20160816; b=P9yjQL291NWF9hnvnxHO0gv1gOMQph6gXxnMqVaOuxM0o3agzRnc2zlwnTk2L7EOui ayx9JH86uAsZ5wVQXGTePMjbrqaFSuozvztiLkEp3um0+jUjwphdBfh7/w41kEB6XmeU Jejz2WWfQON9ZTrf7qEIR+XRnFyFhhwkG/2QeKc4zuarY5EAL6ab8Witzs353wyTdPAQ wio4vMn+/INfKawR89lH0Uvt/ogvb8OVFJJ0AeQC8aNSTp4dfxsHJV3InWB5G7Rbpx/h asNx+cq8mpZ1UsDCpEM6spgm5va7ZV4LWqWUZO4sXTt94kA0Mg8IkLk94ArF2gyQiIKA p/Xw== 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=rAdG4jzX9LWW+aPoQSv66Ls+f57+FymaL0rNfxforhQ=; b=Z4BtktsSPnojfQmrhz4yTMK3xcqUo4lvYvdO8uddwfwCvTaGiaX+I+N9zQh9umroAr jFbQUkzs7OqW5RGIe+/scBa+1asGrWCzzUgQu+GdevcDrNwEzXez14uOffQvYrbv5X/p 54a/FJag9LDqX+Xq4eQV5rsAGpjEYGoJjNTNXK0g7HIAIVrb3xlvCBQZeICkgwR45vrI pHaLehdCOb1HdXdUWCB4a1v9hTF31MUAJb3+Wg4SgKHd+4wtD65UlP2uVqSDt7oyhpl5 cCSV/WQmVjEjpa7yZqMcIx2/T92gxK+BH472G/Oypdjbz67HLYD9zAL3A3LpVrvhzhHS 0bzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=etTDDH1B; 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 bq8si2002634ejb.282.2020.08.17.15.44.16; Mon, 17 Aug 2020 15:44:39 -0700 (PDT) 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=etTDDH1B; 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 S2391973AbgHQTEO (ORCPT + 99 others); Mon, 17 Aug 2020 15:04:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:57582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730782AbgHQPqA (ORCPT ); Mon, 17 Aug 2020 11:46:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 A6AF32053B; Mon, 17 Aug 2020 15:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679160; bh=NO3oy/wruuatyoM2SL5QX6vE66eKC3Mwl2gmVVYSpjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=etTDDH1BDX+Hod2ZljGuzgY+vrFcrSyM2KuuS+xpo0scAQsCs687LqGw1jGKJ+wSN tZWGT8sj9dllssn4ykwEObd3vJh8irkp7zbUNN/r+r9o1x3AeDuKh803Rsqy/8+rIx cfBn9myCopc45G3I4ROExD7YiZlpj1YbrveJIW90= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 5.7 116/393] btrfs: qgroup: free per-trans reserved space when a subvolume gets dropped Date: Mon, 17 Aug 2020 17:12:46 +0200 Message-Id: <20200817143825.244620908@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Qu Wenruo [ Upstream commit a3cf0e4342b6af9e6b34a4b913c630fbd03a82ea ] [BUG] Sometime fsstress could lead to qgroup warning for case like generic/013: BTRFS warning (device dm-3): qgroup 0/259 has unreleased space, type 1 rsv 81920 ------------[ cut here ]------------ WARNING: CPU: 9 PID: 24535 at fs/btrfs/disk-io.c:4142 close_ctree+0x1dc/0x323 [btrfs] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 RIP: 0010:close_ctree+0x1dc/0x323 [btrfs] Call Trace: btrfs_put_super+0x15/0x17 [btrfs] generic_shutdown_super+0x72/0x110 kill_anon_super+0x18/0x30 btrfs_kill_super+0x17/0x30 [btrfs] deactivate_locked_super+0x3b/0xa0 deactivate_super+0x40/0x50 cleanup_mnt+0x135/0x190 __cleanup_mnt+0x12/0x20 task_work_run+0x64/0xb0 __prepare_exit_to_usermode+0x1bc/0x1c0 __syscall_return_slowpath+0x47/0x230 do_syscall_64+0x64/0xb0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 ---[ end trace 6c341cdf9b6cc3c1 ]--- BTRFS error (device dm-3): qgroup reserved space leaked While that subvolume 259 is no longer in that filesystem. [CAUSE] Normally per-trans qgroup reserved space is freed when a transaction is committed, in commit_fs_roots(). However for completely dropped subvolume, that subvolume is completely gone, thus is no longer in the fs_roots_radix, and its per-trans reserved qgroup will never be freed. Since the subvolume is already gone, leaked per-trans space won't cause any trouble for end users. [FIX] Just call btrfs_qgroup_free_meta_all_pertrans() before a subvolume is completely dropped. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/extent-tree.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 54a64d1e18c6b..7c86188b33d43 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5481,6 +5481,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc) } } + /* + * This subvolume is going to be completely dropped, and won't be + * recorded as dirty roots, thus pertrans meta rsv will not be freed at + * commit transaction time. So free it here manually. + */ + btrfs_qgroup_convert_reserved_meta(root, INT_MAX); + btrfs_qgroup_free_meta_all_pertrans(root); + if (test_bit(BTRFS_ROOT_IN_RADIX, &root->state)) btrfs_add_dropped_root(trans, root); else -- 2.25.1