xfs
[Top] [All Lists]

[PATCH v3 02/18] libxfs: track largest metadata LSN in use via verifiers

To: xfs@xxxxxxxxxxx
Subject: [PATCH v3 02/18] libxfs: track largest metadata LSN in use via verifiers
From: Brian Foster <bfoster@xxxxxxxxxx>
Date: Fri, 2 Oct 2015 14:19:39 -0400
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1443809995-20395-1-git-send-email-bfoster@xxxxxxxxxx>
References: <1443809995-20395-1-git-send-email-bfoster@xxxxxxxxxx>
The LSN validation helper is called in the I/O verifier codepath for
metadata that embed a last-modification LSN. While the codepath exists,
this is not used in userspace as in the kernel because the former
doesn't have an active log.

xfs_repair does need to check the validity of the LSN metadata with
respect to the on-disk log, however. Use the LSN validation mechanism to
track the largest LSN that has been seen. Export the value so repair can
use it once it has processed the entire filesystem. Note that the helper
continues to always return true to preserve existing behavior.

Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx>
---
 include/libxfs.h |  1 +
 libxfs/util.c    | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/include/libxfs.h b/include/libxfs.h
index b1604e2..cc06fc6 100644
--- a/include/libxfs.h
+++ b/include/libxfs.h
@@ -134,6 +134,7 @@ typedef struct {
 #define LIBXFS_DIRECT          0x0020  /* can use direct I/O, not buffered */
 
 extern char    *progname;
+extern xfs_lsn_t libxfs_max_lsn;
 extern int     libxfs_init (libxfs_init_t *);
 extern void    libxfs_destroy (void);
 extern int     libxfs_device_to_fd (dev_t);
diff --git a/libxfs/util.c b/libxfs/util.c
index fcf6e96..6192e6c 100644
--- a/libxfs/util.c
+++ b/libxfs/util.c
@@ -730,10 +730,43 @@ xfs_verifier_error(
                  bp->b_bn, BBTOB(bp->b_length));
 }
 
+/*
+ * This is called from I/O verifiers on v5 superblock filesystems. In the
+ * kernel, it validates the metadata LSN parameter against the current LSN of
+ * the active log. We don't have an active log in userspace so this kind of
+ * validation is not required. Therefore, this function always returns true in
+ * userspace.
+ *
+ * xfs_repair piggybacks off this mechanism to help track the largest metadata
+ * LSN in use on a filesystem. Keep a record of the largest LSN seen such that
+ * repair can validate it against the state of the log.
+ */
+xfs_lsn_t      libxfs_max_lsn = 0;
+pthread_mutex_t        libxfs_max_lsn_lock = PTHREAD_MUTEX_INITIALIZER;
+
 bool
 xfs_log_check_lsn(
        struct xfs_mount        *mp,
        xfs_lsn_t               lsn)
 {
+       int                     cycle = CYCLE_LSN(lsn);
+       int                     block = BLOCK_LSN(lsn);
+       int                     max_cycle;
+       int                     max_block;
+
+       if (lsn == NULLCOMMITLSN)
+               return true;
+
+       pthread_mutex_lock(&libxfs_max_lsn_lock);
+
+       max_cycle = CYCLE_LSN(libxfs_max_lsn);
+       max_block = BLOCK_LSN(libxfs_max_lsn);
+
+       if ((cycle > max_cycle) ||
+           (cycle == max_cycle && block > max_block))
+               libxfs_max_lsn = lsn;
+
+       pthread_mutex_unlock(&libxfs_max_lsn_lock);
+
        return true;
 }
-- 
2.1.0

<Prev in Thread] Current Thread [Next in Thread>