block-backend: Preserve AioContext of root across medium change
PATCH 1/1 block-backend: Preserve AioContext of root across medium change
This is nop for non-dataplane case, but it prevents crash (virtio_scsi_ctx_check assertion failure) when a scsi-cd change operation happens on a virtio-scsi dataplane device.
--- block/block-backend.c | 7 +++++++ include/block/block_int.h | 1 + 2 files changed, 8 insertions(+)
block/block-backend.c +7 -0
@@ -1570,6 +1570,7 @@ void blk_update_root_state(BlockBackend *blk) blk->root_state.open_flags = blk->root->bs->open_flags; blk->root_state.read_only = blk->root->bs->read_only; blk->root_state.detect_zeroes = blk->root->bs->detect_zeroes; + blk->root_state.aio_context = blk->root->bs->aio_context; }/*
@@ -1579,7 +1580,13 @@ void blk_update_root_state(BlockBackend *blk)*/ void blk_apply_root_state (BlockBackend *blk,BlockDriverState *bs) { +AioContext *ctx = blk->root_state.aio_context; bs->detect_zeroes = blk->root_state.detect_zeroes; +if (ctx && ctx !=qemu_get_aio_context ()) { +aio_context_acquire (ctx); +bdrv_set_aio_context (bs, ctx); +aio_context_release (ctx); + } }/*
include/block/block_int.h +1 -0
@@ -534,6 +534,7 @@ struct BlockBackendRootState {int open_flags;bool read_only;BlockdevDetectZeroesOptions detect_zeroes; +AioContext *aio_context; }; typedef enum BlockMirrorBackingMode {
Signature · 1 line
2.7.4
Quoted 43 lines · Fam Zheng
This is nop for non-dataplane case, but it prevents crash (
virtio_scsi_ctx_checkassertion failure) when a scsi-cd change operation happens on a virtio-scsi dataplane device.Signed-off-by Fam Zheng <[email protected]>--- block/block-backend.c | 7 +++++++ include/block/block_int.h | 1 + 2 files changed, 8 insertions(+)block/block-backend.c +7
-0@@ -1570,6 +1570,7 @@ void blk_update_root_state(BlockBackend *blk) blk->root_state.open_flags = blk->root->bs->open_flags; blk->root_state.read_only = blk->root->bs->read_only; blk->root_state.detect_zeroes = blk->root->bs->detect_zeroes; + blk->root_state.aio_context = blk->root->bs->aio_context; }/* @@ -1579,7 +1580,13 @@ void blk_update_root_state(BlockBackend *blk)*/ void blk_apply_root_state (BlockBackend *blk,BlockDriverState *bs) { +AioContext *ctx = blk->root_state.aio_context; bs->detect_zeroes = blk->root_state.detect_zeroes; +if (ctx && ctx !=qemu_get_aio_context ()) { +aio_context_acquire (ctx); +bdrv_set_aio_context (bs, ctx); +aio_context_release (ctx); + } }/* include/block/block_int.h +0
-0
include/block/block_int.h struct BlockBackendRootState { · line 540
Quoted 7 lines
include/block/block_int.h +1
-0@@ -534,6 +534,7 @@ struct BlockBackendRootState {int open_flags;bool read_only;BlockdevDetectZeroesOptions detect_zeroes; +AioContext *aio_context; }; typedef enum BlockMirrorBackingMode {
Looks good.
I look forward to when we can drop bdrv_set_aio_context altogether... It's only 70 patches away! :)
Paolo
Quoted 42 lines · Fam Zheng
This is nop for non-dataplane case, but it prevents crash (
virtio_scsi_ctx_checkassertion failure) when a scsi-cd change operation happens on a virtio-scsi dataplane device.Signed-off-by Fam Zheng <[email protected]>--- block/block-backend.c | 7 +++++++ include/block/block_int.h | 1 + 2 files changed, 8 insertions(+)block/block-backend.c +7
-0@@ -1570,6 +1570,7 @@ void blk_update_root_state(BlockBackend *blk) blk->root_state.open_flags = blk->root->bs->open_flags; blk->root_state.read_only = blk->root->bs->read_only; blk->root_state.detect_zeroes = blk->root->bs->detect_zeroes; + blk->root_state.aio_context = blk->root->bs->aio_context; }/* @@ -1579,7 +1580,13 @@ void blk_update_root_state(BlockBackend *blk)*/ void blk_apply_root_state (BlockBackend *blk,BlockDriverState *bs) { +AioContext *ctx = blk->root_state.aio_context; bs->detect_zeroes = blk->root_state.detect_zeroes; +if (ctx && ctx !=qemu_get_aio_context ()) { +aio_context_acquire (ctx); +bdrv_set_aio_context (bs, ctx); +aio_context_release (ctx); + } }/* include/block/block_int.h +0
-0
include/block/block_int.h struct BlockBackendRootState { · line 540
Quoted 7 lines
include/block/block_int.h +1
-0@@ -534,6 +534,7 @@ struct BlockBackendRootState {int open_flags;bool read_only;BlockdevDetectZeroesOptions detect_zeroes; +AioContext *aio_context; }; typedef enum BlockMirrorBackingMode {
The issue with using the BBRS is that it won't work with x-blockdev-{insert,remove}-medium. Instead, I think the AioContext should just be stored in the BB, for which Stefan sent an RFC back in April:
http://lists.nongnu.org/archive/html/qemu-devel/2016-04/msg01844.html
Max