Received: from eggs.gnu.org ([2001:4830:134:3::10]:53401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmKpY-0006JT-TW for qemu-devel@nongnu.org; Tue, 11 Jun 2013 05:25:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UmKpX-0004Qt-PY for qemu-devel@nongnu.org; Tue, 11 Jun 2013 05:25:32 -0400 Received: from mail-ea0-x22d.google.com ([2a00:1450:4013:c01::22d]:60428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmKpX-0004Qh-KH for qemu-devel@nongnu.org; Tue, 11 Jun 2013 05:25:31 -0400 Received: by mail-ea0-f173.google.com with SMTP id g15so5916107eak.32 for ; Tue, 11 Jun 2013 02:25:30 -0700 (PDT) Date: Tue, 11 Jun 2013 11:25:28 +0200 From: Stefan Hajnoczi Message-ID: <20130611092528.GG18312@stefanha-thinkpad.redhat.com> References: <1370674687-13849-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1370674687-13849-7-git-send-email-xiawenc@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1370674687-13849-7-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH 06/11] snapshot: distinguish id and name in snapshot delete List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia 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 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 > { > - 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 {}. > - 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. > { > 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.