From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv3il-0000bS-5w for qemu-devel@nongnu.org; Tue, 15 Jan 2013 05:26:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tv3ih-0001oo-8m for qemu-devel@nongnu.org; Tue, 15 Jan 2013 05:26:19 -0500 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:53462) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv3ig-0001oE-KV for qemu-devel@nongnu.org; Tue, 15 Jan 2013 05:26:15 -0500 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Jan 2013 15:54:37 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 77DB7394004D for ; Tue, 15 Jan 2013 15:56:07 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0FAQ2tm1835310 for ; Tue, 15 Jan 2013 15:56:03 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0FAQ327026642 for ; Tue, 15 Jan 2013 21:26:03 +1100 Message-ID: <50F52E41.90700@linux.vnet.ibm.com> Date: Tue, 15 Jan 2013 18:24:01 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1358147387-8221-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1358147387-8221-8-git-send-email-xiawenc@linux.vnet.ibm.com> <50F4973F.4090608@redhat.com> In-Reply-To: <50F4973F.4090608@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH V3 07/11] block: export function bdrv_find_snapshot() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: aliguori@us.ibm.com, phrdina@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, pbonzini@redhat.com, armbru@redhat.com 于 2013-1-15 7:39, Eric Blake 写道: > On 01/14/2013 12:09 AM, Wenchao Xia wrote: >> This patch move it from savevm.c to block.c and export it. >> >> Signed-off-by: Wenchao Xia >> --- >> block.c | 23 +++++++++++++++++++++++ >> include/block/block.h | 2 ++ >> savevm.c | 22 ---------------------- >> 3 files changed, 25 insertions(+), 22 deletions(-) >> >> diff --git a/block.c b/block.c >> index 8192d8e..b7d2f03 100644 >> --- a/block.c >> +++ b/block.c >> @@ -3351,6 +3351,29 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs, >> return -ENOTSUP; >> } >> >> +int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, >> + const char *name) >> +{ >> + QEMUSnapshotInfo *sn_tab, *sn; >> + int nb_sns, i, ret; >> + >> + ret = -ENOENT; >> + nb_sns = bdrv_snapshot_list(bs, &sn_tab); >> + if (nb_sns < 0) { >> + return ret; >> + } >> + for (i = 0; i < nb_sns; i++) { >> + sn = &sn_tab[i]; >> + if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) { > > It is possible (albeit probably stupid) to create a qcow2 file where > snapshot names are merely numeric strings. In fact, just to see what > would happen, I once[1] created a file where: > > snapshot id '1' was named '2' > snapshot id '2' was named 'foo' > > This code comparison favors ids over names; so if I request to delvm 2, > I end up removing the second snapshot, not the first. This is okay, but > probably worth documenting, and probably worth making sure that all code > that looks up a snapshot by name or id goes through this function so > that we get the same behavior everywhere. My experiment was done > several months ago, but my recollection was that at the time, there was > an inconsistency where 'qemu-img snapshot' picked a different snapshot > for the request of '2' than the online 'delvm' monitor command of qemu; > making it unsafe to rely on either behavior in that version of qemu > source code. > > [1]https://bugzilla.redhat.com/show_bug.cgi?id=733143 > how about: /* if id is not NULL, try find it with id, if not exist, return NULL * if id is NULL and name is not NULL, try find it with name. */ if id and name is NULL, direct return fail. int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, const char *id, const char *name) -- Best Regards Wenchao Xia