Blame SOURCES/kvm-blockjob-Move-RateLimit-to-BlockJob.patch

357786
From cc5d2ab40aeaca344047ae0b6655a69c67fd7ada Mon Sep 17 00:00:00 2001
357786
From: Kevin Wolf <kwolf@redhat.com>
357786
Date: Tue, 26 Jun 2018 09:47:53 +0200
357786
Subject: [PATCH 24/89] blockjob: Move RateLimit to BlockJob
357786
357786
RH-Author: Kevin Wolf <kwolf@redhat.com>
357786
Message-id: <20180626094856.6924-11-kwolf@redhat.com>
357786
Patchwork-id: 81088
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 10/73] blockjob: Move RateLimit to BlockJob
357786
Bugzilla: 1513543
357786
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
357786
RH-Acked-by: Max Reitz <mreitz@redhat.com>
357786
RH-Acked-by: Fam Zheng <famz@redhat.com>
357786
357786
Every block job has a RateLimit, and they all do the exact same thing
357786
with it, so it should be common infrastructure. Move the struct field
357786
for a start.
357786
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
Reviewed-by: Eric Blake <eblake@redhat.com>
357786
Reviewed-by: Max Reitz <mreitz@redhat.com>
357786
Reviewed-by: John Snow <jsnow@redhat.com>
357786
(cherry picked from commit f05fee508f538ca262d2ab19bcd8772196efe848)
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block/backup.c           | 5 ++---
357786
 block/commit.c           | 5 ++---
357786
 block/mirror.c           | 6 +++---
357786
 block/stream.c           | 5 ++---
357786
 include/block/blockjob.h | 4 ++++
357786
 5 files changed, 13 insertions(+), 12 deletions(-)
357786
357786
diff --git a/block/backup.c b/block/backup.c
357786
index 5d95805..7585c43 100644
357786
--- a/block/backup.c
357786
+++ b/block/backup.c
357786
@@ -35,7 +35,6 @@ typedef struct BackupBlockJob {
357786
     /* bitmap for sync=incremental */
357786
     BdrvDirtyBitmap *sync_bitmap;
357786
     MirrorSyncMode sync_mode;
357786
-    RateLimit limit;
357786
     BlockdevOnError on_source_error;
357786
     BlockdevOnError on_target_error;
357786
     CoRwlock flush_rwlock;
357786
@@ -199,7 +198,7 @@ static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp)
357786
         error_setg(errp, QERR_INVALID_PARAMETER, "speed");
357786
         return;
357786
     }
357786
-    ratelimit_set_speed(&s->limit, speed, SLICE_TIME);
357786
+    ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
357786
 }
357786
 
357786
 static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
357786
@@ -346,7 +345,7 @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job)
357786
      * (without, VM does not reboot)
357786
      */
