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 | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) 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 96ce31f..0116e3d 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -733,13 +733,39 @@ xfs_verifier_error( /* * 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 just return + * the active log. We don't have an active log in userspace so always return * true. + * + * 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_valid_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 _______________________________________________ xfs mailing list xfs@xxxxxxxxxxx http://oss.sgi.com/mailman/listinfo/xfs