Skip to contentSkip to conversation

qmp: add 'drive' to enum NewImageMode

PATCH In review Fam Zheng 2 participants 2 messages Jun 17, 2013 – Jun 18, 2013 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 qmp: add 'drive' to enum NewImageMode

Introduce a "drive" option to new image mode. With this mode, QMP command should (this patch only modified drive-backup to support it, and report invalid parameter error for drive-mirror) skip creating the image file or trying to open it, it should just reuse the existing BDS by looking for the named drive with bdrv_find(). It will be useful to utilize "none" sync mode of drive-backup for point-in-time snapshot.

The example with drive-backup is:

    -> { "execute": "drive-backup", "arguments": { "device": "ide0-hd0",
                                                   "mode": "drive",
                                                   "target": "drive_id_here" } }
    <- { "return": {} }

Target bs is not released when block job completes in this case since it's still used as a device drive or exported by nbd server.

---
 block/backup.c            |  9 ++++++--
 blockdev.c                | 57 ++++++++++++++++++++++++++++++++---------------
 include/block/block_int.h |  3 ++-
 qapi-schema.json          |  4 +++-
 4 files changed, 51 insertions(+), 22 deletions(-)
block/backup.c +7 -2
index 6515e04..5ef4724 100644
@@ -45,6 +45,7 @@ typedef struct CowRequest {
 typedef struct BackupBlockJob {
     BlockJob common;
     BlockDriverState *target;
+    bool release_target;
     RateLimit limit;
     CoRwlock flush_rwlock;
     uint64_t sectors_read;
@@ -255,14 +256,17 @@ static void coroutine_fn backup_run(void *opaque)
 
     hbitmap_free(job->bitmap);
 
-    bdrv_delete(job->target);
+    if (job->release_target) {
+        bdrv_close(job->target);
+        bdrv_delete(job->target);
+    }
 
     DPRINTF("backup_run complete %d\n", ret);
     block_job_completed(&job->common, ret);
 }
 
 void backup_start(BlockDriverState *bs, BlockDriverState *target,
-                  int64_t speed,
+                  int64_t speed, bool release_target,
                   BlockDriverCompletionFunc *cb, void *opaque,
                   Error **errp)
 {
@@ -279,6 +283,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
     }
 
     job->target = target;
+    job->release_target = release_target;
     job->common.len = bdrv_getlength(bs);
     job->common.co = qemu_coroutine_create(backup_run);
     qemu_coroutine_enter(job->common.co, job);
blockdev.c +39 -18

79 lines not on this page · raw message

include/block/block_int.h +2 -1
index f7a7892..e1fde9e 100644
@@ -403,6 +403,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
  * @bs: Block device to operate on.
  * @target: Block device to write to.
  * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
+ * @release_target: If block job should release target bs before completion
  * @cb: Completion function for the job.
  * @opaque: Opaque pointer value passed to @cb.
  *
@@ -410,7 +411,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
  * until the job is cancelled or manually completed.
  */
 void backup_start(BlockDriverState *bs, BlockDriverState *target,
-                  int64_t speed,
+                  int64_t speed, bool release_target,
                   BlockDriverCompletionFunc *cb, void *opaque,
                   Error **errp);
 
qapi-schema.json +3 -1
index 134a92d..9391e39 100644
@@ -1593,10 +1593,12 @@
 # @absolute-paths: QEMU should create a new image with absolute paths
 # for the backing file.
 #
+# @drive: QEMU should look for an existing drive
+#
 # Since: 1.1
 ##
 { 'enum': 'NewImageMode'
-  'data': [ 'existing', 'absolute-paths' ] }
+  'data': [ 'existing', 'absolute-paths', 'drive' ] }
 
 ##
 # @BlockdevSnapshot
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 18 lines · Fam Zheng

Introduce a "drive" option to new image mode. With this mode, QMP command should (this patch only modified drive-backup to support it, and report invalid parameter error for drive-mirror) skip creating the image file or trying to open it, it should just reuse the existing BDS by looking for the named drive with bdrv_find(). It will be useful to utilize "none" sync mode of drive-backup for point-in-time snapshot.

The example with drive-backup is:

    -> { "execute": "drive-backup", "arguments": { "device": "ide0-hd0",
                                                   "mode": "drive",
                                                   "target": "drive_id_here" } }
    <- { "return": {} }

Target bs is not released when block job completes in this case since it's still used as a device drive or exported by nbd server.

Quoted 7 lines
---
 block/backup.c            |  9 ++++++--
 blockdev.c                | 57 ++++++++++++++++++++++++++++++++---------------
 include/block/block_int.h |  3 ++-
 qapi-schema.json          |  4 +++-
 4 files changed, 51 insertions(+), 22 deletions(-)

Fam and I chatted about this yesterday. The QMP API change here is that traditionally 'target' and 'mode' always referred to existing filenames. Now you can set 'mode': 'drive' and then 'target' becomes a QEMU block device name.

I think this API extension is reasonable but I think we haven't nailed down the lifecycle of the snapshot block drive yet...

Stefan