move global bdrv_states out of block.c
cover move global bdrv_states out of block.c
In order to support multiple caller from different thread, global inside block layer should be carefully treated. bdrv_states represent a group of bds* which is now used by qemu, so it is a user concept which should be managed by user. This series tries to move it out, so later different thread can feed the API with its own bds* group.
This is a RFC series which does not completely convert the API, the missing part is adding parameter *l in all API which uses bdrv_states, then move bdrv_states to caller. About 10 functions need to be converted, so hope to get comments before that, to see if this is the right direction.
Wenchao Xia (3):
1 block: add typedef for BlockDriverState queue
2 block: add function qemu_get_bds_queue
3 block: add parameter bds queue in bdrv_invalidate_cache_all()
block.c | 11 ++++++++--- include/block/block.h | 7 ++++++- migration.c | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-)
RFC PATCH 1/3 block: add typedef for BlockDriverState queue
--- block.c | 2 +- include/block/block.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-)
block.c +1 -1
@@ -93,7 +93,7 @@ static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,static bool bdrv_exceed_io_limits (BlockDriverState *bs,int nb_sectors,bool is_write,int64_t *wait); -static QTAILQ_HEAD(, BlockDriverState) bdrv_states = +static BlockDrvierStateQueue bdrv_states =QTAILQ_HEAD_INITIALIZER (bdrv_states); static QLIST_HEAD(, BlockDriver) bdrv_drivers =
include/block/block.h +2 -0
@@ -86,6 +86,8 @@ typedef enum { } BlockErrorAction; typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue; +typedef QTAILQ_HEAD(BlockDrvierStateQueue, BlockDriverState) \ +BlockDrvierStateQueue ; typedef struct BDRVReopenState { BlockDriverState *bs;
Signature · 1 line
1.7.1
RFC PATCH 2/3 block: add function qemu_get_bds_queue
In reply to Wenchao XiaIt should be caller's responsibility to tell which bds* needs take action in multithread case, but since now only one thread exist and only one bds* group exist, add this function to manage the bds* queue temporarily. Once the block layer user code manage the bds* queue by itself and global bdrv_states is moved out, this function can be removed.
--- block.c | 5 +++++ include/block/block.h | 3 +++ 2 files changed, 8 insertions(+), 0 deletions(-)
block.c +5 -0
@@ -102,6 +102,11 @@ static QLIST_HEAD(, BlockDriver) bdrv_drivers =/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; +BlockDrvierStateQueue *qemu_get_bds_queue (void ) +{ +return &bdrv_states; +} +#ifdef _WIN32static int is_windows_drive_prefix (const char *filename) {
include/block/block.h +3 -0
@@ -95,6 +95,9 @@ typedef struct BDRVReopenState {void *opaque; } BDRVReopenState; +/* This function could be removed when block layer is thread safe. Then let +caller manage the bds it used, instead of block layer. */ +BlockDrvierStateQueue *qemu_get_bds_queue (void );void bdrv_iostatus_enable (BlockDriverState *bs);void bdrv_iostatus_reset (BlockDriverState *bs);
Signature · 1 line
1.7.1
RFC PATCH 3/3 block: add parameter bds queue in bdrv_invalidate_cache_all()
In reply to Wenchao Xia--- block.c | 4 ++-- include/block/block.h | 2 +- migration.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
block.c +2 -2
@@ -4175,11 +4175,11 @@ void bdrv_invalidate_cache(BlockDriverState *bs) } } -void bdrv_invalidate_cache_all (void ) +void bdrv_invalidate_cache_all (BlockDrvierStateQueue *q) {BlockDriverState *bs; - QTAILQ_FOREACH(bs, &bdrv_states, list) { + QTAILQ_FOREACH(bs, q, list) {bdrv_invalidate_cache (bs); } }
include/block/block.h +1 -1
@@ -267,7 +267,7 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,/* Invalidate any cached metadata used by image formats */ void bdrv_invalidate_cache (BlockDriverState *bs); -void bdrv_invalidate_cache_all (void ); +void bdrv_invalidate_cache_all (BlockDrvierStateQueue *q);void bdrv_clear_incoming_migration_all (void );
migration.c +1 -1
@@ -113,7 +113,7 @@ static void process_incoming_migration_co(void *opaque)bdrv_clear_incoming_migration_all ();/* Make sure all file formats flush their mutable metadata */ -bdrv_invalidate_cache_all (); +bdrv_invalidate_cache_all (qemu_get_bds_queue ());if (autostart) {vm_start ();
Signature · 1 line
1.7.1
Quoted 10 lines · Wenchao Xia
In order to support multiple caller from different thread, global inside block layer should be carefully treated.
bdrv_statesrepresent a group of bds* which is now used by qemu, so it is a user concept which should be managed by user. This series tries to move it out, so later different thread can feed the API with its own bds* group.This is a RFC series which does not completely convert the API, the missing part is adding parameter *l in all API which uses
bdrv_states, then movebdrv_statesto caller. About 10 functions need to be converted, so hope to get comments before that, to see if this is the right direction.
The global bdrv_states list needs to stay, I don't think we should try to remove it.
The list is used to drain and flush all devices so that we can safely shut down or live migrate. If we give each thread their own list then there's no way to globally drain and flush.
The invalidate function that you modified is another example: we *must* invalidate all BDS instances across all threads. Failure to invalidate all instances could mean inconsistencies or data loss.
So in the end I think we need to keep bdrv_states.
Stefan
Quoted 18 lines · Stefan Hajnoczi
Quoted 10 lines · Wenchao Xia
In order to support multiple caller from different thread, global inside block layer should be carefully treated.
bdrv_statesrepresent a group of bds* which is now used by qemu, so it is a user concept which should be managed by user. This series tries to move it out, so later different thread can feed the API with its own bds* group.This is a RFC series which does not completely convert the API, the missing part is adding parameter *l in all API which uses
bdrv_states, then movebdrv_statesto caller. About 10 functions need to be converted, so hope to get comments before that, to see if this is the right direction.The global
bdrv_stateslist needs to stay, I don't think we should try to remove it.The list is used to drain and flush all devices so that we can safely shut down or live migrate. If we give each thread their own list then there's no way to globally drain and flush.
Quoted 5 lines
The invalidate function that you modified is another example: we *must* invalidate all BDS instances across all threads. Failure to invalidate all instances could mean inconsistencies or data loss.
So in the end I think we need to keep
bdrv_states.
I am OK to keep bdrv_states now, after the talk about AioContext
in IRC. I think it is related with thread model, and, If we find drain a subset of BDS is needed, such as per AioContext drain, it is no late to change at that time, after the programming model is built. Looking forward to your next series for AioContext.
Quoted 3 lines
Stefan