Skip to contentSkip to conversation

virtio-blk: Allow config-wce in dataplane

PATCH In review Fam Zheng 3 participants 5 messages May 13, 2014

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 virtio-blk: Allow config-wce in dataplane

Dataplane now uses block layer. Protect bdrv_set_enable_write_cache with aio_context_acquire and aio_context_release, so we can enable config-wce to allow guest to modify the write cache online.

---
This applies on top of Stefan's "dataplane: use QEMU block layer" series.

---
 hw/block/dataplane/virtio-blk.c | 6 ------
 hw/block/virtio-blk.c           | 9 ++++++++-
 2 files changed, 8 insertions(+), 7 deletions(-)
hw/block/dataplane/virtio-blk.c +0 -6
index 79fb612..46a6824 100644
@@ -332,12 +332,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
         return;
     }
 
-    if (blk->config_wce) {
-        error_setg(errp, "device is incompatible with x-data-plane, "
-                         "use config-wce=off");
-        return;
-    }
-
     /* If dataplane is (re-)enabled while the guest is running there could be
      * block jobs that can conflict.
      */
hw/block/virtio-blk.c +8 -1
index 8a568e5..a031e56 100644
@@ -26,6 +26,7 @@
 # include <scsi/sg.h>
 #endif
 #include "hw/virtio/virtio-bus.h"
+#include "block/block_int.h"
 
 typedef struct VirtIOBlockReq
 {
@@ -523,7 +524,10 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
     struct virtio_blk_config blkcfg;
 
     memcpy(&blkcfg, config, sizeof(blkcfg));
+
+    aio_context_acquire(bdrv_get_aio_context(s->bs));
     bdrv_set_enable_write_cache(s->bs, blkcfg.wce != 0);
+    aio_context_release(bdrv_get_aio_context(s->bs));
 }
 
 static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
@@ -582,7 +586,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
      * s->bs would erroneously be placed in writethrough mode.
      */
     if (!(features & (1 << VIRTIO_BLK_F_CONFIG_WCE))) {
-        bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE)));
+        aio_context_acquire(bdrv_get_aio_context(s->bs));
+        bdrv_set_enable_write_cache(s->bs,
+                                    !!(features & (1 << VIRTIO_BLK_F_WCE)));
+        aio_context_release(bdrv_get_aio_context(s->bs));
     }
 }
 
Signature · 1 line
1.9.2
#1 lore raw

Il 13/05/2014 04:24, Fam Zheng ha scritto:

Quoted 38 lines

Dataplane now uses block layer. Protect bdrv_set_enable_write_cache with aio_context_acquire and aio_context_release, so we can enable config-wce to allow guest to modify the write cache online.

---
This applies on top of Stefan's "dataplane: use QEMU block layer" series.

---
 hw/block/dataplane/virtio-blk.c | 6 ------
 hw/block/virtio-blk.c           | 9 ++++++++-
 2 files changed, 8 insertions(+), 7 deletions(-)
hw/block/dataplane/virtio-blk.c +0 -6
index 79fb612..46a6824 100644
@@ -332,12 +332,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
         return;
     }
 
-    if (blk->config_wce) {
-        error_setg(errp, "device is incompatible with x-data-plane, "
-                         "use config-wce=off");
-        return;
-    }
-
     /* If dataplane is (re-)enabled while the guest is running there could be
      * block jobs that can conflict.
      */
hw/block/virtio-blk.c +0 -0
index 8a568e5..a031e56 100644

hw/block/virtio-blk.c line 29

Quoted 4 lines
hw/block/virtio-blk.c +1 -0
@@ -26,6 +26,7 @@
 # include <scsi/sg.h>
 #endif
 #include "hw/virtio/virtio-bus.h"
+#include "block/block_int.h"

You shouldn't need to include this header file. Apart from this, the patch looks good.

Paolo

Quoted 27 lines
hw/block/virtio-blk.c +7 -1
 typedef struct VirtIOBlockReq
 {
@@ -523,7 +524,10 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
     struct virtio_blk_config blkcfg;
 
     memcpy(&blkcfg, config, sizeof(blkcfg));
+
+    aio_context_acquire(bdrv_get_aio_context(s->bs));
     bdrv_set_enable_write_cache(s->bs, blkcfg.wce != 0);
+    aio_context_release(bdrv_get_aio_context(s->bs));
 }
 
 static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
@@ -582,7 +586,10 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
      * s->bs would erroneously be placed in writethrough mode.
      */
     if (!(features & (1 << VIRTIO_BLK_F_CONFIG_WCE))) {
-        bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE)));
+        aio_context_acquire(bdrv_get_aio_context(s->bs));
+        bdrv_set_enable_write_cache(s->bs,
+                                    !!(features & (1 << VIRTIO_BLK_F_WCE)));
+        aio_context_release(bdrv_get_aio_context(s->bs));
     }
 }
 
author
#2 lore raw
Quoted 38 lines · Paolo Bonzini

Il 13/05/2014 04:24, Fam Zheng ha scritto:

Quoted 37 lines

