From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 43/55] xfs: implement the metadata repair ioctl flag
Date: Sat, 21 Jan 2017 00:05:00 -0800 [thread overview]
Message-ID: <148498590004.15323.9956677742787374641.stgit@birch.djwong.org> (raw)
In-Reply-To: <148498561504.15323.8531512066874274553.stgit@birch.djwong.org>
Plumb in the pieces necessary to make the "scrub" subfunction of
the scrub ioctl actually work.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fs/xfs/scrub/common.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++--
fs/xfs/xfs_error.h | 4 +-
2 files changed, 99 insertions(+), 6 deletions(-)
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index b0d0ed2..8b6384f 100644
--- a/fs/xfs/scrub/common.c
+++ b/fs/xfs/scrub/common.c
@@ -41,6 +41,7 @@
#include "xfs_refcount_btree.h"
#include "xfs_rmap.h"
#include "xfs_rmap_btree.h"
+#include "xfs_error.h"
#include "scrub/xfs_scrub.h"
#include "scrub/common.h"
#include "scrub/btree.h"
@@ -108,8 +109,43 @@
* the metadata is correct but otherwise suboptimal, there's a "preen"
* flag to signal that. Finally, if we were unable to access a data
* structure to perform cross-referencing, we can signal that as well.
+ *
+ * If a piece of metadata proves corrupt or suboptimal, the userspace
+ * program can ask the kernel to apply some tender loving care (TLC) to
+ * the metadata object. "Corruption" is defined by metadata violating
+ * the on-disk specification; operations cannot continue if the
+ * violation is left untreated. It is possible for XFS to continue if
+ * an object is "suboptimal", however performance may be degraded.
+ * Repairs are usually performed by rebuilding the metadata entirely out
+ * of redundant metadata. Optimizing, on the other hand, can sometimes
+ * be done without rebuilding entire structures.
+ *
+ * Generally speaking, the repair code has the following code structure:
+ * Lock -> scrub -> repair -> commit -> re-lock -> re-scrub -> unlock.
+ * The first check helps us figure out if we need to rebuild or simply
+ * optimize the structure so that the rebuild knows what to do. The
+ * second check evaluates the completeness of the repair; that is what
+ * is reported to userspace.
*/
+/* Fix something if errors were detected and the user asked for repair. */
+static inline bool
+xfs_scrub_should_fix(
+ struct xfs_scrub_metadata *sm)
+{
+ return (sm->sm_flags & XFS_SCRUB_FLAG_REPAIR) &&
+ (sm->sm_flags & (XFS_SCRUB_FLAG_CORRUPT | XFS_SCRUB_FLAG_PREEN |
+ XFS_SCRUB_FLAG_XCORRUPT));
+}
+
+/* Clear the corruption status flags. */
+static inline bool
+xfs_scrub_reset_corruption_flags(
+ struct xfs_scrub_metadata *sm)
+{
+ return sm->sm_flags &= ~XFS_SCRUB_FLAGS_OUT;
+}
+
/* Check for operational errors. */
bool
xfs_scrub_op_ok(
@@ -609,7 +645,10 @@ xfs_scrub_teardown(
if (sc->ag_lock.agmask != sc->ag_lock.__agmask)
kmem_free(sc->ag_lock.agmask);
sc->ag_lock.agmask = NULL;
- xfs_trans_cancel(sc->tp);
+ if (error == 0 && (sc->sm->sm_flags & XFS_SCRUB_FLAG_REPAIR))
+ error = xfs_trans_commit(sc->tp);
+ else
+ xfs_trans_cancel(sc->tp);
sc->tp = NULL;
if (sc->ip != NULL) {
xfs_iunlock(sc->ip, XFS_ILOCK_EXCL);
@@ -752,6 +791,8 @@ xfs_scrub_metadata(
struct xfs_mount *mp = ip->i_mount;
const struct xfs_scrub_meta_fns *fns;
bool deadlocked = false;
+ bool already_fixed = false;
+ bool was_corrupt = false;
int error = 0;
trace_xfs_scrub(ip, sm->sm_type, sm->sm_agno, sm->sm_ino, sm->sm_gen,
@@ -765,8 +806,6 @@ xfs_scrub_metadata(
sm->sm_flags &= ~XFS_SCRUB_FLAGS_OUT;
if (sm->sm_flags & ~XFS_SCRUB_FLAGS_IN)
goto out;
- if (sm->sm_flags & XFS_SCRUB_FLAG_REPAIR)
- goto out;
error = -ENOENT;
if (sm->sm_type > XFS_SCRUB_TYPE_MAX)
goto out;
@@ -774,6 +813,14 @@ xfs_scrub_metadata(
if (fns->scrub == NULL)
goto out;
error = -EOPNOTSUPP;
+ if ((sm->sm_flags & XFS_SCRUB_FLAG_REPAIR) &&
+ (fns->repair == NULL || !xfs_sb_version_hascrc(&mp->m_sb)))
+ goto out;
+
+ error = -EROFS;
+ if ((sm->sm_flags & XFS_SCRUB_FLAG_REPAIR) &&
+ (mp->m_flags & XFS_MOUNT_RDONLY))
+ goto out;
/* Do we even have this type of metadata? */
error = -ENOENT;
@@ -809,8 +856,52 @@ xfs_scrub_metadata(
} else if (error)
goto out_teardown;
- if (sm->sm_flags & XFS_SCRUB_FLAG_CORRUPT)
- xfs_alert_ratelimited(mp, "Corruption detected during scrub.");
+ /* Let debug users force us into the repair routines. */
+ if ((sm->sm_flags & XFS_SCRUB_FLAG_REPAIR) && !already_fixed &&
+ XFS_TEST_ERROR(false, mp,
+ XFS_ERRTAG_FORCE_SCRUB_REPAIR,
+ XFS_RANDOM_FORCE_SCRUB_REPAIR)) {
+ sm->sm_flags |= XFS_SCRUB_FLAG_CORRUPT;
+ }
+ if (!already_fixed)
+ was_corrupt = (sm->sm_flags & (XFS_SCRUB_FLAG_CORRUPT |
+ XFS_SCRUB_FLAG_XCORRUPT));
+
+ if (!already_fixed && xfs_scrub_should_fix(sm)) {
+ xfs_scrub_ag_btcur_free(&sc.sa);
+
+ /* Ok, something's wrong. Repair it. */
+ trace_xfs_repair_attempt(ip, sm->sm_type, sm->sm_agno,
+ sm->sm_ino, sm->sm_gen, sm->sm_flags, error);
+ error = fns->repair(&sc);
+ trace_xfs_repair_done(ip, sm->sm_type, sm->sm_agno,
+ sm->sm_ino, sm->sm_gen, sm->sm_flags, error);
+ if (error)
+ goto out_teardown;
+
+ /*
+ * Commit the fixes and perform a second dry-run scrub
+ * so that we can tell userspace if we fixed the problem.
+ */
+ error = xfs_scrub_teardown(&sc, ip, error);
+ if (error)
+ goto out;
+ xfs_scrub_reset_corruption_flags(sm);
+ already_fixed = true;
+ goto retry_op;
+ }
+
+ if (sm->sm_flags & (XFS_SCRUB_FLAG_CORRUPT | XFS_SCRUB_FLAG_XCORRUPT)) {
+ char *errstr;
+
+ if (sm->sm_flags & XFS_SCRUB_FLAG_REPAIR)
+ errstr = "Corruption not fixed during online repair. "
+ "Unmount and run xfs_repair.";
+ else
+ errstr = "Corruption detected during scrub.";
+ xfs_alert_ratelimited(mp, errstr);
+ } else if (already_fixed && was_corrupt)
+ xfs_alert_ratelimited(mp, "Corruption repaired during scrub.");
out_teardown:
error = xfs_scrub_teardown(&sc, ip, error);
diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h
index 05f8666..4c22d9a 100644
--- a/fs/xfs/xfs_error.h
+++ b/fs/xfs/xfs_error.h
@@ -96,7 +96,8 @@ extern void xfs_verifier_error(struct xfs_buf *bp);
#define XFS_ERRTAG_REFCOUNT_FINISH_ONE 25
#define XFS_ERRTAG_BMAP_FINISH_ONE 26
#define XFS_ERRTAG_AG_RESV_CRITICAL 27
-#define XFS_ERRTAG_MAX 28
+#define XFS_ERRTAG_FORCE_SCRUB_REPAIR 28
+#define XFS_ERRTAG_MAX 29
/*
* Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -129,6 +130,7 @@ extern void xfs_verifier_error(struct xfs_buf *bp);
#define XFS_RANDOM_REFCOUNT_FINISH_ONE 1
#define XFS_RANDOM_BMAP_FINISH_ONE 1
#define XFS_RANDOM_AG_RESV_CRITICAL 4
+#define XFS_RANDOM_FORCE_SCRUB_REPAIR 1
#ifdef DEBUG
extern int xfs_error_test_active;
next prev parent reply other threads:[~2017-01-21 8:05 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-21 8:00 [PATCH v5 00/55] xfs: online scrub/repair support Darrick J. Wong
2017-01-21 8:00 ` [PATCH 01/55] xfs: fix toctou race when locking an inode to access the data map Darrick J. Wong
2017-01-21 8:00 ` [PATCH 02/55] xfs: fail _dir_open when readahead fails Darrick J. Wong
2017-01-21 8:00 ` [PATCH 03/55] xfs: filter out obviously bad btree pointers Darrick J. Wong
2017-01-21 8:00 ` [PATCH 04/55] xfs: check for obviously bad level values in the bmbt root Darrick J. Wong
2017-01-21 8:00 ` [PATCH 05/55] xfs: verify free block header fields Darrick J. Wong
2017-01-21 8:00 ` [PATCH 06/55] xfs: plumb in needed functions for range querying of the freespace btrees Darrick J. Wong
2017-01-21 8:00 ` [PATCH 07/55] xfs: provide a query_range function for " Darrick J. Wong
2017-01-21 8:01 ` [PATCH 08/55] xfs: create a function to query all records in a btree Darrick J. Wong
2017-01-21 8:01 ` [PATCH 09/55] xfs: introduce the XFS_IOC_GETFSMAP ioctl Darrick J. Wong
2017-01-21 8:01 ` [PATCH 10/55] xfs: report shared extents in getfsmapx Darrick J. Wong
2017-01-21 8:01 ` [PATCH 11/55] xfs: have getfsmap fall back to the freesp btrees when rmap is not present Darrick J. Wong
2017-01-21 8:01 ` [PATCH 12/55] xfs: getfsmap should fall back to rtbitmap when rtrmapbt " Darrick J. Wong
2017-01-21 8:01 ` [PATCH 13/55] xfs: query the per-AG reservation counters Darrick J. Wong
2017-01-21 8:01 ` [PATCH 14/55] xfs: add scrub tracepoints Darrick J. Wong
2017-01-21 8:01 ` [PATCH 15/55] xfs: create an ioctl to scrub AG metadata Darrick J. Wong
2017-01-21 8:01 ` [PATCH 16/55] xfs: generic functions to scrub metadata and btrees Darrick J. Wong
2017-01-21 8:02 ` [PATCH 17/55] xfs: scrub the backup superblocks Darrick J. Wong
2017-01-21 8:02 ` [PATCH 18/55] xfs: scrub AGF and AGFL Darrick J. Wong
2017-01-21 8:02 ` [PATCH 19/55] xfs: scrub the AGI Darrick J. Wong
2017-01-21 8:02 ` [PATCH 20/55] xfs: support scrubbing free space btrees Darrick J. Wong
2017-01-21 8:02 ` [PATCH 21/55] xfs: support scrubbing inode btrees Darrick J. Wong
2017-01-21 8:02 ` [PATCH 22/55] xfs: support scrubbing rmap btree Darrick J. Wong
2017-01-21 8:02 ` [PATCH 23/55] xfs: support scrubbing refcount btree Darrick J. Wong
2017-01-21 8:02 ` [PATCH 24/55] xfs: scrub inodes Darrick J. Wong
2017-01-21 8:02 ` [PATCH 25/55] xfs: scrub inode block mappings Darrick J. Wong
2017-01-21 8:03 ` [PATCH 26/55] xfs: scrub directory/attribute btrees Darrick J. Wong
2017-01-21 8:03 ` [PATCH 27/55] xfs: scrub directory metadata Darrick J. Wong
2017-01-21 8:03 ` [PATCH 28/55] xfs: scrub directory freespace Darrick J. Wong
2017-01-21 8:03 ` [PATCH 29/55] xfs: scrub extended attributes Darrick J. Wong
2017-01-21 8:03 ` [PATCH 30/55] xfs: scrub symbolic links Darrick J. Wong
2017-01-21 8:03 ` [PATCH 31/55] xfs: scrub realtime bitmap/summary Darrick J. Wong
2017-01-21 8:03 ` [PATCH 32/55] xfs: set up cross-referencing helpers Darrick J. Wong
2017-01-21 8:03 ` [PATCH 33/55] xfs: scrub should cross-reference with the bnobt Darrick J. Wong
2017-01-21 8:04 ` [PATCH 34/55] xfs: cross-reference bnobt records with cntbt Darrick J. Wong
2017-01-21 8:04 ` [PATCH 35/55] xfs: cross-reference extents with AG header Darrick J. Wong
2017-01-21 8:04 ` [PATCH 36/55] xfs: cross-reference inode btrees during scrub Darrick J. Wong
2017-01-21 8:04 ` [PATCH 37/55] xfs: cross-reference reverse-mapping btree Darrick J. Wong
2017-01-21 8:04 ` [PATCH 38/55] xfs: cross-reference refcount btree during scrub Darrick J. Wong
2017-01-21 8:04 ` [PATCH 39/55] xfs: scrub should cross-reference the realtime bitmap Darrick J. Wong
2017-01-21 8:04 ` [PATCH 40/55] xfs: cross-reference the block mappings when possible Darrick J. Wong
2017-01-21 8:04 ` [PATCH 41/55] xfs: shut off scrub-related error and corruption messages Darrick J. Wong
2017-01-21 8:04 ` [PATCH 42/55] xfs: create tracepoints for online repair Darrick J. Wong
2017-01-21 8:05 ` Darrick J. Wong [this message]
2017-01-21 8:05 ` [PATCH 44/55] xfs: add helper routines for the repair code Darrick J. Wong
2017-01-21 8:05 ` [PATCH 45/55] xfs: repair superblocks Darrick J. Wong
2017-01-21 8:05 ` [PATCH 46/55] xfs: repair the AGF and AGFL Darrick J. Wong
2017-01-21 8:05 ` [PATCH 47/55] xfs: rebuild the AGI Darrick J. Wong
2017-01-21 8:05 ` [PATCH 48/55] xfs: repair free space btrees Darrick J. Wong
2017-01-21 8:05 ` [PATCH 49/55] xfs: repair inode btrees Darrick J. Wong
2017-01-21 8:05 ` [PATCH 50/55] xfs: rebuild the rmapbt Darrick J. Wong
2017-01-21 8:05 ` [PATCH 51/55] xfs: repair refcount btrees Darrick J. Wong
2017-01-21 8:05 ` [PATCH 52/55] xfs: online repair of inodes Darrick J. Wong
2017-01-21 8:06 ` [PATCH 53/55] xfs: repair inode block maps Darrick J. Wong
2017-01-21 8:06 ` [PATCH 54/55] xfs: repair damaged symlinks Darrick J. Wong
2017-01-21 8:06 ` [PATCH 55/55] xfs: avoid mount-time deadlock in CoW extent recovery Darrick J. Wong
2017-01-24 17:08 ` [PATCH v5 00/55] xfs: online scrub/repair support Brian Foster
2017-01-24 19:37 ` Darrick J. Wong
2017-01-24 20:50 ` Brian Foster
2017-01-24 21:40 ` Dave Chinner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=148498590004.15323.9956677742787374641.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.