From patchwork Tue Jun 28 01:57:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9201685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96924607D3 for ; Tue, 28 Jun 2016 01:57:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87DFB285D7 for ; Tue, 28 Jun 2016 01:57:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CA51285DC; Tue, 28 Jun 2016 01:57:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FF8E285D7 for ; Tue, 28 Jun 2016 01:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752074AbcF1B5x (ORCPT ); Mon, 27 Jun 2016 21:57:53 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:57877 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752054AbcF1B5w (ORCPT ); Mon, 27 Jun 2016 21:57:52 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="647014" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 28 Jun 2016 09:57:50 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id B3F90413CA1C for ; Tue, 28 Jun 2016 09:57:47 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs: Fix leaking bytes_may_use after hitting EDQUOTA Date: Tue, 28 Jun 2016 09:57:29 +0800 Message-Id: <20160628015729.14624-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-yoursite-MailScanner-ID: B3F90413CA1C.AE823 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If one mount btrfs with enospc_debug mount option and hit qgroup limits in btrfs_check_data_free_space(), then at unmount time, kernel warning will be triggered alone with a data space info dump. ------ ------------[ cut here ]------------ WARNING: CPU: 0 PID: 3875 at fs/btrfs/extent-tree.c:9785 btrfs_free_block_groups+0x2b8/0x460 [btrfs] Modules linked in: btrfs ext4 jbd2 mbcache xor zlib_deflate raid6_pq xfs [last unloaded: btrfs] CPU: 0 PID: 3875 Comm: umount Tainted: G W 4.7.0-rc4+ #13 Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 0000000000000000 ffff8800230a7d00 ffffffff813b89e5 0000000000000000 0000000000000000 ffff8800230a7d40 ffffffff810c9b8b 00002639230a7d50 ffff88003d523a78 ffff88003d523b80 ffff88000d1c0000 ffff88000d1c00c8 Call Trace: [] dump_stack+0x67/0x92 [] __warn+0xcb/0xf0 [] warn_slowpath_null+0x1d/0x20 [] btrfs_free_block_groups+0x2b8/0x460 [btrfs] [] close_ctree+0x173/0x350 [btrfs] [] btrfs_put_super+0x19/0x20 [btrfs] [] generic_shutdown_super+0x6a/0xf0 [] kill_anon_super+0x12/0x20 [] btrfs_kill_super+0x18/0x110 [btrfs] [] deactivate_locked_super+0x3e/0x70 [] deactivate_super+0x5c/0x60 [] cleanup_mnt+0x3f/0x90 [] __cleanup_mnt+0x12/0x20 [] task_work_run+0x81/0xc0 [] exit_to_usermode_loop+0xb3/0xc0 [] syscall_return_slowpath+0xb0/0xc0 [] entry_SYSCALL_64_fastpath+0xa6/0xa8 ---[ end trace 99b9af8484495c66 ]--- BTRFS: space_info 1 has 8044544 free, is not full BTRFS: space_info total=8388608, used=344064, pinned=0, reserved=0, may_use=409600, readonly=0 ------ The problem is in btrfs_check_data_free_space(), we reserve data space first and then reserve qgroup space. However if qgroup reserve failed, we didn't cleanup reserved data space, which leads to the kernel warning. Fix it by freeing reserved data space when qgroup_reserve_data() fails. Signed-off-by: Qu Wenruo --- fs/btrfs/extent-tree.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 29e5d00..e349da0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4265,6 +4265,9 @@ int btrfs_check_data_free_space(struct inode *inode, u64 start, u64 len) * range, but don't impact performance on quota disable case. */ ret = btrfs_qgroup_reserve_data(inode, start, len); + if (ret < 0) + /* Qgroup reserve failed, need to cleanup reserved data space */ + btrfs_free_reserved_data_space(inode, start, len); return ret; }