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