Bug 600652

Summary: virsh does not support simple (non-XML editing) method of creating volume snapshots
Product: Red Hat Enterprise Linux 6 Reporter: Justin Clift <justin>
Component: libvirtAssignee: Eric Blake <eblake>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 6.0CC: ajia, berrange, dallan, dyuan, hbrock, llim, mjenner, nzhang, syeghiay, veillard, xen-maint, yoyzhang
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-0.8.7-18.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-06-09 19:07:42 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 628871    
Attachments:
Description Flags
Patch to virsh.c and virsh.pod, adding backing store support to vol-create-as.
none
Updated patch.
none
Updated patch, as submitted upstream. none

Description Justin Clift 2010-06-05 12:40:21 UTC
Created attachment 421422 [details]
Patch to virsh.c and virsh.pod, adding backing store support to vol-create-as.

Description of problem:

virsh doesn't presently support the creation of snapshot volumes (LVM, nor file based) without manual editing of XML file(s).  This is non-optimal for SysAdmins, and for trying to write documentation/guides on how to do this.

The attached patch adds support for snapshot volume creation to the existing vol-create-as command.  It does this by adding two optional parameters:

  --snapshot-source-vol backing_volume
  --snapshot-source-format volume_format

The "backing_volume" value above is the name of the existing volume in the same storage pool, which will be used as the snapshotbacking store.

The "volume_format" value above is applicable to file format volumes (ie qcow, qcow2), and specifies the format of the backing store volume.

Ideally the --snapshot-source-format parameter would not be necessary, but there doesn't yet appear to be a function to query the format of an existing volume.  (ie virStorageVolGetFormat())

This patch has additionally being submitted upstream:

  https://www.redhat.com/archives/libvir-list/2010-June/msg00127.html


Version-Release number of selected component (if applicable):

  libvirt-client-0.7.6-2.el6.x86_64


Additional info:

With the patch applied to libvirt git HEAD, snapshot volumes now work:

LVM Storage Pool
****************

# vgs
  VG               #PV #LV #SN Attr   VSize   VFree  
  guest_images_lvm   1   2   0 wz--n- 465.76g 425.76g
  vg_host2           1   3   0 wz--n- 465.27g      0 
# lvs guest_images_lvm
  LV           VG               Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  rhel6vm1lun1 guest_images_lvm -wi-a- 20.00g                                      
  testvol      guest_images_lvm -wi-a- 20.00g                                      
# virsh
Welcome to lt-virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

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                                            
# virsh
Welcome to lt-virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # vol-delete --pool guest_images_lvm snapvol2
Vol snapvol2 deleted

virsh # vol-delete --pool guest_images_lvm snapvol3
Vol snapvol3 deleted

virsh # vol-list guest_images_lvm
Name                 Path                                    
-----------------------------------------
rhel6vm1lun1         /dev/guest_images_lvm/rhel6vm1lun1      
snapvol1             /dev/guest_images_lvm/snapvol1          
testvol              /dev/guest_images_lvm/testvol           

virsh # 
# 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                        
  testvol      guest_images_lvm -wi-a- 20.00g                                            
#


Directory Storage Pool
**********************

# ls -la /home/images/
total 144
drwx------. 2 root root   4096 Jun  5 22:09 .
drwxr-xr-x. 7 root root   4096 Jun  5 16:51 ..
-rw-------. 1 root root 262144 Jun  5 16:53 imagevol1.qcow2
# virsh 
Welcome to lt-virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

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
# virsh 
Welcome to lt-virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # vol-delete --pool image_dir qcow2snap2
Vol qcow2snap2 deleted

virsh # vol-delete --pool image_dir qcow2snap3
Vol qcow2snap3 deleted

virsh # vol-list image_dir
Name                 Path                                    
-----------------------------------------
imagevol1.qcow2      /home/images/imagevol1.qcow2            
qcow2snap1           /home/images/qcow2snap1                 

virsh # quit

# ls -la /home/images/
total 280
drwx------. 2 root root   4096 Jun  5 22:11 .
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
#

Comment 2 Justin Clift 2010-06-06 10:08:22 UTC
Created attachment 421568 [details]
Updated patch.

Updated patch.  This tries the supplied backing store volume string as a path and key if not found, plus reports failure to locate the volume to the user.

Also submitted upstream:

  http://www.redhat.com/archives/libvir-list/2010-June/msg00134.html

Comment 3 RHEL Program Management 2010-06-07 17:03:39 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux major release.  Product Management has requested further
review of this request by Red Hat Engineering, for potential inclusion in a Red
Hat Enterprise Linux Major release.  This request is not yet committed for
inclusion.

Comment 4 Justin Clift 2010-06-08 16:58:45 UTC
Created attachment 422276 [details]
Updated patch, as submitted upstream.

Submitted upstream:

  https://www.redhat.com/archives/libvir-list/2010-June/msg00179.html

Comment 6 Daniel Veillard 2010-10-11 15:51:50 UTC
This was fixed upstream,

Daniel

Comment 8 zhanghaiyan 2011-04-20 11:01:09 UTC
Verified this bug pass with libvirt-0.8.7-18.el6.x86_64

LVM Storage Pool
****************

# vgs
  VG     #PV #LV #SN Attr   VSize VFree
  HostVG   1   1   0 wz--n- 9.31g 7.31g
