qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] vmdk: Fix cylinders number during convert
@ 2014-10-22 13:25 Arthur Gautier
  2014-10-23  6:55 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 1 reply; 9+ messages in thread
From: Arthur Gautier @ 2014-10-22 13:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Arthur Gautier

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 <william@gandi.net>
Signed-off-by: Arthur Gautier <baloo@gandi.net>
---
 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
+owner=baloo@gandi.net
+
+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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-10-31 15:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-22 13:25 [Qemu-devel] [PATCH] vmdk: Fix cylinders number during convert Arthur Gautier
2014-10-23  6:55 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-10-23  8:03   ` Markus Armbruster
2014-10-28 16:00     ` Stefan Hajnoczi
2014-10-29  1:28       ` Fam Zheng
2014-10-30  9:09         ` Arthur Gautier
2014-10-30 10:27           ` Fam Zheng
2014-10-30 14:28             ` Arthur Gautier
2014-10-31  2:52               ` Fam Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).