Skip to contentSkip to conversation

qemu-img: Fix content mismatch offset of image compare

PATCH In review Fam Zheng 4 participants 5 messages Nov 13, 2013

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

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
index bf3fb4f..2bab20d 100644
@@ -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
#1 lore raw

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
index 926f0a0..1fd664f 100644
@@ -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
#2 lore raw

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 -4

This patch moves ret assignment after reporting original error.

Fam and Amos, can you consolidate the fixes in one patch, and update the test case in the same patch as well?

Kevin

#3 lore raw
In reply to Fam Zheng
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.

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +0 -0
index bf3fb4f..2bab20d 100644

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 -0
                     goto out;
                 }
             }
Signature · 1 line
1.8.4.2
Signature · 1 line
			Amos.
Reviewed-by on v1 1/1
#4 lore raw
In reply to Fam Zheng

----- 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 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
index bf3fb4f..2bab20d 100644
@@ -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