[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 25/45] block: introduce BLOCK_JOB_READY event
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v2 25/45] block: introduce BLOCK_JOB_READY event |
Date: |
Wed, 26 Sep 2012 17:56:31 +0200 |
Even for jobs that need to be manually completed, management may want
to take care itself of the completion, not requiring the user to issue
a command to terminate the job. In this case we want to avoid that
they poll us continuously, waiting for completion to become available.
Thus, add a new event that signals the phase switch and the availability
of the block-job-complete command.
Signed-off-by: Paolo Bonzini <address@hidden>
---
QMP/qmp-events.txt | 20 ++++++++++++++++++++
blockdev.c | 14 --------------
blockjob.c | 21 +++++++++++++++++++++
blockjob.h | 16 ++++++++++++++++
monitor.c | 1 +
monitor.h | 1 +
qapi-schema.json | 3 ++-
7 file modificati, 61 inserzioni(+), 15 rimozioni(-)
diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index ae19db2..ceb36e3 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -116,6 +116,26 @@ Example:
"action": "stop" },
"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
+BLOCK_JOB_READY
+---------------
+
+Emitted when a block job is ready to complete.
+
+Data:
+
+- "device": device name (json-string)
+
+Example:
+
+{ "event": "BLOCK_JOB_READY",
+ "data": { "device": "ide0-hd1",
+ "operation": "write",
+ "action": "stop" },
+ "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
+
+Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR
+event.
+
DEVICE_TRAY_MOVED
-----------------
diff --git a/blockdev.c b/blockdev.c
index 24a839a..9069ca1 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1052,20 +1052,6 @@ void qmp_block_resize(const char *device, int64_t size,
Error **errp)
}
}
-static QObject *qobject_from_block_job(BlockJob *job)
-{
- return qobject_from_jsonf("{ 'type': %s,"
- "'device': %s,"
- "'len': %" PRId64 ","
- "'offset': %" PRId64 ","
- "'speed': %" PRId64 " }",
- job->job_type->job_type,
- bdrv_get_device_name(job->bs),
- job->len,
- job->offset,
- job->speed);
-}
-
static void block_job_cb(void *opaque, int ret)
{
BlockDriverState *bs = opaque;
diff --git a/blockjob.c b/blockjob.c
index cdaae99..8d2687c 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -224,6 +224,27 @@ static void block_job_iostatus_set_err(BlockJob *job, int
error)
}
+QObject *qobject_from_block_job(BlockJob *job)
+{
+ return qobject_from_jsonf("{ 'type': %s,"
+ "'device': %s,"
+ "'len': %" PRId64 ","
+ "'offset': %" PRId64 ","
+ "'speed': %" PRId64 " }",
+ job->job_type->job_type,
+ bdrv_get_device_name(job->bs),
+ job->len,
+ job->offset,
+ job->speed);
+}
+
+void block_job_ready(BlockJob *job)
+{
+ QObject *data = qobject_from_block_job(job);
+ monitor_protocol_event(QEVENT_BLOCK_JOB_READY, data);
+ qobject_decref(data);
+}
+
BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
BlockdevOnError on_err,
int is_read, int error)
diff --git a/blockjob.h b/blockjob.h
index 37e0805..be37cc1 100644
--- a/blockjob.h
+++ b/blockjob.h
@@ -211,6 +211,22 @@ void block_job_pause(BlockJob *job);
void block_job_resume(BlockJob *job);
/**
+ * qobject_from_block_job:
+ * @job: The job whose information is requested.
+ *
+ * Return a QDict corresponding to @job's query-block-jobs entry.
+ */
+QObject *qobject_from_block_job(BlockJob *job);
+
+/**
+ * block_job_ready:
+ * @job: The job which is now ready to complete.
+ *
+ * Send a BLOCK_JOB_READY event for the specified job.
+ */
+void block_job_ready(BlockJob *job);
+
+/**
* block_job_is_paused:
* @job: The job being queried.
*
diff --git a/monitor.c b/monitor.c
index d4bd5fe..c4ac395 100644
--- a/monitor.c
+++ b/monitor.c
@@ -451,6 +451,7 @@ static const char *monitor_event_names[] = {
[QEVENT_BLOCK_JOB_COMPLETED] = "BLOCK_JOB_COMPLETED",
[QEVENT_BLOCK_JOB_CANCELLED] = "BLOCK_JOB_CANCELLED",
[QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR",
+ [QEVENT_BLOCK_JOB_READY] = "BLOCK_JOB_READY",
[QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED",
[QEVENT_SUSPEND] = "SUSPEND",
[QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",
diff --git a/monitor.h b/monitor.h
index 43040af..351f58a 100644
--- a/monitor.h
+++ b/monitor.h
@@ -39,6 +39,7 @@ typedef enum MonitorEvent {
QEVENT_BLOCK_JOB_COMPLETED,
QEVENT_BLOCK_JOB_CANCELLED,
QEVENT_BLOCK_JOB_ERROR,
+ QEVENT_BLOCK_JOB_READY,
QEVENT_DEVICE_TRAY_MOVED,
QEVENT_SUSPEND,
QEVENT_SUSPEND_DISK,
diff --git a/qapi-schema.json b/qapi-schema.json
index 1d78cb3..b466b7a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1959,7 +1959,8 @@
#
# Manually trigger completion of an active background block operation. This
# is supported for drive mirroring, where it also switches the device to
-# write to the target path only.
+# write to the target path only. The ability to complete is signaled with
+# a BLOCK_JOB_READY event.
#
# This command completes an active background block operation synchronously.
# The ordering of this command's return with the BLOCK_JOB_COMPLETED event
--
1.7.12
- Re: [Qemu-devel] [PATCH v2 34/45] host-utils: add ffsl, (continued)
- [Qemu-devel] [PATCH v2 45/45] mirror: support arbitrarily-sized iterations, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 21/45] block: add bdrv_open_backing_file, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 28/45] mirror: implement completion, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 15/45] stream: add on-error argument, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 30/45] iostatus: forward block_job_iostatus_reset to block job, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 31/45] mirror: add support for on-source-error/on-target-error, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 29/45] qemu-iotests: add mirroring test case, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 25/45] block: introduce BLOCK_JOB_READY event,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v2 40/45] block: allow customizing the granularity of the dirty bitmap, Paolo Bonzini, 2012/09/26
- [Qemu-devel] [PATCH v2 33/45] qemu-iotests: add testcases for mirroring on-source-error/on-target-error, Paolo Bonzini, 2012/09/26
- Re: [Qemu-devel] [PATCH v2 00/45] Block job improvements for 1.3, Kevin Wolf, 2012/09/27