From: Paolo Bonzini Date: Mon, 14 Jan 2013 15:26:58 +0000 (+0100) Subject: block: clear dirty bitmap when discarding X-Git-Tag: qemu-xen-4.4.0-rc1~6^2~1400^2~6 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=df702c9b4c1d049b12d7cf2f2ee607ff32f766cb;p=qemu-upstream-4.6-testing.git block: clear dirty bitmap when discarding Note that resetting bits in the dirty bitmap is done _before_ actually processing the request. Writes, instead, set bits after the request is completed. This way, when there are concurrent write and discard requests, the outcome will always be that the blocks are marked dirty. This scenario should never happen, but it is safer to do it this way. Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- diff --git a/block.c b/block.c index 4a90dd1a7..6fa7c9014 100644 --- a/block.c +++ b/block.c @@ -4170,7 +4170,13 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, return -EIO; } else if (bs->read_only) { return -EROFS; - } else if (bs->drv->bdrv_co_discard) { + } + + if (bs->dirty_bitmap) { + set_dirty_bitmap(bs, sector_num, nb_sectors, 0); + } + + if (bs->drv->bdrv_co_discard) { return bs->drv->bdrv_co_discard(bs, sector_num, nb_sectors); } else if (bs->drv->bdrv_aio_discard) { BlockDriverAIOCB *acb;