From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:32971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tulwc-0004Lj-PW for qemu-devel@nongnu.org; Mon, 14 Jan 2013 10:27:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TulwW-0002oW-IG for qemu-devel@nongnu.org; Mon, 14 Jan 2013 10:27:26 -0500 Received: from mail-qa0-f46.google.com ([209.85.216.46]:52882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TulwW-0002oL-Ef for qemu-devel@nongnu.org; Mon, 14 Jan 2013 10:27:20 -0500 Received: by mail-qa0-f46.google.com with SMTP id r4so1520719qaq.12 for ; Mon, 14 Jan 2013 07:27:20 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 14 Jan 2013 16:26:58 +0100 Message-Id: <1358177218-16802-8-git-send-email-pbonzini@redhat.com> In-Reply-To: <1358177218-16802-1-git-send-email-pbonzini@redhat.com> References: <1358177218-16802-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 7/7] block: clear dirty bitmap when discarding List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com 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 --- block.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index b5e64ec..ffcc9e6 100644 --- a/block.c +++ b/block.c @@ -4174,7 +4174,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; -- 1.8.1