Patchwork qemu-img: print error codes when convert fails

login
register
mail settings
Submitter Stefan Hajnoczi
Date Aug. 17, 2011, 4:41 p.m.
Message ID <1313599269-32257-1-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/110338/
State New
Headers show

Comments

Stefan Hajnoczi - Aug. 17, 2011, 4:41 p.m.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 qemu-img.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
Kevin Wolf - Aug. 17, 2011, 6:40 p.m.
Am 17.08.2011 18:41, schrieb Stefan Hajnoczi:
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Thanks, applied to the block branch.

(But is it really helpful to include sector numbers in the error
message? Especially since we're not reading/writing single sectors)

Kevin
Stefan Hajnoczi - Aug. 18, 2011, 2:22 p.m.
On Wed, Aug 17, 2011 at 08:40:57PM +0200, Kevin Wolf wrote:
> Am 17.08.2011 18:41, schrieb Stefan Hajnoczi:
> > Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> 
> Thanks, applied to the block branch.
> 
> (But is it really helpful to include sector numbers in the error
> message? Especially since we're not reading/writing single sectors)

The intention is that it would show suspicious sectors numbers, e.g. ~2
GB or ~4 GB.

In the best case it saves a round-trip on a bug report.  In the worst
case the sector number is a distraction :).

Stefan

Patch

diff --git a/qemu-img.c b/qemu-img.c
index b205e98..d9e6fc8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -890,7 +890,8 @@  static int img_convert(int argc, char **argv)
 
                 ret = bdrv_read(bs[bs_i], bs_num, buf2, nlow);
                 if (ret < 0) {
-                    error_report("error while reading");
+                    error_report("error while reading sector %" PRId64 ": %s",
+                                 bs_num, strerror(-ret));
                     goto out;
                 }
 
@@ -908,8 +909,8 @@  static int img_convert(int argc, char **argv)
                 ret = bdrv_write_compressed(out_bs, sector_num, buf,
                                             cluster_sectors);
                 if (ret != 0) {
-                    error_report("error while compressing sector %" PRId64,
-                          sector_num);
+                    error_report("error while compressing sector %" PRId64
+                                 ": %s", sector_num, strerror(-ret));
                     goto out;
                 }
             }
@@ -972,7 +973,8 @@  static int img_convert(int argc, char **argv)
 
             ret = bdrv_read(bs[bs_i], sector_num - bs_offset, buf, n);
             if (ret < 0) {
-                error_report("error while reading");
+                error_report("error while reading sector %" PRId64 ": %s",
+                             sector_num - bs_offset, strerror(-ret));
                 goto out;
             }
             /* NOTE: at the same time we convert, we do not write zero
@@ -991,7 +993,8 @@  static int img_convert(int argc, char **argv)
                     is_allocated_sectors(buf1, n, &n1)) {
                     ret = bdrv_write(out_bs, sector_num, buf1, n1);
                     if (ret < 0) {
-                        error_report("error while writing");
+                        error_report("error while writing sector %" PRId64
+                                     ": %s", sector_num, strerror(-ret));
                         goto out;
                     }
                 }