[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/10] blockdev: Clean up fragile use of error_is_set
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 09/10] blockdev: Clean up fragile use of error_is_set() |
Date: |
Fri, 25 Apr 2014 18:07:25 +0200 |
From: Markus Armbruster <address@hidden>
Using error_is_set(ERRP) to find out whether a function failed is
either wrong, fragile, or unnecessarily opaque. It's wrong when ERRP
may be null, because errors go undetected when it is. It's fragile
when proving ERRP non-null involves a non-local argument. Else, it's
unnecessarily opaque (see commit 84d18f0).
The error_is_set(errp) in internal_snapshot_prepare() is merely
fragile, because the caller never passes a null errp argument.
Make the code more robust and more obviously correct: receive the
error in a local variable, then propagate it through the parameter.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
blockdev.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 09826f1..952eb60 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1115,6 +1115,7 @@ typedef struct InternalSnapshotState {
static void internal_snapshot_prepare(BlkTransactionState *common,
Error **errp)
{
+ Error *local_err = NULL;
const char *device;
const char *name;
BlockDriverState *bs;
@@ -1163,8 +1164,10 @@ static void
internal_snapshot_prepare(BlkTransactionState *common,
}
/* check whether a snapshot with name exist */
- ret = bdrv_snapshot_find_by_id_and_name(bs, NULL, name, &old_sn, errp);
- if (error_is_set(errp)) {
+ ret = bdrv_snapshot_find_by_id_and_name(bs, NULL, name, &old_sn,
+ &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
return;
} else if (ret) {
error_setg(errp,
--
1.9.0
- [Qemu-devel] [PULL 00/10] Block patches, Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 01/10] block: Prevent coroutine stack overflow when recursing in bdrv_open_backing_file., Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 02/10] doc: add -drive rerror=, werror= to qemu --help output, Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 03/10] qemu-iotests: Improve and make use of QMPTestCase.wait_until_completed(), Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 04/10] MAINTAINERS: Add qemu-img/io to block subsystem, Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 05/10] block: Expose host_* drivers in blockdev-add, Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 06/10] Use error_is_set() only when necessary (again), Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 07/10] qemu-img: Consistently name Error * objects err, and not errp, Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 08/10] nbd: Use return values instead of error_is_set(errp), Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 10/10] iscsi: Don't use error_is_set() to suppress additional errors, Stefan Hajnoczi, 2014/04/25
- [Qemu-devel] [PULL 09/10] blockdev: Clean up fragile use of error_is_set(),
Stefan Hajnoczi <=
- Re: [Qemu-devel] [PULL 00/10] Block patches, Peter Maydell, 2014/04/28