Commit b7aa1315 authored by Nir Soffer's avatar Nir Soffer Committed by Max Reitz
Browse files

qemu-io: Return non-zero exit code on failure



The result of openfile was not checked, leading to failure deep in the
actual command with confusing error message, and exiting with exit code 0.

Here is a simple example - trying to read with the wrong format:

    $ touch file
    $ qemu-io -f qcow2 -c 'read -P 1 0 1024' file; echo $?
    can't open device file: Image is not in qcow2 format
    no file open, try 'help open'
    0

With this patch, we fail earlier with exit code 1:

    $ ./qemu-io -f qcow2 -c 'read -P 1 0 1024' file; echo $?
    can't open device file: Image is not in qcow2 format
    1

Failing earlier, we don't log this error now:

    no file open, try 'help open'

But some tests expected it; the line was removed from the test output.

Signed-off-by: default avatarNir Soffer <nirsof@gmail.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Message-id: 20170201003120.23378-2-nirsof@gmail.com
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent f67409a5
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -595,13 +595,17 @@ int main(int argc, char **argv)
                exit(1);
            }
            opts = qemu_opts_to_qdict(qopts, NULL);
            openfile(NULL, flags, writethrough, opts);
            if (openfile(NULL, flags, writethrough, opts)) {
                exit(1);
            }
        } else {
            if (format) {
                opts = qdict_new();
                qdict_put(opts, "driver", qstring_from_str(format));
            }
            openfile(argv[optind], flags, writethrough, opts);
            if (openfile(argv[optind], flags, writethrough, opts)) {
                exit(1);
            }
        }
    }
    command_loop();
+0 −3
Original line number Diff line number Diff line
@@ -3,17 +3,14 @@ QA output created by 059
=== Testing invalid granularity ===
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
can't open device TEST_DIR/t.vmdk: Invalid granularity, image may be corrupt
no file open, try 'help open'

=== Testing too big L2 table size ===
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
can't open device TEST_DIR/t.vmdk: L2 table size too big
no file open, try 'help open'

=== Testing too big L1 table size ===
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
can't open device TEST_DIR/t.vmdk: L1 size too big
no file open, try 'help open'

=== Testing monolithicFlat creation and opening ===
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
+0 −1
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ QA output created by 070
can't open device TEST_DIR/iotest-dirtylog-10G-4M.vhdx: VHDX image file 'TEST_DIR/iotest-dirtylog-10G-4M.vhdx' opened read-only, but contains a log that needs to be replayed
To replay the log, run:
qemu-img check -r all 'TEST_DIR/iotest-dirtylog-10G-4M.vhdx'
 no file open, try 'help open'
=== Verify open image replays log  ===
read 18874368/18874368 bytes at offset 0
18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+0 −7
Original line number Diff line number Diff line
@@ -10,29 +10,22 @@ read 512/512 bytes at offset 1048064

== block_size must be a multiple of 512 ==
can't open device TEST_DIR/simple-pattern.cloop: block_size 513 must be a multiple of 512
no file open, try 'help open'

== block_size cannot be zero ==
can't open device TEST_DIR/simple-pattern.cloop: block_size cannot be zero
no file open, try 'help open'

== huge block_size ===
can't open device TEST_DIR/simple-pattern.cloop: block_size 4294966784 must be 64 MB or less
no file open, try 'help open'

== offsets_size overflow ===
can't open device TEST_DIR/simple-pattern.cloop: n_blocks 4294967295 must be 536870911 or less
no file open, try 'help open'

== refuse images that require too many offsets ===
can't open device TEST_DIR/simple-pattern.cloop: image requires too many offsets, try increasing block size
no file open, try 'help open'

== refuse images with non-monotonically increasing offsets ==
can't open device TEST_DIR/simple-pattern.cloop: offsets not monotonically increasing at index 1, image file is corrupt
no file open, try 'help open'

== refuse images with invalid compressed block size ==
can't open device TEST_DIR/simple-pattern.cloop: invalid compressed block size at index 1, image file is corrupt
no file open, try 'help open'
*** done
+0 −3
Original line number Diff line number Diff line
@@ -6,15 +6,12 @@ read 65536/65536 bytes at offset 0

== Negative catalog size ==
can't open device TEST_DIR/parallels-v1: Catalog too large
no file open, try 'help open'

== Overflow in catalog allocation ==
can't open device TEST_DIR/parallels-v1: Catalog too large
no file open, try 'help open'

== Zero sectors per track ==
can't open device TEST_DIR/parallels-v1: Invalid image: Zero sectors per track
no file open, try 'help open'

== Read from a valid v2 image ==
read 65536/65536 bytes at offset 0
Loading