Skip to content

Commit 6543990

Browse files
Dave ChinnerDarrick J. Wong
authored andcommitted
xfs: update superblock counters correctly for !lazysbcount
Keep the mount superblock counters up to date for !lazysbcount filesystems so that when we log the superblock they do not need updating in any way because they are already correct. It's found by what Zorro reported: 1. mkfs.xfs -f -l lazy-count=0 -m crc=0 $dev 2. mount $dev $mnt 3. fsstress -d $mnt -p 100 -n 1000 (maybe need more or less io load) 4. umount $mnt 5. xfs_repair -n $dev and I've seen no problem with this patch. Signed-off-by: Dave Chinner <[email protected]> Reported-by: Zorro Lang <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Brian Foster <[email protected]>
1 parent e6c0107 commit 6543990

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

fs/xfs/libxfs/xfs_sb.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,19 @@ xfs_log_sb(
926926
struct xfs_mount *mp = tp->t_mountp;
927927
struct xfs_buf *bp = xfs_trans_getsb(tp);
928928

929-
mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount);
930-
mp->m_sb.sb_ifree = percpu_counter_sum(&mp->m_ifree);
931-
mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
929+
/*
930+
* Lazy sb counters don't update the in-core superblock so do that now.
931+
* If this is at unmount, the counters will be exactly correct, but at
932+
* any other time they will only be ballpark correct because of
933+
* reservations that have been taken out percpu counters. If we have an
934+
* unclean shutdown, this will be corrected by log recovery rebuilding
935+
* the counters from the AGF block counts.
936+
*/
937+
if (xfs_sb_version_haslazysbcount(&mp->m_sb)) {
938+
mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount);
939+
mp->m_sb.sb_ifree = percpu_counter_sum(&mp->m_ifree);
940+
mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
941+
}
932942

933943
xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
934944
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);

fs/xfs/xfs_trans.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,9 @@ xfs_trans_unreserve_and_mod_sb(
622622

623623
/* apply remaining deltas */
624624
spin_lock(&mp->m_sb_lock);
625+
mp->m_sb.sb_fdblocks += tp->t_fdblocks_delta + tp->t_res_fdblocks_delta;
626+
mp->m_sb.sb_icount += idelta;
627+
mp->m_sb.sb_ifree += ifreedelta;
625628
mp->m_sb.sb_frextents += rtxdelta;
626629
mp->m_sb.sb_dblocks += tp->t_dblocks_delta;
627630
mp->m_sb.sb_agcount += tp->t_agcount_delta;

0 commit comments

Comments
 (0)