job: add .cancel handler for the driver
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Fri, 5 Feb 2021 16:37:14 +0000 (19:37 +0300)
committerEric Blake <eblake@redhat.com>
Fri, 12 Feb 2021 17:23:19 +0000 (11:23 -0600)
To be used in mirror in the following commit to cancel in-flight io on
target to not waste the time.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210205163720.887197-5-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
include/qemu/job.h
job.c

index 32aabb1c60009825ca4a921b78643fcdc7468ed9..efc6fa754498475659220d96e66b929bfcbadef0 100644 (file)
@@ -251,6 +251,11 @@ struct JobDriver {
      */
     void (*clean)(Job *job);
 
+    /**
+     * If the callback is not NULL, it will be invoked in job_cancel_async
+     */
+    void (*cancel)(Job *job);
+
 
     /** Called when the job is freed */
     void (*free)(Job *job);
diff --git a/job.c b/job.c
index 3aaaebafe2c87cd83e16ea6bc9577210f1089fa9..289edee143740c4598069d595125b67cc38d204e 100644 (file)
--- a/job.c
+++ b/job.c
@@ -715,6 +715,9 @@ static int job_finalize_single(Job *job)
 
 static void job_cancel_async(Job *job, bool force)
 {
+    if (job->driver->cancel) {
+        job->driver->cancel(job);
+    }
     if (job->user_paused) {
         /* Do not call job_enter here, the caller will handle it.  */
         if (job->driver->user_resume) {