qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v9 04/14] blockjob: Introduce block_job_complete_sync()
Date: Sat,  5 Jul 2014 19:47:18 +0200	[thread overview]
Message-ID: <1404582448-23840-5-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1404582448-23840-1-git-send-email-mreitz@redhat.com>

Implement block_job_complete_sync() by doing the exact same thing as
block_job_cancel_sync() does, only with calling block_job_complete()
instead of block_job_cancel().

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
 blockjob.c               | 39 ++++++++++++++++++++++++++++++++-------
 include/block/blockjob.h | 15 +++++++++++++++
 2 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/blockjob.c b/blockjob.c
index 67a64ea..2c98689 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -152,7 +152,7 @@ void block_job_iostatus_reset(BlockJob *job)
     }
 }
 
-struct BlockCancelData {
+struct BlockFinishData {
     BlockJob *job;
     BlockDriverCompletionFunc *cb;
     void *opaque;
@@ -160,19 +160,22 @@ struct BlockCancelData {
     int ret;
 };
 
-static void block_job_cancel_cb(void *opaque, int ret)
+static void block_job_finish_cb(void *opaque, int ret)
 {
-    struct BlockCancelData *data = opaque;
+    struct BlockFinishData *data = opaque;
 
     data->cancelled = block_job_is_cancelled(data->job);
     data->ret = ret;
     data->cb(data->opaque, ret);
 }
 
-int block_job_cancel_sync(BlockJob *job)
+static int block_job_finish_sync(BlockJob *job,
+                                 void (*finish)(BlockJob *, Error **errp),
+                                 Error **errp)
 {
-    struct BlockCancelData data;
+    struct BlockFinishData data;
     BlockDriverState *bs = job->bs;
+    Error *local_err = NULL;
 
     assert(bs->job == job);
 
@@ -183,15 +186,37 @@ int block_job_cancel_sync(BlockJob *job)
     data.cb = job->cb;
     data.opaque = job->opaque;
     data.ret = -EINPROGRESS;
-    job->cb = block_job_cancel_cb;
+    job->cb = block_job_finish_cb;
     job->opaque = &data;
-    block_job_cancel(job);
+    finish(job, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return -EBUSY;
+    }
     while (data.ret == -EINPROGRESS) {
         qemu_aio_wait();
     }
     return (data.cancelled && data.ret == 0) ? -ECANCELED : data.ret;
 }
 
+/* A wrapper around block_job_cancel() taking an Error ** parameter so it may be
+ * used with block_job_finish_sync() without the need for (rather nasty)
+ * function pointer casts there. */
+static void block_job_cancel_err(BlockJob *job, Error **errp)
+{
+    block_job_cancel(job);
+}
+
+int block_job_cancel_sync(BlockJob *job)
+{
+    return block_job_finish_sync(job, &block_job_cancel_err, NULL);
+}
+
+int block_job_complete_sync(BlockJob *job, Error **errp)
+{
+    return block_job_finish_sync(job, &block_job_complete, errp);
+}
+
 void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns)
 {
     assert(job->busy);
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index f3cf63f..88f4be2 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -273,6 +273,21 @@ bool block_job_is_paused(BlockJob *job);
 int block_job_cancel_sync(BlockJob *job);
 
 /**
+ * block_job_complete_sync:
+ * @job: The job to be completed.
+ * @errp: Error object which may be set by block_job_complete(); this is not
+ *        necessarily set on every error, the job return value has to be
+ *        checked as well.
+ *
+ * Synchronously complete the job.  The completion callback is called before the
+ * function returns, unless it is NULL (which is permissible when using this
+ * function).
+ *
+ * Returns the return value from the job.
+ */
+int block_job_complete_sync(BlockJob *job, Error **errp);
+
+/**
  * block_job_iostatus_reset:
  * @job: The job whose I/O status should be reset.
  *
-- 
2.0.1

  parent reply	other threads:[~2014-07-05 17:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-05 17:47 [Qemu-devel] [PATCH v9 00/14] qemu-img: Implement commit like QMP Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 01/14] qcow2: Allow "full" discard Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 02/14] qcow2: Implement bdrv_make_empty() Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 03/14] qcow2: Optimize bdrv_make_empty() Max Reitz
2014-07-09 21:22   ` Paolo Bonzini
2014-07-09 21:38     ` Max Reitz
2014-07-05 17:47 ` Max Reitz [this message]
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 05/14] blockjob: Add "ready" field Max Reitz
2014-07-07 18:53   ` Eric Blake
2014-07-09 20:21     ` Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 06/14] block/mirror: Improve progress report Max Reitz
2014-07-07 19:13   ` Eric Blake
2014-07-09 21:24     ` Paolo Bonzini
2014-07-09 21:36       ` Eric Blake
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 07/14] qemu-img: Implement commit like QMP Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 08/14] qemu-img: Empty image after commit Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 09/14] qemu-img: Enable progress output for commit Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 10/14] qemu-img: Specify backing file " Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 11/14] iotests: Add _filter_qemu_img_map Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 12/14] iotests: Add test for backing-chain commits Max Reitz
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 13/14] iotests: Add test for qcow2's bdrv_make_empty Max Reitz
2014-07-07 19:15   ` Eric Blake
2014-07-05 17:47 ` [Qemu-devel] [PATCH v9 14/14] iotests: Omit length/offset test in 040 and 041 Max Reitz

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=1404582448-23840-5-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).