提交 bab98bbe 编写于 作者: D Dave Chinner 提交者: Dave Chinner

xfs: introduce xfs_mod_frextents

Add a new helper to modify the incore counter of free realtime
extents. This matches the helpers used for inode and data block
counters, and removes a significant users of the xfs_mod_incore_sb()
interface.

Based on a patch originally from Christoph Hellwig.
Signed-off-by: NDave Chinner <dchinner@redhat.com>
Reviewed-by: NBrian Foster <bfoster@redhat.com>
Signed-off-by: NDave Chinner <david@fromorbit.com>
上级 5681ca40
...@@ -4158,8 +4158,7 @@ xfs_bmapi_reserve_delalloc( ...@@ -4158,8 +4158,7 @@ xfs_bmapi_reserve_delalloc(
ASSERT(indlen > 0); ASSERT(indlen > 0);
if (rt) { if (rt) {
error = xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, error = xfs_mod_frextents(mp, -((int64_t)extsz));
-((int64_t)extsz), 0);
} else { } else {
error = xfs_mod_fdblocks(mp, -((int64_t)alen), false); error = xfs_mod_fdblocks(mp, -((int64_t)alen), false);
} }
...@@ -4194,7 +4193,7 @@ xfs_bmapi_reserve_delalloc( ...@@ -4194,7 +4193,7 @@ xfs_bmapi_reserve_delalloc(
out_unreserve_blocks: out_unreserve_blocks:
if (rt) if (rt)
xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, extsz, 0); xfs_mod_frextents(mp, extsz);
else else
xfs_mod_fdblocks(mp, alen, false); xfs_mod_fdblocks(mp, alen, false);
out_unreserve_quota: out_unreserve_quota:
...@@ -5278,8 +5277,7 @@ xfs_bunmapi( ...@@ -5278,8 +5277,7 @@ xfs_bunmapi(
rtexts = XFS_FSB_TO_B(mp, del.br_blockcount); rtexts = XFS_FSB_TO_B(mp, del.br_blockcount);
do_div(rtexts, mp->m_sb.sb_rextsize); do_div(rtexts, mp->m_sb.sb_rextsize);
xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, xfs_mod_frextents(mp, (int64_t)rtexts);
(int64_t)rtexts, 0);
(void)xfs_trans_reserve_quota_nblks(NULL, (void)xfs_trans_reserve_quota_nblks(NULL,
ip, -((long)del.br_blockcount), 0, ip, -((long)del.br_blockcount), 0,
XFS_QMOPT_RES_RTBLKS); XFS_QMOPT_RES_RTBLKS);
......
...@@ -1198,6 +1198,24 @@ xfs_mod_fdblocks( ...@@ -1198,6 +1198,24 @@ xfs_mod_fdblocks(
return -ENOSPC; return -ENOSPC;
} }
int
xfs_mod_frextents(
struct xfs_mount *mp,
int64_t delta)
{
int64_t lcounter;
int ret = 0;
spin_lock(&mp->m_sb_lock);
lcounter = mp->m_sb.sb_frextents + delta;
if (lcounter < 0)
ret = -ENOSPC;
else
mp->m_sb.sb_frextents = lcounter;
spin_unlock(&mp->m_sb_lock);
return ret;
}
/* /*
* xfs_mod_incore_sb_unlocked() is a utility routine commonly used to apply * xfs_mod_incore_sb_unlocked() is a utility routine commonly used to apply
* a delta to a specified field in the in-core superblock. Simply * a delta to a specified field in the in-core superblock. Simply
...@@ -1227,16 +1245,9 @@ xfs_mod_incore_sb_unlocked( ...@@ -1227,16 +1245,9 @@ xfs_mod_incore_sb_unlocked(
case XFS_SBS_ICOUNT: case XFS_SBS_ICOUNT:
case XFS_SBS_IFREE: case XFS_SBS_IFREE:
case XFS_SBS_FDBLOCKS: case XFS_SBS_FDBLOCKS:
case XFS_SBS_FREXTENTS:
ASSERT(0); ASSERT(0);
return -EINVAL; return -EINVAL;
case XFS_SBS_FREXTENTS:
lcounter = (long long)mp->m_sb.sb_frextents;
lcounter += delta;
if (lcounter < 0) {
return -ENOSPC;
}
mp->m_sb.sb_frextents = lcounter;
return 0;
case XFS_SBS_DBLOCKS: case XFS_SBS_DBLOCKS:
lcounter = (long long)mp->m_sb.sb_dblocks; lcounter = (long long)mp->m_sb.sb_dblocks;
lcounter += delta; lcounter += delta;
......
...@@ -331,6 +331,8 @@ extern int xfs_mod_icount(struct xfs_mount *mp, int64_t delta); ...@@ -331,6 +331,8 @@ extern int xfs_mod_icount(struct xfs_mount *mp, int64_t delta);
extern int xfs_mod_ifree(struct xfs_mount *mp, int64_t delta); extern int xfs_mod_ifree(struct xfs_mount *mp, int64_t delta);
extern int xfs_mod_fdblocks(struct xfs_mount *mp, int64_t delta, extern int xfs_mod_fdblocks(struct xfs_mount *mp, int64_t delta,
bool reserved); bool reserved);
extern int xfs_mod_frextents(struct xfs_mount *mp, int64_t delta);
extern int xfs_mount_log_sb(xfs_mount_t *); extern int xfs_mount_log_sb(xfs_mount_t *);
extern struct xfs_buf *xfs_getsb(xfs_mount_t *, int); extern struct xfs_buf *xfs_getsb(xfs_mount_t *, int);
extern int xfs_readsb(xfs_mount_t *, int); extern int xfs_readsb(xfs_mount_t *, int);
......
...@@ -235,8 +235,7 @@ xfs_trans_reserve( ...@@ -235,8 +235,7 @@ xfs_trans_reserve(
* fail if the count would go below zero. * fail if the count would go below zero.
*/ */
if (rtextents > 0) { if (rtextents > 0) {
error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS, error = xfs_mod_frextents(tp->t_mountp, -((int64_t)rtextents));
-((int64_t)rtextents), rsvd);
if (error) { if (error) {
error = -ENOSPC; error = -ENOSPC;
goto undo_log; goto undo_log;
...@@ -562,10 +561,10 @@ xfs_trans_unreserve_and_mod_sb( ...@@ -562,10 +561,10 @@ xfs_trans_unreserve_and_mod_sb(
} }
/* apply remaining deltas */ /* apply remaining deltas */
if (rtxdelta != 0) { if (rtxdelta) {
msbp->msb_field = XFS_SBS_FREXTENTS; error = xfs_mod_frextents(mp, rtxdelta);
msbp->msb_delta = rtxdelta; if (error)
msbp++; goto out_undo_ifree;
} }
if (tp->t_flags & XFS_TRANS_SB_DIRTY) { if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
...@@ -618,12 +617,15 @@ xfs_trans_unreserve_and_mod_sb( ...@@ -618,12 +617,15 @@ xfs_trans_unreserve_and_mod_sb(
error = xfs_mod_incore_sb_batch(tp->t_mountp, msb, error = xfs_mod_incore_sb_batch(tp->t_mountp, msb,
(uint)(msbp - msb), rsvd); (uint)(msbp - msb), rsvd);
if (error) if (error)
goto out_undo_ifreecount; goto out_undo_frextents;
} }
return; return;
out_undo_ifreecount: out_undo_frextents:
if (rtxdelta)
xfs_mod_frextents(mp, -rtxdelta);
out_undo_ifree:
if (ifreedelta) if (ifreedelta)
xfs_mod_ifree(mp, -ifreedelta); xfs_mod_ifree(mp, -ifreedelta);
out_undo_icount: out_undo_icount:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册