From patchwork Wed Mar 27 09:56:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 10873115 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 64E1C13B5 for ; Wed, 27 Mar 2019 09:58:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FDCF28C10 for ; Wed, 27 Mar 2019 09:58:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43FEA28C19; Wed, 27 Mar 2019 09:58:13 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EB7A228C10 for ; Wed, 27 Mar 2019 09:58:12 +0000 (UTC) Received: from localhost ([127.0.0.1]:44733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h95K0-0001wW-AR for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Mar 2019 05:58:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h95If-0000xJ-6n for qemu-devel@nongnu.org; Wed, 27 Mar 2019 05:56:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h95Ic-0002rf-Ba for qemu-devel@nongnu.org; Wed, 27 Mar 2019 05:56:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h95IZ-0002q3-Ul; Wed, 27 Mar 2019 05:56:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C212C066467; Wed, 27 Mar 2019 09:56:43 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-197.ams2.redhat.com [10.36.116.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EE1E5BBB7; Wed, 27 Mar 2019 09:56:39 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Wed, 27 Mar 2019 10:56:33 +0100 Message-Id: <20190327095634.53038-2-sgarzare@redhat.com> In-Reply-To: <20190327095634.53038-1-sgarzare@redhat.com> References: <20190327095634.53038-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 27 Mar 2019 09:56:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/2] block/vhdx: Remove redundant IEC binary prefixes definition 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: , Cc: Kevin Wolf , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Max Reitz , Jeff Cody , John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP IEC binary prefixes are already defined in "qemu/units.h", so we can remove redundant definitions in "block/vhdx.h". Signed-off-by: Stefano Garzarella Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: John Snow --- block/vhdx.c | 3 ++- block/vhdx.h | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index b785aef4b7..7cd1fc3731 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1889,7 +1889,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, return -EINVAL; } if (block_size > VHDX_BLOCK_SIZE_MAX) { - error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX); + error_setg(errp, "Block size must not exceed %" PRId64, + VHDX_BLOCK_SIZE_MAX); return -EINVAL; } diff --git a/block/vhdx.h b/block/vhdx.h index 1bfb4e4f73..bf72090c8f 100644 --- a/block/vhdx.h +++ b/block/vhdx.h @@ -17,11 +17,7 @@ #ifndef BLOCK_VHDX_H #define BLOCK_VHDX_H - -#define KiB (1 * 1024) -#define MiB (KiB * 1024) -#define GiB (MiB * 1024) -#define TiB ((uint64_t) GiB * 1024) +#include "qemu/units.h" #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */ /* Structures and fields present in the VHDX file */ From patchwork Wed Mar 27 09:56:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 10873117 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 1F56913B5 for ; Wed, 27 Mar 2019 09:58:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A84B28C10 for ; Wed, 27 Mar 2019 09:58:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2FFB28C19; Wed, 27 Mar 2019 09:58:22 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8FEF728C10 for ; Wed, 27 Mar 2019 09:58:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:44735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h95K9-000242-Sy for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Mar 2019 05:58:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h95Io-00015O-AH for qemu-devel@nongnu.org; Wed, 27 Mar 2019 05:56:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h95In-0002xA-6X for qemu-devel@nongnu.org; Wed, 27 Mar 2019 05:56:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51054) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h95Ih-0002th-Ap; Wed, 27 Mar 2019 05:56:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D4D5C002965; Wed, 27 Mar 2019 09:56:49 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-116-197.ams2.redhat.com [10.36.116.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 059B55D9C5; Wed, 27 Mar 2019 09:56:43 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Wed, 27 Mar 2019 10:56:34 +0100 Message-Id: <20190327095634.53038-3-sgarzare@redhat.com> In-Reply-To: <20190327095634.53038-1-sgarzare@redhat.com> References: <20190327095634.53038-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 27 Mar 2019 09:56:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/2] block/vhdx: Use IEC binary prefixes for size constants 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: , Cc: Kevin Wolf , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Max Reitz , Jeff Cody , John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Using IEC binary prefixes in order to make the code more readable, with the exception of DEFAULT_LOG_SIZE because it's passed to stringify(). Signed-off-by: Stefano Garzarella Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: John Snow --- block/vhdx-log.c | 2 +- block/vhdx.c | 4 ++-- block/vhdx.h | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/block/vhdx-log.c b/block/vhdx-log.c index 3149ff08d8..5e946846f1 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -551,7 +551,7 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s, } if (file_length < desc_entries->hdr.last_file_offset) { new_file_size = desc_entries->hdr.last_file_offset; - if (new_file_size % (1024*1024)) { + if (new_file_size % (1 * MiB)) { /* round up to nearest 1MB boundary */ new_file_size = QEMU_ALIGN_UP(new_file_size, MiB); if (new_file_size > INT64_MAX) { diff --git a/block/vhdx.c b/block/vhdx.c index 7cd1fc3731..a143a57657 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1175,7 +1175,7 @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s, *new_offset = current_len; /* per the spec, the address for a block is in units of 1MB */ - *new_offset = ROUND_UP(*new_offset, 1024 * 1024); + *new_offset = ROUND_UP(*new_offset, 1 * MiB); if (*new_offset > INT64_MAX) { return -EINVAL; } @@ -1338,7 +1338,7 @@ static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, case PAYLOAD_BLOCK_FULLY_PRESENT: /* if the file offset address is in the header zone, * there is a problem */ - if (sinfo.file_offset < (1024 * 1024)) { + if (sinfo.file_offset < (1 * MiB)) { ret = -EFAULT; goto error_bat_restore; } diff --git a/block/vhdx.h b/block/vhdx.h index bf72090c8f..0b74924cee 100644 --- a/block/vhdx.h +++ b/block/vhdx.h @@ -20,6 +20,8 @@ #include "qemu/units.h" #define DEFAULT_LOG_SIZE 1048576 /* 1MiB */ +/* Note: can't use 1 * MiB, because it's passed to stringify() */ + /* Structures and fields present in the VHDX file */ /* The header section has the following blocks, @@ -32,7 +34,7 @@ * 0.........64KB...........128KB........192KB..........256KB................1MB */ -#define VHDX_HEADER_BLOCK_SIZE (64 * 1024) +#define VHDX_HEADER_BLOCK_SIZE (64 * KiB) #define VHDX_FILE_ID_OFFSET 0 #define VHDX_HEADER1_OFFSET (VHDX_HEADER_BLOCK_SIZE * 1) @@ -81,7 +83,7 @@ typedef struct QEMU_PACKED MSGUID { #define guid_eq(a, b) \ (memcmp(&(a), &(b), sizeof(MSGUID)) == 0) -#define VHDX_HEADER_SIZE (4 * 1024) /* although the vhdx_header struct in disk +#define VHDX_HEADER_SIZE (4 * KiB) /* although the vhdx_header struct in disk is only 582 bytes, for purposes of crc the header is the first 4KB of the 64KB block */ @@ -157,8 +159,8 @@ typedef struct QEMU_PACKED VHDXRegionTableEntry { /* ---- LOG ENTRY STRUCTURES ---- */ -#define VHDX_LOG_MIN_SIZE (1024 * 1024) -#define VHDX_LOG_SECTOR_SIZE 4096 +#define VHDX_LOG_MIN_SIZE (1 * MiB) +#define VHDX_LOG_SECTOR_SIZE (4 * KiB) #define VHDX_LOG_HDR_SIZE 64 #define VHDX_LOG_SIGNATURE 0x65676f6c typedef struct QEMU_PACKED VHDXLogEntryHeader {