All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Liu <jeff.liu@oracle.com>
To: xfs@oss.sgi.com
Subject: [PATCH 13/15] xfs: Introduce a helper to truncate an AG
Date: Fri, 16 Nov 2012 14:46:50 +0800	[thread overview]
Message-ID: <50A5E15A.90905@oracle.com> (raw)

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

                 reply	other threads:[~2012-11-16  6:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50A5E15A.90905@oracle.com \
    --to=jeff.liu@oracle.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.