diff options
author | Dave Chinner <dchinner@redhat.com> | 2015-02-23 05:22:54 -0500 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2015-02-23 05:22:54 -0500 |
commit | bab98bbe6e1e38bf2fa5018a195608553095f51b (patch) | |
tree | 7d22e47227132f29ad6f9d7e116d1e4eabfca04f /fs/xfs | |
parent | 5681ca40064fdb3efe477a604d690ab0425708b3 (diff) |
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: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r-- | fs/xfs/libxfs/xfs_bmap.c | 8 | ||||
-rw-r--r-- | fs/xfs/xfs_mount.c | 27 | ||||
-rw-r--r-- | fs/xfs/xfs_mount.h | 2 | ||||
-rw-r--r-- | fs/xfs/xfs_trans.c | 18 |
4 files changed, 34 insertions, 21 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index e39c9e83670e..b8e97fd0bac1 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c | |||
@@ -4158,8 +4158,7 @@ xfs_bmapi_reserve_delalloc( | |||
4158 | ASSERT(indlen > 0); | 4158 | ASSERT(indlen > 0); |
4159 | 4159 | ||
4160 | if (rt) { | 4160 | if (rt) { |
4161 | error = xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, | 4161 | error = xfs_mod_frextents(mp, -((int64_t)extsz)); |
4162 | -((int64_t)extsz), 0); | ||
4163 | } else { | 4162 | } else { |
4164 | error = xfs_mod_fdblocks(mp, -((int64_t)alen), false); | 4163 | error = xfs_mod_fdblocks(mp, -((int64_t)alen), false); |
4165 | } | 4164 | } |
@@ -4194,7 +4193,7 @@ xfs_bmapi_reserve_delalloc( | |||
4194 | 4193 | ||
4195 | out_unreserve_blocks: | 4194 | out_unreserve_blocks: |
4196 | if (rt) | 4195 | if (rt) |
4197 | xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, extsz, 0); | 4196 | xfs_mod_frextents(mp, extsz); |
4198 | else | 4197 | else |
4199 | xfs_mod_fdblocks(mp, alen, false); | 4198 | xfs_mod_fdblocks(mp, alen, false); |
4200 | out_unreserve_quota: | 4199 | out_unreserve_quota: |
@@ -5278,8 +5277,7 @@ xfs_bunmapi( | |||
5278 | 5277 | ||
5279 | rtexts = XFS_FSB_TO_B(mp, del.br_blockcount); | 5278 | rtexts = XFS_FSB_TO_B(mp, del.br_blockcount); |
5280 | do_div(rtexts, mp->m_sb.sb_rextsize); | 5279 | do_div(rtexts, mp->m_sb.sb_rextsize); |
5281 | xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, | 5280 | xfs_mod_frextents(mp, (int64_t)rtexts); |
5282 | (int64_t)rtexts, 0); | ||
5283 | (void)xfs_trans_reserve_quota_nblks(NULL, | 5281 | (void)xfs_trans_reserve_quota_nblks(NULL, |
5284 | ip, -((long)del.br_blockcount), 0, | 5282 | ip, -((long)del.br_blockcount), 0, |
5285 | XFS_QMOPT_RES_RTBLKS); | 5283 | XFS_QMOPT_RES_RTBLKS); |
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 05b392e35e35..df4c32fdc706 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c | |||
@@ -1198,6 +1198,24 @@ fdblocks_enospc: | |||
1198 | return -ENOSPC; | 1198 | return -ENOSPC; |
1199 | } | 1199 | } |
1200 | 1200 | ||
1201 | int | ||
1202 | xfs_mod_frextents( | ||
1203 | struct xfs_mount *mp, | ||
1204 | int64_t delta) | ||
1205 | { | ||
1206 | int64_t lcounter; | ||
1207 | int ret = 0; | ||
1208 | |||
1209 | spin_lock(&mp->m_sb_lock); | ||
1210 | lcounter = mp->m_sb.sb_frextents + delta; | ||
1211 | if (lcounter < 0) | ||
1212 | ret = -ENOSPC; | ||
1213 | else | ||
1214 | mp->m_sb.sb_frextents = lcounter; | ||
1215 | spin_unlock(&mp->m_sb_lock); | ||
1216 | return ret; | ||
1217 | } | ||
1218 | |||
1201 | /* | 1219 | /* |
1202 | * xfs_mod_incore_sb_unlocked() is a utility routine commonly used to apply | 1220 | * xfs_mod_incore_sb_unlocked() is a utility routine commonly used to apply |
1203 | * a delta to a specified field in the in-core superblock. Simply | 1221 | * a delta to a specified field in the in-core superblock. Simply |
@@ -1227,16 +1245,9 @@ xfs_mod_incore_sb_unlocked( | |||
1227 | case XFS_SBS_ICOUNT: | 1245 | case XFS_SBS_ICOUNT: |
1228 | case XFS_SBS_IFREE: | 1246 | case XFS_SBS_IFREE: |
1229 | case XFS_SBS_FDBLOCKS: | 1247 | case XFS_SBS_FDBLOCKS: |
1248 | case XFS_SBS_FREXTENTS: | ||
1230 | ASSERT(0); | 1249 | ASSERT(0); |
1231 | return -EINVAL; | 1250 | return -EINVAL; |
1232 | case XFS_SBS_FREXTENTS: | ||
1233 | lcounter = (long long)mp->m_sb.sb_frextents; | ||
1234 | lcounter += delta; | ||
1235 | if (lcounter < 0) { | ||
1236 | return -ENOSPC; | ||
1237 | } | ||
1238 | mp->m_sb.sb_frextents = lcounter; | ||
1239 | return 0; | ||
1240 | case XFS_SBS_DBLOCKS: | 1251 | case XFS_SBS_DBLOCKS: |
1241 | lcounter = (long long)mp->m_sb.sb_dblocks; | 1252 | lcounter = (long long)mp->m_sb.sb_dblocks; |
1242 | lcounter += delta; | 1253 | lcounter += delta; |
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 205f23a240a7..d65e0f23b847 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h | |||
@@ -331,6 +331,8 @@ extern int xfs_mod_icount(struct xfs_mount *mp, int64_t delta); | |||
331 | extern int xfs_mod_ifree(struct xfs_mount *mp, int64_t delta); | 331 | extern int xfs_mod_ifree(struct xfs_mount *mp, int64_t delta); |
332 | extern int xfs_mod_fdblocks(struct xfs_mount *mp, int64_t delta, | 332 | extern int xfs_mod_fdblocks(struct xfs_mount *mp, int64_t delta, |
333 | bool reserved); | 333 | bool reserved); |
334 | extern int xfs_mod_frextents(struct xfs_mount *mp, int64_t delta); | ||
335 | |||
334 | extern int xfs_mount_log_sb(xfs_mount_t *); | 336 | extern int xfs_mount_log_sb(xfs_mount_t *); |
335 | extern struct xfs_buf *xfs_getsb(xfs_mount_t *, int); | 337 | extern struct xfs_buf *xfs_getsb(xfs_mount_t *, int); |
336 | extern int xfs_readsb(xfs_mount_t *, int); | 338 | extern int xfs_readsb(xfs_mount_t *, int); |
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index e99f5e552c64..4e4bc5aed6b6 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c | |||
@@ -235,8 +235,7 @@ xfs_trans_reserve( | |||
235 | * fail if the count would go below zero. | 235 | * fail if the count would go below zero. |
236 | */ | 236 | */ |
237 | if (rtextents > 0) { | 237 | if (rtextents > 0) { |
238 | error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS, | 238 | error = xfs_mod_frextents(tp->t_mountp, -((int64_t)rtextents)); |
239 | -((int64_t)rtextents), rsvd); | ||
240 | if (error) { | 239 | if (error) { |
241 | error = -ENOSPC; | 240 | error = -ENOSPC; |
242 | goto undo_log; | 241 | goto undo_log; |
@@ -562,10 +561,10 @@ xfs_trans_unreserve_and_mod_sb( | |||
562 | } | 561 | } |
563 | 562 | ||
564 | /* apply remaining deltas */ | 563 | /* apply remaining deltas */ |
565 | if (rtxdelta != 0) { | 564 | if (rtxdelta) { |
566 | msbp->msb_field = XFS_SBS_FREXTENTS; | 565 | error = xfs_mod_frextents(mp, rtxdelta); |
567 | msbp->msb_delta = rtxdelta; | 566 | if (error) |
568 | msbp++; | 567 | goto out_undo_ifree; |
569 | } | 568 | } |
570 | 569 | ||
571 | if (tp->t_flags & XFS_TRANS_SB_DIRTY) { | 570 | if (tp->t_flags & XFS_TRANS_SB_DIRTY) { |
@@ -618,12 +617,15 @@ xfs_trans_unreserve_and_mod_sb( | |||
618 | error = xfs_mod_incore_sb_batch(tp->t_mountp, msb, | 617 | error = xfs_mod_incore_sb_batch(tp->t_mountp, msb, |
619 | (uint)(msbp - msb), rsvd); | 618 | (uint)(msbp - msb), rsvd); |
620 | if (error) | 619 | if (error) |
621 | goto out_undo_ifreecount; | 620 | goto out_undo_frextents; |
622 | } | 621 | } |
623 | 622 | ||
624 | return; | 623 | return; |
625 | 624 | ||
626 | out_undo_ifreecount: | 625 | out_undo_frextents: |
626 | if (rtxdelta) | ||
627 | xfs_mod_frextents(mp, -rtxdelta); | ||
628 | out_undo_ifree: | ||
627 | if (ifreedelta) | 629 | if (ifreedelta) |
628 | xfs_mod_ifree(mp, -ifreedelta); | 630 | xfs_mod_ifree(mp, -ifreedelta); |
629 | out_undo_icount: | 631 | out_undo_icount: |