fixup! block-migration: acquire AioContext as necessary
PATCH 1/1 fixup! block-migration: acquire AioContext as necessary
--- migration/block.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
migration/block.c +10 -4
@@ -54,6 +54,7 @@ typedef struct BlkMigDevState {int shared_base;int64_t total_sectors;QSIMPLEQ_ENTRY (BlkMigDevState) entry; +Error *blocker;/* Only used by migration thread. Does not need a lock. */ int bulk_completed;
@@ -68,9 +69,10 @@ typedef struct BlkMigDevState {/* Protected by block migration lock. */ int64_t completed_sectors; -/* Protected by iothread lock / AioContext. */ +/* During migration this is protected by iothread lock / AioContext. +* Allocation and free happen during setup and cleanup respectively. +*/ BdrvDirtyBitmap *dirty_bitmap; -Error *blocker; } BlkMigDevState; typedef struct BlkMigBlock {
@@ -339,9 +341,10 @@ static int set_dirty_tracking(void)int ret; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { -/* Creating/dropping dirty bitmaps only requires the big QEMU lock. */ +aio_context_acquire (bdrv_get_aio_context (bmds->bs)); bmds->dirty_bitmap =bdrv_create_dirty_bitmap (bmds->bs,BLOCK_SIZE ,NULL ,NULL ); +aio_context_release (bdrv_get_aio_context (bmds->bs));if (!bmds->dirty_bitmap) { ret = -errno; goto fail;
@@ -352,7 +355,9 @@ static int set_dirty_tracking(void) fail: QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {if (bmds->dirty_bitmap) { +aio_context_acquire (bdrv_get_aio_context (bmds->bs));bdrv_release_dirty_bitmap (bmds->bs, bmds->dirty_bitmap); +aio_context_release (bdrv_get_aio_context (bmds->bs)); } }return ret;
@@ -365,8 +370,9 @@ static void unset_dirty_tracking(void)BlkMigDevState *bmds; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { -/* Creating/dropping dirty bitmaps only requires the big QEMU lock. */ +aio_context_acquire (bdrv_get_aio_context (bmds->bs));bdrv_release_dirty_bitmap (bmds->bs, bmds->dirty_bitmap); +aio_context_release (bdrv_get_aio_context (bmds->bs)); } }
Signature · 1 line
2.5.0
Quoted 66 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- migration/block.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)migration/block.c +10
-4@@ -54,6 +54,7 @@ typedef struct BlkMigDevState {int shared_base;int64_t total_sectors;QSIMPLEQ_ENTRY (BlkMigDevState) entry; +Error *blocker;/* Only used by migration thread. Does not need a lock. */ int bulk_completed;@@ -68,9 +69,10 @@ typedef struct BlkMigDevState {/* Protected by block migration lock. */ int64_t completed_sectors; -/* Protected by iothread lock / AioContext. */ +/* During migration this is protected by iothread lock / AioContext. +* Allocation and free happen during setup and cleanup respectively. +*/ BdrvDirtyBitmap *dirty_bitmap; -Error *blocker; } BlkMigDevState; typedef struct BlkMigBlock {@@ -339,9 +341,10 @@ static int set_dirty_tracking(void)int ret; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { -/* Creating/dropping dirty bitmaps only requires the big QEMU lock. */ +aio_context_acquire (bdrv_get_aio_context (bmds->bs)); bmds->dirty_bitmap =bdrv_create_dirty_bitmap (bmds->bs,BLOCK_SIZE ,NULL ,NULL ); +aio_context_release (bdrv_get_aio_context (bmds->bs));if (!bmds->dirty_bitmap) { ret = -errno; goto fail;@@ -352,7 +355,9 @@ static int set_dirty_tracking(void) fail: QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {if (bmds->dirty_bitmap) { +aio_context_acquire (bdrv_get_aio_context (bmds->bs));bdrv_release_dirty_bitmap (bmds->bs, bmds->dirty_bitmap); +aio_context_release (bdrv_get_aio_context (bmds->bs)); } }return ret;@@ -365,8 +370,9 @@ static void unset_dirty_tracking(void)BlkMigDevState *bmds; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { -/* Creating/dropping dirty bitmaps only requires the big QEMU lock. */ +aio_context_acquire (bdrv_get_aio_context (bmds->bs));bdrv_release_dirty_bitmap (bmds->bs, bmds->dirty_bitmap); +aio_context_release (bdrv_get_aio_context (bmds->bs)); } }Signature · 1 line
2.5.0
BTW, could you also explain the blk_mig_lock() question (*) I had?
*: https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03317.html
Fam
Quoted 3 lines · Fam Zheng
BTW, could you also explain the
blk_mig_lock()question (*) I had?*: https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03317.html
Sorry, missed that:
Quoted 7 lines
Quoted 7 lines
(quoted diff) +1
-0@@ -597,21 +627,28 @@ static void block_migration_cleanup(void *opaque) { BlkMigDevState *bmds; BlkMigBlock *blk; + AioContext *ctx;
Quoted 7 lines
Review static void block_migration_cleanup(void *opaque) · line 605
Quoted 5 lines
(quoted diff) +0
-1bdrv_drain_all(); unset_dirty_tracking(); - blk_mig_lock();Why is it okay to skip the
blk_mig_lock()for block_mig_state.bmds_list?
The bmds_list is not protected by blk_mig_lock:
/* Written during setup phase. Can be read without a lock. */
int blk_enable;
int shared_base;
QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list;
int64_t total_sector_sum;
bool zero_blocks;block_migration_cleanup is called from qemu_savevm_state_cleanup, when there can be no concurrency between the migration thread and the I/O thread. In fact the call of qemu_savevm_state_cleanup might as well be moved out of the migration thread.
Paolo
Quoted 33 lines · Paolo Bonzini
Quoted 3 lines · Fam Zheng
BTW, could you also explain the
blk_mig_lock()question (*) I had?*: https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03317.html
Sorry, missed that:
Quoted 7 lines
Quoted 7 lines
(quoted diff) +1
-0@@ -597,21 +627,28 @@ static void block_migration_cleanup(void *opaque) { BlkMigDevState *bmds; BlkMigBlock *blk; + AioContext *ctx;Quoted 7 lines
Review static void block_migration_cleanup(void *opaque) · line 605
Quoted 5 lines
(quoted diff) +0
-1bdrv_drain_all(); unset_dirty_tracking(); - blk_mig_lock();Why is it okay to skip the
blk_mig_lock()for block_mig_state.bmds_list?The
bmds_listis not protected byblk_mig_lock:/* Written during setup phase. Can be read without a lock. */ int blk_enable; int shared_base; QSIMPLEQ_HEAD(bmds_list, BlkMigDevState) bmds_list; int64_t total_sector_sum; bool zero_blocks;
Quoted 4 lines
block_migration_cleanupis called fromqemu_savevm_state_cleanup, when there can be no concurrency between the migration thread and the I/O thread. In fact the call ofqemu_savevm_state_cleanupmight as well be moved out of the migration thread.
Thanks!
Fam