From patchwork Mon Jul 30 02:47:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10548401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38610112E for ; Mon, 30 Jul 2018 02:50:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29444299C6 for ; Mon, 30 Jul 2018 02:50:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2676429BF9; Mon, 30 Jul 2018 02:50:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AB5FE299C6 for ; Mon, 30 Jul 2018 02:50:20 +0000 (UTC) Received: from localhost ([::1]:50319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjyGJ-0007EL-Mo for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Jul 2018 22:50:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjyDq-0004Id-Vj for qemu-devel@nongnu.org; Sun, 29 Jul 2018 22:47:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fjyDq-0001eg-58 for qemu-devel@nongnu.org; Sun, 29 Jul 2018 22:47:47 -0400 Received: from synology.com ([59.124.61.242]:41361) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fjyDk-0001ai-PE; Sun, 29 Jul 2018 22:47:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1532918857; bh=+YgBZSp6nMmVmqHiJmRclSagvETpUHJ2mRat9NpDwP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C07nXeSTMtyuziZGJGXDYWQhyblUXhLJwUA04F7OaxPcylDxSa7wijUzCXrl8XCFp eIf81jd76+U3SpMNbay5S5j6vXCeR2TCsgBvvHtlmuRm8/pjjJaeKbflX6IJR0cEY8 3X9RIw2C4/AFtrKez5LvwmcjuTdsyfDXI6KFDFPw= To: qemu-devel@nongnu.org Date: Mon, 30 Jul 2018 10:47:00 +0800 Message-Id: <20180730024701.7613-2-yuchenlin@synology.com> In-Reply-To: <20180730024701.7613-1-yuchenlin@synology.com> References: <20180730024701.7613-1-yuchenlin@synology.com> X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 5, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 59.124.61.242 Subject: [Qemu-devel] [PATCH 1/2] vdi: remove CONFIG_VDI_WRITE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: yuchenlin--- via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: yuchenlin@synology.com Cc: sw@weilnetz.de, yuchenlin , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: yuchenlin The CONFIG_VDI_WRITE is here when the first time vdi is added. But there is no reason to leave an always on and cannot configure option in the code-side. Signed-off-by: yuchenlin --- block/vdi.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 6555cffb88..12f92e7891 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -70,9 +70,6 @@ /* Enable debug messages. */ //~ #define CONFIG_VDI_DEBUG -/* Support write operations on VDI images. */ -#define CONFIG_VDI_WRITE - /* Support non-standard block (cluster) size. This is untested. * Maybe it will be needed for very large images. */ @@ -1016,9 +1013,7 @@ static BlockDriver bdrv_vdi = { .bdrv_make_empty = vdi_make_empty, .bdrv_co_preadv = vdi_co_preadv, -#if defined(CONFIG_VDI_WRITE) .bdrv_co_pwritev = vdi_co_pwritev, -#endif .bdrv_get_info = vdi_get_info, From patchwork Mon Jul 30 02:47:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10548397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C576112E for ; Mon, 30 Jul 2018 02:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B42E2997E for ; Mon, 30 Jul 2018 02:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FBA629985; Mon, 30 Jul 2018 02:48:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B66512997E for ; Mon, 30 Jul 2018 02:48:57 +0000 (UTC) Received: from localhost ([::1]:50309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjyEy-0005f6-Vs for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Jul 2018 22:48:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjyDr-0004J8-Fb for qemu-devel@nongnu.org; Sun, 29 Jul 2018 22:47:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fjyDq-0001f0-IV for qemu-devel@nongnu.org; Sun, 29 Jul 2018 22:47:47 -0400 Received: from synology.com ([59.124.61.242]:41368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fjyDk-0001b0-O4; Sun, 29 Jul 2018 22:47:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1532918858; bh=cTvzsYUoUeWixvitfOuMdQLqkgScJB4FqEYXzH20R84=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jRitJhY6ixxOLK1UkvZOjAIV6BON6Yc8hZeu9mGakn9KUvKIxXRCinTW2xEWGsdQ2 mWubpirNyGuaUrA2wULU1L6vu6xqPCYvf+BoFqbZrSpI53dVwG9syy27+PsJgh6t9w Pkjr+gWK/fecfzes+XoJz5mO91aw1EoGWH6xjc5M= To: qemu-devel@nongnu.org Date: Mon, 30 Jul 2018 10:47:01 +0800 Message-Id: <20180730024701.7613-3-yuchenlin@synology.com> In-Reply-To: <20180730024701.7613-1-yuchenlin@synology.com> References: <20180730024701.7613-1-yuchenlin@synology.com> X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 5, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 59.124.61.242 Subject: [Qemu-devel] [PATCH 2/2] vdi: refine code for vdi_open X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: yuchenlin--- via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: yuchenlin@synology.com Cc: sw@weilnetz.de, yuchenlin , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: yuchenlin 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 --- 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);