cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
958e1b
From 96f8c9bed66c9c910332d86368b7e0e94c190f62 Mon Sep 17 00:00:00 2001
2382db
From: Eric Blake <eblake@redhat.com>
2382db
Date: Wed, 20 Aug 2014 16:40:09 +0200
958e1b
Subject: [PATCH 06/11] blockjob: Add block_job_yield()
2382db
2382db
Message-id: <1408552814-23031-3-git-send-email-eblake@redhat.com>
2382db
Patchwork-id: 60644
2382db
O-Subject: [qemu-kvm-rhev 7.0.z PATCH 2/7] blockjob: Add block_job_yield()
958e1b
Bugzilla: 1130603
2382db
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
2382db
RH-Acked-by: Fam Zheng <famz@redhat.com>
2382db
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2382db
2382db
From: Fam Zheng <famz@redhat.com>
2382db
2382db
This will unset busy flag and put coroutine to sleep, can be used to
2382db
wait for QMP complete/cancel.
2382db
2382db
Signed-off-by: Fam Zheng <famz@redhat.com>
2382db
Reviewed-by: Eric Blake <eblake@redhat.com>
2382db
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2382db
(cherry picked from commit dc71ce45ded4e872e25c2de32d5e7a71842b0985)
2382db
Signed-off-by: Eric Blake <eblake@redhat.com>
2382db
2382db
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
2382db
---
2382db
 blockjob.c               |   14 ++++++++++++++
2382db
 include/block/blockjob.h |    8 ++++++++
2382db
 2 files changed, 22 insertions(+), 0 deletions(-)
2382db
2382db
diff --git a/blockjob.c b/blockjob.c
2382db
index a4430a0..1117ee7 100644
2382db
--- a/blockjob.c
2382db
+++ b/blockjob.c
2382db
@@ -206,6 +206,20 @@ void block_job_sleep_ns(BlockJob *job, QEMUClock *clock, int64_t ns)
2382db
     job->busy = true;
2382db
 }
2382db
 
2382db
+void block_job_yield(BlockJob *job)
2382db
+{
2382db
+    assert(job->busy);
2382db
+
2382db
+    /* Check cancellation *before* setting busy = false, too!  */
2382db
+    if (block_job_is_cancelled(job)) {
2382db
+        return;
2382db
+    }
2382db
+
2382db
+    job->busy = false;
2382db
+    qemu_coroutine_yield();
2382db
+    job->busy = true;
2382db
+}
2382db
+
2382db
 BlockJobInfo *block_job_query(BlockJob *job)
2382db
 {
2382db
     BlockJobInfo *info = g_new0(BlockJobInfo, 1);
2382db
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
2382db
index 5a7d859..11f7c7e 100644
2382db
--- a/include/block/blockjob.h
2382db
+++ b/include/block/blockjob.h
2382db
@@ -144,6 +144,14 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
2382db
 void block_job_sleep_ns(BlockJob *job, QEMUClock *clock, int64_t ns);
2382db
 
2382db
 /**
2382db
+ * block_job_yield:
2382db
+ * @job: The job that calls the function.
2382db
+ *
2382db
+ * Yield the block job coroutine.
2382db
+ */
2382db
+void block_job_yield(BlockJob *job);
2382db
+
2382db
+/**
2382db
  * block_job_completed:
2382db
  * @job: The job being completed.
2382db
  * @ret: The status code.
2382db
-- 
2382db
1.7.1
2382db