Skip to contentSkip to conversation

blockjob: cancel blockjobs before stopping all iothreads

PATCH In review sochin.jiang 2 participants 3 messages Jun 3, 2017 – Jun 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blockjob: cancel blockjobs before stopping all iothreads

From: "sochin.jiang" <[email protected]>

commit 88b062c and commit c9d1a56 introduce BDRV_POLL_WHILE, checking bs->in_flight in the main thread and exit till bs->in_flight reaches 0. This leaves a chance that BDRV_POLL_WHILE will hang until iothread complete the relative block job when bdrv_drain is called from outside the I/O thread, say call 'iothread_stop_all' when shutting down the vm. Cancelling blockjobs seems more reasonable before iothread_stop_all is called when vm shutdown.

---
 block.c                  | 9 ++++++++-
 blockjob.c               | 5 +++++
 include/block/block.h    | 1 +
 include/block/blockjob.h | 7 +++++++
 vl.c                     | 1 +
 5 files changed, 22 insertions(+), 1 deletion(-)
block.c +8 -1
index fa1d06d..b564c29 100644
@@ -3084,9 +3084,16 @@ static void bdrv_close(BlockDriverState *bs)
     bdrv_drained_end(bs);
 }
 
+void bdrv_cancel_all(void)
+{
+    if (!block_jobs_is_empty()) {
+        block_job_cancel_sync_all();
+    }
+}
+
 void bdrv_close_all(void)
 {
-    block_job_cancel_sync_all();
+    bdrv_cancel_all();
     nbd_export_close_all();
 
     /* Drop references from requests still in flight, such as canceled block
blockjob.c +5 -0
index a0d7e29..c659994 100644
@@ -539,6 +539,11 @@ void block_job_cancel_sync_all(void)
     }
 }
 
+bool block_jobs_is_empty(void)
+{
+    return QLIST_EMPTY(&block_jobs);
+}
+
 int block_job_complete_sync(BlockJob *job, Error **errp)
 {
     return block_job_finish_sync(job, &block_job_complete, errp);
include/block/block.h +1 -0
index 9b355e9..0ebbd50 100644
@@ -376,6 +376,7 @@ int bdrv_inactivate_all(void);
 int bdrv_flush(BlockDriverState *bs);
 int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
 int bdrv_flush_all(void);
+void bdrv_cancel_all(void);
 void bdrv_close_all(void);
 void bdrv_drain(BlockDriverState *bs);
 void coroutine_fn bdrv_co_drain(BlockDriverState *bs);
include/block/blockjob.h +7 -0
index 09c7c69..d9ee58d 100644
@@ -282,6 +282,13 @@ int block_job_cancel_sync(BlockJob *job);
 void block_job_cancel_sync_all(void);
 
 /**
+ * block_jobs_is_empty:
+ *
+ * Check whether block_jobs is empty.
+ */
+bool block_jobs_is_empty(void);
+
+/**
  * block_job_complete_sync:
  * @job: The job to be completed.
  * @errp: Error object which may be set by block_job_complete(); this is not
vl.c +1 -0
index 80b86c0..cff6ec7 100644
@@ -4751,6 +4751,7 @@ int main(int argc, char **argv, char **envp)
 
     main_loop();
     replay_disable_events();
+    bdrv_cancel_all();
     iothread_stop_all();
 
     bdrv_close_all();
Signature · 1 line
1.8.3.1
#1 lore raw

block.c static void bdrv_close(BlockDriverState *bs) · line 3092

Quoted 12 lines · sochin.jiang
block.c +6 -0
@@ -3084,9 +3084,16 @@ static void bdrv_close(BlockDriverState *bs)
     bdrv_drained_end(bs);
 }
 
+void bdrv_cancel_all(void)
+{
+    if (!block_jobs_is_empty()) {
+        block_job_cancel_sync_all();
+    }
+}

Why do you need this function at all? block_job_cancel_sync_all() is already doing nothing when the block_jobs list is empty.

Berto

#2 lore raw

Indeed, thank you for replying and reminding. I'll be more careful next time.

Quoted 21 lines · Alberto Garcia

block.c static void bdrv_close(BlockDriverState *bs) · line 3092

Quoted 12 lines · sochin.jiang
block.c +6 -0
@@ -3084,9 +3084,16 @@ static void bdrv_close(BlockDriverState *bs)
     bdrv_drained_end(bs);
 }
 
+void bdrv_cancel_all(void)
+{
+    if (!block_jobs_is_empty()) {
+        block_job_cancel_sync_all();
+    }
+}

Why do you need this function at all? block_job_cancel_sync_all() is already doing nothing when the block_jobs list is empty.

Berto

.