From patchwork Mon Jan 7 07:28:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 209876 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 3F15B2C007E for ; Mon, 7 Jan 2013 19:07:27 +1100 (EST) Received: from localhost ([::1]:37648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7BJ-0006K3-RB for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 02:31:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7Aq-0005hZ-60 for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:31:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ts7An-0005el-Ny for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:31:08 -0500 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:60534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7Am-0005eV-LH for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:31:05 -0500 Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Jan 2013 17:29:37 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp08.au.ibm.com (202.81.31.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 Jan 2013 17:29:09 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id D656A3578023 for ; Mon, 7 Jan 2013 18:30:33 +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 r077IueJ27328738 for ; Mon, 7 Jan 2013 18:18:57 +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 r077UVkd023671 for ; Mon, 7 Jan 2013 18:30:32 +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 r077Rp6d018491; Mon, 7 Jan 2013 18:30:29 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 7 Jan 2013 15:28:07 +0800 Message-Id: <1357543689-11415-10-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-5140-0000-0000-0000029559C2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.141 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 08/10] snapshot: qmp add internal snapshot transaction interface 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 Now qmp_transaction support creating internal snapshot. Signed-off-by: Wenchao Xia --- blockdev.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 24 +++++++++++++++++------- 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/blockdev.c b/blockdev.c index 299039f..09eeb7f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1218,6 +1218,41 @@ static int fill_blk_trs_ext_create_sync(BlockdevSnapshot *create_sync, return 0; } +static int fill_blk_trs_int_create_sync(BlockdevSnapshotInternal *create_sync, + BlkTransStatesSync *st_sync, + SNTime *time, + const char *time_str, + Error **errp) +{ + BlockDriverState *bs; + const char *device = create_sync->device; + const char *name = NULL; + + if (create_sync->has_name) { + name = create_sync->name; + } + + /* find the target bs */ + bs = bdrv_find(device); + if (!bs) { + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return -1; + } + + st_sync->use_existing = false; + + /* internal case, if caller need create new one with default string */ + if (name == NULL) { + st_sync->internal.sn_name = time_str; + } else { + st_sync->internal.sn_name = name; + } + st_sync->internal.bs = bs; + st_sync->internal.time = *time; + + return 0; +} + static int fill_blk_trs(BlockdevAction *dev_info, BlkTransStates *states, SNTime *time, @@ -1234,6 +1269,17 @@ static int fill_blk_trs(BlockdevAction *dev_info, &states->st_sync, errp); break; + case BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC: + states->st_sync.type = BLK_SNAPSHOT_INTERNAL; + states->st_sync.op = BLK_SN_SYNC_CREATE; + BlockdevSnapshotInternal *create_sync; + create_sync = dev_info->blockdev_snapshot_internal_sync; + ret = fill_blk_trs_int_create_sync(create_sync, + &states->st_sync, + time, + time_str, + errp); + break; default: abort(); } diff --git a/qapi-schema.json b/qapi-schema.json index 5dfa052..ea3ef77 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1474,6 +1474,20 @@ 'data': [ 'existing', 'absolute-paths' ] } ## +# @NewSnapshotMode +# +# An enumeration that tells QEMU how to create internal snapshot. +# +# @existing: QEMU should look for an existing snapshot. +# +# @new: QEMU should create a new internal snapshot, if it exist, overwrite it. +# +# Since: 1.4 +## +{ 'enum': 'NewSnapshotMode' + 'data': [ 'existing', 'new' ] } + +## # @BlockdevSnapshot # # @device: the name of the device to generate the snapshot from. @@ -1490,6 +1504,20 @@ '*mode': 'NewImageMode' } } ## +# @BlockdevSnapshotInternal +# +# @device: the name of the device to generate the snapshot from. +# +# @name: #optional the name of the internal snapshot to create, default is to +# generate it automatically according to host time. If a snapshot with +# name exist, it will be overwritten. +# +# Since: 1.4 +## +{ 'type': 'BlockdevSnapshotInternal', + 'data': { 'device': 'str', '*name': 'str', } } + +## # @BlockdevAction # # A discriminated record of operations that can be performed with @@ -1498,6 +1526,7 @@ { 'union': 'BlockdevAction', 'data': { 'blockdev-snapshot-sync': 'BlockdevSnapshot', + 'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal', } } ## diff --git a/qmp-commands.hx b/qmp-commands.hx index 5c692d0..3c2f468 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -863,10 +863,13 @@ any of the operations, all snapshots for the group are abandoned, and the original disks pre-snapshot attempt are used. A list of dictionaries is accepted, that contains the actions to be performed. -For snapshots this is the device, the file to use for the new snapshot, -and the format. The default format, if not specified, is qcow2. +For external snapshots this is the device, the file to use for the new +snapshot, and the format. The default format, if not specified, is qcow2. +For internal snapshots this is the device, the snapshot name. If name is +not specified, it would be generated automatically according to host time. +If an internal snapshot with name exist, it will be over written. -Each new snapshot defaults to being created by QEMU (wiping any +Each new external snapshot defaults to being created by QEMU (wiping any contents if the file already exists), but it is also possible to reuse an externally-created file. In the latter case, you should ensure that the new image file has the same contents as the current one; QEMU cannot @@ -876,15 +879,20 @@ current image file as the backing file for the new image. Arguments: actions array: - - "type": the operation to perform. The only supported - value is "blockdev-snapshot-sync". (json-string) + - "type": the operation to perform. The supported values are + "blockdev-snapshot-sync" and "blockdev-snapshot-internal-sync". + (json-string) - "data": a dictionary. The contents depend on the value - of "type". When "type" is "blockdev-snapshot-sync": + of "type". + When "type" is "blockdev-snapshot-sync": - "device": device name to snapshot (json-string) - "snapshot-file": name of new image file (json-string) - "format": format of new image (json-string, optional) - "mode": whether and how QEMU should create the snapshot file (NewImageMode, optional, default "absolute-paths") + When "type" is "blockdev-snapshot-internal-sync": + - "device": device name to snapshot (json-string) + - "name": name of internal snapshot (json-string, optional) Example: @@ -896,7 +904,9 @@ Example: { 'type': 'blockdev-snapshot-sync', 'data' : { "device": "ide-hd1", "snapshot-file": "/some/place/my-image2", "mode": "existing", - "format": "qcow2" } } ] } } + "format": "qcow2" } }, + { 'type': 'blockdev-snapshot-internal-sync', 'data' : { "device": "ide-hd2", + "name": "snapshot0" } } ] } } <- { "return": {} } EQMP