diff options
author | Max Reitz <mreitz@redhat.com> | 2016-03-16 19:54:40 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-03-17 15:47:56 +0100 |
commit | fe1a9cbc339bb54d20f1ca4c1e8788d16944d5cf (patch) | |
tree | b82a37e5db7cc2b3ecfe080f25a6f99e62eb046d /block/block-backend.c | |
parent | 7c735873d93ac18a6f06850c7ca6b3722b1b32c5 (diff) |
block: Move some bdrv_*_all() functions to BB
Move bdrv_commit_all() and bdrv_flush_all() to the BlockBackend level.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/block-backend.c')
-rw-r--r-- | block/block-backend.c | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index 68f3662e7d..b3c3d39db8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -904,11 +904,6 @@ int blk_flush(BlockBackend *blk) return bdrv_flush(blk->bs); } -int blk_flush_all(void) -{ - return bdrv_flush_all(); -} - void blk_drain(BlockBackend *blk) { if (blk->bs) { @@ -1357,5 +1352,42 @@ BlockBackendRootState *blk_get_root_state(BlockBackend *blk) int blk_commit_all(void) { - return bdrv_commit_all(); + BlockBackend *blk = NULL; + + while ((blk = blk_all_next(blk)) != NULL) { + AioContext *aio_context = blk_get_aio_context(blk); + + aio_context_acquire(aio_context); + if (blk_is_inserted(blk) && blk->bs->backing) { + int ret = bdrv_commit(blk->bs); + if (ret < 0) { + aio_context_release(aio_context); + return ret; + } + } + aio_context_release(aio_context); + } + return 0; +} + +int blk_flush_all(void) +{ + BlockBackend *blk = NULL; + int result = 0; + + while ((blk = blk_all_next(blk)) != NULL) { + AioContext *aio_context = blk_get_aio_context(blk); + int ret; + + aio_context_acquire(aio_context); + if (blk_is_inserted(blk)) { + ret = blk_flush(blk); + if (ret < 0 && !result) { + result = ret; + } + } + aio_context_release(aio_context); + } + + return result; } |