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