Skip to contentSkip to conversation

qcow2: Emit errp when truncating the image tail

PATCH In review Max Reitz 3 participants 4 messages Oct 9, 2017 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qcow2: Emit errp when truncating the image tail

bdrv_truncate() has an errp parameter which is always set when an error occurs. Let's use that instead of a plain strerror().

---
 block/qcow2.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
block/qcow2.c +7 -6
index dff903e05c..2f6a8e1ff8 100644
@@ -3150,12 +3150,13 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,
             return last_cluster;
         }
         if ((last_cluster + 1) * s->cluster_size < old_file_size) {
-            ret = bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
-                                PREALLOC_MODE_OFF, NULL);
-            if (ret < 0) {
-                warn_report("Failed to truncate the tail of the image: %s",
-                            strerror(-ret));
-                ret = 0;
+            Error *local_err = NULL;
+
+            bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
+                          PREALLOC_MODE_OFF, &local_err);
+            if (local_err) {
+                warn_reportf_err(local_err,
+                                 "Failed to truncate the tail of the image: ");
             }
         }
     } else {
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Max Reitz

bdrv_truncate() has an errp parameter which is always set when an error occurs. Let's use that instead of a plain strerror().

---
  block/qcow2.c | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)
block/qcow2.c +0 -6
index dff903e05c..2f6a8e1ff8 100644
@@ -3150,12 +3150,13 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,
              return last_cluster;
          }
          if ((last_cluster + 1) * s->cluster_size < old_file_size) {
-            ret = bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
-                                PREALLOC_MODE_OFF, NULL);
-            if (ret < 0) {
-                warn_report("Failed to truncate the tail of the image: %s",
-                            strerror(-ret));
-                ret = 0;

block/qcow2.c static int qcow2_truncate(BlockDriverState *bs, int64_t offset, · line 3162

Quoted 10 lines
block/qcow2.c +7 -0
+            Error *local_err = NULL;
+
+            bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
+                          PREALLOC_MODE_OFF, &local_err);
+            if (local_err) {
+                warn_reportf_err(local_err,
+                                 "Failed to truncate the tail of the image: ");
              }
          }
      } else {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Max Reitz
Quoted 36 lines · Max Reitz

bdrv_truncate() has an errp parameter which is always set when an error occurs. Let's use that instead of a plain strerror().

---
 block/qcow2.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
block/qcow2.c +7 -6
index dff903e05c..2f6a8e1ff8 100644
@@ -3150,12 +3150,13 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,
             return last_cluster;
         }
         if ((last_cluster + 1) * s->cluster_size < old_file_size) {
-            ret = bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
-                                PREALLOC_MODE_OFF, NULL);
-            if (ret < 0) {
-                warn_report("Failed to truncate the tail of the image: %s",
-                            strerror(-ret));
-                ret = 0;
+            Error *local_err = NULL;
+
+            bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
+                          PREALLOC_MODE_OFF, &local_err);
+            if (local_err) {
+                warn_reportf_err(local_err,
+                                 "Failed to truncate the tail of the image: ");
             }
         }
     } else {
Signature · 1 line
2.13.6