Skip to contentSkip to conversation

block: qemu-iotests, more quoting fixes

PATCH Applied Jeff Cody 3 participants 16 messages Oct 31, 2013 – Nov 5, 2013

lore
Share & tools
lore

Jeff Cody

author
#0 lore raw

cover block: qemu-iotests, more quoting fixes

There are still problems with the qemu-iotests, if the pathname of the working directory contains spaces. This series fixes most of them. To verify,
./check -qcow2 was run from a pathname with spaces (e.g., renamed ~/qemu-kvm
to "~/qemu-kvm test/").

The following tests still fail due to pathnames with spaces, and are not addressed in this series: 059, 067.

Jeff Cody (7):
block: qemu-iotests, add quotes to $TEST_IMG usage io pattern tests
block: qemu-iotests, fix _make_test_img() to work with spaced
pathnames
block: qemu-iotests, add quotes to $TEST_IMG.base usage in 017
block: qemu-iotests, add quotes to $TEST_IMG usage in 019
block: qemu-iotests, removes duplicate double quotes in 039
block: qemu-iotests, add quotes to $TEST_IMG usage for 051
block: qemu-iotests, add quotes to $TEST_IMG usage in 061

 tests/qemu-iotests/017            |  2 +-
 tests/qemu-iotests/019            |  6 +++---
 tests/qemu-iotests/039            |  2 +-
 tests/qemu-iotests/051            |  8 ++++----
 tests/qemu-iotests/061            |  6 +++---
 tests/qemu-iotests/common.pattern | 12 ++++++------
 tests/qemu-iotests/common.rc      | 13 +++++++++++--
 7 files changed, 29 insertions(+), 20 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/7 block: qemu-iotests, add quotes to $TEST_IMG usage io pattern tests

The usage of $TEST_IMG was not properly quoted everywhere in common.pattern.

---
 tests/qemu-iotests/common.pattern | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tests/qemu-iotests/common.pattern +6 -6
