|
|
357786 |
From bba237b4cbbd22a61ef4cc961a1b0937b806480b Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Date: Tue, 26 Jun 2018 09:48:27 +0200
|
|
|
357786 |
Subject: [PATCH 58/89] job: Add job_is_ready()
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Message-id: <20180626094856.6924-45-kwolf@redhat.com>
|
|
|
357786 |
Patchwork-id: 81128
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 44/73] job: Add job_is_ready()
|
|
|
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 |
Instead of having a 'bool ready' in BlockJob, add a function that
|
|
|
357786 |
derives its value from the job status.
|
|
|
357786 |
|
|
|
357786 |
At the same time, this fixes the behaviour to match what the QAPI
|
|
|
357786 |
documentation promises for query-block-job: 'true if the job may be
|
|
|
357786 |
completed'. When the ready flag was introduced in commit ef6dbf1e46e,
|
|
|
357786 |
the flag never had to be reset to match the description because after
|
|
|
357786 |
being ready, the jobs would immediately complete and disappear.
|
|
|
357786 |
|
|
|
357786 |
Job transactions and manual job finalisation were introduced only later.
|
|
|
357786 |
With these changes, jobs may stay around even after having completed
|
|
|
357786 |
(and they are not ready to be completed a second time), however their
|
|
|
357786 |
patches forgot to reset the ready flag.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit df956ae2014340bf7de0190edb1d09be55d9eadf)
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
blockjob.c | 3 +--
|
|
|
357786 |
include/block/blockjob.h | 5 -----
|
|
|
357786 |
include/qemu/job.h | 3 +++
|
|
|
357786 |
job.c | 22 ++++++++++++++++++++++
|
|
|
357786 |
qemu-img.c | 2 +-
|
|
|
357786 |
tests/test-blockjob.c | 2 +-
|
|
|
357786 |
6 files changed, 28 insertions(+), 9 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/blockjob.c b/blockjob.c
|
|
|
357786 |
index 3ca009b..38f18e9 100644
|
|
|
357786 |
--- a/blockjob.c
|
|
|
357786 |
+++ b/blockjob.c
|
|
|
357786 |
@@ -269,7 +269,7 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
|
|
|
357786 |
info->offset = job->offset;
|
|
|
357786 |
info->speed = job->speed;
|
|
|
357786 |
info->io_status = job->iostatus;
|
|
|
357786 |
- info->ready = job->ready;
|
|
|
357786 |
+ info->ready = job_is_ready(&job->job),
|
|
|
357786 |
info->status = job->job.status;
|
|
|
357786 |
info->auto_finalize = job->job.auto_finalize;
|
|
|
357786 |
info->auto_dismiss = job->job.auto_dismiss;
|
|
|
357786 |
@@ -436,7 +436,6 @@ void block_job_user_resume(Job *job)
|
|
|
357786 |
void block_job_event_ready(BlockJob *job)
|
|
|
357786 |
{
|
|
|
357786 |
job_state_transition(&job->job, JOB_STATUS_READY);
|
|
|
357786 |
- job->ready = true;
|
|
|
357786 |
|
|
|
357786 |
if (block_job_is_internal(job)) {
|
|
|
357786 |
return;
|
|
|
357786 |
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
|
|
|
357786 |
index 5a81afc..8e1e1ee 100644
|
|
|
357786 |
--- a/include/block/blockjob.h
|
|
|
357786 |
+++ b/include/block/blockjob.h
|
|
|
357786 |
@@ -49,11 +49,6 @@ typedef struct BlockJob {
|
|
|
357786 |
/** The block device on which the job is operating. */
|
|
|
357786 |
BlockBackend *blk;
|
|
|
357786 |
|
|
|
357786 |
- /**
|
|
|
357786 |
- * Set to true when the job is ready to be completed.
|
|
|
357786 |
- */
|
|
|
357786 |
- bool ready;
|
|
|
357786 |
-
|
|
|
357786 |
/** Status that is published by the query-block-jobs QMP API */
|
|
|
357786 |
BlockDeviceIoStatus iostatus;
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/qemu/job.h b/include/qemu/job.h
|
|
|
357786 |
index 1e8050c..487f9d9 100644
|
|
|
357786 |
--- a/include/qemu/job.h
|
|
|
357786 |
+++ b/include/qemu/job.h
|
|
|
357786 |
@@ -367,6 +367,9 @@ bool job_is_cancelled(Job *job);
|
|
|
357786 |
/** Returns whether the job is in a completed state. */
|
|
|
357786 |
bool job_is_completed(Job *job);
|
|
|
357786 |
|
|
|
357786 |
+/** Returns whether the job is ready to be completed. */
|
|
|
357786 |
+bool job_is_ready(Job *job);
|
|
|
357786 |
+
|
|
|
357786 |
/**
|
|
|
357786 |
* Request @job to pause at the next pause point. Must be paired with
|
|
|
357786 |
* job_resume(). If the job is supposed to be resumed by user action, call
|
|
|
357786 |
diff --git a/job.c b/job.c
|
|
|
357786 |
index 7cd3602..aa4c746 100644
|
|
|
357786 |
--- a/job.c
|
|
|
357786 |
+++ b/job.c
|
|
|
357786 |
@@ -199,6 +199,28 @@ bool job_is_cancelled(Job *job)
|
|
|
357786 |
return job->cancelled;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+bool job_is_ready(Job *job)
|
|
|
357786 |
+{
|
|
|
357786 |
+ switch (job->status) {
|
|
|
357786 |
+ case JOB_STATUS_UNDEFINED:
|
|
|
357786 |
+ case JOB_STATUS_CREATED:
|
|
|
357786 |
+ case JOB_STATUS_RUNNING:
|
|
|
357786 |
+ case JOB_STATUS_PAUSED:
|
|
|
357786 |
+ case JOB_STATUS_WAITING:
|
|
|
357786 |
+ case JOB_STATUS_PENDING:
|
|
|
357786 |
+ case JOB_STATUS_ABORTING:
|
|
|
357786 |
+ case JOB_STATUS_CONCLUDED:
|
|
|
357786 |
+ case JOB_STATUS_NULL:
|
|
|
357786 |
+ return false;
|
|
|
357786 |
+ case JOB_STATUS_READY:
|
|
|
357786 |
+ case JOB_STATUS_STANDBY:
|
|
|
357786 |
+ return true;
|
|
|
357786 |
+ default:
|
|
|
357786 |
+ g_assert_not_reached();
|
|
|
357786 |
+ }
|
|
|
357786 |
+ return false;
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
bool job_is_completed(Job *job)
|
|
|
357786 |
{
|
|
|
357786 |
switch (job->status) {
|
|
|
357786 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
357786 |
index 734ea94..3c449a2 100644
|
|
|
357786 |
--- a/qemu-img.c
|
|
|
357786 |
+++ b/qemu-img.c
|
|
|
357786 |
@@ -878,7 +878,7 @@ static void run_block_job(BlockJob *job, Error **errp)
|
|
|
357786 |
aio_poll(aio_context, true);
|
|
|
357786 |
qemu_progress_print(job->len ?
|
|
|
357786 |
((float)job->offset / job->len * 100.f) : 0.0f, 0);
|
|
|
357786 |
- } while (!job->ready && !job_is_completed(&job->job));
|
|
|
357786 |
+ } while (!job_is_ready(&job->job) && !job_is_completed(&job->job));
|
|
|
357786 |
|
|
|
357786 |
if (!job_is_completed(&job->job)) {
|
|
|
357786 |
ret = job_complete_sync(&job->job, errp);
|
|
|
357786 |
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
|
|
|
357786 |
index 7131cab..8180d03 100644
|
|
|
357786 |
--- a/tests/test-blockjob.c
|
|
|
357786 |
+++ b/tests/test-blockjob.c
|
|
|
357786 |
@@ -185,7 +185,7 @@ static void coroutine_fn cancel_job_start(void *opaque)
|
|
|
357786 |
goto defer;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- if (!s->common.ready && s->should_converge) {
|
|
|
357786 |
+ if (!job_is_ready(&s->common.job) && s->should_converge) {
|
|
|
357786 |
block_job_event_ready(&s->common);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|