2012-06-14 21:18:53 +00:00
|
|
|
==============
|
|
|
|
QEMU and RBD
|
|
|
|
==============
|
|
|
|
|
|
|
|
Ceph integrates with the QEMU virtual machine. For details on QEMU, see
|
|
|
|
`QEMU Open Source Processor Emulator`_. For QEMU documentation, see
|
|
|
|
`QEMU Manual`_.
|
2012-06-19 17:10:51 +00:00
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
.. important:: To use Ceph block devices with QEMU, you must have a running Ceph cluster.
|
2012-06-14 21:18:53 +00:00
|
|
|
|
2012-06-19 17:10:51 +00:00
|
|
|
Installing QEMU on Ubuntu 12.04 Precise
|
2012-11-03 19:12:11 +00:00
|
|
|
=======================================
|
|
|
|
|
2012-06-14 21:18:53 +00:00
|
|
|
QEMU packages are incorporated into the Ubuntu 12.04 precise distribution. To
|
|
|
|
install QEMU on precise, execute the following::
|
|
|
|
|
|
|
|
sudo apt-get install qemu
|
|
|
|
|
|
|
|
Installing QEMU on Earlier Versions of Ubuntu
|
2012-11-03 19:12:11 +00:00
|
|
|
=============================================
|
|
|
|
|
|
|
|
For Ubuntu distributions 11.10 Oneiric and earlier, you must install
|
2012-06-14 21:18:53 +00:00
|
|
|
the 0.15 version of QEMU or later. To build QEMU from source, use the
|
|
|
|
following procedure::
|
|
|
|
|
|
|
|
cd {your-development-directory}
|
|
|
|
git clone git://git.qemu.org/qemu.git
|
|
|
|
cd qemu
|
|
|
|
./configure --enable-rbd
|
|
|
|
make; make install
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
Creating Images with QEMU
|
|
|
|
=========================
|
|
|
|
|
|
|
|
You can create a block device image from QEMU. You must specify ``rbd``, the
|
|
|
|
pool name, and the name of the image you wish to create. You must also specify
|
|
|
|
the size of the image. ::
|
2012-06-14 21:18:53 +00:00
|
|
|
|
|
|
|
qemu-img create -f rbd rbd:{pool-name}/{image-name} {size}
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
qemu-img create -f rbd rbd:data/foo 10G
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
Resizing Images with QEMU
|
|
|
|
=========================
|
|
|
|
|
|
|
|
You can resize a block device image from QEMU. You must specify ``rbd``,
|
2012-06-14 21:18:53 +00:00
|
|
|
the pool name, and the name of the image you wish to resize. You must also
|
2012-06-19 17:10:51 +00:00
|
|
|
specify the size of the image. ::
|
2012-06-14 21:18:53 +00:00
|
|
|
|
|
|
|
qemu-img resize -f rbd rbd:{pool-name}/{image-name} {size}
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
qemu-img resize -f rbd rbd:data/foo 10G
|
|
|
|
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
Retrieving Image Information with QEMU
|
|
|
|
======================================
|
|
|
|
|
|
|
|
You can retrieve block device image information from QEMU. You must
|
2012-06-14 21:18:53 +00:00
|
|
|
specify ``rbd``, the pool name, and the name of the image. ::
|
|
|
|
|
|
|
|
qemu-img info -f rbd rbd:{pool-name}/{image-name}
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
qemu-img info -f rbd rbd:data/foo
|
|
|
|
|
2012-09-26 00:08:48 +00:00
|
|
|
|
|
|
|
Running QEMU with RBD
|
2012-11-03 19:12:11 +00:00
|
|
|
=====================
|
2012-09-26 00:08:48 +00:00
|
|
|
|
|
|
|
QEMU can pass a block device from the host on to a guest, but since
|
2012-11-03 19:12:11 +00:00
|
|
|
QEMU 0.15, there's no need to map an image as a block device on
|
|
|
|
the host. Instead, QEMU can access an image as a virtual block
|
2012-09-26 00:08:48 +00:00
|
|
|
device directly via ``librbd``. This performs better because it avoids
|
|
|
|
an additional context switch, and can take advantage of `RBD caching`_.
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
You can use ``qemu-img`` to convert existing virtual machine images to Ceph
|
|
|
|
block device images. For example, if you have a qcow2 image, you could run::
|
2012-09-26 00:08:48 +00:00
|
|
|
|
|
|
|
qemu-img convert -f qcow2 -O rbd debian_squeeze.qcow2 rbd:data/squeeze
|
|
|
|
|
|
|
|
To run a virtual machine booting from that image, you could run::
|
|
|
|
|
|
|
|
qemu -m 1024 -drive format=raw,file=rbd:data/squeeze
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
`RBD caching`_ can significantly improve performance.
|
|
|
|
Since QEMU 1.2, QEMU's cache options control ``librbd`` caching::
|
2012-09-26 00:08:48 +00:00
|
|
|
|
|
|
|
qemu -m 1024 -drive format=rbd,file=rbd:data/squeeze,cache=writeback
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
If you have an older version of QEMU, you can set the ``librbd`` cache
|
2012-09-26 00:08:48 +00:00
|
|
|
configuration (like any Ceph configuration option) as part of the
|
|
|
|
'file' parameter::
|
|
|
|
|
2012-12-26 22:25:51 +00:00
|
|
|
qemu -m 1024 -drive format=raw,file=rbd:data/squeeze:rbd_cache=true,cache=writeback
|
|
|
|
|
|
|
|
.. important:: If you set rbd_cache=true, you must set cache=writeback
|
|
|
|
or risk data loss. Without cache=writeback, QEMU will not send
|
|
|
|
flush requests to librbd. If QEMU exits uncleanly in this
|
|
|
|
configuration, filesystems on top of rbd can be corrupted.
|
2012-09-26 00:08:48 +00:00
|
|
|
|
2012-11-14 22:57:51 +00:00
|
|
|
.. _RBD caching: ../rbd-config-ref/#rbd-cache-config-settings
|
2012-09-26 00:08:48 +00:00
|
|
|
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
Enabling Discard/TRIM
|
|
|
|
=====================
|
2012-09-26 00:08:48 +00:00
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
Since Ceph version 0.46 and QEMU version 1.1, Ceph block devices support the
|
|
|
|
discard operation. This means that a guest can send TRIM requests to let a Ceph
|
|
|
|
block device reclaim unused space. This can be enabled in the guest by mounting
|
|
|
|
ext4 or XFS with the ``discard`` option.
|
2012-09-26 00:08:48 +00:00
|
|
|
|
|
|
|
For this to be available to the guest, it must be explicitly enabled
|
|
|
|
for the block device. To do this, you must specify a
|
2012-11-03 19:12:11 +00:00
|
|
|
``discard_granularity`` associated with the drive::
|
2012-09-26 00:08:48 +00:00
|
|
|
|
|
|
|
qemu -m 1024 -drive format=raw,file=rbd:data/squeeze,id=drive1,if=none \
|
|
|
|
-device driver=ide-hd,drive=drive1,discard_granularity=512
|
|
|
|
|
|
|
|
Note that this uses the IDE driver. The virtio driver does not
|
|
|
|
support discard.
|
|
|
|
|
|
|
|
|
2012-11-03 19:12:11 +00:00
|
|
|
QEMU Cache Options
|
|
|
|
==================
|
|
|
|
|
|
|
|
QEMU's cache options correspond to the following Ceph `RBD Cache`_ settings.
|
|
|
|
|
|
|
|
Writeback::
|
|
|
|
|
|
|
|
rbd_cache = true
|
|
|
|
|
|
|
|
Writethrough::
|
|
|
|
|
|
|
|
rbd_cache = true
|
|
|
|
rbd_cache_max_dirty = 0
|
|
|
|
|
|
|
|
None::
|
|
|
|
|
|
|
|
rbd_cache = false
|
|
|
|
|
|
|
|
QEMU's cache settings override Ceph's default settings (i.e., settings that are
|
|
|
|
not explicitly set in the Ceph configuration file). If you explicitly set `RBD
|
|
|
|
Cache`_ settings in your Ceph configuration file, your Ceph settings override
|
|
|
|
the QEMU cache settings. If you set cache settings on the QEMU command line, the
|
|
|
|
QEMU command line settings override the Ceph configuration file settings.
|
|
|
|
|
|
|
|
|
2012-06-14 21:18:53 +00:00
|
|
|
.. _QEMU Open Source Processor Emulator: http://wiki.qemu.org/Main_Page
|
|
|
|
.. _QEMU Manual: http://wiki.qemu.org/Manual
|
2012-12-26 22:25:51 +00:00
|
|
|
.. _RBD Cache: ../rbd-config-ref/
|