Translated from: http://www.pixelbeat.org/docs/openstack_libvirt_images/
The main stages of a Virtual machine disk image as it transfers through OpenStack to be booted under Libvirt is:
Initially the image is downloaded from glance and cached in Libvirt base. We'll consider the options for handling a qcow2 image stored in glance, as/format can be downloaded quite efficiently From glance as it supports compression, and image sparseness can maintained. This article'll focus on the flow and transformations in "Libvirt base", which are used to cache, preprocess and optional Ly back, VM disk images.
Configuration
First we ' ll summarize the config variables involved, before presenting the operations associated with each config Combinat Ion, in each OpenStack release. Note I ' m describing upstream openstack here, and not my employer ' s Red Hat OpenStack which have back-ported enhancements be Tween versions where appropriate.
Config |
Default |
Release |
Description |
Use_cow_images |
True |
Cactus |
Whether to use CoW images for "libvirt instance disks" |
Force_raw_images |
True |
Essex |
Allows disabling convert to Raw in "libvirt base" for operational reasons |
Libvirt_images_type |
' Default ' |
Folsom |
Deprecates use_cow_images and allows selecting LVM libvirt images |
[Libvirt]/images_type |
' Default ' |
Icehouse |
Deprecates Libvirt_images_type in the [DEFAULT] section |
Preallocate_images |
' None ' |
Grizzly |
Instance disks preallocation mode. ' Space ' = fallocate images |
Resize_fs_using_block_device |
False |
Havana |
Allows enabling of direct resize for qcow2 images |
The main reason that raw images was written in ' Libvirt base ' by default (since Diablo), was to remove possible compression From the Qcow2 image received from glance. Note compression in Qcow2 images are read only, and so this would impact reads from unwritten portions of the qcow2 image. Users may want to the change this option, depending on CPU resources and I/O bandwidth available. For example, systems with slower I/O or less space available, could want to trade the higher CPU requirements of compression , to minimize input bandwidth. Note RAW images is used unconditionally with LIBVIRT_IMAGES_TYPE=LVM.
Whether to use CoW images for the "Libvirt instance disks" also depends on I/O characteristics of the user ' s system. Without CoW, more space would be used to common parts of the disk image, but on the flip side depending on the backing Sto Re and host caching, there may is better concurrency achieved by have each VM operate on its own copy.
Enabling preallocation of space for the ' Libvirt instance disks ' can help with both space guarantees and I/O performance. Even when isn't using CoW instance disks, the copy each VM gets be sparse and so the VM could fail unexpectedly at run time WI Th ENOSPC. By running Fallocate (1) on the instance disk images, we immediately and efficiently allocate the space for them in the FIL e system (if supported). Also run time performance should be improved as the file system doesn ' t has to dynamically allocate blocks at run time, R Educing CPU Overhead and more importantly file fragmentation.
Disk Image Operations
For each release and config combination, here is the created files and associated operations in getting a qcow2 Image from glance through to being booted on a libvirt Virtual machine.
Folsom, Force_raw_images=true, use_cow_images=true
This results is instance booting from a CoW image, and backed by a resized raw image.
Nova command |
Source Code |
Notes |
wget http://glance/$image-o base_/$hex. part |
Images.fetch |
|
Qemu-img Convert-o Raw $hex. Part $hex. Converted |
Images.fetch_to_raw |
Creates sparse file |
MV $hex. Converted $hex; RM $hex. Part |
Images.fetch_to_raw |
|
|
Imagebackend.create_image |
|
CP $hex $hex _$size |
Libvirt.utils.copy_image |
Creates sparse file |
Qemu-img Resize $hex _$size $size |
Disk.extend |
|
RESIZE2FS $hex _size |
Disk.extend |
unpartitioned ext[234] |
Qemu-img create-f qcow2-o backing_file= ... $instance _dir/disk |
Libvirt.utils.create_image |
|
Folsom, Force_raw_images=true, Use_cow_images=false
This results is instance booting from a copy of a resized raw image.
Nova command |
Source code |
Notes |
wget http://glance/$image-o base_ /$hex. Part |
images.fetch |
&n BSP; |
qemu-img convert-o Raw $hex. Part $hex. Converted |
Images.fetch_to_raw |
creates spars E file |
mv $hex. Converted $hex; rm $hex. Part |
images.fetch_to_raw |
< /td> |
|
imagebackend.create_image |
|
CP $hex &NBSP ; $instance _dir /disk |
libvirt.utils.copy_image |
|
qemu-img Resize Disk |
disk.extend |
|
resize2fs disk |
disk.extend |
unpartitioned ext[234] |
Folsom, Force_raw_images=false, Use_cow_images=false
This results is instance booting from a copy of a resized qcow2 image.
Nova command |
Source Code |
Notes |
wget http://glance/$image-o base_/$hex. part |
Images.fetch |
|
MV $hex. Part $hex |
Images.fetch_to_raw |
|
|
Imagebackend.create_image |
|
CP $hex $instance _dir/disk |
Libvirt.utils.copy_image |
|
QEMU-IMG Resize Disk |
Disk.extend |
|
RESIZE2FS disk |
Disk.extend |
Ignored for Qcow2¹ |
Folsom, Force_raw_images=false, use_cow_images=true
This results the instance booting from a CoW image, and backed by a resized qcow2 image.
Nova command |
Source code |
Notes |
wget http://glance/$image-o base_ /$hex. Part |
images.fetch |
&n BSP; |
mv $hex. Part $hex |
images.fetch_to_raw |
|
|
Imagebackend.create_image |
|
cp $hex $hex _$size |
libvirt.utils.copy_image |
|
qemu-img Resize $hex _$size $size |
disk.extend |
|
resize2fs $hex _size |
disk.extend |
ignored for qcow2 ¹ |
qemu-img create-f qcow2-o backing_file=... $instance _dir /disk |
l Ibvirt.utils.create_image |
|
Grizzly, Force_raw_images=true, use_cow_images=true
Grizzly introduces a change for use_cow_images=True, where it'll resize in the $instance _dir rather than in BAS E_. So the resize are not being cached, but that's minimal CPU tradeoff per instance boot, for the extra space saved in Base_. We ' ll just present the default Config values here which illustrates the only significant change from Folsom.
This results is instance booting from a resized CoW image, and backed by a raw image.
Nova command |
Source Code |
Notes |
wget http://glance/$image-o base_/$hex. part |
Images.fetch |
|
Qemu-img Convert-o Raw $hex. Part $hex. Converted |
Images.fetch_to_raw |
Creates sparse file |
MV $hex. Converted $hex; RM $hex. Part |
Images.fetch_to_raw |
|
|
Imagebackend.create_image |
|
Qemu-img create-f qcow2-o backing_file= ... $instance _dir/disk |
Libvirt.utils.create_image |
|
QEMU-IMG Resize Disk $size |
Disk.extend |
|
RESIZE2FS disk |
Disk.extend |
Grizzly always ignores² |
[² Update SEP 2013:stanislaw Pitucha also noticed the above referenced Grizzly change introduced a regression where unpartitioned qcow2 images were no longer resized. See the Havana resize_fs_using_block_device option below for details.]
Grizzly, preallocate_images= ' space '
Grizzly also has a new fallocate functionality in this area controlled by the preallocate_images config option. If that was set to ' space ' and then after the operations above, the $instance _dir/images would be fallocated to immediately de Termine If enough space is available, and to possibly improve VM I/O performance due to ongoing allocation avoidance, and Better locality of block allocations.
¹havana, Resize_fs_using_block_device=false
As noted in the first Grizzly change above, Stanislaw Pitucha noticed ' change introduced a regression where unpartitio Ned Qcow2 images were no longer resized. He supplied a fix to resize qcow directly rather than relying on the raw image being available, which would also cater for The Force_raw_images=false case, even pre Grizzly did not. This new option can is used to enable the this support, but there is some large performance and possible security issues so I T ' s not enabled by default. This support would be available in the upcoming Havana release.
General performance considerations
Performance have improved in this area through each OpenStack release, with some of the main topics to consider, for past a nd future changes being:
Minimize I/O
Note these were implemented in Essex:
- Copy images, then resize, rather than vice versa
- Directly generating images in the $instance _dir/
- Intelligent reading of sparse input
- Reproduction of sparse input on output
- Use compression
Note this is implemented in Folsom:
- Avoid file sytem overhead by setting LIBVIRT_IMAGES_TYPE=LVM. Note file system overhead varies depending on file system
Minimize Storage
- Use compression
- Use sparse output/generation
- Avoid resized copies when not needed
- Use CoW if appropriate
Improve Caching
- Avoid thrashing the page cache with large intermediate images
- Improve low level caching through better storage allocation
Preprocessing
- Preprocessing May is possible on images like Preallocation=metadata which trades off initial CPU cost for possibly much is Tter run time I/O performance
- Such cost would is some what alleviated by have asynchronous population of the Base_ cache
Nova:libvirt the life cycle of image