qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Cody <jcody@redhat.com>
To: qemu-block@nongnu.org
Cc: peter.maydell@linaro.org, jcody@redhat.com,
	vsementsov@virtuozzo.com, jsnow@redhat.com,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 06/10] blockjob: kick jobs on set-speed
Date: Mon, 18 Dec 2017 16:08:15 -0500	[thread overview]
Message-ID: <20171218210819.31576-7-jcody@redhat.com> (raw)
In-Reply-To: <20171218210819.31576-1-jcody@redhat.com>

From: John Snow <jsnow@redhat.com>

If users set an unreasonably low speed (like one byte per second), the
calculated delay may exceed many hours. While we like to punish users
for asking for stupid things, we do also like to allow users to correct
their wicked ways.

When a user provides a new speed, kick the job to allow it to recalculate
its delay.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20171213204611.26276-1-jsnow@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 blockjob.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/blockjob.c b/blockjob.c
index 715c2c2..6173e47 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -59,6 +59,7 @@ static void __attribute__((__constructor__)) block_job_init(void)
 
 static void block_job_event_cancelled(BlockJob *job);
 static void block_job_event_completed(BlockJob *job, const char *msg);
+static void block_job_enter_cond(BlockJob *job, bool(*fn)(BlockJob *job));
 
 /* Transactional group of block jobs */
 struct BlockJobTxn {
@@ -480,9 +481,16 @@ static void block_job_completed_txn_success(BlockJob *job)
     }
 }
 
+/* Assumes the block_job_mutex is held */
+static bool block_job_timer_pending(BlockJob *job)
+{
+    return timer_pending(&job->sleep_timer);
+}
+
 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
 {
     Error *local_err = NULL;
+    int64_t old_speed = job->speed;
 
     if (!job->driver->set_speed) {
         error_setg(errp, QERR_UNSUPPORTED);
@@ -495,6 +503,12 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
     }
 
     job->speed = speed;
+    if (speed <= old_speed) {
+        return;
+    }
+
+    /* kick only if a timer is pending */
+    block_job_enter_cond(job, block_job_timer_pending);
 }
 
 void block_job_complete(BlockJob *job, Error **errp)
@@ -821,7 +835,11 @@ void block_job_resume_all(void)
     }
 }
 
-void block_job_enter(BlockJob *job)
+/*
+ * Conditionally enter a block_job pending a call to fn() while
+ * under the block_job_lock critical section.
+ */
+static void block_job_enter_cond(BlockJob *job, bool(*fn)(BlockJob *job))
 {
     if (!block_job_started(job)) {
         return;
@@ -836,6 +854,11 @@ void block_job_enter(BlockJob *job)
         return;
     }
 
+    if (fn && !fn(job)) {
+        block_job_unlock();
+        return;
+    }
+
     assert(!job->deferred_to_main_loop);
     timer_del(&job->sleep_timer);
     job->busy = true;
@@ -843,6 +866,11 @@ void block_job_enter(BlockJob *job)
     aio_co_wake(job->co);
 }
 
+void block_job_enter(BlockJob *job)
+{
+    block_job_enter_cond(job, NULL);
+}
+
 bool block_job_is_cancelled(BlockJob *job)
 {
     return job->cancelled;
-- 
2.9.5

  parent reply	other threads:[~2017-12-18 21:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18 21:08 [Qemu-devel] [PULL 00/10] Block patches Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 01/10] hbitmap: add next_zero function Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 02/10] backup: move from done_bitmap to copy_bitmap Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 03/10] backup: init copy_bitmap from sync_bitmap for incremental Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 04/10] backup: simplify non-dirty bits progress processing Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 05/10] backup: use copy_bitmap in incremental backup Jeff Cody
2017-12-18 21:08 ` Jeff Cody [this message]
2017-12-18 21:08 ` [Qemu-devel] [PULL 07/10] block/sheepdog: remove spurious NULL check Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 08/10] block/sheepdog: code beautification Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 09/10] block/curl: check error return of curl_global_init() Jeff Cody
2017-12-18 21:08 ` [Qemu-devel] [PULL 10/10] block/curl: fix minor memory leaks Jeff Cody
2017-12-19 19:10 ` [Qemu-devel] [PULL 00/10] Block patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171218210819.31576-7-jcody@redhat.com \
    --to=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).