From patchwork Wed Oct 7 04:59:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 7342261 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 440B39F302 for ; Wed, 7 Oct 2015 04:59:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3EBBA20504 for ; Wed, 7 Oct 2015 04:59:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3566E2066D for ; Wed, 7 Oct 2015 04:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753243AbbJGE7t (ORCPT ); Wed, 7 Oct 2015 00:59:49 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:36485 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752998AbbJGE7t (ORCPT ); Wed, 7 Oct 2015 00:59:49 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t974xgb0008387 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 7 Oct 2015 04:59:42 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t974xfaa009612 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 7 Oct 2015 04:59:41 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t974xfN8003821; Wed, 7 Oct 2015 04:59:41 GMT Received: from localhost (/24.21.154.84) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Oct 2015 21:59:41 -0700 Subject: [PATCH 41/58] libxfs: adjust refcount when unmapping file blocks From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: linux-fsdevel@vger.kernel.org, xfs@oss.sgi.com Date: Tue, 06 Oct 2015 21:59:40 -0700 Message-ID: <20151007045940.30457.7139.stgit@birch.djwong.org> In-Reply-To: <20151007045443.30457.47038.stgit@birch.djwong.org> References: <20151007045443.30457.47038.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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=unavailable 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 When we're unmapping blocks from a reflinked file, decrease the refcount of the affected blocks and free the extents that are no longer in use. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 16 +++++++++++++--- fs/xfs/libxfs/xfs_refcount.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_refcount.h | 4 ++++ 3 files changed, 59 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 81f0ae0..f6812ba 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -46,6 +46,7 @@ #include "xfs_attr_leaf.h" #include "xfs_filestream.h" #include "xfs_rmap_btree.h" +#include "xfs_refcount.h" kmem_zone_t *xfs_bmap_free_item_zone; @@ -5182,9 +5183,18 @@ xfs_bmap_del_extent( /* * If we need to, add to list of extents to delete. */ - if (do_fx) - xfs_bmap_add_free(mp, flist, del->br_startblock, - del->br_blockcount, NULL); + if (do_fx) { + if (xfs_is_reflink_inode(ip)) { + error = xfs_refcount_put_extent(mp, tp, flist, + del->br_startblock, + del->br_blockcount, NULL); + if (error) + goto done; + } else + xfs_bmap_add_free(mp, flist, del->br_startblock, + del->br_blockcount, NULL); + } + /* * Adjust inode # blocks in the file. */ diff --git a/fs/xfs/libxfs/xfs_refcount.c b/fs/xfs/libxfs/xfs_refcount.c index 02892bc..bd611d3 100644 --- a/fs/xfs/libxfs/xfs_refcount.c +++ b/fs/xfs/libxfs/xfs_refcount.c @@ -938,3 +938,45 @@ xfs_refcount_decrease( return xfs_refcountbt_adjust_refcount(mp, tp, agbp, agno, agbno, aglen, -1, flist, oinfo); } + +/** + * xfs_refcount_put_extent() - release a range of blocks + * + * @mp: XFS mount object + * @tp: transaction that goes with the free operation + * @flist: List of blocks to be freed at the end of the transaction + * @fsbno: First fs block of the range to release + * @len: Length of range + * @owner: owner of the extent + */ +int +xfs_refcount_put_extent( + struct xfs_mount *mp, + struct xfs_trans *tp, + struct xfs_bmap_free *flist, + xfs_fsblock_t fsbno, + xfs_filblks_t fslen, + struct xfs_owner_info *oinfo) +{ + int error; + struct xfs_buf *agbp; + xfs_agnumber_t agno; /* allocation group number */ + xfs_agblock_t agbno; /* ag start of range to free */ + xfs_extlen_t aglen; /* ag length of range to free */ + + agno = XFS_FSB_TO_AGNO(mp, fsbno); + agbno = XFS_FSB_TO_AGBNO(mp, fsbno); + aglen = fslen; + + /* + * Drop reference counts in the refcount tree. + */ + error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp); + if (error) + return error; + + error = xfs_refcount_decrease(mp, tp, agbp, agno, agbno, aglen, flist, + oinfo); + xfs_trans_brelse(tp, agbp); + return error; +} diff --git a/fs/xfs/libxfs/xfs_refcount.h b/fs/xfs/libxfs/xfs_refcount.h index 6640e3d..074d620 100644 --- a/fs/xfs/libxfs/xfs_refcount.h +++ b/fs/xfs/libxfs/xfs_refcount.h @@ -34,4 +34,8 @@ extern int xfs_refcount_decrease(struct xfs_mount *mp, struct xfs_trans *tp, xfs_extlen_t aglen, struct xfs_bmap_free *flist, struct xfs_owner_info *oinfo); +extern int xfs_refcount_put_extent(struct xfs_mount *mp, struct xfs_trans *tp, + struct xfs_bmap_free *flist, xfs_fsblock_t fsbno, + xfs_filblks_t len, struct xfs_owner_info *oinfo); + #endif /* __XFS_REFCOUNT_H__ */