From patchwork Mon Aug 31 20:18:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 32681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id CEDD9B7B63 for ; Tue, 1 Sep 2009 06:24:42 +1000 (EST) Received: from localhost ([127.0.0.1]:40698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MiDQd-00066I-6z for incoming@patchwork.ozlabs.org; Mon, 31 Aug 2009 16:24:39 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MiDKM-00048n-E1 for qemu-devel@nongnu.org; Mon, 31 Aug 2009 16:18:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MiDKH-00046S-Up for qemu-devel@nongnu.org; Mon, 31 Aug 2009 16:18:09 -0400 Received: from [199.232.76.173] (port=51923 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MiDKH-00046N-G9 for qemu-devel@nongnu.org; Mon, 31 Aug 2009 16:18:05 -0400 Received: from verein.lst.de ([213.95.11.210]:33979) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1MiDKH-0001JN-0y for qemu-devel@nongnu.org; Mon, 31 Aug 2009 16:18:05 -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 n7VKI3VL004961 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Mon, 31 Aug 2009 22:18:03 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id n7VKI2vS004960; Mon, 31 Aug 2009 22:18:02 +0200 From: Christoph Hellwig Date: Mon, 31 Aug 2009 22:18:02 +0200 To: qemu-devel@nongnu.org Message-ID: <20090831201802.GD4874@lst.de> References: <20090831201627.GA4811@lst.de> Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090831201627.GA4811@lst.de> User-Agent: Mutt/1.3.28i X-Spam-Score: 0 () X-Scanned-By: MIMEDefang 2.39 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: rusty@rustcorp.com.au Subject: [Qemu-devel] [PATCH 4/4] virtio-blk: add volatile writecache feature X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a new VIRTIO_BLK_F_WCACHE feature to virtio-blk to indicate that we have a volatile write cache that needs controlled flushing. Implement a VIRTIO_BLK_T_FLUSH operation to flush it. Signed-off-by: Christoph Hellwig Index: qemu-kvm/hw/virtio-blk.c =================================================================== --- qemu-kvm.orig/hw/virtio-blk.c +++ qemu-kvm/hw/virtio-blk.c @@ -129,6 +129,13 @@ static void virtio_blk_rw_complete(void virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); } +static void virtio_blk_flush_complete(void *opaque, int ret) +{ + VirtIOBlockReq *req = opaque; + + virtio_blk_req_complete(req, ret ? VIRTIO_BLK_S_IOERR : VIRTIO_BLK_S_OK); +} + static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s) { VirtIOBlockReq *req = qemu_mallocz(sizeof(*req)); @@ -252,6 +259,16 @@ static void virtio_blk_handle_scsi(VirtI } #endif /* __linux__ */ +static void virtio_blk_handle_flush(VirtIOBlockReq *req) +{ + BlockDriverAIOCB *acb; + + acb = bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); + if (!acb) { + virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); + } +} + static void virtio_blk_handle_write(VirtIOBlockReq *req) { BlockDriverAIOCB *acb; @@ -294,7 +311,9 @@ static void virtio_blk_handle_output(Vir req->out = (void *)req->elem.out_sg[0].iov_base; req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base; - if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) { + if (req->out->type & VIRTIO_BLK_T_FLUSH) { + virtio_blk_handle_flush(req); + } else if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) { virtio_blk_handle_scsi(req); } else if (req->out->type & VIRTIO_BLK_T_OUT) { qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1], @@ -382,6 +401,9 @@ static uint32_t virtio_blk_get_features( features |= (1 << VIRTIO_BLK_F_SEG_MAX); features |= (1 << VIRTIO_BLK_F_GEOMETRY); + + if (bdrv_enable_write_cache(s->bs)) + features |= (1 << VIRTIO_BLK_F_WCACHE); #ifdef __linux__ features |= (1 << VIRTIO_BLK_F_SCSI); #endif Index: qemu-kvm/hw/virtio-blk.h =================================================================== --- qemu-kvm.orig/hw/virtio-blk.h +++ qemu-kvm/hw/virtio-blk.h @@ -31,6 +31,7 @@ #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ #define VIRTIO_BLK_F_IDENTIFY 8 /* ATA IDENTIFY supported */ +#define VIRTIO_BLK_F_WCACHE 9 /* write cache enabled */ #define VIRTIO_BLK_ID_LEN 256 /* length of identify u16 array */ #define VIRTIO_BLK_ID_SN 10 /* start of char * serial# */ @@ -55,6 +56,9 @@ struct virtio_blk_config /* This bit says it's a scsi command, not an actual read or write. */ #define VIRTIO_BLK_T_SCSI_CMD 2 +/* Flush the volatile write cache */ +#define VIRTIO_BLK_T_FLUSH 4 + /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000