@@ -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)) {
@@ -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++;
}
@@ -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++;
}
new file mode 100755
@@ -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 <http://www.gnu.org/licenses/>.
+#
+
+# 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
new file mode 100644
@@ -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
@@ -99,3 +99,4 @@
090 rw auto quick
091 rw auto
092 rw auto quick
+093 rw auto
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- 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