Bug 1299877 - virsh create-snapshot ignores <disks> parameter and snapshots all disks
Summary: virsh create-snapshot ignores <disks> parameter and snapshots all disks
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libvirt
Version: unspecified
Hardware: Unspecified
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Libvirt Maintainers
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-01-19 13:09 UTC by Pieter Hollants
Modified: 2016-01-19 13:29 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-01-19 13:29:29 UTC


Attachments (Terms of Use)

Description Pieter Hollants 2016-01-19 13:09:09 UTC
Description of problem:
-----------------------
According to the manpage it should be possible to restrict the disks being snapshoted:

  "Normally, the only properties settable for a domain snapshot are the <name>
  and <description> elements, as well as <disks> if --disk-only is given; the
  rest of the fields are ignored, and automatically filled in by libvirt."

However virsh seems to ignore the <disks> element and always snapshot all disks.


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


How reproducible:
-----------------
See below


Steps to Reproduce:
-------------------
1. Create a temporary directory:
   mkdir /tmp/test

2. Create a storage pool:
   virsh -c qemu:///session pool-create-as testpool dir --target /tmp/test

3. Create two qcow2 disk images:
   virsh -c qemu:///session vol-create-as --format qcow2 testpool Test1 1G
   virsh -c qemu:///session vol-create-as --format qcow2 testpool Test2 1G

4. Create a domain using these images:
   virsh -c qemu:///session define /dev/stdin <<EOF
<domain type='kvm'>
  <name>Test</name>
  <uuid>f44e2d21-32be-4129-936f-440e75c691a5</uuid>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.4'>hvm</type>
  </os>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/tmp/test/Test1'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/tmp/test/Test2'/>
      <target dev='hdb' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
  </devices>
</domain>
EOF

5. Inspect the contents of the storage pool BEFORE taking the snapshot:
   ls -la /tmp/test

6. Create a snapshot:
   virsh -c qemu:///session snapshot-create Test --disk-only /dev/stdin <<EOF
<domainsnapshot>
  <name>Snapshot1</name>
  <disks>
    <disk name="/tmp/test/Test1" snapshot="external">
      <source file="/tmp/test/Test1_Snapshot" />
    </disk>
  </disks>
</domainsnapshot>
EOF

7. Inspect the contents of the storage pool AFTER taking the snapshot:
   ls -la /tmp/test


Actual results:
---------------
Before taking the snapshot:

drwxr-xr-x  2 pief users   4096 19. Jan 13:49 .
drwxrwxrwt 72 root root   28672 19. Jan 13:49 ..
-rw-------  1 pief users 197120 19. Jan 13:49 Test1
-rw-------  1 pief users 197120 19. Jan 13:49 Test2

After taking the snapshot:

drwxr-xr-x  2 pief users   4096 19. Jan 13:49 .
drwxrwxrwt 72 root root   28672 19. Jan 13:49 ..
-rw-------  1 pief users 197120 19. Jan 13:49 Test1
-rw-r--r--  1 pief users 197120 19. Jan 13:49 Test1_Snapshot
-rw-------  1 pief users 197120 19. Jan 13:49 Test2
-rw-r--r--  1 pief users 197120 19. Jan 13:49 Test2.Snapshot1


Expected results:
-----------------
There shouldn't have been a file "Test2.Snapshot1" because the XML specified that only Test1 should be snapshotted.


Additional info:
----------------
Seeing that it's named "Test2.Snapshot1" and not "Test2_Snapshot", it appears libvirt is not RESTRICTING snapshoting to Test1 but merely CHANGING the snapshot parameters for Test1 while maintaining the default behavior for Test2.
(The default name for a snapshot is constructed by libvirt by appending the snapshot to the domain name, separated by a colon ".")

Comment 1 Pieter Hollants 2016-01-19 13:29:29 UTC
On second thought, it appears that if such restrictions of snapshots to single disks is desired, ALL disks must be listed nevertheless and the disks that are NOT to be snapshotted must have a snapshot property of "no":

  <disk name="/tmp/test/Test2" snapshot="no">
  </disk>

This wasn't really clear to me out of the documentation.


Note You need to log in before you can comment on or make changes to this bug.