qemu-img: Fix content mismatch offset of image compare
PATCH 1/1 qemu-img: Fix content mismatch offset of image compare
We were lucky to pass qemu-iotests 048 (qemu-img compare case) but when I tried to run with TEST_DIR=/tmp (tmpfs), it fails with a very weird mismatch offset. This fixes the bug.
In the if branch, setting ret to 1 before using it makes dead code in the next line: pnum is never added to mismatch offset even if ret was 0.
--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
@@ -1020,10 +1020,10 @@ static int img_compare(int argc, char **argv) } ret =compare_sectors (buf1, buf2, nb_sectors, &pnum);if (ret || pnum != nb_sectors) { - ret =1 ;qprintf (quiet,"Content mismatch at offset %" PRId64"!\n" ,sectors_to_bytes ( ret ? sector_num : sector_num + pnum)); + ret =1 ; goto out; } }
Signature · 1 line
1.8.4.2
PATCH 1/1 qemu-img: re-assign ret after reporting original error
Currently the output error is always:
strerror(-4) -> Unknown error -4
This patch moves ret assignment after reporting original error.
--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
@@ -1045,9 +1045,9 @@ static int img_compare(int argc, char **argv) }if (ret) {if (ret <0 ) { - ret =4 ;error_report ("Error while reading offset %" PRId64": %s" ,sectors_to_bytes (sector_num),strerror (-ret)); + ret =4 ; } goto out; }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error
Am 13.11.2013 um 06:24 hat Amos Kong geschrieben:
Quoted 6 lines
Currently the output error is always:
strerror(-4) -> Unknown error -4This patch moves ret assignment after reporting original error.
Signed-off-by Amos Kong <[email protected]>
Fam and Amos, can you consolidate the fixes in one patch, and update the test case in the same patch as well?
Kevin
Quoted 17 lines · Fam Zheng
We were lucky to pass qemu-iotests 048 (qemu-img compare case) but when I tried to run with TEST_DIR=/tmp (tmpfs), it fails with a very weird mismatch offset. This fixes the bug.
In the if branch, setting ret to 1 before using it makes dead code in the next line: pnum is never added to mismatch offset even if ret was 0.
Signed-off-by Fam Zheng <[email protected]>--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qemu-img.c +0
-0
qemu-img.c static int img_compare(int argc, char **argv) · line 1026
Quoted 8 lines
qemu-img.c +1
-1@@ -1020,10 +1020,10 @@ static int img_compare(int argc, char **argv) } ret =compare_sectors (buf1, buf2, nb_sectors, &pnum);if (ret || pnum != nb_sectors) { - ret =1 ;qprintf (quiet,"Content mismatch at offset %" PRId64"!\n" ,sectors_to_bytes ( ret ? sector_num : sector_num + pnum)); + ret =1 ;
Looks good
Quoted 6 lines
qemu-img.c +0
-0goto out; } }Signature · 1 line
1.8.4.2
Signature · 1 line
Amos.
----- Original Message -----
Quoted 35 lines
From: "Fam Zheng" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], "Miroslav Rezanina" <[email protected]>
Sent: Wednesday, November 13, 2013 5:04:18 AM
Subject: [PATCH] qemu-img: Fix content mismatch offset of image compareWe were lucky to pass qemu-iotests 048 (qemu-img compare case) but when I tried to run with TEST_DIR=/tmp (tmpfs), it fails with a very weird mismatch offset. This fixes the bug.
In the if branch, setting ret to 1 before using it makes dead code in the next line: pnum is never added to mismatch offset even if ret was 0.
Signed-off-by Fam Zheng <[email protected]>--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)qemu-img.c +1
-1@@ -1020,10 +1020,10 @@ static int img_compare(int argc, char **argv) } ret =compare_sectors (buf1, buf2, nb_sectors, &pnum);if (ret || pnum != nb_sectors) { - ret =1 ;qprintf (quiet,"Content mismatch at offset %" PRId64"!\n" ,sectors_to_bytes ( ret ? sector_num : sector_num + pnum)); + ret =1 ; goto out; }}
Quoted 4 lines
--
1.8.4.2
Correct fix, setting variable to constant before test is definitely wrong.
Signature · 2 lines
Miroslav Rezanina Software Engineer - Virtualization Team