Patchwork [v2,3/3] qemu-iotests: Add 041 backing file chain infinite loop test

login
register
mail settings
Submitter Stefan Hajnoczi
Date Oct. 15, 2012, 12:44 p.m.
Message ID <1350305057-6287-4-git-send-email-stefanha@redhat.com>
Download mbox | patch
Permalink /patch/191555/
State New
Headers show

Comments

Stefan Hajnoczi - Oct. 15, 2012, 12:44 p.m.
This new test verifies that qemu-img info --backing-chain safely aborts
when an image file has a backing file infinite loop.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 tests/qemu-iotests/041       | 90 ++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/041.out   | 81 +++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/common.rc |  9 +++++
 tests/qemu-iotests/group     |  1 +
 4 files changed, 181 insertions(+)
 create mode 100755 tests/qemu-iotests/041
 create mode 100644 tests/qemu-iotests/041.out
Eric Blake - Oct. 15, 2012, 5:47 p.m.
On 10/15/2012 06:44 AM, Stefan Hajnoczi wrote:
> This new test verifies that qemu-img info --backing-chain safely aborts
> when an image file has a backing file infinite loop.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  tests/qemu-iotests/041       | 90 ++++++++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/041.out   | 81 +++++++++++++++++++++++++++++++++++++++

Didn't Paolo already request test id 41, and 42 is already claimed,
leaving you at 43?
https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg02481.html
Stefan Hajnoczi - Oct. 16, 2012, 8:21 a.m.
On Mon, Oct 15, 2012 at 11:47:04AM -0600, Eric Blake wrote:
> On 10/15/2012 06:44 AM, Stefan Hajnoczi wrote:
> > This new test verifies that qemu-img info --backing-chain safely aborts
> > when an image file has a backing file infinite loop.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  tests/qemu-iotests/041       | 90 ++++++++++++++++++++++++++++++++++++++++++++
> >  tests/qemu-iotests/041.out   | 81 +++++++++++++++++++++++++++++++++++++++
> 
> Didn't Paolo already request test id 41, and 42 is already claimed,
> leaving you at 43?
> https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg02481.html

Okay, thanks.  I didn't see that before sending.

Kevin, Paolo: let me know after you've reviewed these patches and I can
bump to 043.

