From patchwork Thu Jun 12 03:54:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 358981 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 A56E21400A7 for ; Thu, 12 Jun 2014 13:58:26 +1000 (EST) Received: from localhost ([::1]:50412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wuw9g-00011y-KS for incoming@patchwork.ozlabs.org; Wed, 11 Jun 2014 23:58:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wuw7t-0006xW-RB for qemu-devel@nongnu.org; Wed, 11 Jun 2014 23:56:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wuw7p-0004KE-44 for qemu-devel@nongnu.org; Wed, 11 Jun 2014 23:56:33 -0400 Received: from [59.151.112.132] (port=49763 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wuw7o-0004Jl-Fc for qemu-devel@nongnu.org; Wed, 11 Jun 2014 23:56:29 -0400 X-IronPort-AV: E=Sophos;i="5.00,693,1396972800"; d="scan'208";a="31793501" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Jun 2014 11:53:43 +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 s5C3uLEi029958; Thu, 12 Jun 2014 11:56:21 +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; Thu, 12 Jun 2014 11:56:26 +0800 From: Hu Tao To: Date: Thu, 12 Jun 2014 11:54:22 +0800 Message-ID: <345911fcf403ca42fccab4abfcd203c3aea311cb.1402544518.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: kwolf@redhat.com, Peter Lieven , Markus Armbruster , Max Reitz , Stefan Hajnoczi , y-goto@jp.fujitsu.com Subject: [Qemu-devel] [PATCH v10 1/6] block: round up file size to nearest sector 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 Signed-off-by: Hu Tao Reviewed-by: Max Reitz --- block/qcow2.c | 2 +- block/raw-posix.c | 2 +- block/raw-win32.c | 2 +- tests/qemu-iotests/093 | 64 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/093.out | 14 ++++++++++ tests/qemu-iotests/group | 1 + 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100755 tests/qemu-iotests/093 create mode 100644 tests/qemu-iotests/093.out diff --git a/block/qcow2.c b/block/qcow2.c index a54d2ba..75b28cd 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1778,7 +1778,7 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options, /* Read out options */ while (options && options->name) { if (!strcmp(options->name, BLOCK_OPT_SIZE)) { - sectors = options->value.n / 512; + sectors = DIV_ROUND_UP(options->value.n, BDRV_SECTOR_SIZE); } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) { backing_file = options->value.s; } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) { diff --git a/block/raw-posix.c b/block/raw-posix.c index c2b30be..c5b81e1 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1285,7 +1285,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options, /* Read out options */ while (options && options->name) { if (!strcmp(options->name, BLOCK_OPT_SIZE)) { - total_size = options->value.n / BDRV_SECTOR_SIZE; + total_size = DIV_ROUND_UP(options->value.n, BDRV_SECTOR_SIZE); } options++; } diff --git a/block/raw-win32.c b/block/raw-win32.c index 324e818..8f83fab 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -514,7 +514,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options, /* Read out options */ while (options && options->name) { if (!strcmp(options->name, BLOCK_OPT_SIZE)) { - total_size = options->value.n / 512; + total_size = DIV_ROUND_UP(options->value.n, BDRV_SECTOR_SIZE); } options++; } diff --git a/tests/qemu-iotests/093 b/tests/qemu-iotests/093 new file mode 100755 index 0000000..02316d1 --- /dev/null +++ b/tests/qemu-iotests/093 @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Test qcow2 preallocation with different cluster_sizes +# +# Copyright (C) 2014 Fujitsu. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=hutao@cn.fujitsu.com + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +function test_qemu_img() +{ + echo qemu-img "$@" | _filter_testdir + $QEMU_IMG "$@" 2>&1 | _filter_testdir + echo +} + +echo "=== Check qemu-img info output ===" +echo +image_sizes="1024 1234" + +for s in $image_sizes; do + _make_test_img $s + _img_info +done + +# success, all done +echo "*** done" +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/093.out b/tests/qemu-iotests/093.out new file mode 100644 index 0000000..766b512 --- /dev/null +++ b/tests/qemu-iotests/093.out @@ -0,0 +1,14 @@ +QA output created by 093 +=== Check qemu-img info output === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1024 +image: TEST_DIR/t.IMGFMT +file format: IMGFMT +virtual size: 1.0K (1024 bytes) +cluster_size: 65536 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1234 +image: TEST_DIR/t.IMGFMT +file format: IMGFMT +virtual size: 1.5K (1536 bytes) +cluster_size: 65536 +***done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 0f07440..304b596 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -99,3 +99,4 @@ 090 rw auto quick 091 rw auto 092 rw auto quick +093 rw auto