aboutsummaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
authorHanna Reitz <hreitz@redhat.com>2021-10-06 17:19:32 +0200
committerVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2021-10-07 10:42:09 +0200
commit4cfb3f05627ad82af473e7f7ae113c3884cd04e3 (patch)
tree4d25a7313cf5df35abc65ef3733a0bdc79ad9344 /job.c
parent1d4a43e9464f8945bd8aa2ed9d95f184b011befe (diff)
job: @force parameter for job_cancel_sync()
Callers should be able to specify whether they want job_cancel_sync() to force-cancel the job or not. In fact, almost all invocations do not care about consistency of the result and just want the job to terminate as soon as possible, so they should pass force=true. The replication block driver is the exception, specifically the active commit job it runs. As for job_cancel_sync_all(), all callers want it to force-cancel all jobs, because that is the point of it: To cancel all remaining jobs as quickly as possible (generally on process termination). So make it invoke job_cancel_sync() with force=true. This changes some iotest outputs, because quitting qemu while a mirror job is active will now lead to it being cancelled instead of completed, which is what we want. (Cancelling a READY mirror job with force=false may take an indefinite amount of time, which we do not want when quitting. If users want consistent results, they must have all jobs be done before they quit qemu.) Buglink: https://gitlab.com/qemu-project/qemu/-/issues/462 Signed-off-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20211006151940.214590-6-hreitz@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Diffstat (limited to 'job.c')
-rw-r--r--job.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/job.c b/job.c
index e74d81928d..dfac35d553 100644
--- a/job.c
+++ b/job.c
@@ -981,9 +981,21 @@ static void job_cancel_err(Job *job, Error **errp)
job_cancel(job, false);
}
-int job_cancel_sync(Job *job)
+/**
+ * Same as job_cancel_err(), but force-cancel.
+ */
+static void job_force_cancel_err(Job *job, Error **errp)
{
- return job_finish_sync(job, &job_cancel_err, NULL);
+ job_cancel(job, true);
+}
+
+int job_cancel_sync(Job *job, bool force)
+{
+ if (force) {
+ return job_finish_sync(job, &job_force_cancel_err, NULL);
+ } else {
+ return job_finish_sync(job, &job_cancel_err, NULL);
+ }
}
void job_cancel_sync_all(void)
@@ -994,7 +1006,7 @@ void job_cancel_sync_all(void)
while ((job = job_next(NULL))) {
aio_context = job->aio_context;
aio_context_acquire(aio_context);
- job_cancel_sync(job);
+ job_cancel_sync(job, true);
aio_context_release(aio_context);
}
}