# lvs HostVG
  LV         VG     Attr   LSize Origin Snap%  Move Log Copy%  Convert
  HostVG-vol HostVG -wi-a- 2.00g                                      
# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # vol-list HostVG
Name                 Path                                    
-----------------------------------------
HostVG-vol           /dev/HostVG/HostVG-vol                  

virsh # vol-create-as --pool HostVG snapvol1 5G --backing-vol HostVG-vol
Vol snapvol1 created

virsh # vol-create-as --pool HostVG snapvol2 1G --backing-vol HostVG-vol
Vol snapvol2 created

virsh # vol-create-as --pool HostVG snapvol3 1G --backing-vol HostVG-vol --backing-vol-format qcow2
Vol snapvol3 created

virsh # vol-list HostVG
Name                 Path                                    
-----------------------------------------
HostVG-vol           /dev/HostVG/HostVG-vol                  
snapvol1             /dev/HostVG/snapvol1                    
snapvol2             /dev/HostVG/snapvol2                    
snapvol3             /dev/HostVG/snapvol3                    

virsh # exit

# lvs HostVG
  LV         VG     Attr   LSize Origin     Snap%  Move Log Copy%  Convert
  HostVG-vol HostVG owi-a- 2.00g                                          
  snapvol1   HostVG swi-a- 5.00g HostVG-vol   0.00                        
  snapvol2   HostVG swi-a- 1.00g HostVG-vol   0.00                        
  snapvol3   HostVG swi-a- 1.00g HostVG-vol   0.00                        

# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # vol-delete --pool HostVG snapvol1
Vol snapvol1 deleted

virsh # vol-list HostVG
Name                 Path                                    
-----------------------------------------
HostVG-vol           /dev/HostVG/HostVG-vol                  
snapvol2             /dev/HostVG/snapvol2                    
snapvol3             /dev/HostVG/snapvol3                    

virsh # exit


# lvs HostVG
  LV         VG     Attr   LSize Origin     Snap%  Move Log Copy%  Convert
  HostVG-vol HostVG owi-a- 2.00g                                          
  snapvol2   HostVG swi-a- 1.00g HostVG-vol   0.00                        
  snapvol3   HostVG swi-a- 1.00g HostVG-vol   0.00 




Directory Storage Pool
**********************
                       
# ls -la /var/lib/libvirt/images/pool-dir/ -h
total 1.1G
drwx------. 2 root root 4.0K Apr 20 05:38 .
drwx--x--x. 3 root root 4.0K Apr 20 05:38 ..
-rw-------. 1 root root 1.0G Apr 20 05:38 pool-vol

# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # vol-list pool-dir
Name                 Path                                    
-----------------------------------------
pool-vol             /var/lib/libvirt/images/pool-dir/pool-vol

virsh # vol-create-as pool-dir pool-vol-snapshot1 1G --format qcow2 --backing-vol pool-vol --backing-vol-format qcow2
Vol pool-vol-snapshot1 created

virsh # vol-create-as pool-dir pool-vol-snapshot2 1G --format qcow2 --backing-vol pool-vol --backing-vol-format qcow2
Vol pool-vol-snapshot2 created


virsh # vol-list pool-dir
Name                 Path                                    
-----------------------------------------
pool-vol             /var/lib/libvirt/images/pool-dir/pool-vol
pool-vol-snapshot1   /var/lib/libvirt/images/pool-dir/pool-vol-snapshot1
pool-vol-snapshot2   /var/lib/libvirt/images/pool-dir/pool-vol-snapshot2

virsh # exit


# ls -lah /var/lib/libvirt/images/pool-dir/
total 1.1G
drwx------. 2 root root 4.0K Apr 20 06:02 .
drwx--x--x. 3 root root 4.0K Apr 20 05:38 ..
-rw-------. 1 root root 1.0G Apr 20 05:38 pool-vol
-rw-------. 1 root root 256K Apr 20 06:02 pool-vol-snapshot1
-rw-------. 1 root root 256K Apr 20 06:02 pool-vol-snapshot2

# qemu-img info /var/lib/libvirt/images/pool-dir/pool-vol-snapshot2 
image: /var/lib/libvirt/images/pool-dir/pool-vol-snapshot2
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 140K
cluster_size: 65536
backing file: /var/lib/libvirt/images/pool-dir/pool-vol (actual path: /var/lib/libvirt/images/pool-dir/pool-vol)

# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit


virsh # vol-delete --pool pool-dir pool-vol-snapshot1
Vol pool-vol-snapshot1 deleted

virsh #  vol-list pool-dir
Name                 Path                                    
-----------------------------------------
pool-vol             /var/lib/libvirt/images/pool-dir/pool-vol
pool-vol-snapshot2   /var/lib/libvirt/images/pool-dir/pool-vol-snapshot2

virsh # exit

# ls -lah /var/lib/libvirt/images/pool-dir/
total 1.1G
drwx------. 2 root root 4.0K Apr 20 06:04 .
drwx--x--x. 3 root root 4.0K Apr 20 05:38 ..
-rw-------. 1 root root 1.0G Apr 20 05:38 pool-vol
-rw-------. 1 root root 256K Apr 20 06:02 pool-vol-snapshot2

Comment 9 errata-xmlrpc 2011-06-09 19:07:42 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0596.html