From patchwork Tue Mar 15 14:11:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 86985 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 ozlabs.org (Postfix) with ESMTPS id C14A0B6FAC for ; Wed, 16 Mar 2011 01:13:12 +1100 (EST) Received: from localhost ([127.0.0.1]:38238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzUzk-0004nQ-M7 for incoming@patchwork.ozlabs.org; Tue, 15 Mar 2011 10:13:08 -0400 Received: from [140.186.70.92] (port=60773 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzUyZ-0004kd-Au for qemu-devel@nongnu.org; Tue, 15 Mar 2011 10:11:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzUyY-0002is-0K for qemu-devel@nongnu.org; Tue, 15 Mar 2011 10:11:55 -0400 Received: from verein.lst.de ([213.95.11.211]:38248 helo=newverein.lst.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzUyX-0002ik-MA for qemu-devel@nongnu.org; Tue, 15 Mar 2011 10:11:53 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 883E313F9C; Tue, 15 Mar 2011 15:11:53 +0100 (CET) Date: Tue, 15 Mar 2011 15:11:53 +0100 From: Christoph Hellwig To: qemu-devel@nongnu.org Message-ID: <20110315141153.GD30710@lst.de> References: <20110315141049.GA30627@lst.de> <20110315141132.GB30710@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110315141132.GB30710@lst.de> User-Agent: Mutt/1.5.17 (2007-11-01) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 213.95.11.211 Cc: kwolf@redhat.com, stefanha@gmail.com, aliguori@us.ibm.com, prerna@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 4/4] virtio-blk: add runtime cache control 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 writeable features config space field, which allows the guest to communicate features it wants enabled/disabled at runtime. The only feature defined so far is the status of the volatile write cache. Also rename the virtio_blk_update_config to virtio_blk_get_config to fit the method naming scheme. Signed-off-by: Christoph Hellwig Index: qemu/hw/virtio-blk.c =================================================================== --- qemu.orig/hw/virtio-blk.c 2011-03-15 13:07:10.093633862 +0100 +++ qemu/hw/virtio-blk.c 2011-03-15 13:07:54.108135875 +0100 @@ -434,7 +434,7 @@ static void virtio_blk_reset(VirtIODevic /* coalesce internal state, copy to pci i/o region 0 */ -static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) +static void virtio_blk_get_config(VirtIODevice *vdev, uint8_t *config) { VirtIOBlock *s = to_virtio_blk(vdev); struct virtio_blk_config blkcfg; @@ -455,9 +455,26 @@ static void virtio_blk_update_config(Vir blkcfg.alignment_offset = 0; blkcfg.min_io_size = s->conf->min_io_size / blkcfg.blk_size; blkcfg.opt_io_size = s->conf->opt_io_size / blkcfg.blk_size; + if (bdrv_enable_write_cache(s->bs)) + blkcfg.features |= VIRTIO_BLK_RT_WCE; memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); } +static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config) +{ + VirtIOBlock *s = to_virtio_blk(vdev); + struct virtio_blk_config blkcfg; + bool enable = false; + + memcpy(&blkcfg, config, sizeof(blkcfg)); + + if (blkcfg.features & VIRTIO_BLK_RT_WCE) + enable = true; + + /* no error reporting, needs to be checked by a config re-read */ + bdrv_change_cache(s->bs, enable); +} + static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) { VirtIOBlock *s = to_virtio_blk(vdev); @@ -466,6 +483,7 @@ static uint32_t virtio_blk_get_features( features |= (1 << VIRTIO_BLK_F_GEOMETRY); features |= (1 << VIRTIO_BLK_F_TOPOLOGY); features |= (1 << VIRTIO_BLK_F_BLK_SIZE); + features |= (1 << VIRTIO_BLK_F_DYNAMIC); if (bdrv_enable_write_cache(s->bs)) features |= (1 << VIRTIO_BLK_F_WCACHE); @@ -543,7 +561,8 @@ VirtIODevice *virtio_blk_init(DeviceStat sizeof(struct virtio_blk_config), sizeof(VirtIOBlock)); - s->vdev.get_config = virtio_blk_update_config; + s->vdev.get_config = virtio_blk_get_config; + s->vdev.set_config = virtio_blk_set_config; s->vdev.get_features = virtio_blk_get_features; s->vdev.reset = virtio_blk_reset; s->bs = conf->bs; Index: qemu/hw/virtio-blk.h =================================================================== --- qemu.orig/hw/virtio-blk.h 2011-03-15 13:07:10.109636192 +0100 +++ qemu/hw/virtio-blk.h 2011-03-15 13:07:54.112135546 +0100 @@ -33,6 +33,7 @@ /* #define VIRTIO_BLK_F_IDENTIFY 8 ATA IDENTIFY supported, DEPRECATED */ #define VIRTIO_BLK_F_WCACHE 9 /* write cache enabled */ #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */ +#define VIRTIO_BLK_F_DYNAMIC 11 /* Dynamic features field */ struct virtio_blk_config { @@ -47,6 +48,8 @@ struct virtio_blk_config uint8_t alignment_offset; uint16_t min_io_size; uint32_t opt_io_size; + uint32_t features; +#define VIRTIO_BLK_RT_WCE (1 << 0) } __attribute__((packed)); /* These two define direction. */