qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] vmdk: Fix cylinders number during convert


From: Arthur Gautier
Subject: [Qemu-devel] [PATCH] vmdk: Fix cylinders number during convert
Date: Wed, 22 Oct 2014 15:25:20 +0200

We can not rely on int cast to get a correct number of cylinders. The
cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Reviewed-by: William Dauchy <address@hidden>
Signed-off-by: Arthur Gautier <address@hidden>
---
 block/vmdk.c               |  4 +--
 tests/qemu-iotests/106     | 67 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/106.out |  5 ++++
 tests/qemu-iotests/group   |  1 +
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100755 tests/qemu-iotests/106
 create mode 100644 tests/qemu-iotests/106.out

diff --git a/block/vmdk.c b/block/vmdk.c
index 4ae6c75..c22a6c6 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1928,8 +1928,8 @@ static int vmdk_create(const char *filename, QemuOpts 
*opts, Error **errp)
                            parent_desc_line,
                            ext_desc_lines->str,
                            (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
-                           total_size /
-                               (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE),
+                           DIV_ROUND_UP(total_size,
+                               (int64_t)(63 * number_heads * 
BDRV_SECTOR_SIZE)),
                            number_heads,
                            adapter_type);
     desc_len = strlen(desc);
diff --git a/tests/qemu-iotests/106 b/tests/qemu-iotests/106
new file mode 100755
index 0000000..d17c588
--- /dev/null
+++ b/tests/qemu-iotests/106
@@ -0,0 +1,67 @@
+#!/bin/bash
+#
+# Create then convert raw to vmdk with a little image
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#               2014 Gandi SAS
+#
+# 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
address@hidden
+
+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 vmdk
+_supported_proto generic
+_supported_os Linux
+
+IMG_SIZE=1K
+
+TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_img_create
+
+#echo "=== Convert image to vmdk ==="
+#echo
+$QEMU_IMG convert -f raw -O vmdk "$TEST_IMG.base" "$TEST_IMG"
+
+echo "=== Check for correct number of cylinders ==="
+echo
+
+# Cylinders are in the top of the file
+CYLINDERS=`grep -a 'cylinders' $TEST_IMG | head -1 | sed -r 
's/.*"([0-9]+)".*/\1/' | tr -d '\n'`
+
+
+# Check the cylinders number is plausible
+[ "x$CYLINDERS" = "x0" ] && (echo "Cylinders cannot be zero" >&2 && exit 1)
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/106.out b/tests/qemu-iotests/106.out
new file mode 100644
index 0000000..5d2f0a3
--- /dev/null
+++ b/tests/qemu-iotests/106.out
@@ -0,0 +1,5 @@
+QA output created by 106
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1024 
+=== Check for correct number of cylinders ===
+
+*** done
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index b230996..0c68320 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -106,3 +106,4 @@
 103 rw auto quick
 104 rw auto
 105 rw auto quick
+106 rw auto quick
-- 
2.1.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]