From: yuchenlin@synology.com
To: qemu-devel@nongnu.org
Cc: sw@weilnetz.de, qemu-block@nongnu.org,
yuchenlin <yuchenlin@synology.com>
Subject: [Qemu-devel] [PATCH 2/2] vdi: refine code for vdi_open
Date: Mon, 30 Jul 2018 10:47:01 +0800 [thread overview]
Message-ID: <20180730024701.7613-3-yuchenlin@synology.com> (raw)
In-Reply-To: <20180730024701.7613-1-yuchenlin@synology.com>
From: yuchenlin <yuchenlin@synology.com>
When the condition of each if or else if is true,
the code flow will goto fail. Which means we can decouple
if else if chain to get some readability.
Signed-off-by: yuchenlin <yuchenlin@synology.com>
---
block/vdi.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index 12f92e7891..28fc6210a7 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -405,35 +405,41 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
")", header.signature);
ret = -EINVAL;
goto fail;
- } else if (header.version != VDI_VERSION_1_1) {
+ }
+ if (header.version != VDI_VERSION_1_1) {
error_setg(errp, "unsupported VDI image (version %" PRIu32 ".%" PRIu32
")", header.version >> 16, header.version & 0xffff);
ret = -ENOTSUP;
goto fail;
- } else if (header.offset_bmap % SECTOR_SIZE != 0) {
+ }
+ if (header.offset_bmap % SECTOR_SIZE != 0) {
/* We only support block maps which start on a sector boundary. */
error_setg(errp, "unsupported VDI image (unaligned block map offset "
"0x%" PRIx32 ")", header.offset_bmap);
ret = -ENOTSUP;
goto fail;
- } else if (header.offset_data % SECTOR_SIZE != 0) {
+ }
+ if (header.offset_data % SECTOR_SIZE != 0) {
/* We only support data blocks which start on a sector boundary. */
error_setg(errp, "unsupported VDI image (unaligned data offset 0x%"
PRIx32 ")", header.offset_data);
ret = -ENOTSUP;
goto fail;
- } else if (header.sector_size != SECTOR_SIZE) {
+ }
+ if (header.sector_size != SECTOR_SIZE) {
error_setg(errp, "unsupported VDI image (sector size %" PRIu32
" is not %u)", header.sector_size, SECTOR_SIZE);
ret = -ENOTSUP;
goto fail;
- } else if (header.block_size != DEFAULT_CLUSTER_SIZE) {
+ }
+ if (header.block_size != DEFAULT_CLUSTER_SIZE) {
error_setg(errp, "unsupported VDI image (block size %" PRIu32
" is not %" PRIu64 ")",
header.block_size, DEFAULT_CLUSTER_SIZE);
ret = -ENOTSUP;
goto fail;
- } else if (header.disk_size >
+ }
+ if (header.disk_size >
(uint64_t)header.blocks_in_image * header.block_size) {
error_setg(errp, "unsupported VDI image (disk size %" PRIu64 ", "
"image bitmap has room for %" PRIu64 ")",
@@ -441,15 +447,18 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
(uint64_t)header.blocks_in_image * header.block_size);
ret = -ENOTSUP;
goto fail;
- } else if (!qemu_uuid_is_null(&header.uuid_link)) {
+ }
+ if (!qemu_uuid_is_null(&header.uuid_link)) {
error_setg(errp, "unsupported VDI image (non-NULL link UUID)");
ret = -ENOTSUP;
goto fail;
- } else if (!qemu_uuid_is_null(&header.uuid_parent)) {
+ }
+ if (!qemu_uuid_is_null(&header.uuid_parent)) {
error_setg(errp, "unsupported VDI image (non-NULL parent UUID)");
ret = -ENOTSUP;
goto fail;
- } else if (header.blocks_in_image > VDI_BLOCKS_IN_IMAGE_MAX) {
+ }
+ if (header.blocks_in_image > VDI_BLOCKS_IN_IMAGE_MAX) {
error_setg(errp, "unsupported VDI image "
"(too many blocks %u, max is %u)",
header.blocks_in_image, VDI_BLOCKS_IN_IMAGE_MAX);
--
2.17.0
next prev parent reply other threads:[~2018-07-30 2:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-30 2:46 [Qemu-devel] [PATCH 0/2] Refine some vdi code yuchenlin
2018-07-30 2:47 ` [Qemu-devel] [PATCH 1/2] vdi: remove CONFIG_VDI_WRITE yuchenlin
2018-07-30 2:47 ` yuchenlin [this message]
2018-07-30 7:12 ` [Qemu-devel] [PATCH 0/2] Refine some vdi code Stefan Weil
2018-07-30 7:49 ` yuchenlin
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=20180730024701.7613-3-yuchenlin@synology.com \
--to=yuchenlin@synology.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/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).