From patchwork Mon Jan 7 07:28:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 209875 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 C937A2C0085 for ; Mon, 7 Jan 2013 19:02:41 +1100 (EST) Received: from localhost ([::1]:36377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7Au-0005dA-AN for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 02:31:12 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7AV-00051Y-Lj for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ts7AU-0005bd-81 for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:47 -0500 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:51937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7AT-0005aS-1R for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:45 -0500 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Jan 2013 17:23:25 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 Jan 2013 17:23:23 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 709542BB004A for ; Mon, 7 Jan 2013 18:30:41 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r077J55p3801536 for ; Mon, 7 Jan 2013 18:19:05 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r077UdJ7023877 for ; Mon, 7 Jan 2013 18:30:41 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.237]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r077Rp6a018491; Mon, 7 Jan 2013 18:30:16 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 7 Jan 2013 15:28:04 +0800 Message-Id: <1357543689-11415-7-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1357543689-11415-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1357543689-11415-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13010707-9264-0000-0000-000002F36649 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.146 Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, Wenchao Xia , lcapitulino@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com Subject: [Qemu-devel] [PATCH V2 05/10] snapshot: design of internal common API to take snapshots 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 added API to take snapshots in unified style for both internal or external type. The core structure is based on transaction, for that there is a qmp interface need to support , qmp_transaction, so all operations are packed as requests. In this way a sperate internal layer for snapshot is splitted out from qmp layer, and now qmp can just translate the user request and fill in internal API. Internal API use params defined inside qemu, so other component inside qemu can use it without considering the qmp's parameter format. v2: Renamed BlkTransaction* to BlkTrans* to make name shorter. Use present tense in comments. Deleted async snapshot related member. Use qemu_timeval in SNTime. Signed-off-by: Wenchao Xia --- include/sysemu/blockdev.h | 119 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 119 insertions(+), 0 deletions(-) diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index 1fe5332..4d61485 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -66,4 +66,123 @@ void qmp_change_blockdev(const char *device, const char *filename, bool has_format, const char *format, Error **errp); void do_commit(Monitor *mon, const QDict *qdict); int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); + + +/* snapshot transaction API. + * Split out a layer around core struct BlkTransStates, so other + * component in qemu can fill the request and simply use the API to submit, + * QMP may just use part of the API's function, no need to expose all internal + * function to user. + */ + +/* sync snapshot */ + +typedef enum BlkTransOperationSync { + BLK_SN_SYNC_CREATE = 0, + BLK_SN_SYNC_DELETE, +} BlkTransOperationSync; + +/* internal snapshot */ + +typedef struct SNTime { + qemu_timeval tv; + uint64_t vm_clock_nsec; /* VM clock relative to boot */ +} SNTime; + +typedef enum BlkSnapshotIntStep { + BLK_SNAPSHOT_INT_START = 0, + BLK_SNAPSHOT_INT_CREATED, + BLK_SNAPSHOT_INT_CANCELED, +} BlkSnapshotIntStep; + +typedef struct BlkSnapshotInternal { + /* caller input */ + const char *sn_name; /* must be set in create/delete. */ + BlockDriverState *bs; /* must be set in create/delete */ + SNTime time; /* must be set in create. */ + uint64_t vm_state_size; /* optional, default is 0, only valid in create. */ + /* following are used internal */ + QEMUSnapshotInfo sn; + QEMUSnapshotInfo old_sn; + bool old_sn_exist; + BlkSnapshotIntStep step; +} BlkSnapshotInternal; + +/* external snapshot */ + +typedef enum BlkSnapshotExtStep { + BLK_SNAPSHOT_EXT_START = 0, + BLK_SNAPSHOT_EXT_CREATED, + BLK_SNAPSHOT_EXT_INVALIDATED, + BLK_SNAPSHOT_EXT_CANCELED, +} BlkSnapshotExtStep; + +typedef struct BlkSnapshotExternal { + /* caller input */ + const char *new_image_file; /* must be set in create/delete. */ + BlockDriverState *old_bs; /* must be set in create/delete. */ + const char *format; /* must be set in create. */ + /* following are used internal */ + BlockDriverState *new_bs; + BlockDriver *format_drv; + BlkSnapshotExtStep step; +} BlkSnapshotExternal; + +typedef enum BlkSnapshotType { + BLK_SNAPSHOT_INTERNAL = 0, + BLK_SNAPSHOT_EXTERNAL, + BLK_SNAPSHOT_NOSUPPORT, +} BlkSnapshotType; + +/* for simple sync type params are all put here ignoring the difference of + different operation type as create/delete. */ +typedef struct BlkTransStatesSync { + /* caller input */ + BlkSnapshotType type; + union { + BlkSnapshotInternal internal; + BlkSnapshotExternal external; + }; + bool use_existing; + BlkTransOperationSync op; +} BlkTransStatesSync; + +/* Core structure for group snapshots, fill in it and then call the API. */ +typedef struct BlkTransStates BlkTransStates; + +struct BlkTransStates { + /* caller input */ + BlkTransStatesSync st_sync; + /* following are used internal */ + Error *err; + int (*blk_trans_do)(BlkTransStates *states, Error **errp); + int (*blk_trans_invalid)(BlkTransStates *states, Error **errp); + int (*blk_trans_cancel)(BlkTransStates *states, Error **errp); + QSIMPLEQ_ENTRY(BlkTransStates) entry; +}; + +typedef QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransStates) \ + BlkTransStatesList; + +/* API */ +BlkTransStates *blk_trans_st_new(void); +void blk_trans_st_delete(BlkTransStates **p_st); +BlkTransStatesList *blk_trans_st_list_new(void); +void blk_trans_st_list_delete(BlkTransStatesList **p_list); + +/* add a request to list, request would be checked to see if it is valid, + return -1 when met error and states would not be queued. */ +int add_transaction(BlkTransStatesList *list, + BlkTransStates *states, + Error **errp); + +/* 'Atomic' submit the request. In snapshot creation case, if any + * fail then we do not pivot any of the devices in the group, and abandon the + * snapshots + */ +int submit_transaction(BlkTransStatesList *list, Error **errp); + +/* helper */ +SNTime get_sn_time(void); +void generate_sn_name_from_time(SNTime *time, char *time_str, int size); #endif