qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com,
	stefanha@gmail.com, Wenchao Xia <xiawenc@linux.vnet.ibm.com>,
	lcapitulino@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com
Subject: [Qemu-devel] [PATCH V2 08/10] snapshot: qmp add internal snapshot transaction interface
Date: Mon,  7 Jan 2013 15:28:07 +0800	[thread overview]
Message-ID: <1357543689-11415-10-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1357543689-11415-1-git-send-email-xiawenc@linux.vnet.ibm.com>

  Now qmp_transaction support creating internal snapshot.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 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
-- 
1.7.1

  parent reply	other threads:[~2013-01-07  7:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-07  7:27 [Qemu-devel] [PATCH V2 00/10] snapshot: take block snapshots in unified way Wenchao Xia
2013-01-07  7:27 ` [Qemu-devel] [PATCH V2 01/10] block: export function bdrv_find_snapshot() Wenchao Xia
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 02/10] block: add function deappend() Wenchao Xia
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 03/10] error: add function error_set_check() Wenchao Xia
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 04/10] oslib-win32: add lock for time functions Wenchao Xia
2013-01-07 17:12   ` Stefan Weil
2013-01-08  2:27     ` Wenchao Xia
2013-01-07  7:28 ` Wenchao Xia
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 05/10] snapshot: design of internal common API to take snapshots Wenchao Xia
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 06/10] snapshot: implemention " Wenchao Xia
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 07/10] snapshot: qmp use new internal API for external snapshot transaction Wenchao Xia
2013-01-09 12:44   ` Stefan Hajnoczi
2013-01-10  3:21     ` Wenchao Xia
2013-01-10 12:41       ` Stefan Hajnoczi
2013-01-11  6:22         ` Wenchao Xia
2013-01-11  9:12           ` Stefan Hajnoczi
2013-01-14  2:56             ` Wenchao Xia
2013-01-14 10:06               ` Stefan Hajnoczi
2013-01-15  7:03                 ` Wenchao Xia
2013-03-12  8:30                   ` Wenchao Xia
2013-03-12 15:43                     ` Stefan Hajnoczi
2013-03-13  1:36                       ` Wenchao Xia
2013-03-13  8:42                         ` Stefan Hajnoczi
2013-03-13 10:18                     ` Kevin Wolf
2013-03-14  5:08                       ` Wenchao Xia
2013-03-14  8:22                         ` Kevin Wolf
2013-03-18 10:00                           ` Wenchao Xia
2013-01-07  7:28 ` Wenchao Xia [this message]
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 09/10] snapshot: qmp add blockdev-snapshot-internal-sync interface Wenchao Xia
2013-01-07  7:28 ` [Qemu-devel] [PATCH V2 10/10] snapshot: hmp add internal snapshot support for block device Wenchao Xia
2013-01-09 22:34 ` [Qemu-devel] [PATCH V2 00/10] snapshot: take block snapshots in unified way Eric Blake
2013-01-10  6:01   ` Wenchao Xia
2013-01-11 13:56     ` Luiz Capitulino
2013-01-14  2:09       ` Wenchao Xia
2013-01-14 10:08         ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1357543689-11415-10-git-send-email-xiawenc@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=dietmar@proxmox.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).