Stefan
Kevin Wolf - Oct. 16, 2012, 10:22 a.m.
Am 15.10.2012 14:44, schrieb Stefan Hajnoczi:
> This new test verifies that qemu-img info --backing-chain safely aborts
> when an image file has a backing file infinite loop.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  tests/qemu-iotests/041       | 90 ++++++++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/041.out   | 81 +++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/common.rc |  9 +++++
>  tests/qemu-iotests/group     |  1 +
>  4 files changed, 181 insertions(+)
>  create mode 100755 tests/qemu-iotests/041
>  create mode 100644 tests/qemu-iotests/041.out
> 
> diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
> new file mode 100755
> index 0000000..839255f
> --- /dev/null
> +++ b/tests/qemu-iotests/041
> @@ -0,0 +1,90 @@
> +#!/bin/bash
> +#
> +# Test that qemu-img info --backing-chain detects infinite loops
> +#
> +# Copyright (C) 2012 Red Hat, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +
> +# creator
> +owner=stefanha@redhat.com
> +
> +seq=`basename $0`
> +echo "QA output created by $seq"
> +
> +here=`pwd`
> +tmp=/tmp/$$
> +status=1	# failure is the default!
> +
> +_cleanup()
> +{
> +	_cleanup_test_img

This forgets to remove $TEST_IMG.[123].base.

> diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
> new file mode 100644
> index 0000000..0c871b0
> --- /dev/null
> +++ b/tests/qemu-iotests/041.out
> @@ -0,0 +1,81 @@
> +QA output created by 041
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
> +
> +== backing file references self ==
> +qemu-img: Aborting due to backing file chain infinite loop.
> +image: TEST_DIR/t.IMGFMT
> +file format: IMGFMT
> +virtual size: 128M (134217728 bytes)
> +cluster_size: 65536
> +backing file: TEST_DIR/t.IMGFMT

I'd expect the error message to be at the end. Should we disable stdout
buffering completely in qemu-img or add an fflush(stdout)?

Also I think adding a test for JSON mode would make sense.

Kevin
Stefan Hajnoczi - Oct. 16, 2012, 2:53 p.m.
On Tue, Oct 16, 2012 at 12:22:38PM +0200, Kevin Wolf wrote:
> Am 15.10.2012 14:44, schrieb Stefan Hajnoczi:
> > This new test verifies that qemu-img info --backing-chain safely aborts
> > when an image file has a backing file infinite loop.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  tests/qemu-iotests/041       | 90 ++++++++++++++++++++++++++++++++++++++++++++
> >  tests/qemu-iotests/041.out   | 81 +++++++++++++++++++++++++++++++++++++++
> >  tests/qemu-iotests/common.rc |  9 +++++
> >  tests/qemu-iotests/group     |  1 +
> >  4 files changed, 181 insertions(+)
> >  create mode 100755 tests/qemu-iotests/041
> >  create mode 100644 tests/qemu-iotests/041.out
> > 
> > diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
> > new file mode 100755
> > index 0000000..839255f
> > --- /dev/null
> > +++ b/tests/qemu-iotests/041
> > @@ -0,0 +1,90 @@
> > +#!/bin/bash
> > +#
> > +# Test that qemu-img info --backing-chain detects infinite loops
> > +#
> > +# Copyright (C) 2012 Red Hat, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 2 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> > +#
> > +
> > +# creator
> > +owner=stefanha@redhat.com
> > +
> > +seq=`basename $0`
> > +echo "QA output created by $seq"
> > +
> > +here=`pwd`
> > +tmp=/tmp/$$
> > +status=1	# failure is the default!
> > +
> > +_cleanup()
> > +{
> > +	_cleanup_test_img
> 
> This forgets to remove $TEST_IMG.[123].base.

Thanks for pointing this out.

> > diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
> > new file mode 100644
> > index 0000000..0c871b0
> > --- /dev/null
> > +++ b/tests/qemu-iotests/041.out
> > @@ -0,0 +1,81 @@
> > +QA output created by 041
> > +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
> > +
> > +== backing file references self ==
> > +qemu-img: Aborting due to backing file chain infinite loop.
> > +image: TEST_DIR/t.IMGFMT
> > +file format: IMGFMT
> > +virtual size: 128M (134217728 bytes)
> > +cluster_size: 65536
> > +backing file: TEST_DIR/t.IMGFMT
> 
> I'd expect the error message to be at the end. Should we disable stdout
> buffering completely in qemu-img or add an fflush(stdout)?

This is a special case - we'll also need to carefully terminate the JSON
array.  So a fflush(stdout) with a comment works well.  I will add it.

> Also I think adding a test for JSON mode would make sense.

I'll do that.

Stefan

Patch

diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
new file mode 100755
index 0000000..839255f
--- /dev/null
+++ b/tests/qemu-iotests/041
@@ -0,0 +1,90 @@ 
+#!/bin/bash
+#
+# Test that qemu-img info --backing-chain detects infinite loops
+#
+# Copyright (C) 2012 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# creator
+owner=stefanha@redhat.com
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+
+_cleanup()
+{
+	_cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# Any format supporting backing files
+_supported_fmt qcow qcow2 vmdk qed
+_supported_proto generic
+_supported_os Linux
+
+
+size=128M
+_make_test_img $size
+$QEMU_IMG rebase -u -b $TEST_IMG $TEST_IMG
+
+echo
+echo "== backing file references self =="
+_img_info --backing-chain
+
+_make_test_img $size
+mv $TEST_IMG $TEST_IMG.base
+_make_test_img -b $TEST_IMG.base $size
+$QEMU_IMG rebase -u -b $TEST_IMG $TEST_IMG.base
+
+echo
+echo "== parent references self =="
+_img_info --backing-chain
+
+_make_test_img $size
+mv $TEST_IMG $TEST_IMG.1.base
+_make_test_img -b $TEST_IMG.1.base $size
+mv $TEST_IMG $TEST_IMG.2.base
+_make_test_img -b $TEST_IMG.2.base $size
+mv $TEST_IMG $TEST_IMG.3.base
+_make_test_img -b $TEST_IMG.3.base $size
+$QEMU_IMG rebase -u -b $TEST_IMG.2.base $TEST_IMG.1.base
+
+echo
+echo "== ancestor references another ancestor =="
+_img_info --backing-chain
+
+_make_test_img $size
+mv $TEST_IMG $TEST_IMG.1.base
+_make_test_img -b $TEST_IMG.1.base $size
+mv $TEST_IMG $TEST_IMG.2.base
+_make_test_img -b $TEST_IMG.2.base $size
+
+echo
+echo "== finite chain of length 3 =="
+_img_info --backing-chain
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
new file mode 100644
index 0000000..0c871b0
--- /dev/null
+++ b/tests/qemu-iotests/041.out
@@ -0,0 +1,81 @@ 
+QA output created by 041
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
+
+== backing file references self ==
+qemu-img: Aborting due to backing file chain infinite loop.
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR/t.IMGFMT.base' 
+
+== parent references self ==
+qemu-img: Aborting due to backing file chain infinite loop.
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT.base
+
+image: TEST_DIR/t.IMGFMT.base
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR/t.IMGFMT.1.base' 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR/t.IMGFMT.2.base' 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR/t.IMGFMT.3.base' 
+
+== ancestor references another ancestor ==
+qemu-img: Aborting due to backing file chain infinite loop.
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT.3.base
+
+image: TEST_DIR/t.IMGFMT.3.base
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT.2.base
+
+image: TEST_DIR/t.IMGFMT.2.base
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT.1.base
+
+image: TEST_DIR/t.IMGFMT.1.base
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT.2.base
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR/t.IMGFMT.1.base' 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR/t.IMGFMT.2.base' 
+
+== finite chain of length 3 ==
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT.2.base
+
+image: TEST_DIR/t.IMGFMT.2.base
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+backing file: TEST_DIR/t.IMGFMT.1.base
+
+image: TEST_DIR/t.IMGFMT.1.base
+file format: IMGFMT
+virtual size: 128M (134217728 bytes)
+cluster_size: 65536
+*** done
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index d534e94..aa80b5f 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -145,6 +145,15 @@  _check_test_img()
     	sed -e 's/qemu-img\: This image format does not support checks/No errors were found on the image./'
 }
 
+_img_info()
+{
+    $QEMU_IMG info "$@" $TEST_IMG | \
+        sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
+            -e "s#$TEST_DIR#TEST_DIR#g" \
+            -e "s#$IMGFMT#IMGFMT#g" \
+            -e "/^disk size:/ D" # ignore on-disk size, it can vary
+}
+
 _get_pids_by_name()
 {
     if [ $# -ne 1 ]
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 66d2ba9..ee73b8d 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -47,3 +47,4 @@ 
 038 rw auto backing
 039 rw auto
 040 rw auto
+041 rw auto backing