* [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare
@ 2013-11-13 4:04 Fam Zheng
2013-11-13 5:24 ` [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error Amos Kong
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Fam Zheng @ 2013-11-13 4:04 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, Miroslav Rezanina, stefanha
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 <famz@redhat.com>
---
qemu-img.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/qemu-img.c b/qemu-img.c
index bf3fb4f..2bab20d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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;
}
}
--
1.8.4.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error
2013-11-13 4:04 [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare Fam Zheng
@ 2013-11-13 5:24 ` Amos Kong
2013-11-13 9:25 ` Kevin Wolf
2013-11-13 7:36 ` [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare Amos Kong
2013-11-13 8:55 ` Miroslav Rezanina
2 siblings, 1 reply; 5+ messages in thread
From: Amos Kong @ 2013-11-13 5:24 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, famz
Currently the output error is always:
strerror(-4) -> Unknown error -4
This patch moves ret assignment after reporting original error.
Signed-off-by: Amos Kong <akong@redhat.com>
---
qemu-img.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/qemu-img.c b/qemu-img.c
index 926f0a0..1fd664f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare
2013-11-13 4:04 [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare Fam Zheng
2013-11-13 5:24 ` [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error Amos Kong
@ 2013-11-13 7:36 ` Amos Kong
2013-11-13 8:55 ` Miroslav Rezanina
2 siblings, 0 replies; 5+ messages in thread
From: Amos Kong @ 2013-11-13 7:36 UTC (permalink / raw)
To: Fam Zheng; +Cc: kwolf, Miroslav Rezanina, qemu-devel, stefanha
On Wed, Nov 13, 2013 at 12:04:18PM +0800, Fam Zheng wrote:
> 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 <famz@redhat.com>
> ---
> qemu-img.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index bf3fb4f..2bab20d 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -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
> goto out;
> }
> }
> --
> 1.8.4.2
>
--
Amos.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare
2013-11-13 4:04 [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare Fam Zheng
2013-11-13 5:24 ` [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error Amos Kong
2013-11-13 7:36 ` [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare Amos Kong
@ 2013-11-13 8:55 ` Miroslav Rezanina
2 siblings, 0 replies; 5+ messages in thread
From: Miroslav Rezanina @ 2013-11-13 8:55 UTC (permalink / raw)
To: Fam Zheng; +Cc: kwolf, qemu-devel, stefanha
----- Original Message -----
> From: "Fam Zheng" <famz@redhat.com>
> To: qemu-devel@nongnu.org
> Cc: stefanha@redhat.com, kwolf@redhat.com, "Miroslav Rezanina" <mrezanin@redhat.com>
> Sent: Wednesday, November 13, 2013 5:04:18 AM
> Subject: [PATCH] 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.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> qemu-img.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index bf3fb4f..2bab20d 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -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;
> }
> }
> --
> 1.8.4.2
>
>
Correct fix, setting variable to constant before test is definitely wrong.
Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com>
--
Miroslav Rezanina
Software Engineer - Virtualization Team
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error
2013-11-13 5:24 ` [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error Amos Kong
@ 2013-11-13 9:25 ` Kevin Wolf
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2013-11-13 9:25 UTC (permalink / raw)
To: Amos Kong; +Cc: famz, qemu-devel
Am 13.11.2013 um 06:24 hat Amos Kong geschrieben:
> Currently the output error is always:
> strerror(-4) -> Unknown error -4
>
> This patch moves ret assignment after reporting original error.
>
> Signed-off-by: Amos Kong <akong@redhat.com>
Fam and Amos, can you consolidate the fixes in one patch, and update the
test case in the same patch as well?
Kevin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-11-13 9:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-13 4:04 [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare Fam Zheng
2013-11-13 5:24 ` [Qemu-devel] [PATCH] qemu-img: re-assign ret after reporting original error Amos Kong
2013-11-13 9:25 ` Kevin Wolf
2013-11-13 7:36 ` [Qemu-devel] [PATCH] qemu-img: Fix content mismatch offset of image compare Amos Kong
2013-11-13 8:55 ` Miroslav Rezanina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).