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

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