From patchwork Thu Jun 13 05:41:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 250979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3CB222C008F for ; Thu, 13 Jun 2013 15:41:52 +1000 (EST) Received: from localhost ([::1]:37179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un0I7-00075h-9m for incoming@patchwork.ozlabs.org; Thu, 13 Jun 2013 01:41:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un0Ht-00075b-I0 for qemu-devel@nongnu.org; Thu, 13 Jun 2013 01:41:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Un0Hs-0001e5-1q for qemu-devel@nongnu.org; Thu, 13 Jun 2013 01:41:33 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:53043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un0Hr-0001dS-CN for qemu-devel@nongnu.org; Thu, 13 Jun 2013 01:41:31 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 13 Jun 2013 11:06:44 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 13 Jun 2013 11:06:43 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 96A40394004E for ; Thu, 13 Jun 2013 11:11:28 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5D5fP1P26214426 for ; Thu, 13 Jun 2013 11:11:25 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5D5fQkd004982 for ; Thu, 13 Jun 2013 05:41:26 GMT Received: from [127.0.0.1] (wenchaox.cn.ibm.com [9.115.122.53]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r5D5fLwW004747; Thu, 13 Jun 2013 05:41:24 GMT Message-ID: <51B95B7F.3010601@linux.vnet.ibm.com> Date: Thu, 13 Jun 2013 13:41:19 +0800 From: Wenchao Xia User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: Stefan Hajnoczi References: <1370674687-13849-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1370674687-13849-7-git-send-email-xiawenc@linux.vnet.ibm.com> <20130611092528.GG18312@stefanha-thinkpad.redhat.com> In-Reply-To: <20130611092528.GG18312@stefanha-thinkpad.redhat.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13061305-8256-0000-0000-000007E66DBC X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.5 Cc: kwolf@redhat.com, phrdina@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com Subject: Re: [Qemu-devel] [PATCH 06/11] snapshot: distinguish id and name in snapshot delete X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 于 2013-6-11 17:25, Stefan Hajnoczi 写道: > On Sat, Jun 08, 2013 at 02:58:02PM +0800, Wenchao Xia wrote: >> static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name) > > I suggest renaming the argument to make it less confusing: const char *name_or_id > will rename it. >> { >> - BDRVQcowState *s = bs->opaque; >> - int i, ret; >> + int ret; >> >> - ret = find_snapshot_by_id(bs, name); >> + ret = find_snapshot_by_id_and_name(bs, name, NULL); >> if (ret >= 0) >> return ret; > > Since you're touching the other lines in this function you could add {}. > OK. >> - for(i = 0; i < s->nb_snapshots; i++) { >> - if (!strcmp(s->snapshots[i].name, name)) >> - return i; >> - } >> - return -1; >> + return find_snapshot_by_id_and_name(bs, NULL, name); >> } >> >> /* if no id is provided, a new one is constructed */ >> @@ -333,7 +347,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) >> } >> >> /* Check that the ID is unique */ >> - if (find_snapshot_by_id(bs, sn_info->id_str) >= 0) { >> + if (find_snapshot_by_id_and_name(bs, sn_info->id_str, NULL) >= 0) { >> return -EEXIST; >> } >> >> @@ -530,15 +544,21 @@ fail: >> return ret; >> } >> >> -int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) >> +int qcow2_snapshot_delete(BlockDriverState *bs, >> + const char *snapshot_id, >> + const char *name, >> + Error **errp) > > This patch will fail to compile. You haven't changed the > .bdrv_snapshot_delete() prototype. > > Please make sure every patch compiles. > shouldn't following line in this patch changed the prototype? >> { >> BDRVQcowState *s = bs->opaque; >> QCowSnapshot sn; >> int snapshot_index, ret; >> >> /* Search the snapshot */ >> - snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id); >> + snapshot_index = find_snapshot_by_id_and_name(bs, snapshot_id, name); >> if (snapshot_index < 0) { >> + error_setg(errp, >> + "Can't find a snapshot with ID %s and name %s", >> + snapshot_id, name); > > Are both snapshot_id and name guaranteed to be non-NULL here? It is > dangerous to pass NULL strings to sprintf() functions. IIRC some libc > implementations will crash, others will print "(null)" like Linux. > OK, will check it. --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -157,7 +157,10 @@ struct BlockDriver { QEMUSnapshotInfo *sn_info); int (*bdrv_snapshot_goto)(BlockDriverState *bs, const char *snapshot_id); - int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id); + int (*bdrv_snapshot_delete)(BlockDriverState *bs, + const char *snapshot_id, + const char *name, + Error **errp); let me retry.