]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: track largest metadata LSN in use via verifiers
authorBrian Foster <bfoster@redhat.com>
Tue, 13 Oct 2015 23:58:24 +0000 (10:58 +1100)
committerDave Chinner <david@fromorbit.com>
Tue, 13 Oct 2015 23:58:24 +0000 (10:58 +1100)
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@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
include/libxfs.h
libxfs/util.c

index b1604e2e15bb1fd7c6bfadec576dc83911122c7d..cc06fc65f8ad31b175fb2c58bbd37024fb12090d 100644 (file)
@@ -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);
index fcf6e962ebaa1d3128311892bbc44a358a8e6168..6192e6c873cd3727f3fc469793308bc2749b53b6 100644 (file)
@@ -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;
 }