qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH v1 20/25] block: Update error API usages


From: Peter Crosthwaite
Subject: [Qemu-devel] [RFC PATCH v1 20/25] block: Update error API usages
Date: Thu, 10 Sep 2015 22:33:30 -0700

Use error_prefix() and error_report_err() as appropriate. Use the
prefix + propagate combo rather than manual prefix + freeing.

Cc: Kevin Wolf <address@hidden>
Cc: address@hidden
Signed-off-by: Peter Crosthwaite <address@hidden>
---

 block.c                         |  5 ++---
 block/qcow2.c                   |  5 ++---
 block/qed.c                     |  5 ++---
 block/sheepdog.c                |  8 +++-----
 blockdev.c                      | 10 +++++-----
 hw/block/dataplane/virtio-blk.c |  5 ++---
 qemu-img.c                      | 38 ++++++++++++++++++--------------------
 7 files changed, 34 insertions(+), 42 deletions(-)

diff --git a/block.c b/block.c
index 090923c..f743f1e 100644
--- a/block.c
+++ b/block.c
@@ -1233,9 +1233,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
         bdrv_unref(backing_hd);
         backing_hd = NULL;
         bs->open_flags |= BDRV_O_NO_BACKING;
-        error_setg(errp, "Could not open backing file: %s",
-                   error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "Could not open backing file: ");
+        error_propagate(errp, local_err);
         goto free_exit;
     }
 
diff --git a/block/qcow2.c b/block/qcow2.c
index ea34ae2..b5c45e1 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1581,9 +1581,8 @@ static void qcow2_invalidate_cache(BlockDriverState *bs, 
Error **errp)
     ret = qcow2_open(bs, options, flags, &local_err);
     QDECREF(options);
     if (local_err) {
-        error_setg(errp, "Could not reopen qcow2 layer: %s",
-                   error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "Could not reopen qcow2 layer: ");
+        error_propagate(errp, local_err);
         return;
     } else if (ret < 0) {
         error_setg_errno(errp, -ret, "Could not reopen qcow2 layer");
diff --git a/block/qed.c b/block/qed.c
index 954ed00..0c4c5b6 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1605,9 +1605,8 @@ static void bdrv_qed_invalidate_cache(BlockDriverState 
*bs, Error **errp)
     memset(s, 0, sizeof(BDRVQEDState));
     ret = bdrv_qed_open(bs, NULL, bs->open_flags, &local_err);
     if (local_err) {
-        error_setg(errp, "Could not reopen qed layer: %s",
-                   error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "Could not reopen qed layer: ");
+        error_propagate(errp, local_err);
         return;
     } else if (ret < 0) {
         error_setg_errno(errp, -ret, "Could not reopen qed layer");
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 9585beb..4712da0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1776,8 +1776,7 @@ static int sd_create(const char *filename, QemuOpts *opts,
 
         fd = connect_to_sdog(s, &local_err);
         if (fd < 0) {
-            error_report("%s", error_get_pretty(local_err));
-            error_free(local_err);
+            error_report_err(local_err);
             ret = -EIO;
             goto out;
         }
@@ -2318,9 +2317,8 @@ static int sd_snapshot_create(BlockDriverState *bs, 
QEMUSnapshotInfo *sn_info)
 
     ret = do_sd_create(s, &new_vid, 1, &local_err);
     if (ret < 0) {
-        error_report("failed to create inode for snapshot: %s",
-                     error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "failed to create inode for snapshot: ");
+        error_report_err(local_err);
         goto cleanup;
     }
 
diff --git a/blockdev.c b/blockdev.c
index 6b48be6..78921fb 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1391,13 +1391,13 @@ static void internal_snapshot_abort(BlkTransactionState 
*common)
     }
 
     if (bdrv_snapshot_delete(bs, sn->id_str, sn->name, &local_error) < 0) {
-        error_report("Failed to delete snapshot with id '%s' and name '%s' on "
-                     "device '%s' in abort: %s",
+        error_prefix(local_error,
+                     "Failed to delete snapshot with id '%s' and name '%s' on "
+                     "device '%s' in abort:",
                      sn->id_str,
                      sn->name,
-                     bdrv_get_device_name(bs),
-                     error_get_pretty(local_error));
-        error_free(local_error);
+                     bdrv_get_device_name(bs));
+        error_report_err(local_error);
     }
 }
 
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 6106e46..ead5585 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -166,9 +166,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, 
VirtIOBlkConf *conf,
      */
     if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE,
                           &local_err)) {
-        error_setg(errp, "cannot start dataplane thread: %s",
-                   error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "cannot start dataplane thread: ");
+        error_propagate(errp, local_err);
         return;
     }
 