357786
     if (job->common.speed) {
357786
-        uint64_t delay_ns = ratelimit_calculate_delay(&job->limit,
357786
+        uint64_t delay_ns = ratelimit_calculate_delay(&job->common.limit,
357786
                                                       job->bytes_read);
357786
         job->bytes_read = 0;
357786
         block_job_sleep_ns(&job->common, delay_ns);
357786
diff --git a/block/commit.c b/block/commit.c
357786
index 50b191c..beec5d0 100644
357786
--- a/block/commit.c
357786
+++ b/block/commit.c
357786
@@ -35,7 +35,6 @@ enum {
357786
 
357786
 typedef struct CommitBlockJob {
357786
     BlockJob common;
357786
-    RateLimit limit;
357786
     BlockDriverState *commit_top_bs;
357786
     BlockBackend *top;
357786
     BlockBackend *base;
357786
@@ -201,7 +200,7 @@ static void coroutine_fn commit_run(void *opaque)
357786
         block_job_progress_update(&s->common, n);
357786
 
357786
         if (copy && s->common.speed) {
357786
-            delay_ns = ratelimit_calculate_delay(&s->limit, n);
357786
+            delay_ns = ratelimit_calculate_delay(&s->common.limit, n);
357786
         } else {
357786
             delay_ns = 0;
357786
         }
357786
@@ -225,7 +224,7 @@ static void commit_set_speed(BlockJob *job, int64_t speed, Error **errp)
357786
         error_setg(errp, QERR_INVALID_PARAMETER, "speed");
357786
         return;
357786
     }
357786
-    ratelimit_set_speed(&s->limit, speed, SLICE_TIME);
357786
+    ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
357786
 }
357786
 
357786
 static const BlockJobDriver commit_job_driver = {
357786
diff --git a/block/mirror.c b/block/mirror.c
357786
index ed711b5..a515ec1 100644
357786
--- a/block/mirror.c
357786
+++ b/block/mirror.c
357786
@@ -36,7 +36,6 @@ typedef struct MirrorBuffer {
357786
 
357786
 typedef struct MirrorBlockJob {
357786
     BlockJob common;
357786
-    RateLimit limit;
357786
     BlockBackend *target;
357786
     BlockDriverState *mirror_top_bs;
357786
     BlockDriverState *source;
357786
@@ -450,7 +449,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
357786
         offset += io_bytes;
357786
         nb_chunks -= DIV_ROUND_UP(io_bytes, s->granularity);
357786
         if (s->common.speed) {
357786
-            delay_ns = ratelimit_calculate_delay(&s->limit, io_bytes_acct);
357786
+            delay_ns = ratelimit_calculate_delay(&s->common.limit,
357786
+                                                 io_bytes_acct);
357786
         }
357786
     }
357786
     return delay_ns;
357786
@@ -916,7 +916,7 @@ static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp)
357786
         error_setg(errp, QERR_INVALID_PARAMETER, "speed");
357786
         return;
357786
     }
357786
-    ratelimit_set_speed(&s->limit, speed, SLICE_TIME);
357786
+    ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
357786
 }
357786
 
357786
 static void mirror_complete(BlockJob *job, Error **errp)
357786
diff --git a/block/stream.c b/block/stream.c
357786
index 8369852..a1d4768 100644
357786
--- a/block/stream.c
357786
+++ b/block/stream.c
357786
@@ -33,7 +33,6 @@ enum {
357786
 
357786
 typedef struct StreamBlockJob {
357786
     BlockJob common;
357786
-    RateLimit limit;
357786
     BlockDriverState *base;
357786
     BlockdevOnError on_error;
357786
     char *backing_file_str;
357786
@@ -189,7 +188,7 @@ static void coroutine_fn stream_run(void *opaque)
357786
         /* Publish progress */
357786
         block_job_progress_update(&s->common, n);
357786
         if (copy && s->common.speed) {
357786
-            delay_ns = ratelimit_calculate_delay(&s->limit, n);
357786
+            delay_ns = ratelimit_calculate_delay(&s->common.limit, n);
357786
         } else {
357786
             delay_ns = 0;
357786
         }
357786
@@ -219,7 +218,7 @@ static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp)
357786
         error_setg(errp, QERR_INVALID_PARAMETER, "speed");
357786
         return;
357786
     }
357786
-    ratelimit_set_speed(&s->limit, speed, SLICE_TIME);
357786
+    ratelimit_set_speed(&s->common.limit, speed, SLICE_TIME);
357786
 }
357786
 
357786
 static const BlockJobDriver stream_job_driver = {
357786
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
357786
index a2cc522..22bf418 100644
357786
--- a/include/block/blockjob.h
357786
+++ b/include/block/blockjob.h
357786
@@ -27,6 +27,7 @@
357786
 #define BLOCKJOB_H
357786
 
357786
 #include "block/block.h"
357786
+#include "qemu/ratelimit.h"
357786
 
357786
 typedef struct BlockJobDriver BlockJobDriver;
357786
 typedef struct BlockJobTxn BlockJobTxn;
357786
@@ -118,6 +119,9 @@ typedef struct BlockJob {
357786
     /** Speed that was set with @block_job_set_speed.  */
357786
     int64_t speed;
357786
 
357786
+    /** Rate limiting data structure for implementing @speed. */
357786
+    RateLimit limit;
357786
+
357786
     /** The completion function that will be called when the job completes.  */
357786
     BlockCompletionFunc *cb;
357786
 
357786
-- 
357786
1.8.3.1
357786