iotests: Simplify _filter_img_create() a bit

Not only is it a bit stupid to try to filter multi-line "Formatting"
output (because we only need it for a single test, which can easily be
amended to no longer need it), it is also problematic when there can be
output after a "Formatting" line that we do not want to filter as if it
were part of it.

So rename _filter_img_create to _do_filter_img_create, let it filter
only a single line, and let _filter_img_create loop over all input
lines, calling _do_filter_img_create only on those that match
/^Formatting/ (basically, what _filter_img_create_in_qmp did already).
(And fix 020 to work with that.)

Reported-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200709110205.310942-1-mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Max Reitz 2020-07-09 13:02:05 +02:00 committed by Kevin Wolf
parent 20c1df5476
commit 4b196cd16d
4 changed files with 45 additions and 61 deletions

View File

@ -115,7 +115,7 @@ TEST_IMG="$TEST_IMG.base" _make_test_img 1M
# Create an image with a null backing file to which committing will fail (with
# ENOSPC so we can distinguish the result from some generic EIO which may be
# generated anywhere in the block layer)
_make_test_img -b "json:{'driver': '$IMGFMT',
backing="json:{'driver': '$IMGFMT',
'file': {
'driver': 'blkdebug',
'inject-error': [{
@ -128,6 +128,11 @@ _make_test_img -b "json:{'driver': '$IMGFMT',
'filename': '$TEST_IMG.base'
}}}"
# Filter out newlines and collapse spaces
backing=$(echo "$backing" | tr -d '\n' | tr -s ' ')
_make_test_img -b "$backing"
# Just write anything so committing will not be a no-op
$QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_io

View File

@ -1079,18 +1079,7 @@ No errors were found on the image.
Testing failing commit
Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1048576
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=json:{'driver': 'IMGFMT',,
'file': {
'driver': 'blkdebug',,
'inject-error': [{
'event': 'write_aio',,
'errno': 28,,
'once': true
}],,
'image': {
'driver': 'file',,
'filename': 'TEST_DIR/t.IMGFMT.base'
}}}
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=json:{'driver': 'IMGFMT',, 'file': { 'driver': 'blkdebug',, 'inject-error': [{ 'event': 'write_aio',, 'errno': 28,, 'once': true }],, 'image': { 'driver': 'file',, 'filename': 'TEST_DIR/t.IMGFMT.base' }}}
wrote 65536/65536 bytes at offset 0
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
qemu-img: Block job failed: No space left on device

View File

@ -68,7 +68,7 @@ test_blockjob()
_send_qemu_cmd $QEMU_HANDLE \
"$1" \
"$2" \
| _filter_img_create_in_qmp | _filter_qmp_empty_return
| _filter_img_create | _filter_qmp_empty_return
# We want this to return an error because the block job is still running
_send_qemu_cmd $QEMU_HANDLE \

View File

@ -119,8 +119,21 @@ _filter_actual_image_size()
$SED -s 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g'
}
# Filename filters for qemu-img create
_filter_img_create_filenames()
{
$SED \
-e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
-e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
-e "s#$TEST_DIR#TEST_DIR#g" \
-e "s#$SOCK_DIR#SOCK_DIR#g" \
-e "s#$IMGFMT#IMGFMT#g" \
-e 's#nbd:127.0.0.1:[0-9]\\+#TEST_DIR/t.IMGFMT#g' \
-e 's#nbd+unix:///\??socket=SOCK_DIR/nbd#TEST_DIR/t.IMGFMT#g'
}
# replace driver-specific options in the "Formatting..." line
_filter_img_create()
_do_filter_img_create()
{
# Split the line into the pre-options part ($filename_part, which
# precedes ", fmt=") and the options part ($options, which starts
@ -128,23 +141,10 @@ _filter_img_create()
# (And just echo everything before the first "^Formatting")
readarray formatting_line < <($SED -e 's/, fmt=/\n/')
filename_part=''
options=''
lines=${#formatting_line[@]}
for ((i = 0; i < $lines; i++)); do
line=${formatting_line[i]}
unset formatting_line[i]
filename_part=${formatting_line[0]}
unset formatting_line[0]
filename_part="$filename_part$line"
if echo "$line" | grep -q '^Formatting'; then
next_i=$((i + 1))
if [ -n "${formatting_line[next_i]}" ]; then
options="fmt=${formatting_line[@]}"
fi
break
fi
done
# Set grep_data_file to '\|data_file' to keep it; make it empty
# to drop it.
@ -156,17 +156,7 @@ _filter_img_create()
grep_data_file=()
fi
filename_filters=(
-e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
-e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
-e "s#$TEST_DIR#TEST_DIR#g" \
-e "s#$SOCK_DIR#SOCK_DIR#g" \
-e "s#$IMGFMT#IMGFMT#g" \
-e 's#nbd:127.0.0.1:[0-9]\\+#TEST_DIR/t.IMGFMT#g' \
-e 's#nbd+unix:///\??socket=SOCK_DIR/nbd#TEST_DIR/t.IMGFMT#g'
)
filename_part=$(echo "$filename_part" | $SED "${filename_filters[@]}")
filename_part=$(echo "$filename_part" | _filter_img_create_filenames)
# Break the option line before each option (preserving pre-existing
# line breaks by replacing them by \0 and restoring them at the end),
@ -179,7 +169,8 @@ _filter_img_create()
| $SED -e 's/ \([a-z0-9_.-]*\)=/\n\1=/g' \
| grep -a -e '^fmt' -e '^size' -e '^backing' -e '^preallocation' \
-e '^encryption' "${grep_data_file[@]}" \
| $SED "${filename_filters[@]}" \
| _filter_img_create_filenames \
| $SED \
-e 's/^\(fmt\)/0-\1/' \
-e 's/^\(size\)/1-\1/' \
-e 's/^\(backing\)/2-\1/' \
@ -199,17 +190,16 @@ _filter_img_create()
fi
}
# Filter the "Formatting..." line in QMP output (leaving the QMP output
# untouched)
# (In contrast to _filter_img_create(), this function does not support
# multi-line Formatting output)
_filter_img_create_in_qmp()
# Filter qemu-img create output:
# Pipe all ^Formatting lines through _do_filter_img_create, and all
# other lines through _filter_img_create_filenames
_filter_img_create()
{
while read -r line; do
if echo "$line" | grep -q '^Formatting'; then
echo "$line" | _filter_img_create
echo "$line" | _do_filter_img_create
else
echo "$line"
echo "$line" | _filter_img_create_filenames
fi
done
}