diff --git a/qemu-img.c b/qemu-img.c
index 6ff4e85..22fc1d0 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -213,9 +213,8 @@ static BlockBackend *img_open(const char *id, const char 
*filename,
 
     blk = blk_new_open(id, filename, NULL, options, flags, &local_err);
     if (!blk) {
-        error_report("Could not open '%s': %s", filename,
-                     error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "Could not open '%s': ", filename);
+        error_report_err(local_err);
         goto fail;
     }
 
@@ -359,8 +358,8 @@ static int img_create(int argc, char **argv)
     bdrv_img_create(filename, fmt, base_filename, base_fmt,
                     options, img_size, BDRV_O_FLAGS, &local_err, quiet);
     if (local_err) {
-        error_report("%s: %s", filename, error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "%s: ", filename);
+        error_report_err(local_err);
         goto fail;
     }
 
@@ -1712,9 +1711,8 @@ static int img_convert(int argc, char **argv)
         bdrv_snapshot_load_tmp_by_id_or_name(bs[0], snapshot_name, &local_err);
     }
     if (local_err) {
-        error_report("Failed to load snapshot: %s",
-                     error_get_pretty(local_err));
-        error_free(local_err);
+        error_prefix(local_err, "Failed to load snapshot: ");
+        error_report_err(local_err);
         ret = -1;
         goto out;
     }
@@ -1810,9 +1808,9 @@ static int img_convert(int argc, char **argv)
         /* Create the new image */
         ret = bdrv_create(drv, out_filename, opts, &local_err);
         if (ret < 0) {
-            error_report("%s: error while converting %s: %s",
-                         out_filename, out_fmt, error_get_pretty(local_err));
-            error_free(local_err);
+            error_prefix(local_err, "%s: error while converting %s: ",
+                         out_filename, out_fmt);
+            error_report_err(local_err);
             goto out;
         }
     }
@@ -2437,9 +2435,9 @@ static int img_snapshot(int argc, char **argv)
     case SNAPSHOT_DELETE:
         bdrv_snapshot_delete_by_id_or_name(bs, snapshot_name, &err);
         if (err) {
-            error_report("Could not delete snapshot '%s': (%s)",
-                         snapshot_name, error_get_pretty(err));
-            error_free(err);
+            error_prefix(err, "Could not delete snapshot '%s': ",
+                         snapshot_name);
+            error_report_err(err);
             ret = 1;
         }
         break;
@@ -2572,9 +2570,9 @@ static int img_rebase(int argc, char **argv)
         blk_old_backing = blk_new_open("old_backing", backing_name, NULL,
                                        options, src_flags, &local_err);
         if (!blk_old_backing) {
-            error_report("Could not open old backing file '%s': %s",
-                         backing_name, error_get_pretty(local_err));
-            error_free(local_err);
+            error_prefix(local_err, "Could not open old backing file '%s': ",
+                         backing_name);
+            error_report_err(local_err);
             goto out;
         }
 
@@ -2589,9 +2587,9 @@ static int img_rebase(int argc, char **argv)
             blk_new_backing = blk_new_open("new_backing", out_baseimg, NULL,
                                            options, src_flags, &local_err);
             if (!blk_new_backing) {
-                error_report("Could not open new backing file '%s': %s",
-                             out_baseimg, error_get_pretty(local_err));
-                error_free(local_err);
+                error_prefix(local_err, "Could not open new backing file 
'%s':",
+                             out_baseimg);
+                error_report_err(local_err);
                 goto out;
             }
         }
-- 
1.9.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]