From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Mao Zhongyi <maozy.fnst@cn.fujitsu.com>,
John Snow <jsnow@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 03/23] hw/block: Fix the return type
Date: Mon, 18 Dec 2017 14:35:10 +0000 [thread overview]
Message-ID: <20171218143530.12082-4-stefanha@redhat.com> (raw)
In-Reply-To: <20171218143530.12082-1-stefanha@redhat.com>
From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
When the function no success value to transmit, it usually make the
function return void. It has turned out not to be a success, because
it means that the extra local_err variable and error_propagate() will
be needed. It leads to cumbersome code, therefore, transmit success/
failure in the return value is worth.
So fix the return type of blkconf_apply_backend_options(),
blkconf_geometry() and virtio_blk_data_plane_create() to avoid it.
Cc: John Snow <jsnow@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Max Reitz <mreitz@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: ac0edc1fc70c4457e5cec94405eb7d1f89f9c2c1.1511317952.git.maozy.fnst@cn.fujitsu.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/block/dataplane/virtio-blk.h | 2 +-
include/hw/block/block.h | 4 ++--
hw/block/block.c | 15 +++++++++------
hw/block/dataplane/virtio-blk.c | 12 +++++++-----
4 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/hw/block/dataplane/virtio-blk.h b/hw/block/dataplane/virtio-blk.h
index db3f47b173..5e18bb99ae 100644
--- a/hw/block/dataplane/virtio-blk.h
+++ b/hw/block/dataplane/virtio-blk.h
@@ -19,7 +19,7 @@
typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane;
-void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
+bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
VirtIOBlockDataPlane **dataplane,
Error **errp);
void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s);
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
index f3f6e8ef02..64b9298829 100644
--- a/include/hw/block/block.h
+++ b/include/hw/block/block.h
@@ -72,11 +72,11 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
/* Configuration helpers */
void blkconf_serial(BlockConf *conf, char **serial);
-void blkconf_geometry(BlockConf *conf, int *trans,
+bool blkconf_geometry(BlockConf *conf, int *trans,
unsigned cyls_max, unsigned heads_max, unsigned secs_max,
Error **errp);
void blkconf_blocksizes(BlockConf *conf);
-void blkconf_apply_backend_options(BlockConf *conf, bool readonly,
+bool blkconf_apply_backend_options(BlockConf *conf, bool readonly,
bool resizable, Error **errp);
/* Hard disk geometry */
diff --git a/hw/block/block.c b/hw/block/block.c
index 27878d0087..b0269c857f 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -51,7 +51,7 @@ void blkconf_blocksizes(BlockConf *conf)
}
}
-void blkconf_apply_backend_options(BlockConf *conf, bool readonly,
+bool blkconf_apply_backend_options(BlockConf *conf, bool readonly,
bool resizable, Error **errp)
{
BlockBackend *blk = conf->blk;
@@ -76,7 +76,7 @@ void blkconf_apply_backend_options(BlockConf *conf, bool readonly,
ret = blk_set_perm(blk, perm, shared_perm, errp);
if (ret < 0) {
- return;
+ return false;
}
switch (conf->wce) {
@@ -99,9 +99,11 @@ void blkconf_apply_backend_options(BlockConf *conf, bool readonly,
blk_set_enable_write_cache(blk, wce);
blk_set_on_error(blk, rerror, werror);
+
+ return true;
}
-void blkconf_geometry(BlockConf *conf, int *ptrans,
+bool blkconf_geometry(BlockConf *conf, int *ptrans,
unsigned cyls_max, unsigned heads_max, unsigned secs_max,
Error **errp)
{
@@ -129,15 +131,16 @@ void blkconf_geometry(BlockConf *conf, int *ptrans,
if (conf->cyls || conf->heads || conf->secs) {
if (conf->cyls < 1 || conf->cyls > cyls_max) {
error_setg(errp, "cyls must be between 1 and %u", cyls_max);
- return;
+ return false;
}
if (conf->heads < 1 || conf->heads > heads_max) {
error_setg(errp, "heads must be between 1 and %u", heads_max);
- return;
+ return false;
}
if (conf->secs < 1 || conf->secs > secs_max) {
error_setg(errp, "secs must be between 1 and %u", secs_max);
- return;
+ return false;
}
}
+ return true;
}
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 5556f0e64e..f6fc639e88 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -76,7 +76,7 @@ static void notify_guest_bh(void *opaque)
}
/* Context: QEMU global mutex held */
-void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
+bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
VirtIOBlockDataPlane **dataplane,
Error **errp)
{
@@ -91,11 +91,11 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
error_setg(errp,
"device is incompatible with iothread "
"(transport does not support notifiers)");
- return;
+ return false;
}
if (!virtio_device_ioeventfd_enabled(vdev)) {
error_setg(errp, "ioeventfd is required for iothread");
- return;
+ return false;
}
/* If dataplane is (re-)enabled while the guest is running there could
@@ -103,12 +103,12 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
*/
if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) {
error_prepend(errp, "cannot start virtio-blk dataplane: ");
- return;
+ return false;
}
}
/* Don't try if transport does not support notifiers. */
if (!virtio_device_ioeventfd_enabled(vdev)) {
- return;
+ return false;
}
s = g_new0(VirtIOBlockDataPlane, 1);
@@ -126,6 +126,8 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
s->batch_notify_vqs = bitmap_new(conf->num_queues);
*dataplane = s;
+
+ return true;
}
/* Context: QEMU global mutex held */
--
2.14.3
next prev parent reply other threads:[~2017-12-18 14:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-18 14:35 [Qemu-devel] [PULL 00/23] Block patches Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 01/23] coroutine: simplify co_aio_sleep_ns() prototype Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 02/23] hw/block/nvme: Convert to realize Stefan Hajnoczi
2017-12-18 14:35 ` Stefan Hajnoczi [this message]
2017-12-18 14:35 ` [Qemu-devel] [PULL 04/23] hw/block: Use errp directly rather than local_err Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 05/23] dev-storage: Fix the unusual function name Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 06/23] qdev: drop unused #include "sysemu/iothread.h" Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 07/23] blockdev: hold AioContext for bdrv_unref() in external_snapshot_clean() Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 08/23] block: don't keep AioContext acquired after external_snapshot_prepare() Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 09/23] block: don't keep AioContext acquired after drive_backup_prepare() Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 10/23] block: don't keep AioContext acquired after blockdev_backup_prepare() Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 11/23] block: don't keep AioContext acquired after internal_snapshot_prepare() Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 12/23] block: drop unused BlockDirtyBitmapState->aio_context field Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 13/23] iothread: add iothread_by_id() API Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 14/23] blockdev: add x-blockdev-set-iothread testing command Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 15/23] qemu-iotests: add 202 external snapshots IOThread test Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 16/23] virtio-blk: make queue size configurable Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 17/23] virtio-blk: reject configs with logical block size > physical block size Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 18/23] block: avoid recursive AioContext acquire in bdrv_inactivate_all() Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 19/23] docs: mark nested AioContext locking as a legacy API Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 20/23] blockdev: add x-blockdev-set-iothread force boolean Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 21/23] iotests: add VM.add_object() Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 22/23] iothread: fix iothread_stop() race condition Stefan Hajnoczi
2017-12-18 14:35 ` [Qemu-devel] [PULL 23/23] qemu-iotests: add 203 savevm with IOThreads test Stefan Hajnoczi
2017-12-19 0:15 ` [Qemu-devel] [PULL 00/23] Block patches Peter Maydell
2017-12-19 9:15 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171218143530.12082-4-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=maozy.fnst@cn.fujitsu.com \
--cc=mreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).