Re: [Qemu-block] [PATCH v2 03/13] blockjob: create block_job_relax

2018-02-07 Thread Max Reitz
On 2018-01-19 21:58, John Snow wrote:
> This will replace mirror_throttle, for reuse in other jobs.
> 
> Signed-off-by: John Snow 
> ---
>  block/mirror.c   | 15 ++-
>  blockjob.c   | 11 +++
>  include/block/blockjob_int.h |  9 +
>  3 files changed, 22 insertions(+), 13 deletions(-)

Reviewed-by: Max Reitz 



signature.asc
Description: OpenPGP digital signature


[Qemu-block] [PATCH v2 03/13] blockjob: create block_job_relax

2018-01-19 Thread John Snow
This will replace mirror_throttle, for reuse in other jobs.

Signed-off-by: John Snow 
---
 block/mirror.c   | 15 ++-
 blockjob.c   | 11 +++
 include/block/blockjob_int.h |  9 +
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index 1fb5fc0cb8..36c681c7a1 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -590,17 +590,6 @@ static void mirror_exit(BlockJob *job, void *opaque)
 bdrv_unref(src);
 }
 
-static void mirror_throttle(MirrorBlockJob *s)
-{
-int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
-
-if (now - s->common.last_enter_ns > SLICE_TIME) {
-block_job_sleep_ns(>common, 0);
-} else {
-block_job_pause_point(>common);
-}
-}
-
 static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
 {
 int64_t offset;
@@ -621,7 +610,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
 int bytes = MIN(s->bdev_length - offset,
 QEMU_ALIGN_DOWN(INT_MAX, s->granularity));
 
-mirror_throttle(s);
+block_job_relax(>common);
 
 if (block_job_is_cancelled(>common)) {
 s->initial_zeroing_ongoing = false;
@@ -649,7 +638,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s)
 int bytes = MIN(s->bdev_length - offset,
 QEMU_ALIGN_DOWN(INT_MAX, s->granularity));
 
-mirror_throttle(s);
+block_job_relax(>common);
 
 if (block_job_is_cancelled(>common)) {
 return 0;
diff --git a/blockjob.c b/blockjob.c
index 2a9ff66b95..6f2e709b51 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -906,6 +906,17 @@ void block_job_yield(BlockJob *job)
 block_job_pause_point(job);
 }
 
+void block_job_relax(BlockJob *job)
+{
+int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+
+if (now - job->last_enter_ns > SLICE_TIME) {
+block_job_sleep_ns(job, 0);
+} else {
+block_job_pause_point(job);
+}
+}
+
 void block_job_iostatus_reset(BlockJob *job)
 {
 if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
index 209fa1bb3e..553784d86f 100644
--- a/include/block/blockjob_int.h
+++ b/include/block/blockjob_int.h
@@ -157,6 +157,15 @@ void block_job_sleep_ns(BlockJob *job, int64_t ns);
  */
 void block_job_yield(BlockJob *job);
 
+/**
+ * block_job_relax:
+ * @job: The job that calls the function.
+ *
+ * Yield if it has been SLICE_TIME nanoseconds since the last yield.
+ * Otherwise, check if we need to pause, and yield if so.
+ */
+void block_job_relax(BlockJob *job);
+
 /**
  * block_job_pause_all:
  *
-- 
2.14.3