[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 23/30] coroutine: add co_aio_sleep_ns() to allow slee
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 23/30] coroutine: add co_aio_sleep_ns() to allow sleep in block drivers |
Date: |
Thu, 31 Oct 2013 16:48:37 +0100 |
From: MORITA Kazutaka <address@hidden>
This helper function behaves similarly to co_sleep_ns(), but the
sleeping coroutine will be resumed when using qemu_aio_wait().
Signed-off-by: MORITA Kazutaka <address@hidden>
Tested-by: Liu Yuan <address@hidden>
Reviewed-by: Liu Yuan <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/block/coroutine.h | 9 +++++++++
qemu-coroutine-sleep.c | 14 ++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/include/block/coroutine.h b/include/block/coroutine.h
index 4232569..4d5c0cf 100644
--- a/include/block/coroutine.h
+++ b/include/block/coroutine.h
@@ -216,6 +216,15 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);
void coroutine_fn co_sleep_ns(QEMUClockType type, int64_t ns);
/**
+ * Yield the coroutine for a given duration
+ *
+ * Behaves similarly to co_sleep_ns(), but the sleeping coroutine will be
+ * resumed when using qemu_aio_wait().
+ */
+void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
+ int64_t ns);
+
+/**
* Yield until a file descriptor becomes readable
*
* Note that this function clobbers the handlers for the file descriptor.
diff --git a/qemu-coroutine-sleep.c b/qemu-coroutine-sleep.c
index f6db978..ad78fba 100644
--- a/qemu-coroutine-sleep.c
+++ b/qemu-coroutine-sleep.c
@@ -13,6 +13,7 @@
#include "block/coroutine.h"
#include "qemu/timer.h"
+#include "block/aio.h"
typedef struct CoSleepCB {
QEMUTimer *ts;
@@ -37,3 +38,16 @@ void coroutine_fn co_sleep_ns(QEMUClockType type, int64_t ns)
timer_del(sleep_cb.ts);
timer_free(sleep_cb.ts);
}
+
+void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
+ int64_t ns)
+{
+ CoSleepCB sleep_cb = {
+ .co = qemu_coroutine_self(),
+ };
+ sleep_cb.ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &sleep_cb);
+ timer_mod(sleep_cb.ts, qemu_clock_get_ns(type) + ns);
+ qemu_coroutine_yield();
+ timer_del(sleep_cb.ts);
+ timer_free(sleep_cb.ts);
+}
--
1.8.1.4
- [Qemu-devel] [PULL 14/30] ahci: fix win7 hang on boot, (continued)
- [Qemu-devel] [PULL 14/30] ahci: fix win7 hang on boot, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 13/30] sheepdog: pass copy_policy in the request, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 15/30] block: Disable BDRV_O_COPY_ON_READ for the backing file, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 16/30] block: Avoid unecessary drv->bdrv_getlength() calls, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 17/30] qemu-iotests: Fix 051 reference output, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 18/30] qemu-iotests: drop duplicated "create_image", Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 19/30] qemu-iotests: Test case for backing file deletion, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 20/30] sheepdog: check return values of qemu_co_recv/send correctly, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 21/30] sheepdog: handle vdi objects in resend_aio_req, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 22/30] sheepdog: reload inode outside of resend_aioreq, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 23/30] coroutine: add co_aio_sleep_ns() to allow sleep in block drivers,
Kevin Wolf <=
- [Qemu-devel] [PULL 24/30] sheepdog: try to reconnect to sheepdog after network error, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 25/30] sheepdog: make add_aio_request and send_aioreq void functions, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 27/30] sheepdog: check simultaneous create in resend_aioreq, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 26/30] sheepdog: cancel aio requests if possible, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 28/30] qemu-iotests: prefill some data to test image, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 29/30] qapi: Add optional field 'compressed' to ImageInfo, Kevin Wolf, 2013/10/31
- [Qemu-devel] [PULL 30/30] vmdk: Implment bdrv_get_specific_info, Kevin Wolf, 2013/10/31
- Re: [Qemu-devel] [PULL v2 00/30] Block patches, Anthony Liguori, 2013/10/31