qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

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: Nir Soffer <nirsof@gmail.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20170201003120.23378-2-nirsof@gmail.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>

authored by

Nir Soffer and committed by
Max Reitz
b7aa1315 f67409a5

+6 -84
+6 -2
qemu-io.c
··· 595 595 exit(1); 596 596 } 597 597 opts = qemu_opts_to_qdict(qopts, NULL); 598 - openfile(NULL, flags, writethrough, opts); 598 + if (openfile(NULL, flags, writethrough, opts)) { 599 + exit(1); 600 + } 599 601 } else { 600 602 if (format) { 601 603 opts = qdict_new(); 602 604 qdict_put(opts, "driver", qstring_from_str(format)); 603 605 } 604 - openfile(argv[optind], flags, writethrough, opts); 606 + if (openfile(argv[optind], flags, writethrough, opts)) { 607 + exit(1); 608 + } 605 609 } 606 610 } 607 611 command_loop();
-3
tests/qemu-iotests/059.out
··· 3 3 === Testing invalid granularity === 4 4 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 5 5 can't open device TEST_DIR/t.vmdk: Invalid granularity, image may be corrupt 6 - no file open, try 'help open' 7 6 8 7 === Testing too big L2 table size === 9 8 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 10 9 can't open device TEST_DIR/t.vmdk: L2 table size too big 11 - no file open, try 'help open' 12 10 13 11 === Testing too big L1 table size === 14 12 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 15 13 can't open device TEST_DIR/t.vmdk: L1 size too big 16 - no file open, try 'help open' 17 14 18 15 === Testing monolithicFlat creation and opening === 19 16 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
-1
tests/qemu-iotests/070.out
··· 4 4 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 5 5 To replay the log, run: 6 6 qemu-img check -r all 'TEST_DIR/iotest-dirtylog-10G-4M.vhdx' 7 - no file open, try 'help open' 8 7 === Verify open image replays log === 9 8 read 18874368/18874368 bytes at offset 0 10 9 18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-7
tests/qemu-iotests/075.out
··· 10 10 11 11 == block_size must be a multiple of 512 == 12 12 can't open device TEST_DIR/simple-pattern.cloop: block_size 513 must be a multiple of 512 13 - no file open, try 'help open' 14 13 15 14 == block_size cannot be zero == 16 15 can't open device TEST_DIR/simple-pattern.cloop: block_size cannot be zero 17 - no file open, try 'help open' 18 16 19 17 == huge block_size === 20 18 can't open device TEST_DIR/simple-pattern.cloop: block_size 4294966784 must be 64 MB or less 21 - no file open, try 'help open' 22 19 23 20 == offsets_size overflow === 24 21 can't open device TEST_DIR/simple-pattern.cloop: n_blocks 4294967295 must be 536870911 or less 25 - no file open, try 'help open' 26 22 27 23 == refuse images that require too many offsets === 28 24 can't open device TEST_DIR/simple-pattern.cloop: image requires too many offsets, try increasing block size 29 - no file open, try 'help open' 30 25 31 26 == refuse images with non-monotonically increasing offsets == 32 27 can't open device TEST_DIR/simple-pattern.cloop: offsets not monotonically increasing at index 1, image file is corrupt 33 - no file open, try 'help open' 34 28 35 29 == refuse images with invalid compressed block size == 36 30 can't open device TEST_DIR/simple-pattern.cloop: invalid compressed block size at index 1, image file is corrupt 37 - no file open, try 'help open' 38 31 *** done
-3
tests/qemu-iotests/076.out
··· 6 6 7 7 == Negative catalog size == 8 8 can't open device TEST_DIR/parallels-v1: Catalog too large 9 - no file open, try 'help open' 10 9 11 10 == Overflow in catalog allocation == 12 11 can't open device TEST_DIR/parallels-v1: Catalog too large 13 - no file open, try 'help open' 14 12 15 13 == Zero sectors per track == 16 14 can't open device TEST_DIR/parallels-v1: Invalid image: Zero sectors per track 17 - no file open, try 'help open' 18 15 19 16 == Read from a valid v2 image == 20 17 read 65536/65536 bytes at offset 0
-6
tests/qemu-iotests/078.out
··· 6 6 7 7 == Negative catalog size == 8 8 can't open device TEST_DIR/empty.bochs: Catalog size is too large 9 - no file open, try 'help open' 10 9 11 10 == Overflow for catalog size * sizeof(uint32_t) == 12 11 can't open device TEST_DIR/empty.bochs: Catalog size is too large 13 - no file open, try 'help open' 14 12 15 13 == Too small catalog bitmap for image size == 16 14 can't open device TEST_DIR/empty.bochs: Catalog size is too small for this disk size 17 - no file open, try 'help open' 18 15 can't open device TEST_DIR/empty.bochs: Catalog size is too small for this disk size 19 - no file open, try 'help open' 20 16 21 17 == Negative extent size == 22 18 can't open device TEST_DIR/empty.bochs: Extent size 2147483648 is too large 23 - no file open, try 'help open' 24 19 25 20 == Zero extent size == 26 21 can't open device TEST_DIR/empty.bochs: Extent size must be at least 512 27 - no file open, try 'help open' 28 22 *** done
-18
tests/qemu-iotests/080.out
··· 3 3 == Huge header size == 4 4 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 5 5 can't open device TEST_DIR/t.qcow2: qcow2 header exceeds cluster size 6 - no file open, try 'help open' 7 6 can't open device TEST_DIR/t.qcow2: qcow2 header exceeds cluster size 8 - no file open, try 'help open' 9 7 10 8 == Huge unknown header extension == 11 9 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 12 10 can't open device TEST_DIR/t.qcow2: Invalid backing file offset 13 - no file open, try 'help open' 14 11 can't open device TEST_DIR/t.qcow2: Header extension too large 15 - no file open, try 'help open' 16 12 can't open device TEST_DIR/t.qcow2: Header extension too large 17 - no file open, try 'help open' 18 13 19 14 == Huge refcount table size == 20 15 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 21 16 can't open device TEST_DIR/t.qcow2: Reference count table too large 22 - no file open, try 'help open' 23 17 can't open device TEST_DIR/t.qcow2: Reference count table too large 24 - no file open, try 'help open' 25 18 26 19 == Misaligned refcount table == 27 20 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 28 21 can't open device TEST_DIR/t.qcow2: Invalid reference count table offset 29 - no file open, try 'help open' 30 22 31 23 == Huge refcount offset == 32 24 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 33 25 can't open device TEST_DIR/t.qcow2: Invalid reference count table offset 34 - no file open, try 'help open' 35 26 36 27 == Invalid snapshot table == 37 28 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 38 29 can't open device TEST_DIR/t.qcow2: Too many snapshots 39 - no file open, try 'help open' 40 30 can't open device TEST_DIR/t.qcow2: Too many snapshots 41 - no file open, try 'help open' 42 31 can't open device TEST_DIR/t.qcow2: Invalid snapshot table offset 43 - no file open, try 'help open' 44 32 can't open device TEST_DIR/t.qcow2: Invalid snapshot table offset 45 - no file open, try 'help open' 46 33 47 34 == Hitting snapshot table size limit == 48 35 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 ··· 53 40 == Invalid L1 table == 54 41 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 55 42 can't open device TEST_DIR/t.qcow2: Active L1 table too large 56 - no file open, try 'help open' 57 43 can't open device TEST_DIR/t.qcow2: Active L1 table too large 58 - no file open, try 'help open' 59 44 can't open device TEST_DIR/t.qcow2: Invalid L1 table offset 60 - no file open, try 'help open' 61 45 can't open device TEST_DIR/t.qcow2: Invalid L1 table offset 62 - no file open, try 'help open' 63 46 64 47 == Invalid L1 table (with internal snapshot in the image) == 65 48 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 ··· 68 51 == Invalid backing file size == 69 52 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 70 53 can't open device TEST_DIR/t.qcow2: Backing file name too long 71 - no file open, try 'help open' 72 54 73 55 == Invalid L2 entry (huge physical offset) == 74 56 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
-17
tests/qemu-iotests/083.out
··· 2 2 === Check disconnect before neg1 === 3 3 4 4 can't open device nbd:127.0.0.1:PORT:exportname=foo 5 - no file open, try 'help open' 6 5 7 6 === Check disconnect after neg1 === 8 7 9 8 can't open device nbd:127.0.0.1:PORT:exportname=foo 10 - no file open, try 'help open' 11 9 12 10 === Check disconnect 8 neg1 === 13 11 14 12 can't open device nbd:127.0.0.1:PORT:exportname=foo 15 - no file open, try 'help open' 16 13 17 14 === Check disconnect 16 neg1 === 18 15 19 16 can't open device nbd:127.0.0.1:PORT:exportname=foo 20 - no file open, try 'help open' 21 17 22 18 === Check disconnect before export === 23 19 24 20 can't open device nbd:127.0.0.1:PORT:exportname=foo 25 - no file open, try 'help open' 26 21 27 22 === Check disconnect after export === 28 23 29 24 can't open device nbd:127.0.0.1:PORT:exportname=foo 30 - no file open, try 'help open' 31 25 32 26 === Check disconnect 4 export === 33 27 34 28 can't open device nbd:127.0.0.1:PORT:exportname=foo 35 - no file open, try 'help open' 36 29 37 30 === Check disconnect 12 export === 38 31 39 32 can't open device nbd:127.0.0.1:PORT:exportname=foo 40 - no file open, try 'help open' 41 33 42 34 === Check disconnect 16 export === 43 35 44 36 can't open device nbd:127.0.0.1:PORT:exportname=foo 45 - no file open, try 'help open' 46 37 47 38 === Check disconnect before neg2 === 48 39 49 40 can't open device nbd:127.0.0.1:PORT:exportname=foo 50 - no file open, try 'help open' 51 41 52 42 === Check disconnect after neg2 === 53 43 ··· 56 46 === Check disconnect 8 neg2 === 57 47 58 48 can't open device nbd:127.0.0.1:PORT:exportname=foo 59 - no file open, try 'help open' 60 49 61 50 === Check disconnect 10 neg2 === 62 51 63 52 can't open device nbd:127.0.0.1:PORT:exportname=foo 64 - no file open, try 'help open' 65 53 66 54 === Check disconnect before request === 67 55 ··· 99 87 === Check disconnect before neg-classic === 100 88 101 89 can't open device nbd:127.0.0.1:PORT 102 - no file open, try 'help open' 103 90 104 91 === Check disconnect 8 neg-classic === 105 92 106 93 can't open device nbd:127.0.0.1:PORT 107 - no file open, try 'help open' 108 94 109 95 === Check disconnect 16 neg-classic === 110 96 111 97 can't open device nbd:127.0.0.1:PORT 112 - no file open, try 'help open' 113 98 114 99 === Check disconnect 24 neg-classic === 115 100 116 101 can't open device nbd:127.0.0.1:PORT 117 - no file open, try 'help open' 118 102 119 103 === Check disconnect 28 neg-classic === 120 104 121 105 can't open device nbd:127.0.0.1:PORT 122 - no file open, try 'help open' 123 106 124 107 === Check disconnect after neg-classic === 125 108
-6
tests/qemu-iotests/088.out
··· 3 3 == Invalid block size == 4 4 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 5 5 can't open device TEST_DIR/t.vpc: Invalid block size 0 6 - no file open, try 'help open' 7 6 can't open device TEST_DIR/t.vpc: Invalid block size 0 8 - no file open, try 'help open' 9 7 can't open device TEST_DIR/t.vpc: Invalid block size 128 10 - no file open, try 'help open' 11 8 can't open device TEST_DIR/t.vpc: Invalid block size 128 12 - no file open, try 'help open' 13 9 can't open device TEST_DIR/t.vpc: Invalid block size 305419896 14 - no file open, try 'help open' 15 10 can't open device TEST_DIR/t.vpc: Invalid block size 305419896 16 - no file open, try 'help open' 17 11 *** done
-12
tests/qemu-iotests/092.out
··· 3 3 == Invalid cluster size == 4 4 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 5 5 can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k 6 - no file open, try 'help open' 7 6 can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k 8 - no file open, try 'help open' 9 7 can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k 10 - no file open, try 'help open' 11 8 can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k 12 - no file open, try 'help open' 13 9 14 10 == Invalid L2 table size == 15 11 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 16 12 can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k 17 - no file open, try 'help open' 18 13 can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k 19 - no file open, try 'help open' 20 14 can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k 21 - no file open, try 'help open' 22 15 can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k 23 - no file open, try 'help open' 24 16 25 17 == Invalid size == 26 18 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 27 19 can't open device TEST_DIR/t.qcow: Image too large 28 - no file open, try 'help open' 29 20 can't open device TEST_DIR/t.qcow: Image too large 30 - no file open, try 'help open' 31 21 32 22 == Invalid backing file length == 33 23 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 34 24 can't open device TEST_DIR/t.qcow: Backing file name too long 35 - no file open, try 'help open' 36 25 can't open device TEST_DIR/t.qcow: Backing file name too long 37 - no file open, try 'help open' 38 26 *** done
-7
tests/qemu-iotests/116.out
··· 3 3 == truncated header cluster == 4 4 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 5 5 can't open device TEST_DIR/t.qed: Could not open 'TEST_DIR/t.qed': Invalid argument 6 - no file open, try 'help open' 7 6 8 7 == invalid header magic == 9 8 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 10 9 can't open device TEST_DIR/t.qed: Image not in QED format 11 - no file open, try 'help open' 12 10 13 11 == invalid cluster size == 14 12 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 15 13 can't open device TEST_DIR/t.qed: Could not open 'TEST_DIR/t.qed': Invalid argument 16 - no file open, try 'help open' 17 14 18 15 == invalid table size == 19 16 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 20 17 can't open device TEST_DIR/t.qed: Could not open 'TEST_DIR/t.qed': Invalid argument 21 - no file open, try 'help open' 22 18 23 19 == invalid header size == 24 20 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 25 21 can't open device TEST_DIR/t.qed: Could not open 'TEST_DIR/t.qed': Invalid argument 26 - no file open, try 'help open' 27 22 28 23 == invalid L1 table offset == 29 24 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 30 25 can't open device TEST_DIR/t.qed: Could not open 'TEST_DIR/t.qed': Invalid argument 31 - no file open, try 'help open' 32 26 33 27 == invalid image size == 34 28 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 35 29 can't open device TEST_DIR/t.qed: Could not open 'TEST_DIR/t.qed': Invalid argument 36 - no file open, try 'help open' 37 30 *** done
-1
tests/qemu-iotests/131.out
··· 23 23 32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 24 24 == Corrupt image == 25 25 can't open device TEST_DIR/t.parallels: parallels: Image was not closed correctly; cannot be opened read/write 26 - no file open, try 'help open' 27 26 ERROR image was not closed correctly 28 27 29 28 1 errors were found on the image.
-1
tests/qemu-iotests/140.out
··· 9 9 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 10 10 {"return": {}} 11 11 can't open device nbd+unix:///drv?socket=TEST_DIR/nbd: No export with name 'drv' available 12 - no file open, try 'help open' 13 12 {"return": {}} 14 13 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"} 15 14 *** done