cryptospore / rpms / qemu-kvm

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