Bug 651341

Summary: Delete snapshot of vm from parent to children will report an error
Product: [Fedora] Fedora Reporter: weizhang <weizhan>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: berrange, clalance, crobinso, eblake, itamar, jforbes, llim, lueshizhe, veillard, virt-maint, yoyzhang
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-12-01 12:21:15 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description weizhang 2010-11-09 05:25:57 EST
Description of problem:
when I test snapshot, I create a parent snapshot and a chindren snapshot, when I first delete the parent snapshot and then delete the children snapshot, there will be an error: "Domain snapshot not found: no domain snapshot parent with matching name 'snapshot1'"


Version-Release number of selected component (if applicable):
libvirt-0.8.4-3.fc15.x86_64
kernel-2.6.35.6-45.fc14.x86_64
qemu-kvm-0.13.0-1.fc14.x86_64

How reproducible:
100%

Steps to Reproduce:
1.#cat snapshot1.xml
      <domainsnapshot>
         <name>snapshot1</name>
         <description>Snapshot of OS install and updates</description>
         <state>running</state>
         <creationTime>1290186373</creationTime>
         <domain>
            <uuid>6d49ba8d-15d7-4456-923f-f83d7253982c</uuid>
         </domain>
      </domainsnapshot>
  #cat snapshot2.xml
      <domainsnapshot>
         <name>snapshot2</name>
         <description>Snapshot of OS install and updates</description>
         <state>running</state>
         <creationTime>1290186373</creationTime>
         <domain>
            <uuid>6d49ba1d-15d7-4456-923f-f83d7253982c</uuid>
         </domain>
      </domainsnapshot>
2.#virsh start vm-qcow2
3.#virsh snapshot-create vm-qcow2 snapshot.xml
  #virsh snapshot-current vm-qcow2
  <domainsnapshot>
  <name>snapshot1</name>
  <description>Snapshot of OS install and updates</description>
  <state>running</state>
  <creationTime>1289294305</creationTime>
  <domain>
    <uuid>6d49ba8d-15d7-4456-923f-f83d7253982c</uuid>
  </domain>
</domainsnapshot>
4.# virsh snapshot-create vm-qcow2 snapshot2.xml
  # virsh snapshot-current vm-qcow2
<domainsnapshot>
  <name>snapshot2</name>
  <description>Snapshot of OS install and updates</description>
  <state>running</state>
  <parent>
    <name>snapshot1</name>
  </parent>
  <creationTime>1289294492</creationTime>
  <domain>
    <uuid>6d49ba8d-15d7-4456-923f-f83d7253982c</uuid>
  </domain>
</domainsnapshot>
5.# virsh snapshot-list vm-qcow2
 Name                 Creation Time             State
---------------------------------------------------
 snapshot1            2010-11-09 17:18:25 +0800 running
 snapshot2            2010-11-09 17:21:32 +0800 running
6.# virsh snapshot-delete qcow2 snapshot1
  
  # virsh snapshot-delete qcow2 snapshot2

Actual results:

error: Domain snapshot not found: no domain snapshot parent with matching name 'snapshot1'

Expected results:

delete successfully with no error

Additional info:
if I restart libvirtd before delete the snapshot2 which set the current snapshot of vm-qcow2 to none, then it can be deleted successfully


on /var/log/messages

Nov  9 18:28:51 dhcp-93-102 libvirtd: 18:28:51.146: error : qemuMonitorTextDeleteSnapshot:2559 : operation failed: Error -2 while deleting snapshot on 'drive-ide0-0-0'#015#012
Nov  9 18:28:51 dhcp-93-102 libvirtd: 18:28:51.148: error : qemuDomainSnapshotDiscard:12447 : Domain snapshot not found: no domain snapshot parent with matching name 'snapshot1'
Comment 1 Mr.King 2010-11-24 00:06:31 EST
HI, I make a patch for using libvirt-0.8.1. I have tried it. It is ok.
 
--- libvirt-0.8.1/src/qemu/qemu_driver.c      2010-11-24 10:14:11.000000000 +0800
+++ libvirt-0.8.1.new/src/qemu/qemu_driver.c  2010-11-24 11:02:59.000000000 +0800
@@ -12733,13 +12733,11 @@ static int qemuDomainSnapshotDiscard(str
             parentsnap = virDomainSnapshotFindByName(&vm->snapshots,
                                                      snap->def->parent);
             if (!parentsnap) {
-                qemuReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
-                                _("no domain snapshot parent with matching name '%s'"),
-                                snap->def->parent);
-                goto cleanup;
+                VIR_FREE(snap->def->parent);
+                snap->def->parent = NULL;
             }

-            /* Now we set the new current_snapshot for the domain */
+            /* Now we set the new current_snapshot for the domain , may be parentsnap is null*/
             vm->current_snapshot = parentsnap;
         }
         else
Comment 2 Fedora Admin XMLRPC Client 2011-09-22 13:50:24 EDT
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 3 Fedora Admin XMLRPC Client 2011-09-22 13:53:08 EDT
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 4 Fedora Admin XMLRPC Client 2011-09-22 13:58:40 EDT
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 5 Fedora Admin XMLRPC Client 2011-11-30 14:31:10 EST
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 6 Fedora Admin XMLRPC Client 2011-11-30 14:34:43 EST
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 7 Fedora Admin XMLRPC Client 2011-11-30 14:41:22 EST
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 8 Fedora Admin XMLRPC Client 2011-11-30 14:52:33 EST
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 9 Eric Blake 2011-12-01 12:21:15 EST
This should be fixed in 0.9.5, via this commit and a few others:

commit cb231b4bee882213c77d360d2d8ff96851542b64
Author: Eric Blake <eblake@redhat.com>
Date:   Fri Aug 12 07:05:50 2011 -0600

    snapshot: avoid crash when deleting qemu snapshots
    
    This one's nasty.  Ever since we fixed virHashForEach to prevent
    nested hash iterations for safety reasons (commit fba550f6),
    virDomainSnapshotDelete with VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN
    has been broken for qemu: it deletes children, while leaving
    grandchildren intact but pointing to a no-longer-present parent.
    But even before then, the code would often appear to succeed to
    clean up grandchildren, but risked memory corruption if you have
    a large and deep hierarchy of snapshots.
    
    For acting on just children, a single virHashForEach is sufficient.
    But for acting on an entire subtree, it requires iteration; and
    since we declared recursion as invalid, we have to switch to a
    while loop.  Doing this correctly requires quite a bit of overhaul,
    so I added a new helper function to isolate the algorithm from the
    actions, so that callers do not have to reinvent the iteration.