[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 18/35] qemu-img: Drop redundant error message in comp
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 18/35] qemu-img: Drop redundant error message in compare |
Date: |
Thu, 26 Oct 2017 15:17:24 +0200 |
From: Eric Blake <address@hidden>
If a read error is encountered during 'qemu-img compare', we
were printing the "Error while reading offset ..." message twice;
this was because our helper function was awkward, printing output
on some but not all paths. Fix it to consistently report errors
on all paths, so that the callers do not risk a redundant message,
and update the testsuite for the improved output.
Further simplify the code by hoisting the conversion from an error
message to an exit code into the helper function, rather than
repeating that logic at all callers (yes, the helper function is
now less generic, but it's a net win in lines of code).
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: John Snow <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-img.c | 19 +++++--------------
tests/qemu-iotests/074.out | 2 --
2 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 89f1093d81..53cae6bb66 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1197,8 +1197,10 @@ static int64_t sectors_to_bytes(int64_t sectors)
/*
* Check if passed sectors are empty (not allocated or contain only 0 bytes)
*
- * Returns 0 in case sectors are filled with 0, 1 if sectors contain non-zero
- * data and negative value on error.
+ * Intended for use by 'qemu-img compare': Returns 0 in case sectors are
+ * filled with 0, 1 if sectors contain non-zero data (this is a comparison
+ * failure), and 4 on error (the exit status for read errors), after emitting
+ * an error message.
*
* @param blk: BlockBackend for the image
* @param sect_num: Number of first sector to check
@@ -1219,7 +1221,7 @@ static int check_empty_sectors(BlockBackend *blk, int64_t
sect_num,
if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of %s: %s",
sectors_to_bytes(sect_num), filename, strerror(-ret));
- return ret;
+ return 4;
}
idx = find_nonzero(buffer, sect_count * BDRV_SECTOR_SIZE);
if (idx >= 0) {
@@ -1476,11 +1478,6 @@ static int img_compare(int argc, char **argv)
filename2, buf1, quiet);
}
if (ret) {
- if (ret < 0) {
- error_report("Error while reading offset %" PRId64 ": %s",
- sectors_to_bytes(sector_num), strerror(-ret));
- ret = 4;
- }
goto out;
}
}
@@ -1525,12 +1522,6 @@ static int img_compare(int argc, char **argv)
ret = check_empty_sectors(blk_over, sector_num, nb_sectors,
filename_over, buf1, quiet);
if (ret) {
- if (ret < 0) {
- error_report("Error while reading offset %" PRId64
- " of %s: %s",
sectors_to_bytes(sector_num),
- filename_over, strerror(-ret));
- ret = 4;
- }
goto out;
}
}
diff --git a/tests/qemu-iotests/074.out b/tests/qemu-iotests/074.out
index 8fba5aea9c..ede66c3f81 100644
--- a/tests/qemu-iotests/074.out
+++ b/tests/qemu-iotests/074.out
@@ -4,7 +4,6 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
wrote 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
qemu-img: Error while reading offset 0 of
blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error
-qemu-img: Error while reading offset 0: Input/output error
4
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
Formatting 'TEST_DIR/t.IMGFMT.2', fmt=IMGFMT size=0
@@ -12,7 +11,6 @@ Formatting 'TEST_DIR/t.IMGFMT.2', fmt=IMGFMT size=0
wrote 512/512 bytes at offset 512
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
qemu-img: Error while reading offset 0 of
blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error
-qemu-img: Error while reading offset 0 of
blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error
Warning: Image size mismatch!
4
Cleanup
--
2.13.6
- [Qemu-devel] [PULL 06/35] qcow2: Switch is_zero_sectors() to byte-based, (continued)
- [Qemu-devel] [PULL 06/35] qcow2: Switch is_zero_sectors() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 08/35] qemu-img: Switch get_block_status() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 05/35] block: Make bdrv_round_to_clusters() signature more useful, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 12/35] block: Switch bdrv_common_block_status_above() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 10/35] block: Switch bdrv_co_get_block_status() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 15/35] qemu-img: Simplify logic in img_compare(), Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 11/35] block: Switch BdrvCoGetBlockStatusData to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 13/35] block: Switch bdrv_co_get_block_status_above() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 16/35] qemu-img: Speed up compare on pre-allocated larger file, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 14/35] block: Convert bdrv_get_block_status_above() to bytes, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 18/35] qemu-img: Drop redundant error message in compare,
Kevin Wolf <=
- [Qemu-devel] [PULL 17/35] qemu-img: Add find_nonzero(), Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 19/35] qemu-img: Change check_empty_sectors() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 22/35] qemu-img: Change img_compare() to be byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 24/35] block: Reduce bdrv_aligned_preadv() rounding, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 25/35] qcow2: Reduce is_zero() rounding, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 21/35] qemu-img: Change img_rebase() to be byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 20/35] qemu-img: Change compare_sectors() to be byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 23/35] block: Align block status requests, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 26/35] qemu-io: Relax 'alloc' now that block-status doesn't assert, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 28/35] qcow2: Use BDRV_SECTOR_BITS instead of its literal value, Kevin Wolf, 2017/10/26