index 00e0f60..ddfbca1 100644
@@ -28,7 +28,7 @@ function do_is_allocated() {
 }
 
 function is_allocated() {
-    do_is_allocated "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
+    do_is_allocated "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
 }
 
 function do_io() {
@@ -46,18 +46,18 @@ function do_io() {
 }
 
 function io_pattern() {
-    do_io "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
+    do_io "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
 }
 
 function io() {
     local start=$2
     local pattern=$(( (start >> 9) % 256 ))
 
-    do_io "$@" $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io
+    do_io "$@" $pattern | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
 }
 
 function io_zero() {
-    do_io "$@" 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io
+    do_io "$@" 0 | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
 }
 
 function io_test() {
@@ -117,8 +117,8 @@ function io_test2() {
     echo === Clusters to be compressed [3]
     io_pattern writev $((offset + 8 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
 
-    mv $TEST_IMG $TEST_IMG.orig
-    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG
+    mv "$TEST_IMG" "$TEST_IMG.orig"
+    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c "$TEST_IMG.orig" "$TEST_IMG"
 
     # Write the used clusters
     echo === Used clusters [1]
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH 2/7 block: qemu-iotests, fix _make_test_img() to work with spaced pathnames

In reply to Jeff Cody

_make_test_img() currently works with spaced pathnames only when not specifying a backing file. This fixes it so that the backing file argument is properly quoted.

---
 tests/qemu-iotests/common.rc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tests/qemu-iotests/common.rc +11 -2
index 4e82604..d24de2c 100644
@@ -111,6 +111,8 @@ _make_test_img()
     local image_size=$*
     local optstr=""
     local img_name=""
+    local use_backing=0
+    local backing_file=""
 
     if [ -n "$TEST_IMG_FILE" ]; then
         img_name=$TEST_IMG_FILE
@@ -123,7 +125,8 @@ _make_test_img()
     fi
 
     if [ "$1" = "-b" ]; then
-        extra_img_options="$1 $2"
+        use_backing=1
+        backing_file=$2
         image_size=$3
     fi
     if [ \( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \) -a -n "$CLUSTER_SIZE" ]; then
@@ -135,7 +138,13 @@ _make_test_img()
     fi
 
     # XXX(hch): have global image options?
-    $QEMU_IMG create -f $IMGFMT $extra_img_options $img_name $image_size 2>&1 | \
+    (
+     if [ $use_backing = 1 ]; then
+        $QEMU_IMG create -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" $image_size 2>&1
+     else
+        $QEMU_IMG create -f $IMGFMT $extra_img_options "$img_name" $image_size 2>&1
+     fi
+    ) | \
         sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
             -e "s#$TEST_DIR#TEST_DIR#g" \
             -e "s#$IMGFMT#IMGFMT#g" \
Signature · 1 line
1.8.3.1
author
#5 lore raw

PATCH 3/7 block: qemu-iotests, add quotes to $TEST_IMG.base usage in 017

In reply to Jeff Cody

$TEST_IMG.base is used unquoted. Add quotes so that pathnames with spaces are supported.

---
 tests/qemu-iotests/017 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/017 +1 -1
index 45f2c0b..aba3faf 100755
@@ -66,7 +66,7 @@ echo "Creating test image with backing file"
 echo
 
 TEST_IMG=$TEST_IMG_SAVE
-_make_test_img -b $TEST_IMG.base 6G
+_make_test_img -b "$TEST_IMG.base" 6G
 
 echo "Filling test image"
 echo
Signature · 1 line
1.8.3.1
author
#7 lore raw

PATCH 4/7 block: qemu-iotests, add quotes to $TEST_IMG usage in 019

In reply to Jeff Cody

There were still instances of $TEST_IMG not being properly quoted. This was in the usage of a string built up for a 'for' loop; modify the loop so we can quote $TEST_IMG properly.

---
 tests/qemu-iotests/019 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/qemu-iotests/019 +3 -3
index cd3582c..5bb18d0 100755
@@ -90,12 +90,12 @@ mv "$TEST_IMG" "$TEST_IMG.orig"
 # Test the conversion twice: One test with the old-style -B option and another
 # one with -o backing_file
 
-for backing_option in "-B $TEST_IMG.base" "-o backing_file=$TEST_IMG.base"; do
+for backing_option in "-B " "-o backing_file="; do
 
     echo
-    echo Testing conversion with $backing_option | _filter_testdir | _filter_imgfmt
+    echo Testing conversion with $backing_option$TEST_IMG.base | _filter_testdir | _filter_imgfmt
     echo
-    $QEMU_IMG convert -O $IMGFMT $backing_option "$TEST_IMG.orig" "$TEST_IMG"
+    $QEMU_IMG convert -O $IMGFMT $backing_option"$TEST_IMG.base" "$TEST_IMG.orig" "$TEST_IMG"
 
     echo "Checking if backing clusters are allocated when they shouldn't"
     echo
Signature · 1 line
1.8.3.1
author
#9 lore raw

PATCH 5/7 block: qemu-iotests, removes duplicate double quotes in 039

In reply to Jeff Cody

Test 039 had $TEST_IMG with duplicate double quotes - remove duplicate.

---
 tests/qemu-iotests/039 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/039 +1 -1
index f85b4ce..8bade92 100755
@@ -54,7 +54,7 @@ echo "== Checking that image is clean on shutdown =="
 IMGOPTS="compat=1.1,lazy_refcounts=on"
 _make_test_img $size
 
-$QEMU_IO -c "write -P 0x5a 0 512" ""$TEST_IMG"" | _filter_qemu_io
+$QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
 
 # The dirty bit must not be set
 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
Signature · 1 line
1.8.3.1
author
#11 lore raw

PATCH 6/7 block: qemu-iotests, add quotes to $TEST_IMG usage for 051

In reply to Jeff Cody

There were still a couple of instances of unquoted usage of $TEST_IMG and $TEST_IMG.orig. Quoted these so they will not fail on pathnames with spaces in them.

---
 tests/qemu-iotests/051 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/qemu-iotests/051 +4 -4
index 356c375..0a4971d 100755
@@ -64,9 +64,9 @@ function run_qemu()
 size=128M
 
 _make_test_img $size
-cp $TEST_IMG $TEST_IMG.orig
-mv $TEST_IMG $TEST_IMG.base
-_make_test_img -b $TEST_IMG.base $size
+cp "$TEST_IMG" "$TEST_IMG.orig"
+mv "$TEST_IMG" "$TEST_IMG.base"
+_make_test_img -b "$TEST_IMG.base" $size
 
 echo
 echo === Unknown option ===
@@ -81,7 +81,7 @@ echo
 echo === Overriding backing file ===
 echo
 
-echo "info block" | run_qemu -drive file=$TEST_IMG,driver=qcow2,backing.file.filename=$TEST_IMG.orig -nodefaults
+echo "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig" -nodefaults
 
 echo
 echo === Enable and disable lazy refcounting on the command line, plus some invalid values ===
Signature · 1 line
1.8.3.1
author
#13 lore raw

PATCH 7/7 block: qemu-iotests, add quotes to $TEST_IMG usage in 061

In reply to Jeff Cody

When creating images with backing files in the test, the backing file argument was not quoted properly. This caused the test to fail when run from a pathname with a space. Pass the backing argument in with the -b option to _make_test_img, so it can be properly quoted.

---
 tests/qemu-iotests/061 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/qemu-iotests/061 +3 -3
index fa9319d..e42f9bd 100755
@@ -163,7 +163,7 @@ echo "=== Testing zero expansion on backed image ==="
 echo
 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
-IMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
+IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
 _check_test_img
@@ -174,7 +174,7 @@ echo "=== Testing zero expansion on backed inactive clusters ==="
 echo
 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
-IMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
+IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
 $QEMU_IMG snapshot -c foo "$TEST_IMG"
 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
@@ -190,7 +190,7 @@ echo "=== Testing zero expansion on backed image with shared L2 table ==="
 echo
 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
-IMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
+IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
 $QEMU_IMG snapshot -c foo "$TEST_IMG"
 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/7
#4 lore raw

Re: [Qemu-devel] [PATCH 2/7] block: qemu-iotests, fix _make_test_img() to work with spaced pathnames

In reply to Jeff Cody
Quoted 8 lines · Jeff Cody

_make_test_img() currently works with spaced pathnames only when not specifying a backing file. This fixes it so that the backing file argument is properly quoted.

---
 tests/qemu-iotests/common.rc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

As a slight optimization, you could avoid a subshell:

tests/qemu-iotests/common.rc _make_test_img() · line 147

Quoted 9 lines

# XXX(hch): have global image options?

tests/qemu-iotests/common.rc +7 -1
-    $QEMU_IMG create -f $IMGFMT $extra_img_options $img_name $image_size 2>&1 | \
+    (
+     if [ $use_backing = 1 ]; then
+        $QEMU_IMG create -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" $image_size 2>&1
+     else
+        $QEMU_IMG create -f $IMGFMT $extra_img_options "$img_name" $image_size 2>&1
+     fi
+    ) | \

$QEMU_IMG create -f $IMGFMT $extra_img_options \
${backing_file:+-b "$backing_file"} "$img_name" $image_size 2>&1 |

But as not everyone is a shell guru to recognize the ${var+:expansion} trick, I'm fine with the version you proposed.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 1/7
#2 lore raw

Re: [Qemu-devel] [PATCH 1/7] block: qemu-iotests, add quotes to $TEST_IMG usage io pattern tests

In reply to Jeff Cody
Quoted 7 lines · Jeff Cody

The usage of $TEST_IMG was not properly quoted everywhere in common.pattern.

---
 tests/qemu-iotests/common.pattern | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 3/7
#6 lore raw

Re: [Qemu-devel] [PATCH 3/7] block: qemu-iotests, add quotes to $TEST_IMG.base usage in 017

In reply to Jeff Cody
Quoted 7 lines · Jeff Cody

$TEST_IMG.base is used unquoted. Add quotes so that pathnames with spaces are supported.

---
 tests/qemu-iotests/017 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 5/7
#10 lore raw

Re: [Qemu-devel] [PATCH 5/7] block: qemu-iotests, removes duplicate double quotes in 039

In reply to Jeff Cody
Quoted 6 lines · Jeff Cody

Test 039 had $TEST_IMG with duplicate double quotes - remove duplicate.

---
 tests/qemu-iotests/039 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 7/7
#14 lore raw

Re: [Qemu-devel] [PATCH 7/7] block: qemu-iotests, add quotes to $TEST_IMG usage in 061

In reply to Jeff Cody
Quoted 9 lines · Jeff Cody

When creating images with backing files in the test, the backing file argument was not quoted properly. This caused the test to fail when run from a pathname with a space. Pass the backing argument in with the -b option to _make_test_img, so it can be properly quoted.

---
 tests/qemu-iotests/061 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 6/7
#12 lore raw

Re: [Qemu-devel] [PATCH 6/7] block: qemu-iotests, add quotes to $TEST_IMG usage for 051

In reply to Jeff Cody
Quoted 8 lines · Jeff Cody

There were still a couple of instances of unquoted usage of $TEST_IMG and $TEST_IMG.orig. Quoted these so they will not fail on pathnames with spaces in them.

---
 tests/qemu-iotests/051 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 4/7
#8 lore raw

Re: [Qemu-devel] [PATCH 4/7] block: qemu-iotests, add quotes to $TEST_IMG usage in 019

In reply to Jeff Cody
Quoted 15 lines · Jeff Cody

There were still instances of $TEST_IMG not being properly quoted. This was in the usage of a string built up for a 'for' loop; modify the loop so we can quote $TEST_IMG properly.

---
 tests/qemu-iotests/019 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/qemu-iotests/019 +0 -0
index cd3582c..5bb18d0 100755

tests/qemu-iotests/019 mv "$TEST_IMG" "$TEST_IMG.orig" · line 96

Quoted 9 lines
tests/qemu-iotests/019 +2 -2
@@ -90,12 +90,12 @@ mv "$TEST_IMG" "$TEST_IMG.orig"
 # Test the conversion twice: One test with the old-style -B option and another
 # one with -o backing_file
 
-for backing_option in "-B $TEST_IMG.base" "-o backing_file=$TEST_IMG.base"; do
+for backing_option in "-B " "-o backing_file="; do
 
     echo
-    echo Testing conversion with $backing_option | _filter_testdir | _filter_imgfmt
+    echo Testing conversion with $backing_option$TEST_IMG.base | _filter_testdir | _filter_imgfmt

If $TEST_IMG has 2 consecutive spaces [*], this echo produces spurious output (flattening to only 1 space). To be completely robust, you must quote here in the same manner...

tests/qemu-iotests/019 mv "$TEST_IMG" "$TEST_IMG.orig" · line 98

Quoted 3 lines
tests/qemu-iotests/019 +1 -1
     echo
-    $QEMU_IMG convert -O $IMGFMT $backing_option "$TEST_IMG.orig" "$TEST_IMG"
+    $QEMU_IMG convert -O $IMGFMT $backing_option"$TEST_IMG.base" "$TEST_IMG.orig" "$TEST_IMG"

...as what you execute. But as that corner case of misquoting doesn't fail the test, your patch is a strict improvement, so I'm okay whether you post a v2, or whether you keep this as-is and add:

[*] My favorite test for quoting bugs is renaming a directory to use 'two spaces', because some quoting bugs are missed when you only test 'one space'.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#15 lore raw
In reply to Jeff Cody
Quoted 19 lines · Jeff Cody

There are still problems with the qemu-iotests, if the pathname of the working directory contains spaces. This series fixes most of them. To verify,
./check -qcow2 was run from a pathname with spaces (e.g., renamed ~/qemu-kvm
to "~/qemu-kvm test/").

The following tests still fail due to pathnames with spaces, and are not addressed in this series: 059, 067.

Jeff Cody (7):
block: qemu-iotests, add quotes to $TEST_IMG usage io pattern tests
block: qemu-iotests, fix _make_test_img() to work with spaced
pathnames
block: qemu-iotests, add quotes to $TEST_IMG.base usage in 017
block: qemu-iotests, add quotes to $TEST_IMG usage in 019
block: qemu-iotests, removes duplicate double quotes in 039
block: qemu-iotests, add quotes to $TEST_IMG usage for 051
block: qemu-iotests, add quotes to $TEST_IMG usage in 061

Quoted 8 lines
 tests/qemu-iotests/017            |  2 +-
 tests/qemu-iotests/019            |  6 +++---
 tests/qemu-iotests/039            |  2 +-
 tests/qemu-iotests/051            |  8 ++++----
 tests/qemu-iotests/061            |  6 +++---
 tests/qemu-iotests/common.pattern | 12 ++++++------
 tests/qemu-iotests/common.rc      | 13 +++++++++++--
 7 files changed, 29 insertions(+), 20 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan