]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Avoid using the disk cache on volume initialisation
authorDirk Mueller <dirk@dmllr.de>
Tue, 5 Aug 2014 14:13:33 +0000 (16:13 +0200)
committerDirk Mueller <dirk@dmllr.de>
Fri, 29 Aug 2014 10:00:43 +0000 (12:00 +0200)
When caching is involved, the volume might be
unmapped before the copy actually hit the disk or the
VM starts booting before all of the data has been flushed,
which causes the VM to crash at an arbitrary point in time.

Closes-Bug: #1363016

Change-Id: I7a04f683add8c23b9125fe837c4048ccc3ac224d

cinder/image/image_utils.py
cinder/tests/test_image_utils.py

index f656e287ae57030f0e668964037718ba738c8817..c7a0e3df2c001294acc3b1186cbe54fbd512b565 100644 (file)
@@ -64,11 +64,15 @@ def qemu_img_info(path):
 def convert_image(source, dest, out_format, bps_limit=None):
     """Convert image to other format."""
     start_time = timeutils.utcnow()
-    cmd = ('qemu-img', 'convert', '-O', out_format, source, dest)
+    # Always set -t none. First it is needed for cgroup io/limiting
+    # and it is needed to ensure that all data hit the device before
+    # it gets unmapped remotely from the host
+    cmd = ('qemu-img', 'convert',
+           '-t', 'none',
+           '-O', out_format, source, dest)
     cgcmd = volume_utils.setup_blkio_cgroup(source, dest, bps_limit)
     if cgcmd:
         cmd = tuple(cgcmd) + cmd
-        cmd += ('-t', 'none')  # required to enable ratelimit by blkio cgroup
     utils.execute(*cmd, run_as_root=True)
 
     duration = timeutils.delta_seconds(start_time, timeutils.utcnow())
index 5a542db24cec8582313665a95b116bfd61d17f78..3523d7a704ff99db4b11d6a2ab3e370d914c6710 100644 (file)
@@ -88,8 +88,9 @@ class TestUtils(test.TestCase):
         TEST_SOURCE = 'img/qemu.img'
         TEST_DEST = '/img/vmware.vmdk'
 
-        utils.execute('qemu-img', 'convert', '-O', TEST_OUT_FORMAT,
-                      TEST_SOURCE, TEST_DEST, run_as_root=True)
+        utils.execute(
+            'qemu-img', 'convert', '-t', 'none', '-O', TEST_OUT_FORMAT,
+            TEST_SOURCE, TEST_DEST, run_as_root=True)
 
         mox.ReplayAll()
 
@@ -235,11 +236,10 @@ class TestUtils(test.TestCase):
         if has_qemu and dest_inf:
             if bps_limit:
                 prefix = ('cgexec', '-g', 'blkio:test')
-                postfix = ('-t', 'none')
             else:
-                prefix = postfix = ()
-            cmd = prefix + ('qemu-img', 'convert', '-O', 'raw',
-                            self.TEST_DEV_PATH, self.TEST_DEV_PATH) + postfix
+                prefix = ()
+            cmd = prefix + ('qemu-img', 'convert', '-t', 'none', '-O', 'raw',
+                            self.TEST_DEV_PATH, self.TEST_DEV_PATH)
 
             volume_utils.setup_blkio_cgroup(
                 self.TEST_DEV_PATH, self.TEST_DEV_PATH,
@@ -440,11 +440,10 @@ class TestUtils(test.TestCase):
         if bps_limit:
             CONF.set_override('volume_copy_bps_limit', bps_limit)
             prefix = ('cgexec', '-g', 'blkio:test')
-            postfix = ('-t', 'none')
         else:
-            prefix = postfix = ()
-        cmd = prefix + ('qemu-img', 'convert', '-O', 'qcow2',
-                        mox.IgnoreArg(), mox.IgnoreArg()) + postfix
+            prefix = ()
+        cmd = prefix + ('qemu-img', 'convert', '-t', 'none', '-O', 'qcow2',
+                        mox.IgnoreArg(), mox.IgnoreArg())
 
         m = self._mox
         m.StubOutWithMock(utils, 'execute')
@@ -494,7 +493,7 @@ class TestUtils(test.TestCase):
         m = self._mox
         m.StubOutWithMock(utils, 'execute')
 
-        utils.execute('qemu-img', 'convert', '-O', 'qcow2',
+        utils.execute('qemu-img', 'convert', '-t', 'none', '-O', 'qcow2',
                       mox.IgnoreArg(), mox.IgnoreArg(), run_as_root=True)
         utils.execute(
             'env', 'LC_ALL=C', 'qemu-img', 'info',