From e183ef75cc28d31addbb937a4680090495786944 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 20 Oct 2011 13:16:23 +0200 Subject: block: take lock around bdrv_write implementations This does the first part of the conversion to coroutines, by wrapping bdrv_write implementations to take the mutex. Drivers that implement bdrv_write rather than bdrv_co_writev can then benefit from asynchronous operation (at least if the underlying protocol supports it, which is not the case for raw-win32), even though they still operate with a bounce buffer. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- block/vvfat.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'block/vvfat.c') diff --git a/block/vvfat.c b/block/vvfat.c index 970cccf1a4..e1fcdbc45b 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2727,6 +2727,17 @@ DLOG(checkpoint()); return 0; } +static coroutine_fn int vvfat_co_write(BlockDriverState *bs, int64_t sector_num, + const uint8_t *buf, int nb_sectors) +{ + int ret; + BDRVVVFATState *s = bs->opaque; + qemu_co_mutex_lock(&s->lock); + ret = vvfat_write(bs, sector_num, buf, nb_sectors); + qemu_co_mutex_unlock(&s->lock); + return ret; +} + static int vvfat_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int* n) { @@ -2817,7 +2828,7 @@ static BlockDriver bdrv_vvfat = { .instance_size = sizeof(BDRVVVFATState), .bdrv_file_open = vvfat_open, .bdrv_read = vvfat_co_read, - .bdrv_write = vvfat_write, + .bdrv_write = vvfat_co_write, .bdrv_close = vvfat_close, .bdrv_is_allocated = vvfat_is_allocated, .protocol_name = "fat", -- cgit v1.2.1