From: Dirk Mueller Date: Tue, 5 Aug 2014 14:13:33 +0000 (+0200) Subject: Avoid using the disk cache on volume initialisation X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5c5f3c0684caada0fb7efe33d59bc7f1d66c72d8;p=openstack-build%2Fcinder-build.git Avoid using the disk cache on volume initialisation 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 --- diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index f656e287a..c7a0e3df2 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -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()) diff --git a/cinder/tests/test_image_utils.py b/cinder/tests/test_image_utils.py index 5a542db24..3523d7a70 100644 --- a/cinder/tests/test_image_utils.py +++ b/cinder/tests/test_image_utils.py @@ -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',