yeahuh / rpms / qemu-kvm

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