Received: from eggs.gnu.org ([2001:4830:134:3::10]:51790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wkauc-0002PU-Mb for qemu-devel@nongnu.org; Wed, 14 May 2014 11:16:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkauW-0005lk-Jh for qemu-devel@nongnu.org; Wed, 14 May 2014 11:16:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkauW-0005lT-DG for qemu-devel@nongnu.org; Wed, 14 May 2014 11:16:00 -0400 Date: Wed, 14 May 2014 17:15:55 +0200 From: Kevin Wolf Message-ID: <20140514151555.GO3610@noname.redhat.com> References: <1399926438-32292-1-git-send-email-ncmike@ncultra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1399926438-32292-1-git-send-email-ncmike@ncultra.org> Subject: Re: [Qemu-devel] [PATCH v2] qemu-img fails to delete last snapshot List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mike Day Cc: qemu-devel@nongnu.org, stefanha@redhat.com Am 12.05.2014 um 22:27 hat Mike Day geschrieben: > When deleting the last snapshot, copying the resulting snapshot table > currently fails, causing the delete operation to also fail. Fix the > failure by skipping the copy and just writing the snapshot header and > freeing the extra clusters. Do you have an easy reproducer? Because I can't see the bug. > There are two specific problems in the current code. First is a lack of > parenthesis in the calculation of the memmove size parameter: > > s->nb_snapshots - snapshot_index - 1 > > When s->nb_snapshots is 0, snapshot_index is 1. > > 0 - 1 - 1 = 0xfffffffe > > it should be: > > 0 - (1 - 1) = 0x00 Not really. With s->nb_snapshots == 0, there is no snapshot to delete to start with. Therefore find_snapshot_by_id_and_name() returns -1 and we return immediately. > The second problem is shifting the snapshot table to the left. After > removing the last snapshot there are no existing snapshots to be > shifted. All that needs to be done is to write the header and > unallocate the blocks. When removing the last snapshot, we have: nb_snapshots = 1 snapshot_index = 0 memmove(..., (1 - 0 - 1) * sizeof(sn)); So we're not moving anything, which is what you correctly said needs to happen. Kevin