qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/4] virtio-blk: add runtime cache control


From: Christoph Hellwig
Subject: [Qemu-devel] [PATCH 4/4] virtio-blk: add runtime cache control
Date: Tue, 15 Mar 2011 15:11:53 +0100
User-agent: Mutt/1.5.17 (2007-11-01)

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 <address@hidden>

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. */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]