|
|
@@ -2422,11 +2422,20 @@ xlog_write(
|
|
|
&partial_copy_len);
|
|
|
xlog_verify_dest_ptr(log, ptr);
|
|
|
|
|
|
- /* copy region */
|
|
|
+ /*
|
|
|
+ * Copy region.
|
|
|
+ *
|
|
|
+ * Unmount records just log an opheader, so can have
|
|
|
+ * empty payloads with no data region to copy. Hence we
|
|
|
+ * only copy the payload if the vector says it has data
|
|
|
+ * to copy.
|
|
|
+ */
|
|
|
ASSERT(copy_len >= 0);
|
|
|
- memcpy(ptr, reg->i_addr + copy_off, copy_len);
|
|
|
- xlog_write_adv_cnt(&ptr, &len, &log_offset, copy_len);
|
|
|
-
|
|
|
+ if (copy_len > 0) {
|
|
|
+ memcpy(ptr, reg->i_addr + copy_off, copy_len);
|
|
|
+ xlog_write_adv_cnt(&ptr, &len, &log_offset,
|
|
|
+ copy_len);
|
|
|
+ }
|
|
|
copy_len += start_rec_copy + sizeof(xlog_op_header_t);
|
|
|
record_cnt++;
|
|
|
data_cnt += contwr ? copy_len : 0;
|
|
|
@@ -3165,11 +3174,19 @@ xlog_state_switch_iclogs(
|
|
|
}
|
|
|
|
|
|
if (log->l_curr_block >= log->l_logBBsize) {
|
|
|
+ /*
|
|
|
+ * Rewind the current block before the cycle is bumped to make
|
|
|
+ * sure that the combined LSN never transiently moves forward
|
|
|
+ * when the log wraps to the next cycle. This is to support the
|
|
|
+ * unlocked sample of these fields from xlog_valid_lsn(). Most
|
|
|
+ * other cases should acquire l_icloglock.
|
|
|
+ */
|
|
|
+ log->l_curr_block -= log->l_logBBsize;
|
|
|
+ ASSERT(log->l_curr_block >= 0);
|
|
|
+ smp_wmb();
|
|
|
log->l_curr_cycle++;
|
|
|
if (log->l_curr_cycle == XLOG_HEADER_MAGIC_NUM)
|
|
|
log->l_curr_cycle++;
|
|
|
- log->l_curr_block -= log->l_logBBsize;
|
|
|
- ASSERT(log->l_curr_block >= 0);
|
|
|
}
|
|
|
ASSERT(iclog == log->l_iclog);
|
|
|
log->l_iclog = iclog->ic_next;
|
|
|
@@ -4023,3 +4040,45 @@ xlog_iclogs_empty(
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+ * Verify that an LSN stamped into a piece of metadata is valid. This is
|
|
|
+ * intended for use in read verifiers on v5 superblocks.
|
|
|
+ */
|
|
|
+bool
|
|
|
+xfs_log_check_lsn(
|
|
|
+ struct xfs_mount *mp,
|
|
|
+ xfs_lsn_t lsn)
|
|
|
+{
|
|
|
+ struct xlog *log = mp->m_log;
|
|
|
+ bool valid;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * norecovery mode skips mount-time log processing and unconditionally
|
|
|
+ * resets the in-core LSN. We can't validate in this mode, but
|
|
|
+ * modifications are not allowed anyways so just return true.
|
|
|
+ */
|
|
|
+ if (mp->m_flags & XFS_MOUNT_NORECOVERY)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Some metadata LSNs are initialized to NULL (e.g., the agfl). This is
|
|
|
+ * handled by recovery and thus safe to ignore here.
|
|
|
+ */
|
|
|
+ if (lsn == NULLCOMMITLSN)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ valid = xlog_valid_lsn(mp->m_log, lsn);
|
|
|
+
|
|
|
+ /* warn the user about what's gone wrong before verifier failure */
|
|
|
+ if (!valid) {
|
|
|
+ spin_lock(&log->l_icloglock);
|
|
|
+ xfs_warn(mp,
|
|
|
+"Corruption warning: Metadata has LSN (%d:%d) ahead of current LSN (%d:%d). "
|
|
|
+"Please unmount and run xfs_repair (>= v4.3) to resolve.",
|
|
|
+ CYCLE_LSN(lsn), BLOCK_LSN(lsn),
|
|
|
+ log->l_curr_cycle, log->l_curr_block);
|
|
|
+ spin_unlock(&log->l_icloglock);
|
|
|
+ }
|
|
|
+
|
|
|
+ return valid;
|
|
|
+}
|