From 65ba31366c2c13ca70342200865b7b5f6624f2e3 Mon Sep 17 00:00:00 2001 From: Rafi Khardalian Date: Sun, 10 Feb 2013 06:05:59 +0000 Subject: Properly write non-raw LVM images on creation Fixes bug 1075333 When force_raw_images=False and libvirt_images_type=lvm were set together, selecting anything other than a RAW image would result in an unbootable instance. This is because the downloaded image was being directly dd'd onto the new LVM root, which will obviously not work for any format other than RAW. Simple change to use qemu-img to read from the image (letting it decide the format) and write to the LVM root as raw. Change-Id: I36494e6d0671c07f7511c10ef886c8cf84c18df7 --- nova/tests/test_imagebackend.py | 8 ++++---- nova/virt/images.py | 4 ++-- nova/virt/libvirt/imagebackend.py | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) mode change 100644 => 100755 nova/virt/images.py diff --git a/nova/tests/test_imagebackend.py b/nova/tests/test_imagebackend.py index 76fd1d5b6..87e51819d 100644 --- a/nova/tests/test_imagebackend.py +++ b/nova/tests/test_imagebackend.py @@ -241,8 +241,8 @@ class LvmTestCase(_ImageTestCase, test.TestCase): sparse=sparse) self.disk.get_disk_size(self.TEMPLATE_PATH ).AndReturn(self.TEMPLATE_SIZE) - cmd = ('dd', 'if=%s' % self.TEMPLATE_PATH, - 'of=%s' % self.PATH, 'bs=4M') + cmd = ('qemu-img', 'convert', '-O', 'raw', self.TEMPLATE_PATH, + self.PATH) self.utils.execute(*cmd, run_as_root=True) self.mox.ReplayAll() @@ -271,8 +271,8 @@ class LvmTestCase(_ImageTestCase, test.TestCase): self.SIZE, sparse=sparse) self.disk.get_disk_size(self.TEMPLATE_PATH ).AndReturn(self.TEMPLATE_SIZE) - cmd = ('dd', 'if=%s' % self.TEMPLATE_PATH, - 'of=%s' % self.PATH, 'bs=4M') + cmd = ('qemu-img', 'convert', '-O', 'raw', self.TEMPLATE_PATH, + self.PATH) self.utils.execute(*cmd, run_as_root=True) self.disk.resize2fs(self.PATH, run_as_root=True) self.mox.ReplayAll() diff --git a/nova/virt/images.py b/nova/virt/images.py old mode 100644 new mode 100755 index 018badecf..a5c960486 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -184,10 +184,10 @@ def qemu_img_info(path): return QemuImgInfo(out) -def convert_image(source, dest, out_format): +def convert_image(source, dest, out_format, run_as_root=False): """Convert image to other format.""" cmd = ('qemu-img', 'convert', '-O', out_format, source, dest) - utils.execute(*cmd) + utils.execute(*cmd, run_as_root=run_as_root) def fetch(context, image_href, path, _user_id, _project_id): diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py index 74148a866..7e7175865 100755 --- a/nova/virt/libvirt/imagebackend.py +++ b/nova/virt/libvirt/imagebackend.py @@ -248,8 +248,7 @@ class Lvm(Image): size = size if resize else base_size libvirt_utils.create_lvm_image(self.vg, self.lv, size, sparse=self.sparse) - cmd = ('dd', 'if=%s' % base, 'of=%s' % self.path, 'bs=4M') - utils.execute(*cmd, run_as_root=True) + images.convert_image(base, self.path, 'raw', run_as_root=True) if resize: disk.resize2fs(self.path, run_as_root=True) -- cgit