From patchwork Sat Dec 8 08:24:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 204429 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 51B792C00D0 for ; Fri, 7 Dec 2012 19:52:31 +1100 (EST) Received: from localhost ([::1]:57555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgtfZ-0003MG-BG for incoming@patchwork.ozlabs.org; Fri, 07 Dec 2012 03:52:29 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tgtez-000253-9d for qemu-devel@nongnu.org; Fri, 07 Dec 2012 03:51:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tgteq-0001WZ-5g for qemu-devel@nongnu.org; Fri, 07 Dec 2012 03:51:53 -0500 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:57100) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tgtep-0001WO-GE for qemu-devel@nongnu.org; Fri, 07 Dec 2012 03:51:44 -0500 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Dec 2012 14:21:26 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 7 Dec 2012 14:21:25 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id DB56F125804A for ; Fri, 7 Dec 2012 14:21:24 +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 qB78pbw638469678 for ; Fri, 7 Dec 2012 14:21:37 +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 qB78pbkK016414 for ; Fri, 7 Dec 2012 08:51:38 GMT Received: from RedHat62GAWSWenchao (wenchaox.cn.ibm.com [9.115.127.243]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qB78nevA007845; Fri, 7 Dec 2012 08:51:34 GMT From: Wenchao Xia To: qemu-devel@nongnu.org Date: Sat, 8 Dec 2012 16:24:18 +0800 Message-Id: <1354955059-14391-2-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1354955059-14391-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1354955059-14391-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12120708-8878-0000-0000-000005139BCE X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.7 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, Wenchao Xia , blauwirbel@gmail.com, pbonzini@redhat.com, dietmar@proxmox.com Subject: [Qemu-devel] [RFC PATCH 1/2] live backup vm, export functions 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 This patch moved bdrv_snapshot_find() from savevm.c to block.c, also exports some function in savevm.c. Signed-off-by: Wenchao Xia --- block.c | 21 +++++++++++++++++++++ block.h | 2 ++ savevm.c | 37 +++++++++++-------------------------- sysemu.h | 2 ++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/block.c b/block.c index c05875f..155b562 100644 --- a/block.c +++ b/block.c @@ -3322,6 +3322,27 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn) return buf; } +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)) { + *sn_info = *sn; + ret = 0; + break; + } + } + g_free(sn_tab); + return ret; +} /**************************************************************/ /* async I/Os */ diff --git a/block.h b/block.h index 722c620..0838736 100644 --- a/block.h +++ b/block.h @@ -330,6 +330,8 @@ int bdrv_snapshot_list(BlockDriverState *bs, 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); 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 5d04d59..e1bad85 100644 --- a/savevm.c +++ b/savevm.c @@ -698,7 +698,7 @@ int qemu_get_byte(QEMUFile *f) return result; } -static int64_t qemu_ftell(QEMUFile *f) +int64_t qemu_ftell(QEMUFile *f) { return f->buf_offset - f->buf_size + f->buf_index; } @@ -2061,32 +2061,10 @@ out: return ret; } -static 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)) { - *sn_info = *sn; - ret = 0; - break; - } - } - g_free(sn_tab); - return ret; -} - /* * Deletes snapshots of a given name in all opened images. */ -static int del_existing_snapshots(Monitor *mon, const char *name) +int del_existing_snapshots(Monitor *mon, Error **errp, const char *name) { BlockDriverState *bs; QEMUSnapshotInfo sn1, *snapshot = &sn1; @@ -2099,9 +2077,16 @@ static int del_existing_snapshots(Monitor *mon, const char *name) { ret = bdrv_snapshot_delete(bs, name); if (ret < 0) { - monitor_printf(mon, + if (mon != NULL) { + monitor_printf(mon, "Error while deleting snapshot on '%s'\n", bdrv_get_device_name(bs)); + } + if (errp != NULL) { + error_setg(errp, + "Error while deleting snapshot on '%s'\n", + bdrv_get_device_name(bs)); + } return -1; } } @@ -2186,7 +2171,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) } /* Delete old snapshots of the same name */ - if (name && del_existing_snapshots(mon, name) < 0) { + if (name && del_existing_snapshots(mon, NULL, name) < 0) { goto the_end; } diff --git a/sysemu.h b/sysemu.h index f5ac664..f44f9ee 100644 --- a/sysemu.h +++ b/sysemu.h @@ -69,6 +69,8 @@ void do_savevm(Monitor *mon, const QDict *qdict); int load_vmstate(const char *name); void do_delvm(Monitor *mon, const QDict *qdict); void do_info_snapshots(Monitor *mon); +int del_existing_snapshots(Monitor *mon, Error **errp, const char *name); +int64_t qemu_ftell(QEMUFile *f); void qemu_announce_self(void);