thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ae23c9
From 7d49650cc825e639180ba1d7580e15cf56fb21da Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Tue, 26 Jun 2018 09:48:07 +0200
ae23c9
Subject: [PATCH 099/268] job: Add Job.aio_context
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20180626094856.6924-25-kwolf@redhat.com>
ae23c9
Patchwork-id: 81075
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 24/73] job: Add Job.aio_context
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
When block jobs need an AioContext, they just take it from their main
ae23c9
block node. Generic jobs don't have a main block node, so we need to
ae23c9
assign them an AioContext explicitly.
ae23c9
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Reviewed-by: Max Reitz <mreitz@redhat.com>
ae23c9
Reviewed-by: John Snow <jsnow@redhat.com>
ae23c9
(cherry picked from commit 08be6fe26f6c76d900fc987f58d322b94bc4e248)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 blockjob.c         | 5 ++++-
ae23c9
 include/qemu/job.h | 7 ++++++-
ae23c9
 job.c              | 4 +++-
ae23c9
 3 files changed, 13 insertions(+), 3 deletions(-)
ae23c9
ae23c9
diff --git a/blockjob.c b/blockjob.c
ae23c9
index f4f9956..0a0b1c4 100644
ae23c9
--- a/blockjob.c
ae23c9
+++ b/blockjob.c
ae23c9
@@ -216,6 +216,7 @@ static void block_job_attached_aio_context(AioContext *new_context,
ae23c9
 {
ae23c9
     BlockJob *job = opaque;
ae23c9
 
ae23c9
+    job->job.aio_context = new_context;
ae23c9
     if (job->driver->attached_aio_context) {
ae23c9
         job->driver->attached_aio_context(job, new_context);
ae23c9
     }
ae23c9
@@ -247,6 +248,7 @@ static void block_job_detach_aio_context(void *opaque)
ae23c9
         block_job_drain(job);
ae23c9
     }
ae23c9
 
ae23c9
+    job->job.aio_context = NULL;
ae23c9
     job_unref(&job->job);
ae23c9
 }
ae23c9
 
ae23c9
@@ -899,7 +901,8 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
ae23c9
         return NULL;
ae23c9
     }
ae23c9
 
ae23c9
-    job = job_create(job_id, &driver->job_driver, errp);
ae23c9
+    job = job_create(job_id, &driver->job_driver, blk_get_aio_context(blk),
ae23c9
+                     errp);
ae23c9
     if (job == NULL) {
ae23c9
         blk_unref(blk);
ae23c9
         return NULL;
ae23c9
diff --git a/include/qemu/job.h b/include/qemu/job.h
ae23c9
index 5dfbec5..01e083f 100644
ae23c9
--- a/include/qemu/job.h
ae23c9
+++ b/include/qemu/job.h
ae23c9
@@ -47,6 +47,9 @@ typedef struct Job {
ae23c9
     /** Current state; See @JobStatus for details. */
ae23c9
     JobStatus status;
ae23c9
 
ae23c9
+    /** AioContext to run the job coroutine in */
ae23c9
+    AioContext *aio_context;
ae23c9
+
ae23c9
     /**
ae23c9
      * Set to true if the job should cancel itself.  The flag must
ae23c9
      * always be tested just before toggling the busy flag from false
ae23c9
@@ -79,9 +82,11 @@ struct JobDriver {
ae23c9
  *
ae23c9
  * @job_id: The id of the newly-created job, or %NULL for internal jobs
ae23c9
  * @driver: The class object for the newly-created job.
ae23c9
+ * @ctx: The AioContext to run the job coroutine in.
ae23c9
  * @errp: Error object.
ae23c9
  */
ae23c9
-void *job_create(const char *job_id, const JobDriver *driver, Error **errp);
ae23c9
+void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx,
ae23c9
+                 Error **errp);
ae23c9
 
ae23c9
 /**
ae23c9
  * Add a reference to Job refcnt, it will be decreased with job_unref, and then
ae23c9
diff --git a/job.c b/job.c
ae23c9
index 1abca6a..01074d0 100644
ae23c9
--- a/job.c
ae23c9
+++ b/job.c
ae23c9
@@ -121,7 +121,8 @@ Job *job_get(const char *id)
ae23c9
     return NULL;
ae23c9
 }
ae23c9
 
ae23c9
-void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
ae23c9
+void *job_create(const char *job_id, const JobDriver *driver, AioContext *ctx,
ae23c9
+                 Error **errp)
ae23c9
 {
ae23c9
     Job *job;
ae23c9
 
ae23c9
@@ -140,6 +141,7 @@ void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
ae23c9
     job->driver        = driver;
ae23c9
     job->id            = g_strdup(job_id);
ae23c9
     job->refcnt        = 1;
ae23c9
+    job->aio_context   = ctx;
ae23c9
 
ae23c9
     job_state_transition(job, JOB_STATUS_CREATED);
ae23c9
 
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9