[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 10/13] block: Simplify bdrv_append_temp_snapshot(
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v4 10/13] block: Simplify bdrv_append_temp_snapshot() logic |
Date: |
Tue, 11 Apr 2017 13:50:31 -0500 |
Noticed while checking Coccinelle results. Naming a label 'out:'
when it is only used on error paths is weird. Also, we had some
dead stores to 'ret'. Meanwhile we know that snapshot_options
is NULL on success and that QDECREF(NULL) is safe. So merge the
two exit paths into one by careful control over bs_snapshot.
Signed-off-by: Eric Blake <address@hidden>
---
v4: fix -O2 compilation bug, kill dead 'ret'
v3: split out from bigger v2 patch
---
block.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/block.c b/block.c
index c8a6bce..2bf3d40 100644
--- a/block.c
+++ b/block.c
@@ -2158,7 +2158,7 @@ static BlockDriverState
*bdrv_append_temp_snapshot(BlockDriverState *bs,
char *tmp_filename = g_malloc0(PATH_MAX + 1);
int64_t total_size;
QemuOpts *opts = NULL;
- BlockDriverState *bs_snapshot;
+ BlockDriverState *bs_snapshot = NULL;
Error *local_err = NULL;
int ret;
@@ -2198,28 +2198,25 @@ static BlockDriverState
*bdrv_append_temp_snapshot(BlockDriverState *bs,
bs_snapshot = bdrv_open(NULL, NULL, snapshot_options, flags, errp);
snapshot_options = NULL;
if (!bs_snapshot) {
- ret = -EINVAL;
goto out;
}
- /* bdrv_append() consumes a strong reference to bs_snapshot (i.e. it will
- * call bdrv_unref() on it), so in order to be able to return one, we have
- * to increase bs_snapshot's refcount here */
+ /* bdrv_append() consumes a strong reference to bs_snapshot
+ * (i.e. it will call bdrv_unref() on it) even on error, so in
+ * order to be able to return one, we have to increase
+ * bs_snapshot's refcount here */
bdrv_ref(bs_snapshot);
bdrv_append(bs_snapshot, bs, &local_err);
if (local_err) {
error_propagate(errp, local_err);
- ret = -EINVAL;
+ bs_snapshot = NULL;
goto out;
}
+out:
+ QDECREF(snapshot_options);
g_free(tmp_filename);
return bs_snapshot;
-
-out:
- QDECREF(snapshot_options);
- g_free(tmp_filename);
- return NULL;
}
/*
--
2.9.3
- [Qemu-devel] [PATCH v4 05/13] qobject: Drop useless QObject casts, (continued)
- [Qemu-devel] [PATCH v4 05/13] qobject: Drop useless QObject casts, Eric Blake, 2017/04/11
- [Qemu-devel] [PATCH v4 08/13] tests: Use simpler QDict/QList scalar insertion macros, Eric Blake, 2017/04/11
- [Qemu-devel] [PATCH v4 07/13] block: Use simpler QDict/QList scalar insertion macros, Eric Blake, 2017/04/11
- [Qemu-devel] [PATCH v4 11/13] QemuOpts: Simplify qemu_opts_to_qdict(), Eric Blake, 2017/04/11
- [Qemu-devel] [PATCH v4 10/13] block: Simplify bdrv_append_temp_snapshot() logic,
Eric Blake <=
- [Qemu-devel] [PATCH v4 09/13] qobject: Use simpler QDict/QList scalar insertion macros, Eric Blake, 2017/04/11
- [Qemu-devel] [PATCH v4 13/13] test-qga: Actually test 0xff sync bytes, Eric Blake, 2017/04/11
- [Qemu-devel] [PATCH v4 12/13] fdc-test: Avoid deprecated 'change' command, Eric Blake, 2017/04/11
- Re: [Qemu-devel] [PATCH v4 00/13] qapi-related cleanups, Markus Armbruster, 2017/04/12