Eric-<div><br></div><div>Why wouldn't a 'virsh blockcopy --pivot domain src dest' be sufficient to migrate the volumes to a new storage pool?</div><div><br></div><div>-Jamie </div><br><div class="gmail_quote">On Fri, Feb 1, 2013 at 3:44 PM, Eric Blake <span dir="ltr"><<a href="mailto:eblake@redhat.com" target="_blank">eblake@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 02/01/2013 11:20 AM, Jamie Fargen wrote:<br>
> I am searching for directions for using live block migration to copy<br>
> running vm's to a different storage pool.<br>
><br>
><br>
> Example: VM1 running on Host1, the image(s) for VM1 are stored in<br>
> /var/lib/libvirt/images. I'd like to copy the disk image(s) that VM1<br>
> is using to /nfs/images. Without stopping/pausing/powering down the<br>
> VM.<br>
><br>
> Do you have any examples or documentation of how to accomplish this process?<br>
<br>
</div></div>Unfortunately, we probably need to do a better job on documentation or<br>
examples; there has been a patch proposed that might help:<br>
<a href="https://www.redhat.com/archives/libvir-list/2013-January/msg01637.html" target="_blank">https://www.redhat.com/archives/libvir-list/2013-January/msg01637.html</a><br>
<br>
But it is indeed possible to migrate storage with qemu 1.3 or later,<br>
with a guest downtime of only a fraction of a second.  True avoidance of<br>
guest downtime during a storage migration requires support for<br>
persistent dirty bitmaps, which won't be added until at least qemu 1.5;<br>
likewise, the lack of persistent dirty bitmaps means the current libvirt<br>
will only let you do live storage migration on a transient guest (the<br>
hope is that the persistent bitmap of qemu 1.5 will let libvirt allow<br>
block mirroring across both guest and libvirtd restarts, and therefore I<br>
can add code to libvirt to make blockcopy work for a persistent guest).<br>
 Thankfully, it is possible to make a guest transient, do the storage<br>
migration, then make the guest persistent again.<br>
<br>
So, the way I have done live block migration is as follows:<br>
<br>
# save off the persistent definition for later<br>
virsh dumpxml --inactive $dom > $dom.xml<br>
# make the guest transient<br>
virsh undefine $dom<br>
# remind myself which disks need migration<br>
virsh domblklist $dom<br>
# for each disk (such as "vda"), do a migration<br>
virsh blockcopy $dom $disk /path/to/new --wait --verbose --pivot<br>
# make the guest persistent again<br>
virsh define $dom.xml<br>
<br>
Note that while my example was blocking for each disk, you can also do<br>
migration in parallel for multiple disks at once, if you avoid the<br>
'--wait' parameter to 'virsh blockcopy' and instead use 'virsh blockjob<br>
$dom $disk --pivot' to do the pivots.  An attempt to pivot will fail<br>
until the disk has reached mirroring state; but it does mean that you<br>
have to set up your own polling loop to see when each disk is ready.<br>
<br>
Also, a shallow block copy can result in less downtime in waiting for a<br>
disk to reach mirroring state.  That is, given the following disk layout<br>
prior to the migration (such as by using 'virsh snapshot-create-as $dom<br>
--disk-only):<br>
<br>
base <- snapshot<br>
<br>
then avoiding --shallow has to transfer the entire disk image, creating:<br>
<br>
copy<br>
<br>
while using --shallow only has to transfer the contents of snapashot,<br>
creating:<br>
<br>
base <- copy<br>
<br>
When using --shallow, libvirt will NOT copy the base file; and since<br>
qemu will prefer to create backing chains that used absolute names to<br>
the base files, the copied leaf image defaults to pointing to the<br>
original base image.  If you need to migrate the entire chain including<br>
the base file, then you have to pre-create a blank destination qcow2<br>
file that points to the new desired base image (using qemu-img create),<br>
then use the --reuse-external flag when telling libvirt to do the<br>
blockcopy, and avoid doing the pivot operation until the base file has<br>
been copied to its new location (it is possible to copy the base image<br>
in parallel with waiting for libvirt to reach full mirroring phase of<br>
the shallow blockcopy of the leaf image, and wait do manually do the<br>
pivot until both operations are ready, regardless of which finished first).<br>
<br>
Further use of blockpull or blockcommit can reduce the length of a<br>
backing chain without any guest downtime (although as of qemu 1.4, while<br>
blockpull can be used to collapse down to a single element, blockcommit<br>
only works for collapsing a chain of 3 or more files down to a minimum<br>
of 2).<br>
<br>
I'm happy to answer more questions you may have.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Eric Blake   eblake redhat com    <a href="tel:%2B1-919-301-3266" value="+19193013266">+1-919-301-3266</a><br>
Libvirt virtualization library <a href="http://libvirt.org" target="_blank">http://libvirt.org</a><br>
<br>
</font></span></blockquote></div><br>