Dataplane now uses block layer. Protect bdrv_set_enable_write_cache with aio_context_acquire and aio_context_release, so we can enable config-wce to allow guest to modify the write cache online.

---
This applies on top of Stefan's "dataplane: use QEMU block layer" series.

---
hw/block/dataplane/virtio-blk.c | 6 ------
hw/block/virtio-blk.c | 9 ++++++++-

2 files changed, 8 insertions(+), 7 deletions(-)
hw/block/dataplane/virtio-blk.c +0 -6
index 79fb612..46a6824 100644
@@ -332,12 +332,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
        return;
    }
 
-    if (blk->config_wce) {
-        error_setg(errp, "device is incompatible with x-data-plane, "
-                         "use config-wce=off");
-        return;
-    }
-
    /* If dataplane is (re-)enabled while the guest is running there could be
     * block jobs that can conflict.
     */
hw/block/virtio-blk.c +0 -0
index 8a568e5..a031e56 100644
Quoted 8 lines

hw/block/virtio-blk.c line 29

Quoted 5 lines
hw/block/virtio-blk.c +1 -0
@@ -26,6 +26,7 @@
 # include <scsi/sg.h>
 #endif
 #include "hw/virtio/virtio-bus.h"
+#include "block/block_int.h"

You shouldn't need to include this header file. Apart from this, the patch looks good.

It's for bdrv_get_aio_context, otherwise it doesn't compile.

Fam

#3 lore raw

Il 13/05/2014 09:13, Fam Zheng ha scritto:

Quoted 48 lines · Paolo Bonzini
Quoted 38 lines

Il 13/05/2014 04:24, Fam Zheng ha scritto:

Quoted 37 lines

Dataplane now uses block layer. Protect bdrv_set_enable_write_cache with aio_context_acquire and aio_context_release, so we can enable config-wce to allow guest to modify the write cache online.

---
This applies on top of Stefan's "dataplane: use QEMU block layer" series.

---
hw/block/dataplane/virtio-blk.c | 6 ------
hw/block/virtio-blk.c | 9 ++++++++-

2 files changed, 8 insertions(+), 7 deletions(-)
hw/block/dataplane/virtio-blk.c +0 -6
index 79fb612..46a6824 100644
@@ -332,12 +332,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
        return;
    }
 
-    if (blk->config_wce) {
-        error_setg(errp, "device is incompatible with x-data-plane, "
-                         "use config-wce=off");
-        return;
-    }
-
    /* If dataplane is (re-)enabled while the guest is running there could be
     * block jobs that can conflict.
     */
hw/block/virtio-blk.c +0 -0
index 8a568e5..a031e56 100644
Quoted 8 lines

hw/block/virtio-blk.c line 29

Quoted 5 lines
hw/block/virtio-blk.c +1 -0
@@ -26,6 +26,7 @@
 # include <scsi/sg.h>
 #endif
 #include "hw/virtio/virtio-bus.h"
+#include "block/block_int.h"

You shouldn't need to include this header file. Apart from this, the patch looks good.

Quoted 1 line

It's for bdrv_get_aio_context, otherwise it doesn't compile.

I think it should be moved to block/block.h then. Stefan?

Paolo

#4 lore raw
Quoted 49 lines · Paolo Bonzini

Il 13/05/2014 09:13, Fam Zheng ha scritto:

Quoted 48 lines · Paolo Bonzini
Quoted 46 lines

Il 13/05/2014 04:24, Fam Zheng ha scritto:

Quoted 38 lines

Dataplane now uses block layer. Protect bdrv_set_enable_write_cache with aio_context_acquire and aio_context_release, so we can enable config-wce to allow guest to modify the write cache online.

---
This applies on top of Stefan's "dataplane: use QEMU block layer" series.

---
hw/block/dataplane/virtio-blk.c | 6 ------
hw/block/virtio-blk.c | 9 ++++++++-

2 files changed, 8 insertions(+), 7 deletions(-)
hw/block/dataplane/virtio-blk.c +0 -6
index 79fb612..46a6824 100644
@@ -332,12 +332,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
       return;
   }
 
-    if (blk->config_wce) {
-        error_setg(errp, "device is incompatible with x-data-plane, "
-                         "use config-wce=off");
-        return;
-    }
-
   /* If dataplane is (re-)enabled while the guest is running there could be
    * block jobs that can conflict.
    */
hw/block/virtio-blk.c +0 -0
index 8a568e5..a031e56 100644

hw/block/virtio-blk.c line 29

Quoted 4 lines
hw/block/virtio-blk.c +1 -0
@@ -26,6 +26,7 @@
 # include <scsi/sg.h>
 #endif
 #include "hw/virtio/virtio-bus.h"
+#include "block/block_int.h"

You shouldn't need to include this header file. Apart from this, the patch looks good.

Quoted 3 lines
Quoted 1 line

It's for bdrv_get_aio_context, otherwise it doesn't compile.

I think it should be moved to block/block.h then. Stefan?

Agreed, I was just about to reply the same thing at the top level of the thread :).

block_int.h is for internal block layer functions that are used by the core or block drivers. Emulated devices must not use block_int.h (and we'll fix files that do).

Stefan