Hi all,
This patch adds support for creation of snapshot volumes to the virsh
"vol-create-as" command, which is presently missing it. Thinking it
will be useful, as it's tricky to explain snapshots + hacking XML when
writing up docs. Explaining things as parameters on a command line (no
XML required) is so much easier. :)
The snapshot support was added through two optional parameters to
vol-create-as:
--snapshot-source-vol backing_volume
--snapshot-source-format volume_format
The "--snapshot-source-vol" parameter is the name of a volume to use as
the snapshot backing store. It has to be in the same storage pool as
the volume being created.
The "--snapshot-source-format" parameter is only needed for file based
backing stores (ie qcow, qcow2, etc), and specifies the format of the
backing store volume.
In an ideal scenario, the --snapshot-source-format parameter would not
be necessary, but there didn't appear to be a way to query the format of
an existing volume to determine it automatically. (ie something like a
virStorageVolGetFormat())
Example of using the new parameters with an LVM storage pool:
********************************************************
virsh # vol-list guest_images_lvm
Name Path
-----------------------------------------
rhel6vm1lun1 /dev/guest_images_lvm/rhel6vm1lun1
testvol /dev/guest_images_lvm/testvol
virsh # vol-create-as guest_images_lvm snapvol1 5G --snapshot-source-vol
rhel6vm1lun1
Vol snapvol1 created
virsh # vol-create-as guest_images_lvm snapvol2 5G --snapshot-source-vol
rhel6vm1lun1
Vol snapvol2 created
virsh # vol-create-as guest_images_lvm snapvol3 5G --snapshot-source-vol
rhel6vm1lun1
Vol snapvol3 created
virsh # vol-list guest_images_lvm
Name Path
-----------------------------------------
rhel6vm1lun1 /dev/guest_images_lvm/rhel6vm1lun1
snapvol1 /dev/guest_images_lvm/snapvol1
snapvol2 /dev/guest_images_lvm/snapvol2
snapvol3 /dev/guest_images_lvm/snapvol3
testvol /dev/guest_images_lvm/testvol
# virsh # quit
# lvs guest_images_lvm
LV VG Attr LSize Origin Snap% Move Log
Copy% Convert
rhel6vm1lun1 guest_images_lvm owi-a- 20.00g
snapvol1 guest_images_lvm swi-a- 5.00g rhel6vm1lun1 0.00
snapvol2 guest_images_lvm swi-a- 5.00g rhel6vm1lun1 0.00
snapvol3 guest_images_lvm swi-a- 5.00g rhel6vm1lun1 0.00
testvol guest_images_lvm -wi-a- 20.00g
#
********************************************************
Example of using the new parameters with a directory storage pool:
********************************************************
virsh # vol-list image_dir
Name Path
-----------------------------------------
imagevol1.qcow2 /home/images/imagevol1.qcow2
virsh # vol-create-as image_dir qcow2snap1 5G --format qcow2
--snapshot-source-vol imagevol1.qcow2 --snapshot-source-format qcow2
Vol qcow2snap1 created
virsh # vol-create-as image_dir qcow2snap2 5G --format qcow2
--snapshot-source-vol imagevol1.qcow2 --snapshot-source-format qcow2
Vol qcow2snap2 created
virsh # vol-create-as image_dir qcow2snap3 5G --format qcow2
--snapshot-source-vol imagevol1.qcow2 --snapshot-source-format qcow2
Vol qcow2snap3 created
virsh # vol-list image_dir
Name Path
-----------------------------------------
imagevol1.qcow2 /home/images/imagevol1.qcow2
qcow2snap1 /home/images/qcow2snap1
qcow2snap2 /home/images/qcow2snap2
qcow2snap3 /home/images/qcow2snap3
virsh # quit
# ls -la /home/images/
total 552
drwx------. 2 root root 4096 Jun 5 22:10 .
drwxr-xr-x. 7 root root 4096 Jun 5 16:51 ..
-rw-------. 1 root root 262144 Jun 5 16:53 imagevol1.qcow2
-rw-------. 1 root root 262144 Jun 5 22:10 qcow2snap1
-rw-------. 1 root root 262144 Jun 5 22:10 qcow2snap2
-rw-------. 1 root root 262144 Jun 5 22:10 qcow2snap3
#
********************************************************
A Red Hat BZ has been created for tracking this, if useful:
https://bugzilla.redhat.com/show_bug.cgi?id=600652
Regards and best wishes,
Justin Clift
On 06/05/2010 10:13 PM, Justin Clift wrote:
---
tools/virsh.c | 32 +++++++++++++++++++++++++++++++-
tools/virsh.pod | 7 ++++++-
2 files changed, 37 insertions(+), 2 deletions(-)
<snip>
--
Salasaga - Open Source eLearning IDE
http://www.salasaga.org