From patchwork Tue Sep 1 00:31:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 7109171 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 15EB4BEEC1 for ; Wed, 2 Sep 2015 07:51:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2AC0C20631 for ; Wed, 2 Sep 2015 07:51:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31ED420647 for ; Wed, 2 Sep 2015 07:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752972AbbIBHvo (ORCPT ); Wed, 2 Sep 2015 03:51:44 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:33805 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752814AbbIBHv0 (ORCPT ); Wed, 2 Sep 2015 03:51:26 -0400 Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 01 Sep 2015 08:32:51 +0800 Received: from localhost.localdomain (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t810XlIl023763 for ; Tue, 1 Sep 2015 08:33:58 +0800 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH RFC 08/14] btrfs: qgroup: Introduce function to release/free reserved data range Date: Tue, 1 Sep 2015 08:31:48 +0800 Message-Id: <1441067515-21105-9-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1441067515-21105-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1441067515-21105-1-git-send-email-quwenruo@cn.fujitsu.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce functions btrfs_qgroup_release/free_data() to release/free reserved data range. Release means, just remove the data range from data rsv map, but doesn't free the reserved space. Free means not only remove data range, but also free reserved space. Signed-off-by: Qu Wenruo --- fs/btrfs/qgroup.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/qgroup.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index eee07c2..7ccbd4c 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2941,6 +2941,52 @@ next: return 0; } +static int __btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len, + int free_reserved) +{ + struct data_rsv_range *tmp; + struct btrfs_qgroup_data_rsv_map *map; + u64 reserved = 0; + int ret; + + spin_lock(&BTRFS_I(inode)->qgroup_init_lock); + map = BTRFS_I(inode)->qgroup_rsv_map; + spin_unlock(&BTRFS_I(inode)->qgroup_init_lock); + if (!map) + return 0; + + tmp = kmalloc(sizeof(*tmp), GFP_NOFS); + if (!tmp) + return -ENOMEM; + ret = release_data_range(map, tmp, start, len, &reserved); + /* release_data_range() won't fail only check if memory is used */ + if (ret == 0) + kfree(tmp); + if (free_reserved) + btrfs_qgroup_free(BTRFS_I(inode)->root, reserved); + return 0; +} + +/* + * Caller should be truncate/invalidate_page. + * As it will release the reserved data. + */ +int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len) +{ + return __btrfs_qgroup_release_data(inode, start, len, 1); +} + +/* + * Caller should be finish_ordered_io + * As qgroup accouting happens at commit time, for data written to disk + * its reserved space should not be freed until commit. + * Or we may beyond the limit. + */ +int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len) +{ + return __btrfs_qgroup_release_data(inode, start, len, 0); +} + /* * Init data_rsv_map for a given inode. * diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h index 366b853..8e69dc1 100644 --- a/fs/btrfs/qgroup.h +++ b/fs/btrfs/qgroup.h @@ -88,4 +88,6 @@ int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid, int btrfs_qgroup_init_data_rsv_map(struct inode *inode); void btrfs_qgroup_free_data_rsv_map(struct inode *inode); int btrfs_qgroup_reserve_data(struct inode *inode, u64 start, u64 len); +int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len); +int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len); #endif /* __BTRFS_QGROUP__ */