From mboxrd@z Thu Jan 1 00:00:00 1970 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 Date: Tue, 15 Mar 2011 15:11:53 +0100 From: Christoph Hellwig Message-ID: <20110315141153.GD30710@lst.de> References: <20110315141049.GA30627@lst.de> <20110315141132.GB30710@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110315141132.GB30710@lst.de> Subject: [Qemu-devel] [PATCH 4/4] virtio-blk: add runtime cache control List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@gmail.com, aliguori@us.ibm.com, prerna@linux.vnet.ibm.com 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. */