Skip to content

Commit d7a74ca

Browse files
author
Darrick J. Wong
committed
xfs: track usage statistics of online fsck
Track the usage, outcomes, and run times of the online fsck code, and report these values via debugfs. The columns in the file are: * scrubber name * number of scrub invocations * clean objects found * corruptions found * optimizations found * cross referencing failures * inconsistencies found during cross referencing * incomplete scrubs * warnings * number of time scrub had to retry * cumulative amount of time spent scrubbing (microseconds) * number of repair inovcations * successfully repaired objects * cumuluative amount of time spent repairing (microseconds) Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent a76dba3 commit d7a74ca

File tree

10 files changed

+535
-9
lines changed

10 files changed

+535
-9
lines changed

fs/xfs/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ config XFS_ONLINE_SCRUB
143143

144144
If unsure, say N.
145145

146+
config XFS_ONLINE_SCRUB_STATS
147+
bool "XFS online metadata check usage data collection"
148+
default y
149+
depends on XFS_ONLINE_SCRUB
150+
select FS_DEBUG
151+
help
152+
If you say Y here, the kernel will gather usage data about
153+
the online metadata check subsystem. This includes the number
154+
of invocations, the outcomes, and the results of repairs, if any.
155+
This may slow down scrub slightly due to the use of high precision
156+
timers and the need to merge per-invocation information into the
157+
filesystem counters.
158+
159+
Usage data are collected in /sys/kernel/debug/xfs/scrub.
160+
161+
If unsure, say N.
162+
146163
config XFS_ONLINE_REPAIR
147164
bool "XFS online metadata repair support"
148165
default n

fs/xfs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ xfs-y += $(addprefix scrub/, \
168168
xfile.o \
169169
)
170170

171+
xfs-$(CONFIG_XFS_ONLINE_SCRUB_STATS) += scrub/stats.o
171172
xfs-$(CONFIG_XFS_RT) += scrub/rtbitmap.o
172173
xfs-$(CONFIG_XFS_QUOTA) += scrub/quota.o
173174

fs/xfs/scrub/repair.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "scrub/trace.h"
3333
#include "scrub/repair.h"
3434
#include "scrub/bitmap.h"
35+
#include "scrub/stats.h"
3536

3637
/*
3738
* Attempt to repair some metadata, if the metadata is corrupt and userspace
@@ -40,8 +41,10 @@
4041
*/
4142
int
4243
xrep_attempt(
43-
struct xfs_scrub *sc)
44+
struct xfs_scrub *sc,
45+
struct xchk_stats_run *run)
4446
{
47+
u64 repair_start;
4548
int error = 0;
4649

4750
trace_xrep_attempt(XFS_I(file_inode(sc->file)), sc->sm, error);
@@ -50,8 +53,11 @@ xrep_attempt(
5053

5154
/* Repair whatever's broken. */
5255
ASSERT(sc->ops->repair);
56+
run->repair_attempted = true;
57+
repair_start = xchk_stats_now();
5358
error = sc->ops->repair(sc);
5459
trace_xrep_done(XFS_I(file_inode(sc->file)), sc->sm, error);
60+
run->repair_ns += xchk_stats_elapsed_ns(repair_start);
5561
switch (error) {
5662
case 0:
5763
/*
@@ -60,14 +66,17 @@ xrep_attempt(
6066
*/
6167
sc->sm->sm_flags &= ~XFS_SCRUB_FLAGS_OUT;
6268
sc->flags |= XREP_ALREADY_FIXED;
69+
run->repair_succeeded = true;
6370
return -EAGAIN;
6471
case -ECHRNG:
6572
sc->flags |= XCHK_NEED_DRAIN;
73+
run->retries++;
6674
return -EAGAIN;
6775
case -EDEADLOCK:
6876
/* Tell the caller to try again having grabbed all the locks. */
6977
if (!(sc->flags & XCHK_TRY_HARDER)) {
7078
sc->flags |= XCHK_TRY_HARDER;
79+
run->retries++;
7180
return -EAGAIN;
7281
}
7382
/*

fs/xfs/scrub/repair.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "xfs_quota_defs.h"
1010

11+
struct xchk_stats_run;
12+
1113
static inline int xrep_notsupported(struct xfs_scrub *sc)
1214
{
1315
return -EOPNOTSUPP;
@@ -25,7 +27,7 @@ static inline int xrep_notsupported(struct xfs_scrub *sc)
2527

2628
/* Repair helpers */
2729

28-
int xrep_attempt(struct xfs_scrub *sc);
30+
int xrep_attempt(struct xfs_scrub *sc, struct xchk_stats_run *run);
2931
void xrep_failure(struct xfs_mount *mp);
3032
int xrep_roll_ag_trans(struct xfs_scrub *sc);
3133
int xrep_defer_finish(struct xfs_scrub *sc);
@@ -70,7 +72,8 @@ int xrep_agi(struct xfs_scrub *sc);
7072

7173
static inline int
7274
xrep_attempt(
73-
struct xfs_scrub *sc)
75+
struct xfs_scrub *sc,
76+
struct xchk_stats_run *run)
7477
{
7578
return -EOPNOTSUPP;
7679
}

fs/xfs/scrub/scrub.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "scrub/trace.h"
2323
#include "scrub/repair.h"
2424
#include "scrub/health.h"
25+
#include "scrub/stats.h"
2526

2627
/*
2728
* Online Scrub and Repair
@@ -461,8 +462,10 @@ xfs_scrub_metadata(
461462
struct file *file,
462463
struct xfs_scrub_metadata *sm)
463464
{
465+
struct xchk_stats_run run = { };
464466
struct xfs_scrub *sc;
465467
struct xfs_mount *mp = XFS_I(file_inode(file))->i_mount;
468+
u64 check_start;
466469
int error = 0;
467470

468471
BUILD_BUG_ON(sizeof(meta_scrub_ops) !=
@@ -517,7 +520,9 @@ xfs_scrub_metadata(
517520
goto out_teardown;
518521

519522
/* Scrub for errors. */
523+
check_start = xchk_stats_now();
520524
error = sc->ops->scrub(sc);
525+
run.scrub_ns += xchk_stats_elapsed_ns(check_start);
521526
if (error == -EDEADLOCK && !(sc->flags & XCHK_TRY_HARDER))
522527
goto try_harder;
523528
if (error == -ECHRNG && !(sc->flags & XCHK_NEED_DRAIN))
@@ -551,7 +556,7 @@ xfs_scrub_metadata(
551556
* If it's broken, userspace wants us to fix it, and we haven't
552557
* already tried to fix it, then attempt a repair.
553558
*/
554-
error = xrep_attempt(sc);
559+
error = xrep_attempt(sc, &run);
555560
if (error == -EAGAIN) {
556561
/*
557562
* Either the repair function succeeded or it couldn't
@@ -579,12 +584,15 @@ xfs_scrub_metadata(
579584
sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
580585
error = 0;
581586
}
587+
if (error != -ENOENT)
588+
xchk_stats_merge(mp, sm, &run);
582589
return error;
583590
need_drain:
584591
error = xchk_teardown(sc, 0);
585592
if (error)
586593
goto out_sc;
587594
sc->flags |= XCHK_NEED_DRAIN;
595+
run.retries++;
588596
goto retry_op;
589597
try_harder:
590598
/*
@@ -596,5 +604,6 @@ xfs_scrub_metadata(
596604
if (error)
597605
goto out_sc;
598606
sc->flags |= XCHK_TRY_HARDER;
607+
run.retries++;
599608
goto retry_op;
600609
}

0 commit comments

Comments
 (0)