From patchwork Tue Feb 26 10:40:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 223214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 66D682C031F for ; Tue, 26 Feb 2013 22:54:07 +1100 (EST) Received: from localhost ([::1]:42148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAJ6j-0006d8-Lc for incoming@patchwork.ozlabs.org; Tue, 26 Feb 2013 06:54:05 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAJ6a-0006Z8-EK for qemu-devel@nongnu.org; Tue, 26 Feb 2013 06:53:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAI0J-0003qZ-4R for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:43:29 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:36009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAI0I-0003pw-3U for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:43:22 -0500 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Feb 2013 20:35:48 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 26 Feb 2013 20:35:46 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 7B1482CE804A for ; Tue, 26 Feb 2013 21:43:17 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1QAUobs66846952 for ; Tue, 26 Feb 2013 21:30:50 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r1QAhG8f016303 for ; Tue, 26 Feb 2013 21:43:17 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.152]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r1QAeKOF012693; Tue, 26 Feb 2013 21:43:14 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Tue, 26 Feb 2013 18:40:24 +0800 Message-Id: <1361875228-15769-11-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1361875228-15769-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1361875228-15769-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13022610-0260-0000-0000-00000295B78A X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.140 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V7 10/14] block: distinguish id and name in bdrv_find_snapshot() 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 To make it clear about id and name in searching, the API was changed a bit to distinguish them. Caller can choose to search by id or name now. Searching will be done with higher priority of id. Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake --- block.c | 43 +++++++++++++++++++++++++++++++++++-------- include/block/block.h | 2 +- savevm.c | 10 +++++----- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index a97c7ec..dd2259a 100644 --- a/block.c +++ b/block.c @@ -3421,8 +3421,18 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs, return -ENOTSUP; } +/* + * Try find an internal snapshot with @id or @name, @id have higher priority + * in searching. + * @bs block device to search on, must not be NULL. + * @sn_info snapshot information to be filled in, must not be NULL. + * @id snapshot id to search with, can be NULL. + * @name snapshot name to search with, can be NULL. + * returns 0 and @sn_info is filled with related information if found, + * otherwise it returns negative value. + */ int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, - const char *name) + const char *id, const char *name) { QEMUSnapshotInfo *sn_tab, *sn; int nb_sns, i, ret; @@ -3430,17 +3440,34 @@ int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, ret = -ENOENT; nb_sns = bdrv_snapshot_list(bs, &sn_tab); if (nb_sns < 0) { - return ret; + return nb_sns; } - for (i = 0; i < nb_sns; i++) { - sn = &sn_tab[i]; - if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) { - *sn_info = *sn; - ret = 0; - break; + /* search by id */ + if (id) { + for (i = 0; i < nb_sns; i++) { + sn = &sn_tab[i]; + if (!strcmp(sn->id_str, id)) { + *sn_info = *sn; + ret = 0; + goto out; + } } } + + /* search by name */ + if (name) { + for (i = 0; i < nb_sns; i++) { + sn = &sn_tab[i]; + if (!strcmp(sn->name, name)) { + *sn_info = *sn; + ret = 0; + goto out; + } + } + } + + out: g_free(sn_tab); return ret; } diff --git a/include/block/block.h b/include/block/block.h index d2b8bd1..e436918 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -344,7 +344,7 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name); char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn); int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, - const char *name); + const char *id, const char *name); char *get_human_readable_size(char *buf, int buf_size, int64_t size); int path_is_absolute(const char *path); diff --git a/savevm.c b/savevm.c index f73ac32..e151147 100644 --- a/savevm.c +++ b/savevm.c @@ -2072,7 +2072,7 @@ static int del_existing_snapshots(Monitor *mon, const char *name) bs = NULL; while ((bs = bdrv_next(bs))) { if (bdrv_can_snapshot(bs) && - bdrv_snapshot_find(bs, snapshot, name) >= 0) + bdrv_snapshot_find(bs, snapshot, name, name) >= 0) { ret = bdrv_snapshot_delete(bs, name); if (ret < 0) { @@ -2132,7 +2132,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock); if (name) { - ret = bdrv_snapshot_find(bs, old_sn, name); + ret = bdrv_snapshot_find(bs, old_sn, name, name); if (ret >= 0) { pstrcpy(sn->name, sizeof(sn->name), old_sn->name); pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str); @@ -2223,7 +2223,7 @@ int load_vmstate(const char *name) } /* Don't even try to load empty VM states */ - ret = bdrv_snapshot_find(bs_vm_state, &sn, name); + ret = bdrv_snapshot_find(bs_vm_state, &sn, name, name); if (ret < 0) { return ret; } else if (sn.vm_state_size == 0) { @@ -2247,7 +2247,7 @@ int load_vmstate(const char *name) return -ENOTSUP; } - ret = bdrv_snapshot_find(bs, &sn, name); + ret = bdrv_snapshot_find(bs, &sn, name, name); if (ret < 0) { error_report("Device '%s' does not have the requested snapshot '%s'", bdrv_get_device_name(bs), name); @@ -2353,7 +2353,7 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict) while ((bs1 = bdrv_next(bs1))) { if (bdrv_can_snapshot(bs1) && bs1 != bs) { - ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str); + ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str, NULL); if (ret < 0) { available = 0; break;