From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33992 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OEghB-0001Zl-Lk for qemu-devel@nongnu.org; Wed, 19 May 2010 06:40:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OEgh9-0000tG-VF for qemu-devel@nongnu.org; Wed, 19 May 2010 06:40:13 -0400 Received: from verein.lst.de ([213.95.11.210]:44758) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OEgh9-0000t7-LR for qemu-devel@nongnu.org; Wed, 19 May 2010 06:40:11 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id o4JAe9WY008834 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 19 May 2010 12:40:09 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id o4JAe9b9008833 for qemu-devel@nongnu.org; Wed, 19 May 2010 12:40:09 +0200 Date: Wed, 19 May 2010 12:40:09 +0200 From: Christoph Hellwig Message-ID: <20100519104009.GA8813@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] virtio-blk: fix barrier support List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Before issuing the barrier to the block driver we need to flush our oustanding queue of write requests, as the flush is supposed to be issued after them. Signed-off-by: Christoph Hellwig Index: qemu/hw/virtio-blk.c =================================================================== --- qemu.orig/hw/virtio-blk.c 2010-05-19 11:05:23.259005741 +0200 +++ qemu/hw/virtio-blk.c 2010-05-19 11:08:09.797255846 +0200 @@ -238,10 +238,20 @@ static void do_multiwrite(BlockDriverSta } } -static void virtio_blk_handle_flush(VirtIOBlockReq *req) +static void virtio_blk_handle_flush(BlockRequest *blkreq, int *num_writes, + VirtIOBlockReq *req, BlockDriverState **old_bs) { BlockDriverAIOCB *acb; + /* + * Make sure all outstanding writes are posted to the backing device. + */ + if (*old_bs != NULL) { + do_multiwrite(*old_bs, blkreq, *num_writes); + } + *num_writes = 0; + *old_bs = req->dev->bs; + acb = bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); if (!acb) { virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); @@ -314,7 +324,8 @@ static void virtio_blk_handle_request(Vi req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base; if (req->out->type & VIRTIO_BLK_T_FLUSH) { - virtio_blk_handle_flush(req); + virtio_blk_handle_flush(mrb->blkreq, &mrb->num_writes, + req, &mrb->old_bs); } else if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) { virtio_blk_handle_scsi(req); } else if (req->out->type & VIRTIO_BLK_T_OUT) {