[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 06/11] snapshot: distinguish id and name in snap
From: |
Fam Zheng |
Subject: |
Re: [Qemu-devel] [PATCH 06/11] snapshot: distinguish id and name in snapshot delete |
Date: |
Sat, 8 Jun 2013 15:54:32 +0800 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Sat, 06/08 14:58, Wenchao Xia wrote:
>
> -static int find_snapshot_by_id(BlockDriverState *bs, const char *id_str)
> +static int find_snapshot_by_id_and_name(BlockDriverState *bs,
> + const char *id,
> + const char *name)
> {
> BDRVQcowState *s = bs->opaque;
> int i;
>
> - for(i = 0; i < s->nb_snapshots; i++) {
> - if (!strcmp(s->snapshots[i].id_str, id_str))
> - return i;
> + if (id && name) {
> + for (i = 0; i < s->nb_snapshots; i++) {
> + if (!strcmp(s->snapshots[i].id_str, id) &&
> + !strcmp(s->snapshots[i].name, name)) {
> + return i;
> + }
> + }
> + } else if (id) {
> + for (i = 0; i < s->nb_snapshots; i++) {
> + if (!strcmp(s->snapshots[i].id_str, id)) {
> + return i;
> + }
> + }
> + } else if (name) {
> + for (i = 0; i < s->nb_snapshots; i++) {
> + if (!strcmp(s->snapshots[i].name, name)) {
> + return i;
> + }
> + }
> }
Can be simplified the same way with patch 4.
>
> -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)
> {
> 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);
> return -ENOENT;
> }
> sn = s->snapshots[snapshot_index];
> @@ -550,6 +570,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const
> char *snapshot_id)
> s->nb_snapshots--;
> ret = qcow2_write_snapshots(bs);
> if (ret < 0) {
> + error_setg(errp, "Failed to remove it from snapshot list");
Maybe put name and id in error message, as above?
- Re: [Qemu-devel] [PATCH 05/11] snapshot: add paired functions for internal snapshot id and name, (continued)
[Qemu-devel] [PATCH 04/11] snapshot: new function bdrv_snapshot_find_by_id_and_name(), Wenchao Xia, 2013/06/08
Re: [Qemu-devel] [PATCH 04/11] snapshot: new function bdrv_snapshot_find_by_id_and_name(), Stefan Hajnoczi, 2013/06/11
[Qemu-devel] [PATCH 06/11] snapshot: distinguish id and name in snapshot delete, Wenchao Xia, 2013/06/08
[Qemu-devel] [PATCH 07/11] qmp: add internal snapshot support in qmp_transaction, Wenchao Xia, 2013/06/08
[Qemu-devel] [PATCH 08/11] qmp: add interface blockdev-snapshot-internal-sync, Wenchao Xia, 2013/06/08
[Qemu-devel] [PATCH 09/11] qmp: add interface blockdev-snapshot-delete-internal-sync, Wenchao Xia, 2013/06/08
[Qemu-devel] [PATCH 10/11] hmp: add interface hmp_snapshot_internal_blkdev, Wenchao Xia, 2013/06/08