From patchwork Fri Jul 11 06:09:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 368973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1F21C1400E1 for ; Fri, 11 Jul 2014 16:13:31 +1000 (EST) Received: from localhost ([::1]:42298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5U5J-0004sH-2p for incoming@patchwork.ozlabs.org; Fri, 11 Jul 2014 02:13:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5U4M-00037v-6t for qemu-devel@nongnu.org; Fri, 11 Jul 2014 02:12:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X5U4C-0007Gd-OA for qemu-devel@nongnu.org; Fri, 11 Jul 2014 02:12:30 -0400 Received: from [59.151.112.132] (port=14630 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5U4C-0007D1-4q for qemu-devel@nongnu.org; Fri, 11 Jul 2014 02:12:20 -0400 X-IronPort-AV: E=Sophos;i="5.00,873,1396972800"; d="scan'208";a="33138419" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 Jul 2014 14:09:29 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s6B6CBv8031198; Fri, 11 Jul 2014 14:12:12 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com (10.167.226.102) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 11 Jul 2014 14:12:19 +0800 From: Hu Tao To: Date: Fri, 11 Jul 2014 14:09:59 +0800 Message-ID: <590a2b51bfc53307b4c39109f79d9bd675550bbf.1405058453.git.hutao@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.102] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Kevin Wolf , Yasunori Goto , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v12 2/6] raw, qcow2: don't convert file size to sector size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org and avoid converting it back later. Reviewed-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Hu Tao --- block/qcow2.c | 10 +++++----- block/raw-posix.c | 6 +++--- block/raw-win32.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 0dfbb9a..05df4b9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1715,7 +1715,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, } /* Okay, now that we have a valid image, let's give it the right size */ - ret = bdrv_truncate(bs, total_size * BDRV_SECTOR_SIZE); + ret = bdrv_truncate(bs, total_size); if (ret < 0) { error_setg_errno(errp, -ret, "Could not resize image"); goto out; @@ -1768,7 +1768,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) char *backing_file = NULL; char *backing_fmt = NULL; char *buf = NULL; - uint64_t sectors = 0; + uint64_t size = 0; int flags = 0; size_t cluster_size = DEFAULT_CLUSTER_SIZE; int prealloc = 0; @@ -1777,8 +1777,8 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) int ret; /* Read out options */ - sectors = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); + size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), + BDRV_SECTOR_SIZE); backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT); if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { @@ -1828,7 +1828,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) goto finish; } - ret = qcow2_create2(filename, sectors, backing_file, backing_fmt, flags, + ret = qcow2_create2(filename, size, backing_file, backing_fmt, flags, cluster_size, prealloc, opts, version, &local_err); if (local_err) { error_propagate(errp, local_err); diff --git a/block/raw-posix.c b/block/raw-posix.c index 822522c..2af24af 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1332,8 +1332,8 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) strstart(filename, "file:", &filename); /* Read out options */ - total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); + total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), + BDRV_SECTOR_SIZE); nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false); fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, @@ -1357,7 +1357,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) #endif } - if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) { + if (ftruncate(fd, total_size) != 0) { result = -errno; error_setg_errno(errp, -result, "Could not resize file"); } diff --git a/block/raw-win32.c b/block/raw-win32.c index 1e1880d..9bf8225 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -511,8 +511,8 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) strstart(filename, "file:", &filename); /* Read out options */ - total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); + total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), + BDRV_SECTOR_SIZE); fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); @@ -521,7 +521,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) return -EIO; } set_sparse(fd); - ftruncate(fd, total_size * 512); + ftruncate(fd, total_size); qemu_close(fd); return 0; }