summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2019-04-08 16:45:30 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2019-04-15 17:02:49 -0700
commit4deb4cccf33460586244d74317e2fc9633a121e8 (patch)
tree0b9e183a97e150c38b20f89392e724e719302010
parent0ab9d5c737180b4dd972d2743228ee14ccc4cddb (diff)
Use the same summary counter calculation infrastructure to generate new values for the in-core summary counters. The difference between the scrubber and the repairer is that the repairer will freeze the fs during setup, which means that the values should match exactly. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/Makefile1
-rw-r--r--fs/xfs/scrub/fscounters.c21
-rw-r--r--fs/xfs/scrub/fscounters_repair.c63
-rw-r--r--fs/xfs/scrub/repair.h2
-rw-r--r--fs/xfs/scrub/scrub.c2
-rw-r--r--fs/xfs/scrub/trace.h18
6 files changed, 100 insertions, 7 deletions
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index d7412c191575..f344def0f2af 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -167,6 +167,7 @@ xfs-y += $(addprefix scrub/, \
bitmap.o \
blob.o \
bmap_repair.o \
+ fscounters_repair.o \
ialloc_repair.o \
inode_repair.o \
refcount_repair.o \
diff --git a/fs/xfs/scrub/fscounters.c b/fs/xfs/scrub/fscounters.c
index add36e824845..e5575bb67418 100644
--- a/fs/xfs/scrub/fscounters.c
+++ b/fs/xfs/scrub/fscounters.c
@@ -53,6 +53,8 @@ xchk_setup_fscounters(
struct xfs_scrub *sc,
struct xfs_inode *ip)
{
+ int error;
+
sc->buf = kmem_zalloc(sizeof(struct xchk_fscounters), KM_SLEEP);
if (!sc->buf)
return -ENOMEM;
@@ -61,8 +63,19 @@ xchk_setup_fscounters(
* Pause background reclaim while we're scrubbing to reduce the
* likelihood of background perturbations to the counters throwing
* off our calculations.
+ *
+ * If we're repairing, we need to prevent any other thread from
+ * changing the global fs summary counters while we're repairing them.
+ * This requires the fs to be frozen, which will disable background
+ * reclaim and purge all inactive inodes.
*/
- xchk_disable_reclaim(sc);
+ if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) {
+ error = xchk_fs_freeze(sc);
+ if (error)
+ return error;
+ } else {
+ xchk_disable_reclaim(sc);
+ }
return xchk_trans_alloc(sc, 0);
}
@@ -153,6 +166,7 @@ xchk_fscounters_calc(
* Is the @counter within an acceptable range of @expected?
*
* Currently that means 1/16th (6%) or @nr_range of the @expected value.
+ * If we're repairing then we require an exact match.
*/
static inline bool
xchk_fscounter_within_range(
@@ -164,7 +178,10 @@ xchk_fscounter_within_range(
int64_t value = percpu_counter_sum(counter);
uint64_t range;
- range = max_t(uint64_t, expected >> 4, nr_range);
+ if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)
+ range = 0;
+ else
+ range = max_t(uint64_t, expected >> 4, nr_range);
if (value < 0)
return false;
if (range < expected && value < expected - range)
diff --git a/fs/xfs/scrub/fscounters_repair.c b/fs/xfs/scrub/fscounters_repair.c
new file mode 100644
index 000000000000..c3d2214133ff
--- /dev/null
+++ b/fs/xfs/scrub/fscounters_repair.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Oracle. All Rights Reserved.
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_defer.h"
+#include "xfs_btree.h"
+#include "xfs_bit.h"
+#include "xfs_log_format.h"
+#include "xfs_trans.h"
+#include "xfs_sb.h"
+#include "xfs_inode.h"
+#include "xfs_alloc.h"
+#include "xfs_ialloc.h"
+#include "xfs_rmap.h"
+#include "xfs_health.h"
+#include "scrub/xfs_scrub.h"
+#include "scrub/scrub.h"
+#include "scrub/common.h"
+#include "scrub/trace.h"
+#include "scrub/repair.h"
+
+/*
+ * FS Summary Counters
+ * ===================
+ *
+ * We correct errors in the filesystem summary counters by setting them to the
+ * values computed during the obligatory scrub phase. However, we must be
+ * careful not to allow any other thread to change the counters while we're
+ * computing and setting new values. To achieve this, we freeze the
+ * filesystem for the whole operation if the REPAIR flag is set. The checking
+ * function is stricter when we've frozen the fs.
+ */
+
+/*
+ * Reset the superblock counters. Caller is responsible for freezing the
+ * filesystem during the calculation and reset phases.
+ */
+int
+xrep_fscounters(
+ struct xfs_scrub *sc)
+{
+ struct xfs_mount *mp = sc->mp;
+ struct xchk_fscounters *fsc = sc->buf;
+
+ /*
+ * Reinitialize the in-core counters from what we computed. We froze
+ * the filesystem, so there shouldn't be anyone else trying to modify
+ * these counters.
+ */
+ ASSERT(sc->flags & XCHK_FS_FROZEN);
+ percpu_counter_set(&mp->m_icount, fsc->icount);
+ percpu_counter_set(&mp->m_ifree, fsc->ifree);
+ percpu_counter_set(&mp->m_fdblocks, fsc->fdblocks);
+
+ return 0;
+}
diff --git a/fs/xfs/scrub/repair.h b/fs/xfs/scrub/repair.h
index f0f811ca3e51..5fe91fc7a056 100644
--- a/fs/xfs/scrub/repair.h
+++ b/fs/xfs/scrub/repair.h
@@ -82,6 +82,7 @@ int xrep_quota(struct xfs_scrub *sc);
#else
# define xrep_quota xrep_notsupported
#endif /* CONFIG_XFS_QUOTA */
+int xrep_fscounters(struct xfs_scrub *sc);
#else
@@ -141,6 +142,7 @@ xrep_rmapbt_setup(
#define xrep_symlink xrep_notsupported
#define xrep_xattr xrep_notsupported
#define xrep_quota xrep_notsupported
+#define xrep_fscounters xrep_notsupported
#endif /* CONFIG_XFS_ONLINE_REPAIR */
diff --git a/fs/xfs/scrub/scrub.c b/fs/xfs/scrub/scrub.c
index c96f5dcc22ea..91c1f650802b 100644
--- a/fs/xfs/scrub/scrub.c
+++ b/fs/xfs/scrub/scrub.c
@@ -374,7 +374,7 @@ static const struct xchk_meta_ops meta_scrub_ops[] = {
.type = ST_FS,
.setup = xchk_setup_fscounters,
.scrub = xchk_fscounters,
- .repair = xrep_notsupported,
+ .repair = xrep_fscounters,
},
};
diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h
index 1e958836d27a..c4590a46f355 100644
--- a/fs/xfs/scrub/trace.h
+++ b/fs/xfs/scrub/trace.h
@@ -848,16 +848,26 @@ TRACE_EVENT(xrep_calc_ag_resblks_btsize,
__entry->refcbt_sz)
)
TRACE_EVENT(xrep_reset_counters,
- TP_PROTO(struct xfs_mount *mp),
- TP_ARGS(mp),
+ TP_PROTO(struct xfs_mount *mp, int64_t icount_adj, int64_t ifree_adj,
+ int64_t fdblocks_adj),
+ TP_ARGS(mp, icount_adj, ifree_adj, fdblocks_adj),
TP_STRUCT__entry(
__field(dev_t, dev)
+ __field(int64_t, icount_adj)
+ __field(int64_t, ifree_adj)
+ __field(int64_t, fdblocks_adj)
),
TP_fast_assign(
__entry->dev = mp->m_super->s_dev;
+ __entry->icount_adj = icount_adj;
+ __entry->ifree_adj = ifree_adj;
+ __entry->fdblocks_adj = fdblocks_adj;
),
- TP_printk("dev %d:%d",
- MAJOR(__entry->dev), MINOR(__entry->dev))
+ TP_printk("dev %d:%d icount %lld ifree %lld fdblocks %lld",
+ MAJOR(__entry->dev), MINOR(__entry->dev),
+ __entry->icount_adj,
+ __entry->ifree_adj,
+ __entry->fdblocks_adj)
)
TRACE_EVENT(xrep_ibt_insert,