@@ -309,7 +309,11 @@ __scratch_xfs_fuzz_mdrestore()
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
logdev=$SCRATCH_LOGDEV
- _xfs_mdrestore "${POPULATE_METADUMP}" "${SCRATCH_DEV}" "${logdev}" || \
+ local rtdev=none
+ [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+ rtdev=$SCRATCH_RTDEV
+
+ _xfs_mdrestore "${POPULATE_METADUMP}" "${SCRATCH_DEV}" "${logdev}" "${rtdev}" || \
_fail "${POPULATE_METADUMP}: Could not find metadump to restore?"
}
@@ -1017,7 +1017,11 @@ _scratch_populate_restore_cached() {
case "${FSTYP}" in
"xfs")
- _xfs_mdrestore "${metadump}" "${SCRATCH_DEV}" "${logdev}"
+ local rtdev=none
+ [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+ rtdev=$SCRATCH_RTDEV
+
+ _xfs_mdrestore "${metadump}" "${SCRATCH_DEV}" "${logdev}" "${rtdev}"
return $?
;;
"ext2"|"ext3"|"ext4")
@@ -1039,8 +1043,12 @@ _scratch_populate_save_metadump()
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
logdev=$SCRATCH_LOGDEV
+ local rtdev=none
+ [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+ rtdev=$SCRATCH_RTDEV
+
_xfs_metadump "$metadump_file" "$SCRATCH_DEV" "$logdev" \
- compress
+ "$rtdev" compress
res=$?
;;
"ext2"|"ext3"|"ext4")
@@ -681,11 +681,17 @@ _xfs_metadump() {
local metadump="$1"
local device="$2"
local logdev="$3"
- local compressopt="$4"
- shift; shift; shift; shift
+ local rtdev="$4"
+ local compressopt="$5"
+ shift; shift; shift; shift; shift
local options="$@"
test -z "$options" && options="-a -o"
local metadump_has_dash_x
+ local metadump_has_dash_r
+
+ # Does metadump support capturing realtime devices?
+ $XFS_METADUMP_PROG --help 2>&1 | grep -q -- '-r rtdev' && \
+ metadump_has_dash_r=1
# Use metadump v2 format unless the user gave us a specific version
$XFS_METADUMP_PROG --help 2>&1 | grep -q -- '-v version' && \
@@ -699,6 +705,10 @@ _xfs_metadump() {
options="$options -l $logdev"
fi
+ if [ "$rtdev" != "none" ] && [ -n "$metadump_has_dash_r" ]; then
+ options="$options -r $rtdev"
+ fi
+
$XFS_METADUMP_PROG $options "$device" "$metadump"
res=$?
[ "$compressopt" = "compress" ] && [ -n "$DUMP_COMPRESSOR" ] &&
@@ -710,14 +720,19 @@ _xfs_mdrestore() {
local metadump="$1"
local device="$2"
local logdev="$3"
- shift; shift; shift
+ local rtdev="$4"
+ shift; shift; shift; shift
local options="$@"
local need_repair
local mdrestore_has_dash_l
+ local mdrestore_has_dash_r
# Does mdrestore support restoring to external devices?
$XFS_MDRESTORE_PROG --help 2>&1 | grep -q -- '-l logdev' &&
mdrestore_has_dash_l=1
+ # Does mdrestore support restoring to realtime devices?
+ $XFS_MDRESTORE_PROG --help 2>&1 | grep -q -- '-r rtdev' &&
+ mdrestore_has_dash_r=1
# If we're configured for compressed dumps and there isn't already an
# uncompressed dump, see if we can use DUMP_COMPRESSOR to decompress
@@ -743,6 +758,20 @@ _xfs_mdrestore() {
$XFS_IO_PROG -d -c 'pwrite -S 0 -q 0 1m' "$logdev"
fi
+ if [ "$rtdev" != "none" ]; then
+ # We have a realtime device. If mdrestore supports restoring
+ # to it, configure ourselves to do that.
+ if [ -n "$mdrestore_has_dash_r" ]; then
+ options="$options -r $rtdev"
+ fi
+
+ # Wipe the realtime device. If mdrestore doesn't support
+ # restoring to realtime devices or the metadump file doesn't
+ # capture the realtime group headers, this is our only chance
+ # to signal that the log header needs to be rewritten.
+ $XFS_IO_PROG -d -c 'pwrite -S 0 -q 0 1m' "$rtdev"
+ fi
+
$XFS_MDRESTORE_PROG $options "${metadump}" "${device}"
res=$?
test $res -ne 0 && return $res
@@ -757,6 +786,16 @@ _xfs_mdrestore() {
fi
fi
+ # If there's a realtime device, check to see if the restore rewrote the
+ # rt group headers. If not, we need to run xfs_repair to format new
+ # group headers onto the realtime device.
+ if [ "$rtdev" != "none" ] && [ -z "$need_repair" ]; then
+ magic="$($XFS_IO_PROG -c 'pread -q -v 0 4' "$rtdev")"
+ if [ "$magic" = "00000000: 00 00 00 00 ...." ]; then
+ need_repair=1
+ fi
+ fi
+
test -z "$need_repair" && return 0
echo "repairing fs to fix uncaptured parts of fs." >> $seqres.full
@@ -768,12 +807,16 @@ _scratch_xfs_metadump()
{
local metadump=$1
shift
+
local logdev=none
-
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
logdev=$SCRATCH_LOGDEV
- _xfs_metadump "$metadump" "$SCRATCH_DEV" "$logdev" nocompress "$@"
+ local rtdev=none
+ [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+ rtdev=$SCRATCH_RTDEV
+
+ _xfs_metadump "$metadump" "$SCRATCH_DEV" "$logdev" "$rtdev" nocompress "$@"
}
# Restore snapshotted metadata on the scratch device
@@ -786,7 +829,11 @@ _scratch_xfs_mdrestore()
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
logdev=$SCRATCH_LOGDEV
- _xfs_mdrestore "$metadump" "$SCRATCH_DEV" "$logdev" "$@"
+ local rtdev=none
+ [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+ rtdev=$SCRATCH_RTDEV
+
+ _xfs_mdrestore "$metadump" "$SCRATCH_DEV" "$logdev" "$rtdev" "$@"
}
# Do not use xfs_repair (offline fsck) to rebuild the filesystem
@@ -923,7 +970,7 @@ _check_xfs_filesystem()
if [ "$ok" -ne 1 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then
local flatdev="$(basename "$device")"
_xfs_metadump "$seqres.$flatdev.check.md" "$device" "$logdev" \
- compress >> $seqres.full
+ "$rtdev" compress >> $seqres.full
fi
# Optionally test the index rebuilding behavior.
@@ -956,7 +1003,7 @@ _check_xfs_filesystem()
if [ "$rebuild_ok" -ne 1 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then
local flatdev="$(basename "$device")"
_xfs_metadump "$seqres.$flatdev.rebuild.md" "$device" \
- "$logdev" compress >> $seqres.full
+ "$logdev" "$rtdev" compress >> $seqres.full
fi
fi
@@ -1040,7 +1087,7 @@ _check_xfs_filesystem()
if [ "$orebuild_ok" -ne 1 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then
local flatdev="$(basename "$device")"
_xfs_metadump "$seqres.$flatdev.orebuild.md" "$device" \
- "$logdev" compress >> $seqres.full
+ "$logdev" "$rtdev" compress >> $seqres.full
fi
fi