Skip to content

Commit f467cad

Browse files
committed
xfs: force summary counter recalc at next mount
Use the "bad summary count" mount flag from the previous patch to skip writing the unmount record to force log recovery at the next mount, which will recalculate the summary counters for us. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 53235f2 commit f467cad

5 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎fs/xfs/libxfs/xfs_errortag.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
#define XFS_ERRTAG_LOG_ITEM_PIN 30
5454
#define XFS_ERRTAG_BUF_LRU_REF 31
5555
#define XFS_ERRTAG_FORCE_SCRUB_REPAIR 32
56-
#define XFS_ERRTAG_MAX 33
56+
#define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33
57+
#define XFS_ERRTAG_MAX 34
5758

5859
/*
5960
* Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -91,5 +92,6 @@
9192
#define XFS_RANDOM_LOG_ITEM_PIN 1
9293
#define XFS_RANDOM_BUF_LRU_REF 2
9394
#define XFS_RANDOM_FORCE_SCRUB_REPAIR 1
95+
#define XFS_RANDOM_FORCE_SUMMARY_RECALC 1
9496

9597
#endif /* __XFS_ERRORTAG_H_ */

‎fs/xfs/xfs_error.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static unsigned int xfs_errortag_random_default[] = {
5050
XFS_RANDOM_LOG_ITEM_PIN,
5151
XFS_RANDOM_BUF_LRU_REF,
5252
XFS_RANDOM_FORCE_SCRUB_REPAIR,
53+
XFS_RANDOM_FORCE_SUMMARY_RECALC,
5354
};
5455

5556
struct xfs_errortag_attr {
@@ -157,6 +158,7 @@ XFS_ERRORTAG_ATTR_RW(log_bad_crc, XFS_ERRTAG_LOG_BAD_CRC);
157158
XFS_ERRORTAG_ATTR_RW(log_item_pin, XFS_ERRTAG_LOG_ITEM_PIN);
158159
XFS_ERRORTAG_ATTR_RW(buf_lru_ref, XFS_ERRTAG_BUF_LRU_REF);
159160
XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR);
161+
XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC);
160162

161163
static struct attribute *xfs_errortag_attrs[] = {
162164
XFS_ERRORTAG_ATTR_LIST(noerror),
@@ -192,6 +194,7 @@ static struct attribute *xfs_errortag_attrs[] = {
192194
XFS_ERRORTAG_ATTR_LIST(log_item_pin),
193195
XFS_ERRORTAG_ATTR_LIST(buf_lru_ref),
194196
XFS_ERRORTAG_ATTR_LIST(force_repair),
197+
XFS_ERRORTAG_ATTR_LIST(bad_summary),
195198
NULL,
196199
};
197200

‎fs/xfs/xfs_log.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,16 +848,30 @@ xfs_log_write_unmount_record(
848848
struct xlog_in_core *iclog;
849849
struct xlog_ticket *tic = NULL;
850850
xfs_lsn_t lsn;
851+
uint flags = XLOG_UNMOUNT_TRANS;
851852
int error;
852853

853854
error = xfs_log_reserve(mp, 600, 1, &tic, XFS_LOG, 0);
854855
if (error)
855856
goto out_err;
856857

858+
/*
859+
* If we think the summary counters are bad, clear the unmount header
860+
* flag in the unmount record so that the summary counters will be
861+
* recalculated during log recovery at next mount. Refer to
862+
* xlog_check_unmount_rec for more details.
863+
*/
864+
if (XFS_TEST_ERROR((mp->m_flags & XFS_MOUNT_BAD_SUMMARY), mp,
865+
XFS_ERRTAG_FORCE_SUMMARY_RECALC)) {
866+
xfs_alert(mp, "%s: will fix summary counters at next mount",
867+
__func__);
868+
flags &= ~XLOG_UNMOUNT_TRANS;
869+
}
870+
857871
/* remove inited flag, and account for space used */
858872
tic->t_flags = 0;
859873
tic->t_curr_res -= sizeof(magic);
860-
error = xlog_write(log, &vec, tic, &lsn, NULL, XLOG_UNMOUNT_TRANS);
874+
error = xlog_write(log, &vec, tic, &lsn, NULL, flags);
861875
/*
862876
* At this point, we're umounting anyway, so there's no point in
863877
* transitioning log state to IOERROR. Just continue...

‎fs/xfs/xfs_mount.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,3 +1423,16 @@ xfs_dev_is_read_only(
14231423
}
14241424
return 0;
14251425
}
1426+
1427+
/* Force the summary counters to be recalculated at next mount. */
1428+
void
1429+
xfs_force_summary_recalc(
1430+
struct xfs_mount *mp)
1431+
{
1432+
if (!xfs_sb_version_haslazysbcount(&mp->m_sb))
1433+
return;
1434+
1435+
spin_lock(&mp->m_sb_lock);
1436+
mp->m_flags |= XFS_MOUNT_BAD_SUMMARY;
1437+
spin_unlock(&mp->m_sb_lock);
1438+
}

‎fs/xfs/xfs_mount.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,6 @@ int xfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
435435

436436
struct xfs_error_cfg * xfs_error_get_cfg(struct xfs_mount *mp,
437437
int error_class, int error);
438+
void xfs_force_summary_recalc(struct xfs_mount *mp);
438439

439440
#endif /* __XFS_MOUNT_H__ */

0 commit comments

Comments
 (0)