* [PATCH 13/15] xfs: Introduce a helper to truncate an AG
@ 2012-11-16 6:46 Jeff Liu
0 siblings, 0 replies; only message in thread
From: Jeff Liu @ 2012-11-16 6:46 UTC (permalink / raw)
To: xfs
During FS shrinking, if an affected AG is not empty, we need to truncate it accordingly.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
fs/xfs/xfs_fsops.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 94 insertions(+), 0 deletions(-)
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 24de23f..04a21d1 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -855,6 +855,100 @@ error0:
}
/*
+ * Truncate the given AG and update the metadatas accordingly.
+ */
+static int
+xfs_truncate_ag(
+ xfs_mount_t *mp,
+ xfs_agnumber_t agno,
+ xfs_rfsblock_t tsize,
+ xfs_extlen_t *nfree)
+{
+ xfs_agf_t *agf;
+ xfs_agi_t *agi;
+ xfs_buf_t *bp;
+ xfs_perag_t *pag;
+ xfs_alloc_rec_t *arec;
+ __uint32_t bno_btree_blkno;
+ __uint32_t cnt_btree_blkno;
+ struct xfs_btree_block *block;
+ int error;
+
+ bp = xfs_buf_get(mp->m_ddev_targp,
+ XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
+ XFS_FSS_TO_BB(mp, 1), 0);
+ if (!bp) {
+ error = ENOMEM;
+ goto error0;
+ }
+ agf = XFS_BUF_TO_AGF(bp);
+ be32_add_cpu(&agf->agf_length, -tsize);
+ be32_add_cpu(&agf->agf_freeblks, -tsize);
+ agf->agf_longest = agf->agf_freeblks;
+ bno_btree_blkno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_BNOi]);
+ cnt_btree_blkno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNTi]);
+ error = xfs_bwrite(bp);
+ xfs_buf_relse(bp);
+ if (error)
+ goto error0;
+
+ bp = xfs_buf_get(mp->m_ddev_targp,
+ XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
+ XFS_FSS_TO_BB(mp, 1), 0);
+ if (!bp) {
+ error = ENOMEM;
+ goto error0;
+ }
+ agi = XFS_BUF_TO_AGI(bp);
+ be32_add_cpu(&agi->agi_length, -tsize);
+ error = xfs_bwrite(bp);
+ xfs_buf_relse(bp);
+ if (error)
+ goto error0;
+
+ bp = xfs_buf_get(mp->m_ddev_targp,
+ XFS_AGB_TO_DADDR(mp, agno, bno_btree_blkno),
+ BTOBB(mp->m_sb.sb_blocksize), 0);
+ if (!bp) {
+ error = ENOMEM;
+ goto error0;
+ }
+ block = XFS_BUF_TO_BLOCK(bp);
+ arec = XFS_ALLOC_REC_ADDR(mp, block, 1);
+ be32_add_cpu(&arec->ar_blockcount, -tsize);
+ error = xfs_bwrite(bp);
+ xfs_buf_relse(bp);
+ if (error)
+ goto error0;
+
+ bp = xfs_buf_get(mp->m_ddev_targp,
+ XFS_AGB_TO_DADDR(mp, agno, cnt_btree_blkno),
+ BTOBB(mp->m_sb.sb_blocksize), 0);
+ if (!bp) {
+ error = ENOMEM;
+ goto error0;
+ }
+ block = XFS_BUF_TO_BLOCK(bp);
+ arec = XFS_ALLOC_REC_ADDR(mp, block, 1);
+ be32_add_cpu(&arec->ar_blockcount, -tsize);
+ error = xfs_bwrite(bp);
+ xfs_buf_relse(bp);
+ if (error)
+ goto error0;
+
+ pag = xfs_perag_get(mp, agno);
+ pag->pagf_freeblks -= tsize;
+ pag->pagf_longest = pag->pagf_freeblks;
+ xfs_perag_put(pag);
+
+ if (nfree)
+ *nfree = tsize;
+
+error0:
+ return error;
+}
+
+/*
* exported through ioctl XFS_IOC_FSCOUNTS
*/
--
1.7.4.1
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-11-16 6:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-16 6:46 [PATCH 13/15] xfs: Introduce a helper to truncate an AG Jeff Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.